]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | This file is ANT task GenBuild. \r | |
3 | \r | |
4 | The file is used to parse a specified Module, and generate its build time \r | |
5 | ANT script build.xml, then call the the ANT script to build the module.\r | |
6 | \r | |
7 | Copyright (c) 2006, Intel Corporation\r | |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | **/\r | |
16 | package org.tianocore.build;\r | |
17 | \r | |
18 | import java.io.File;\r | |
19 | import java.util.Hashtable;\r | |
20 | import java.util.Iterator;\r | |
21 | import java.util.LinkedHashSet;\r | |
22 | import java.util.List;\r | |
23 | import java.util.Map;\r | |
24 | import java.util.Set;\r | |
25 | import java.util.Stack;\r | |
26 | import java.util.Vector;\r | |
27 | import java.util.regex.Matcher;\r | |
28 | import java.util.regex.Pattern;\r | |
29 | \r | |
30 | import org.apache.tools.ant.BuildException;\r | |
31 | import org.apache.tools.ant.taskdefs.Ant;\r | |
32 | import org.apache.tools.ant.taskdefs.Property;\r | |
33 | import org.apache.xmlbeans.XmlObject;\r | |
34 | \r | |
35 | import org.tianocore.build.autogen.AutoGen;\r | |
36 | import org.tianocore.build.fpd.FpdParserTask;\r | |
37 | import org.tianocore.build.global.GenBuildLogger;\r | |
38 | import org.tianocore.build.global.GlobalData;\r | |
39 | import org.tianocore.build.global.OutputManager;\r | |
40 | import org.tianocore.build.global.SurfaceAreaQuery;\r | |
41 | import org.tianocore.build.id.FpdModuleIdentification;\r | |
42 | import org.tianocore.build.id.ModuleIdentification;\r | |
43 | import org.tianocore.build.id.PackageIdentification;\r | |
44 | import org.tianocore.build.id.PlatformIdentification;\r | |
45 | import org.tianocore.build.tools.ModuleItem;\r | |
46 | import org.tianocore.exception.EdkException;\r | |
47 | import org.tianocore.logger.EdkLog;\r | |
48 | \r | |
49 | /**\r | |
50 | <p>\r | |
51 | <code>GenBuildTask</code> is an ANT task that can be used in ANT build\r | |
52 | system. The main function of this task is to parse module's surface area,\r | |
53 | then generate the corresponding <em>BaseName_build.xml</em> (the real ANT\r | |
54 | build script) and call this to build the module. The whole process including:\r | |
55 | 1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances; \r | |
56 | 3. build all source files inlcude AutoGen.c; 4. generate sections;\r | |
57 | 5. generate FFS file if it is driver module while LIB file if it is Library module. \r | |
58 | </p>\r | |
59 | \r | |
60 | <p>\r | |
61 | The usage is (take module <em>HelloWorld</em> for example):\r | |
62 | </p>\r | |
63 | \r | |
64 | <pre>\r | |
65 | <GenBuild \r | |
66 | msaFilename="HelloWorld.msa"/> \r | |
67 | processTo="ALL"/>\r | |
68 | </pre>\r | |
69 | \r | |
70 | <p><code>processTo</code> provides a way to customize the whole build process. \r | |
71 | processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE. \r | |
72 | Default is ALL, means whole \r | |
73 | </p>\r | |
74 | \r | |
75 | <p>\r | |
76 | This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and\r | |
77 | <em>AutoGen.h</em>. The task also parses the development environment\r | |
78 | configuration files, such as collecting package information, setting compiler\r | |
79 | flags and so on.\r | |
80 | </p>\r | |
81 | \r | |
82 | \r | |
83 | @since GenBuild 1.0\r | |
84 | **/\r | |
85 | public class GenBuildTask extends Ant {\r | |
86 | \r | |
87 | ///\r | |
88 | /// Module surface area file.\r | |
89 | ///\r | |
90 | File msaFile;\r | |
91 | \r | |
92 | ///\r | |
93 | /// \r | |
94 | ///\r | |
95 | private String type = "all"; // = "build";\r | |
96 | \r | |
97 | ///\r | |
98 | /// Module's Identification.\r | |
99 | ///\r | |
100 | private ModuleIdentification moduleId;\r | |
101 | \r | |
102 | private Vector<Property> properties = new Vector<Property>();\r | |
103 | \r | |
104 | private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();\r | |
105 | \r | |
106 | \r | |
107 | private static Hashtable backupProperties;\r | |
108 | \r | |
109 | /**\r | |
110 | Public construct method. It is necessary for ANT task.\r | |
111 | **/\r | |
112 | public GenBuildTask() {\r | |
113 | }\r | |
114 | \r | |
115 | /**\r | |
116 | \r | |
117 | @throws BuildException\r | |
118 | From module build, exception from module surface area invalid.\r | |
119 | **/\r | |
120 | public void execute() throws BuildException {\r | |
121 | //\r | |
122 | // set Logger\r | |
123 | //\r | |
124 | GenBuildLogger logger = new GenBuildLogger(getProject());\r | |
125 | EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));\r | |
126 | EdkLog.setLogger(logger);\r | |
127 | // remove !!\r | |
128 | try {\r | |
129 | pushProperties();\r | |
130 | //\r | |
131 | // Enable all specified properties\r | |
132 | //\r | |
133 | Iterator<Property> iter = properties.iterator();\r | |
134 | while (iter.hasNext()) {\r | |
135 | Property item = iter.next();\r | |
136 | getProject().setProperty(item.getName(), item.getValue());\r | |
137 | }\r | |
138 | \r | |
139 | //\r | |
140 | // GenBuild should specify either msaFile or moduleGuid & packageGuid\r | |
141 | //\r | |
142 | if (msaFile == null ) {\r | |
143 | String moduleGuid = getProject().getProperty("MODULE_GUID");\r | |
144 | String moduleVersion = getProject().getProperty("MODULE_VERSION");\r | |
145 | String packageGuid = getProject().getProperty("PACKAGE_GUID");\r | |
146 | String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r | |
147 | if (moduleGuid == null || packageGuid == null) {\r | |
148 | throw new BuildException("GenBuild parameters error. ");\r | |
149 | }\r | |
150 | PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r | |
151 | moduleId = new ModuleIdentification(moduleGuid, moduleVersion);\r | |
152 | moduleId.setPackage(packageId);\r | |
153 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);\r | |
154 | SurfaceAreaQuery.setDoc(doc);\r | |
155 | moduleId = SurfaceAreaQuery.getMsaHeader();\r | |
156 | }\r | |
157 | else {\r | |
158 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r | |
159 | SurfaceAreaQuery.setDoc(doc);\r | |
160 | moduleId = SurfaceAreaQuery.getMsaHeader();\r | |
161 | }\r | |
162 | String[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED");\r | |
163 | if (producedLibraryClasses.length == 0) {\r | |
164 | moduleId.setLibrary(false);\r | |
165 | }\r | |
166 | else {\r | |
167 | moduleId.setLibrary(true);\r | |
168 | }\r | |
169 | \r | |
170 | //\r | |
171 | // Judge whether it is single module build or not\r | |
172 | //\r | |
173 | if (getProject().getProperty("PLATFORM") == null) {\r | |
174 | //\r | |
175 | // Single Module build\r | |
176 | //\r | |
177 | prepareSingleModuleBuild();\r | |
178 | }\r | |
179 | else {\r | |
180 | //\r | |
181 | // Platform build. Restore the platform related info\r | |
182 | //\r | |
183 | String platformName = getProject().getProperty("PLATFORM");\r | |
184 | PlatformIdentification platformId = GlobalData.getPlatform(platformName);\r | |
185 | getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r | |
186 | getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r | |
187 | \r | |
188 | String packageGuid = getProject().getProperty("PACKAGE_GUID");\r | |
189 | String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r | |
190 | PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r | |
191 | moduleId.setPackage(packageId);\r | |
192 | }\r | |
193 | \r | |
194 | //\r | |
195 | // If single module : intersection MSA supported ARCHs and tools def!!\r | |
196 | // else, get arch from pass down\r | |
197 | //\r | |
198 | String[] archList = new String[0];\r | |
199 | if ( getProject().getProperty("ARCH") != null ) {\r | |
200 | archList = getProject().getProperty("ARCH").split(" ");\r | |
201 | }\r | |
202 | else {\r | |
203 | archList = GlobalData.getToolChainInfo().getArchs();\r | |
204 | }\r | |
205 | \r | |
206 | \r | |
207 | //\r | |
208 | // Judge if arch is all supported by current module. If not, throw Exception.\r | |
209 | //\r | |
210 | List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs();\r | |
211 | if (moduleSupportedArchs != null) {\r | |
212 | for (int k = 0; k < archList.length; k++) {\r | |
213 | if ( ! moduleSupportedArchs.contains(archList[k])) {\r | |
214 | throw new BuildException("ARCH [" + archList[k] + "] is not supported by " + moduleId + ". " + moduleId + " only supports [" + moduleSupportedArchs + "].");\r | |
215 | }\r | |
216 | }\r | |
217 | }\r | |
218 | \r | |
219 | for (int k = 0; k < archList.length; k++) {\r | |
220 | getProject().setProperty("ARCH", archList[k]);\r | |
221 | \r | |
222 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);\r | |
223 | \r | |
224 | //\r | |
225 | // Whether the module is built before\r | |
226 | //\r | |
227 | if (GlobalData.isModuleBuilt(fpdModuleId)) {\r | |
228 | return ;\r | |
229 | }\r | |
230 | else {\r | |
231 | GlobalData.registerBuiltModule(fpdModuleId);\r | |
232 | }\r | |
233 | \r | |
234 | //\r | |
235 | // For Every TOOLCHAIN, TARGET\r | |
236 | //\r | |
237 | String[] targetList = GlobalData.getToolChainInfo().getTargets();\r | |
238 | for (int i = 0; i < targetList.length; i ++){\r | |
239 | //\r | |
240 | // Prepare for target related common properties\r | |
241 | // TARGET\r | |
242 | //\r | |
243 | getProject().setProperty("TARGET", targetList[i]);\r | |
244 | String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r | |
245 | for(int j = 0; j < toolchainList.length; j ++){\r | |
246 | //\r | |
247 | // Prepare for toolchain related common properties\r | |
248 | // TOOLCHAIN\r | |
249 | //\r | |
250 | getProject().setProperty("TOOLCHAIN", toolchainList[j]);\r | |
251 | \r | |
252 | System.out.println("Build " + moduleId + " start >>>");\r | |
253 | System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);\r | |
254 | SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));\r | |
255 | \r | |
256 | //\r | |
257 | // Prepare for all other common properties\r | |
258 | // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r | |
259 | // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r | |
260 | // MODULE_DIR, MODULE_RELATIVE_DIR\r | |
261 | // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH\r | |
262 | // LIBS, OBJECTS, SDB_FILES\r | |
263 | //\r | |
264 | setModuleCommonProperties(archList[k]);\r | |
265 | \r | |
266 | //\r | |
267 | // OutputManage prepare for \r | |
268 | // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR\r | |
269 | //\r | |
270 | OutputManager.getInstance().update(getProject());\r | |
271 | \r | |
272 | if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {\r | |
273 | applyBuild(targetList[i], toolchainList[j], fpdModuleId);\r | |
274 | }\r | |
275 | else if (type.equalsIgnoreCase("clean")) {\r | |
276 | applyClean(fpdModuleId);\r | |
277 | }\r | |
278 | else if (type.equalsIgnoreCase("cleanall")) {\r | |
279 | applyCleanall(fpdModuleId);\r | |
280 | }\r | |
281 | }\r | |
282 | }\r | |
283 | }\r | |
284 | popProperties();\r | |
285 | }catch (Exception e){\r | |
286 | e.printStackTrace();\r | |
287 | throw new BuildException(e.getMessage());\r | |
288 | }\r | |
289 | }\r | |
290 | \r | |
291 | /**\r | |
292 | This method is used to prepare Platform-related information. \r | |
293 | \r | |
294 | <p>In Single Module Build mode, platform-related information is not ready.\r | |
295 | The method read the system environment variable <code>ACTIVE_PLATFORM</code> \r | |
296 | and search in the Framework Database. Note that platform name in the Framework\r | |
297 | Database must be unique. </p>\r | |
298 | \r | |
299 | **/\r | |
300 | private void prepareSingleModuleBuild(){\r | |
301 | //\r | |
302 | // Find out the package which the module belongs to\r | |
303 | // TBD: Enhance it!!!!\r | |
304 | //\r | |
305 | PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);\r | |
306 | \r | |
307 | moduleId.setPackage(packageId);\r | |
308 | \r | |
309 | //\r | |
310 | // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r | |
311 | //\r | |
312 | String activePlatformName = getProject().getProperty("ACTIVE_PLATFORM");\r | |
313 | \r | |
314 | if (activePlatformName == null){\r | |
315 | throw new BuildException("Plese set ACTIVE_PLATFORM if you want to build a single module. ");\r | |
316 | }\r | |
317 | \r | |
318 | PlatformIdentification platformId = GlobalData.getPlatform(activePlatformName);\r | |
319 | \r | |
320 | //\r | |
321 | // Read FPD file\r | |
322 | //\r | |
323 | FpdParserTask fpdParser = new FpdParserTask();\r | |
324 | fpdParser.setProject(getProject());\r | |
325 | fpdParser.parseFpdFile(platformId.getFpdFile());\r | |
326 | \r | |
327 | //\r | |
328 | // Prepare for Platform related common properties\r | |
329 | // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r | |
330 | //\r | |
331 | getProject().setProperty("PLATFORM", activePlatformName);\r | |
332 | getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r | |
333 | getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r | |
334 | }\r | |
335 | \r | |
336 | \r | |
337 | /**\r | |
338 | Set Module-Related information to properties.\r | |
339 | **/\r | |
340 | private void setModuleCommonProperties(String arch) {\r | |
341 | //\r | |
342 | // Prepare for all other common properties\r | |
343 | // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r | |
344 | //\r | |
345 | PackageIdentification packageId = moduleId.getPackage();\r | |
346 | getProject().setProperty("PACKAGE", packageId.getName());\r | |
347 | getProject().setProperty("PACKAGE_GUID", packageId.getGuid());\r | |
348 | getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());\r | |
349 | getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r | |
350 | getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r | |
351 | \r | |
352 | //\r | |
353 | // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r | |
354 | // MODULE_DIR, MODULE_RELATIVE_DIR\r | |
355 | //\r | |
356 | getProject().setProperty("MODULE", moduleId.getName());\r | |
357 | String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r | |
358 | if (baseName == null) {\r | |
359 | getProject().setProperty("BASE_NAME", moduleId.getName());\r | |
360 | }\r | |
361 | else {\r | |
362 | getProject().setProperty("BASE_NAME", baseName);\r | |
363 | }\r | |
364 | getProject().setProperty("GUID", moduleId.getGuid());\r | |
365 | getProject().setProperty("FILE_GUID", moduleId.getGuid());\r | |
366 | getProject().setProperty("VERSION", moduleId.getVersion());\r | |
367 | getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());\r | |
368 | getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));\r | |
369 | getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));\r | |
370 | \r | |
371 | //\r | |
372 | // SUBSYSTEM\r | |
373 | //\r | |
374 | String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},\r | |
375 | { "SEC", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
376 | { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
377 | { "PEIM", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
378 | { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r | |
379 | { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
380 | { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" }, \r | |
381 | { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
382 | { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
383 | { "TOOL", "EFI_BOOT_SERVICE_DRIVER" }, \r | |
384 | { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r | |
385 | { "UEFI_APPLICATION", "EFI_APPLICATION" }, \r | |
386 | { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} }; \r | |
387 | \r | |
388 | String subsystem = "EFI_BOOT_SERVICE_DRIVER";\r | |
389 | for (int i = 0; i < subsystemMap.length; i++) {\r | |
390 | if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {\r | |
391 | subsystem = subsystemMap[i][1];\r | |
392 | break ;\r | |
393 | }\r | |
394 | }\r | |
395 | getProject().setProperty("SUBSYSTEM", subsystem);\r | |
396 | \r | |
397 | //\r | |
398 | // ENTRYPOINT\r | |
399 | //\r | |
400 | if (arch.equalsIgnoreCase("EBC")) {\r | |
401 | getProject().setProperty("ENTRYPOINT", "EfiStart");\r | |
402 | }\r | |
403 | else {\r | |
404 | getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");\r | |
405 | }\r | |
406 | \r | |
407 | //\r | |
408 | // LIBS, OBJECTS, SDB_FILES\r | |
409 | //\r | |
410 | getProject().setProperty("OBJECTS", "");\r | |
411 | getProject().setProperty("SDB_FILES", "");\r | |
412 | getProject().setProperty("LIBS", "");\r | |
413 | }\r | |
414 | \r | |
415 | private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {\r | |
416 | String[] cmd = GlobalData.getToolChainInfo().getCommands();\r | |
417 | for ( int m = 0; m < cmd.length; m++) {\r | |
418 | //\r | |
419 | // Set cmd, like CC, DLINK\r | |
420 | //\r | |
421 | String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};\r | |
422 | key[4] = "PATH";\r | |
423 | String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
424 | key[4] = "NAME";\r | |
425 | String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
426 | File cmdFile = new File(cmdPath + File.separatorChar + cmdName);\r | |
427 | // GlobalData.log.info("PATH: " + cmdFile.getPath());\r | |
428 | getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));\r | |
429 | \r | |
430 | //\r | |
431 | // set CC_FLAGS\r | |
432 | //\r | |
433 | key[4] = "FLAGS";\r | |
434 | String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
435 | // GlobalData.log.info("Flags: " + cmdFlags);\r | |
436 | Set<String> addset = new LinkedHashSet<String>();\r | |
437 | Set<String> subset = new LinkedHashSet<String>();\r | |
438 | putFlagsToSet(addset, cmdFlags);\r | |
439 | getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));\r | |
440 | \r | |
441 | //\r | |
442 | // Set CC_EXT\r | |
443 | //\r | |
444 | key[4] = "EXT";\r | |
445 | String extName = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
446 | // GlobalData.log.info("Ext: " + extName);\r | |
447 | if ( extName != null && ! extName.equalsIgnoreCase("")) {\r | |
448 | getProject().setProperty(cmd[m] + "_EXT", extName);\r | |
449 | }\r | |
450 | else {\r | |
451 | getProject().setProperty(cmd[m] + "_EXT", "");\r | |
452 | }\r | |
453 | \r | |
454 | //\r | |
455 | // set CC_FAMILY\r | |
456 | //\r | |
457 | key[4] = "FAMILY";\r | |
458 | String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
459 | // GlobalData.log.info("FAMILY: " + toolChainFamily);\r | |
460 | if (toolChainFamily != null) {\r | |
461 | getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);\r | |
462 | }\r | |
463 | \r | |
464 | //\r | |
465 | // set CC_SPATH\r | |
466 | //\r | |
467 | key[4] = "SPATH";\r | |
468 | String spath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
469 | // GlobalData.log.info("SPATH: " + spath);\r | |
470 | if (spath != null) {\r | |
471 | getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));\r | |
472 | }\r | |
473 | else {\r | |
474 | getProject().setProperty(cmd[m] + "_SPATH", "");\r | |
475 | }\r | |
476 | \r | |
477 | //\r | |
478 | // set CC_DPATH\r | |
479 | //\r | |
480 | key[4] = "DPATH";\r | |
481 | String dpath = GlobalData.getCommandSetting(key, fpdModuleId);\r | |
482 | // GlobalData.log.info("DPATH: " + dpath);\r | |
483 | if (dpath != null) {\r | |
484 | getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));\r | |
485 | }\r | |
486 | else {\r | |
487 | getProject().setProperty(cmd[m] + "_DPATH", "");\r | |
488 | }\r | |
489 | }\r | |
490 | }\r | |
491 | \r | |
492 | public void setMsaFile(File msaFile) {\r | |
493 | this.msaFile = msaFile;\r | |
494 | }\r | |
495 | \r | |
496 | /**\r | |
497 | Method is for ANT to initialize MSA file. \r | |
498 | \r | |
499 | @param msaFilename MSA file name\r | |
500 | **/\r | |
501 | public void setMsaFile(String msaFilename) {\r | |
502 | String moduleDir = getProject().getProperty("MODULE_DIR");\r | |
503 | \r | |
504 | //\r | |
505 | // If is Single Module Build, then use the Base Dir defined in build.xml\r | |
506 | //\r | |
507 | if (moduleDir == null) {\r | |
508 | moduleDir = getProject().getBaseDir().getPath();\r | |
509 | }\r | |
510 | msaFile = new File(moduleDir + File.separatorChar + msaFilename);\r | |
511 | }\r | |
512 | \r | |
513 | public void addConfiguredModuleItem(ModuleItem moduleItem) {\r | |
514 | PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());\r | |
515 | ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());\r | |
516 | moduleId.setPackage(packageId);\r | |
517 | this.moduleId = moduleId;\r | |
518 | }\r | |
519 | \r | |
520 | /**\r | |
521 | Add a property. \r | |
522 | \r | |
523 | @param p property\r | |
524 | **/\r | |
525 | public void addProperty(Property p) {\r | |
526 | properties.addElement(p);\r | |
527 | }\r | |
528 | \r | |
529 | public void setType(String type) {\r | |
530 | this.type = type;\r | |
531 | }\r | |
532 | \r | |
533 | private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException{\r | |
534 | //\r | |
535 | // AutoGen\r | |
536 | //\r | |
537 | \r | |
538 | AutoGen autogen = new AutoGen(getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());\r | |
539 | autogen.genAutogen();\r | |
540 | \r | |
541 | \r | |
542 | //\r | |
543 | // Get compiler flags\r | |
544 | //\r | |
545 | getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r | |
546 | \r | |
547 | //\r | |
548 | // Prepare LIBS\r | |
549 | //\r | |
550 | ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r | |
551 | String propertyLibs = "";\r | |
552 | for (int i = 0; i < libinstances.length; i++) {\r | |
553 | propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";\r | |
554 | }\r | |
555 | getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r | |
556 | \r | |
557 | //\r | |
558 | // if it is CUSTOM_BUILD\r | |
559 | // then call the exist BaseName_build.xml directly.\r | |
560 | //\r | |
561 | if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r | |
562 | GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r | |
563 | Ant ant = new Ant();\r | |
564 | ant.setProject(getProject());\r | |
565 | ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
566 | ant.setInheritAll(true);\r | |
567 | ant.init();\r | |
568 | ant.execute();\r | |
569 | return ;\r | |
570 | }\r | |
571 | \r | |
572 | //\r | |
573 | // Generate ${BASE_NAME}_build.xml\r | |
574 | // TBD\r | |
575 | //\r | |
576 | String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword();\r | |
577 | ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId);\r | |
578 | String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r | |
579 | fileGenerator.genBuildFile(buildFilename);\r | |
580 | \r | |
581 | //\r | |
582 | // Ant call ${BASE_NAME}_build.xml\r | |
583 | //\r | |
584 | Ant ant = new Ant();\r | |
585 | ant.setProject(getProject());\r | |
586 | ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
587 | ant.setInheritAll(true);\r | |
588 | ant.init();\r | |
589 | ant.execute();\r | |
590 | }\r | |
591 | \r | |
592 | private void applyClean(FpdModuleIdentification fpdModuleId){\r | |
593 | //\r | |
594 | // if it is CUSTOM_BUILD\r | |
595 | // then call the exist BaseName_build.xml directly.\r | |
596 | //\r | |
597 | if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r | |
598 | GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r | |
599 | Ant ant = new Ant();\r | |
600 | ant.setProject(getProject());\r | |
601 | ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
602 | ant.setTarget("clean");\r | |
603 | ant.setInheritAll(true);\r | |
604 | ant.init();\r | |
605 | ant.execute();\r | |
606 | return ;\r | |
607 | }\r | |
608 | \r | |
609 | Ant ant = new Ant();\r | |
610 | ant.setProject(getProject());\r | |
611 | ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
612 | ant.setTarget("clean");\r | |
613 | ant.setInheritAll(true);\r | |
614 | ant.init();\r | |
615 | ant.execute();\r | |
616 | \r | |
617 | //\r | |
618 | // Delete current module's DEST_DIR_OUTPUT\r | |
619 | // TBD\r | |
620 | }\r | |
621 | \r | |
622 | private void applyCleanall(FpdModuleIdentification fpdModuleId){\r | |
623 | //\r | |
624 | // if it is CUSTOM_BUILD\r | |
625 | // then call the exist BaseName_build.xml directly.\r | |
626 | //\r | |
627 | if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r | |
628 | GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r | |
629 | Ant ant = new Ant();\r | |
630 | ant.setProject(getProject());\r | |
631 | ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
632 | ant.setTarget("cleanall");\r | |
633 | ant.setInheritAll(true);\r | |
634 | ant.init();\r | |
635 | ant.execute();\r | |
636 | return ;\r | |
637 | }\r | |
638 | \r | |
639 | Ant ant = new Ant();\r | |
640 | ant.setProject(getProject());\r | |
641 | ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r | |
642 | ant.setTarget("cleanall");\r | |
643 | ant.setInheritAll(true);\r | |
644 | ant.init();\r | |
645 | ant.execute();\r | |
646 | \r | |
647 | //\r | |
648 | // Delete current module's DEST_DIR_OUTPUT\r | |
649 | // TBD\r | |
650 | }\r | |
651 | \r | |
652 | \r | |
653 | \r | |
654 | \r | |
655 | /**\r | |
656 | Separate the string and instore in set.\r | |
657 | \r | |
658 | <p> String is separated by Java Regulation Expression \r | |
659 | "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>\r | |
660 | \r | |
661 | <p>For example: </p>\r | |
662 | \r | |
663 | <pre>\r | |
664 | "/nologo", "/W3", "/WX"\r | |
665 | "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""\r | |
666 | </pre>\r | |
667 | \r | |
668 | @param set store the separated string\r | |
669 | @param str string to separate\r | |
670 | **/\r | |
671 | private void putFlagsToSet(Set<String> set, String str) {\r | |
672 | if (str == null || str.length() == 0) {\r | |
673 | return;\r | |
674 | }\r | |
675 | \r | |
676 | Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");\r | |
677 | Matcher matcher = myPattern.matcher(str + " ");\r | |
678 | while (matcher.find()) {\r | |
679 | String item = str.substring(matcher.start(1), matcher.end(1));\r | |
680 | set.add(item);\r | |
681 | }\r | |
682 | }\r | |
683 | \r | |
684 | /**\r | |
685 | Generate the final flags string will be used by compile command. \r | |
686 | \r | |
687 | @param add the add flags set\r | |
688 | @param sub the sub flags set\r | |
689 | @return final flags after add set substract sub set\r | |
690 | **/\r | |
691 | private String getFlags(Set<String> add, Set<String> sub) {\r | |
692 | String result = "";\r | |
693 | add.removeAll(sub);\r | |
694 | Iterator iter = add.iterator();\r | |
695 | while (iter.hasNext()) {\r | |
696 | String str = (String) iter.next();\r | |
697 | result += str.substring(1, str.length() - 1) + " ";\r | |
698 | }\r | |
699 | return result;\r | |
700 | }\r | |
701 | \r | |
702 | /**\r | |
703 | Generate the flags string with original format. The format is defined by \r | |
704 | Java Regulation Expression "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>\r | |
705 | \r | |
706 | <p>For example: </p>\r | |
707 | \r | |
708 | <pre>\r | |
709 | "/nologo", "/W3", "/WX"\r | |
710 | "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""\r | |
711 | </pre>\r | |
712 | \r | |
713 | @param add the add flags set\r | |
714 | @param sub the sub flags set\r | |
715 | @return flags with original format\r | |
716 | **/\r | |
717 | private String getRawFlags(Set<String> add, Set<String> sub) {\r | |
718 | String result = null;\r | |
719 | add.removeAll(sub);\r | |
720 | Iterator iter = add.iterator();\r | |
721 | while (iter.hasNext()) {\r | |
722 | String str = (String) iter.next();\r | |
723 | result += "\"" + str.substring(1, str.length() - 1) + "\", ";\r | |
724 | }\r | |
725 | return result;\r | |
726 | }\r | |
727 | \r | |
728 | private String parseOptionString(String optionString, Set<String> addSet, Set<String> subSet) {\r | |
729 | boolean overrideOption = false;\r | |
730 | Pattern pattern = Pattern.compile("ADD\\.\\[(.+)\\]");\r | |
731 | Matcher matcher = pattern.matcher(optionString);\r | |
732 | \r | |
733 | while (matcher.find()) {\r | |
734 | overrideOption = true;\r | |
735 | String addOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();\r | |
736 | putFlagsToSet(addSet, addOption);\r | |
737 | \r | |
738 | }\r | |
739 | \r | |
740 | pattern = Pattern.compile("SUB\\.\\[(.+)\\]");\r | |
741 | matcher = pattern.matcher(optionString);\r | |
742 | \r | |
743 | while (matcher.find()) {\r | |
744 | overrideOption = true;\r | |
745 | String subOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();\r | |
746 | putFlagsToSet(subSet, subOption);\r | |
747 | }\r | |
748 | \r | |
749 | if (overrideOption == true) {\r | |
750 | return null;\r | |
751 | }\r | |
752 | \r | |
753 | return optionString;\r | |
754 | }\r | |
755 | \r | |
756 | private void pushProperties() {\r | |
757 | backupPropertiesStack.push(getProject().getProperties());\r | |
758 | }\r | |
759 | \r | |
760 | private void popProperties() {\r | |
761 | Hashtable backupProperties = backupPropertiesStack.pop();\r | |
762 | Set keys = backupProperties.keySet();\r | |
763 | Iterator iter = keys.iterator();\r | |
764 | while (iter.hasNext()) {\r | |
765 | String item = (String)iter.next();\r | |
766 | getProject().setProperty(item, (String)backupProperties.get(item));\r | |
767 | }\r | |
768 | }\r | |
769 | }\r |