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