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