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