Fixed EDKT484 and rewrite the output message when no arch is found.
[mirror_edk2.git] / Tools / Java / 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
aca6c736 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
25import java.util.Vector;\r
878ddf1f 26\r
878ddf1f 27import org.apache.tools.ant.BuildException;\r
aca6c736 28import org.apache.tools.ant.BuildListener;\r
29import org.apache.tools.ant.Project;\r
878ddf1f 30import org.apache.tools.ant.taskdefs.Ant;\r
a29c47e0 31import org.apache.tools.ant.taskdefs.Property;\r
878ddf1f 32import org.apache.xmlbeans.XmlObject;\r
878ddf1f 33\r
4a6a5026 34import org.tianocore.common.definitions.ToolDefinitions;\r
ff225cbb 35import org.tianocore.common.exception.EdkException;\r
d965d1f6 36import org.tianocore.common.logger.EdkLog;\r
136adffc 37import org.tianocore.build.autogen.AutoGen;\r
892b0e7a 38import org.tianocore.build.exception.AutoGenException;\r
39import org.tianocore.build.exception.GenBuildException;\r
40import org.tianocore.build.exception.PcdAutogenException;\r
41import org.tianocore.build.exception.PlatformPcdPreprocessBuildException;\r
878ddf1f 42import org.tianocore.build.fpd.FpdParserTask;\r
43import org.tianocore.build.global.GlobalData;\r
44import org.tianocore.build.global.OutputManager;\r
45import org.tianocore.build.global.SurfaceAreaQuery;\r
a29c47e0 46import org.tianocore.build.id.FpdModuleIdentification;\r
47import org.tianocore.build.id.ModuleIdentification;\r
48import org.tianocore.build.id.PackageIdentification;\r
49import org.tianocore.build.id.PlatformIdentification;\r
50import org.tianocore.build.tools.ModuleItem;\r
878ddf1f 51\r
52/**\r
53 <p>\r
54 <code>GenBuildTask</code> is an ANT task that can be used in ANT build\r
4a6a5026 55 system. \r
56 \r
57 <p>The main function of this task is to parse module's surface area (MSA),\r
878ddf1f 58 then generate the corresponding <em>BaseName_build.xml</em> (the real ANT\r
a29c47e0 59 build script) and call this to build the module. The whole process including:\r
4b5f5549 60 \r
2d16dcec 61 <pre>\r
4a6a5026 62 1. generate AutoGen.c and AutoGen.h; \r
63 2. build all dependent library instances;\r
64 3. build all source files inlcude AutoGen.c; \r
65 4. generate sections;\r
ff225cbb 66 5. generate FFS file if it is driver module while LIB file if it is Library module.\r
2d16dcec 67 </pre>\r
68\r
ff225cbb 69\r
878ddf1f 70 <p>\r
71 The usage is (take module <em>HelloWorld</em> for example):\r
72 </p>\r
ff225cbb 73\r
878ddf1f 74 <pre>\r
4b5f5549 75 &lt;GenBuild \r
76 msaFile="${PACKAGE_DIR}/Application/HelloWorld/HelloWorld.msa"\r
77 type="cleanall" /&gt;\r
878ddf1f 78 </pre>\r
ff225cbb 79\r
878ddf1f 80 <p>\r
81 This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and\r
4b5f5549 82 <em>AutoGen.h</em>. \r
878ddf1f 83 </p>\r
ff225cbb 84\r
4b5f5549 85 <p>\r
86 This task will also set properties for current module, such as PACKAGE, \r
87 PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR \r
88 (relative to Workspace), MODULE or BASE_NAME, GUID, VERSION, MODULE_DIR, \r
89 MODULE_RELATIVE_DIR (relative to Package), CONFIG_DIR, BIN_DIR, \r
90 DEST_DIR_DEBUG, DEST_DIR_OUTPUT, TARGET, ARCH, TOOLCHAIN, TOOLCHAIN_FAMILY, \r
91 SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH, all compiler command related \r
92 properties (CC, CC_FLAGS, CC_DPATH, CC_SPATH, CC_FAMILY, CC_EXT). \r
93 </p>\r
94 \r
878ddf1f 95 @since GenBuild 1.0\r
96**/\r
a29c47e0 97public class GenBuildTask extends Ant {\r
ff225cbb 98\r
878ddf1f 99 ///\r
100 /// Module surface area file.\r
101 ///\r
a29c47e0 102 File msaFile;\r
19bf6b15 103 \r
104 public ModuleIdentification parentId;\r
105 \r
82516887 106 private String type = "all"; \r
107 \r
878ddf1f 108 ///\r
a29c47e0 109 /// Module's Identification.\r
878ddf1f 110 ///\r
a29c47e0 111 private ModuleIdentification moduleId;\r
878ddf1f 112\r
a29c47e0 113 private Vector<Property> properties = new Vector<Property>();\r
de4bb9f6 114\r
de4bb9f6 115 private boolean isSingleModuleBuild = false;\r
83fba802 116 \r
117 private SurfaceAreaQuery saq = null;\r
ff225cbb 118\r
878ddf1f 119 /**\r
120 Public construct method. It is necessary for ANT task.\r
121 **/\r
122 public GenBuildTask() {\r
123 }\r
124\r
125 /**\r
ff225cbb 126\r
878ddf1f 127 @throws BuildException\r
128 From module build, exception from module surface area invalid.\r
129 **/\r
130 public void execute() throws BuildException {\r
89e1408f 131 this.setTaskName("GenBuild");\r
892b0e7a 132 try {\r
133 processGenBuild();\r
134 } catch (PcdAutogenException e) {\r
47412835 135 BuildException buildException = new BuildException(e.getMessage());\r
136 buildException.setStackTrace(e.getStackTrace());\r
137 throw buildException;\r
892b0e7a 138 } catch (AutoGenException e) {\r
47412835 139 BuildException buildException = new BuildException(e.getMessage());\r
140 buildException.setStackTrace(e.getStackTrace());\r
141 throw buildException;\r
892b0e7a 142 } catch (PlatformPcdPreprocessBuildException e) {\r
47412835 143 BuildException buildException = new BuildException(e.getMessage());\r
144 buildException.setStackTrace(e.getStackTrace());\r
145 throw buildException;\r
892b0e7a 146 } catch (GenBuildException e) {\r
47412835 147 BuildException buildException = new BuildException(e.getMessage());\r
148 buildException.setStackTrace(e.getStackTrace());\r
149 throw buildException;\r
892b0e7a 150 } catch (EdkException e) {\r
47412835 151 BuildException buildException = new BuildException(e.getMessage());\r
152 buildException.setStackTrace(e.getStackTrace());\r
153 throw buildException;\r
892b0e7a 154 }\r
155 }\r
156\r
157 private void processGenBuild() throws EdkException, BuildException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException {\r
aca6c736 158 if (!FrameworkBuildTask.multithread) {\r
159 cleanupProperties();\r
160 }\r
82516887 161\r
878ddf1f 162 //\r
a29c47e0 163 // Enable all specified properties\r
878ddf1f 164 //\r
a29c47e0 165 Iterator<Property> iter = properties.iterator();\r
166 while (iter.hasNext()) {\r
167 Property item = iter.next();\r
aca6c736 168 getProject().setProperty(item.getName(), item.getValue());\r
878ddf1f 169 }\r
ff225cbb 170\r
878ddf1f 171 //\r
a29c47e0 172 // GenBuild should specify either msaFile or moduleGuid & packageGuid\r
878ddf1f 173 //\r
a29c47e0 174 if (msaFile == null ) {\r
175 String moduleGuid = getProject().getProperty("MODULE_GUID");\r
176 String moduleVersion = getProject().getProperty("MODULE_VERSION");\r
177 String packageGuid = getProject().getProperty("PACKAGE_GUID");\r
178 String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r
892b0e7a 179 //\r
180 // If one of module Guid or package Guid is not specified, report error\r
181 //\r
a29c47e0 182 if (moduleGuid == null || packageGuid == null) {\r
391dbbb1 183 throw new BuildException("GenBuild parameter error.");\r
878ddf1f 184 }\r
892b0e7a 185 \r
a29c47e0 186 PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r
892b0e7a 187 GlobalData.refreshPackageIdentification(packageId);\r
a29c47e0 188 moduleId = new ModuleIdentification(moduleGuid, moduleVersion);\r
189 moduleId.setPackage(packageId);\r
892b0e7a 190 GlobalData.refreshModuleIdentification(moduleId);\r
a29c47e0 191 Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);\r
83fba802 192 saq = new SurfaceAreaQuery(doc);\r
82516887 193 } else {\r
a29c47e0 194 Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r
83fba802 195 saq = new SurfaceAreaQuery(doc);\r
196 moduleId = saq.getMsaHeader();\r
89e1408f 197 moduleId.setMsaFile(msaFile);\r
878ddf1f 198 }\r
892b0e7a 199 \r
83fba802 200 String[] producedLibraryClasses = saq.getLibraryClasses("ALWAYS_PRODUCED",null);\r
a29c47e0 201 if (producedLibraryClasses.length == 0) {\r
202 moduleId.setLibrary(false);\r
82516887 203 } else {\r
a29c47e0 204 moduleId.setLibrary(true);\r
878ddf1f 205 }\r
ff225cbb 206\r
878ddf1f 207 //\r
a29c47e0 208 // Judge whether it is single module build or not\r
878ddf1f 209 //\r
de4bb9f6 210 if (isSingleModuleBuild) {\r
878ddf1f 211 //\r
a29c47e0 212 // Single Module build\r
878ddf1f 213 //\r
a29c47e0 214 prepareSingleModuleBuild();\r
878ddf1f 215 }\r
ff225cbb 216\r
a29c47e0 217 //\r
82516887 218 // If single module : get arch from pass down, otherwise intersection MSA \r
219 // supported ARCHs and tools def\r
a29c47e0 220 //\r
ff225cbb 221 Set<String> archListSupByToolChain = new LinkedHashSet<String>();\r
222 String[] archs = GlobalData.getToolChainInfo().getArchs();\r
223\r
3c696250 224 for (int i = 0; i < archs.length; i ++) {\r
225 archListSupByToolChain.add(archs[i]);\r
226 }\r
ff225cbb 227\r
3c696250 228 Set<String> archSet = new LinkedHashSet<String>();\r
bc022470 229 String archString = getProject().getProperty("ARCH");\r
230 if (archString != null) {\r
231 String[] fpdArchList = archString.split(" ");\r
ff225cbb 232\r
3c696250 233 for (int i = 0; i < fpdArchList.length; i++) {\r
234 if (archListSupByToolChain.contains(fpdArchList[i])) {\r
235 archSet.add(fpdArchList[i]);\r
236 }\r
237 }\r
82516887 238 } else {\r
239 archSet = archListSupByToolChain; \r
3c696250 240 }\r
ff225cbb 241\r
3c696250 242 String[] archList = archSet.toArray(new String[archSet.size()]);\r
ff225cbb 243\r
a29c47e0 244 //\r
245 // Judge if arch is all supported by current module. If not, throw Exception.\r
246 //\r
83fba802 247 List moduleSupportedArchs = saq.getModuleSupportedArchs();\r
a29c47e0 248 if (moduleSupportedArchs != null) {\r
249 for (int k = 0; k < archList.length; k++) {\r
250 if ( ! moduleSupportedArchs.contains(archList[k])) {\r
391dbbb1 251 throw new BuildException("Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures.");\r
a29c47e0 252 }\r
253 }\r
878ddf1f 254 }\r
ff225cbb 255\r
c340a28e 256 if (archList.length == 0) {\r
bc022470 257 EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: " + "[" + archString + "] is not supported for " + moduleId + " in this build!\n");\r
c340a28e 258 }\r
259\r
a29c47e0 260 for (int k = 0; k < archList.length; k++) {\r
ff225cbb 261\r
aca6c736 262 getProject().setProperty("ARCH", archList[k]);\r
ff225cbb 263\r
a29c47e0 264 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);\r
ff225cbb 265\r
878ddf1f 266 //\r
a29c47e0 267 // Whether the module is built before\r
878ddf1f 268 //\r
34281092 269 if (moduleId.isLibrary() == false && GlobalData.hasFpdModuleSA(fpdModuleId) == false) {\r
d965d1f6 270 EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");\r
34281092 271 continue;\r
272 } else if (GlobalData.isModuleBuilt(fpdModuleId)) {\r
1fa1cb75 273 break;\r
34281092 274 } else {\r
a29c47e0 275 GlobalData.registerBuiltModule(fpdModuleId);\r
276 }\r
ff225cbb 277\r
878ddf1f 278 //\r
a29c47e0 279 // For Every TOOLCHAIN, TARGET\r
280 //\r
281 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
282 for (int i = 0; i < targetList.length; i ++){\r
283 //\r
284 // Prepare for target related common properties\r
285 // TARGET\r
286 //\r
aca6c736 287 getProject().setProperty("TARGET", targetList[i]);\r
a29c47e0 288 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
289 for(int j = 0; j < toolchainList.length; j ++){\r
c773bec0 290 //\r
291 // check if any tool is defined for current target + toolchain + arch\r
292 // don't do anything if no tools found\r
ff225cbb 293 //\r
c773bec0 294 if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {\r
fd6c41f5 295 EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: No build issued. No tools found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");\r
c773bec0 296 continue;\r
297 }\r
298\r
a29c47e0 299 //\r
300 // Prepare for toolchain related common properties\r
301 // TOOLCHAIN\r
302 //\r
aca6c736 303 getProject().setProperty("TOOLCHAIN", toolchainList[j]);\r
a29c47e0 304\r
d965d1f6 305 EdkLog.log(this, "Build " + moduleId + " start >>>");\r
306 EdkLog.log(this, "Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);\r
83fba802 307 saq.push(GlobalData.getDoc(fpdModuleId));\r
ff225cbb 308\r
a29c47e0 309 //\r
310 // Prepare for all other common properties\r
311 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r
312 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r
313 // MODULE_DIR, MODULE_RELATIVE_DIR\r
314 // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH\r
a29c47e0 315 //\r
316 setModuleCommonProperties(archList[k]);\r
ff225cbb 317\r
a29c47e0 318 //\r
ff225cbb 319 // OutputManage prepare for\r
a29c47e0 320 // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR\r
321 //\r
322 OutputManager.getInstance().update(getProject());\r
ff225cbb 323\r
a29c47e0 324 if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {\r
325 applyBuild(targetList[i], toolchainList[j], fpdModuleId);\r
82516887 326 } else if (type.equalsIgnoreCase("clean")) {\r
a29c47e0 327 applyClean(fpdModuleId);\r
82516887 328 } else if (type.equalsIgnoreCase("cleanall")) {\r
a29c47e0 329 applyCleanall(fpdModuleId);\r
330 }\r
331 }\r
332 }\r
878ddf1f 333 }\r
878ddf1f 334 }\r
335\r
336 /**\r
ff225cbb 337 This method is used to prepare Platform-related information.\r
338\r
a29c47e0 339 <p>In Single Module Build mode, platform-related information is not ready.\r
ff225cbb 340 The method read the system environment variable <code>ACTIVE_PLATFORM</code>\r
a29c47e0 341 and search in the Framework Database. Note that platform name in the Framework\r
342 Database must be unique. </p>\r
ff225cbb 343\r
878ddf1f 344 **/\r
892b0e7a 345 private void prepareSingleModuleBuild() throws EdkException {\r
878ddf1f 346 //\r
a29c47e0 347 // Find out the package which the module belongs to\r
878ddf1f 348 //\r
a29c47e0 349 PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);\r
892b0e7a 350 GlobalData.refreshPackageIdentification(packageId);\r
a29c47e0 351 moduleId.setPackage(packageId);\r
892b0e7a 352 GlobalData.refreshModuleIdentification(moduleId);\r
ff225cbb 353\r
878ddf1f 354 //\r
82516887 355 // Read ACTIVE_PLATFORM's FPD file \r
878ddf1f 356 //\r
de4bb9f6 357 String filename = getProject().getProperty("PLATFORM_FILE");\r
ff225cbb 358\r
de4bb9f6 359 if (filename == null){\r
391dbbb1 360 throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!");\r
878ddf1f 361 }\r
ff225cbb 362\r
de4bb9f6 363 PlatformIdentification platformId = GlobalData.getPlatform(filename);\r
ff225cbb 364\r
878ddf1f 365 //\r
82516887 366 // Read FPD file (Call FpdParserTask's method)\r
878ddf1f 367 //\r
a29c47e0 368 FpdParserTask fpdParser = new FpdParserTask();\r
369 fpdParser.setProject(getProject());\r
07193171 370 fpdParser.parseFpdFile(platformId.getFpdFile());\r
aca6c736 371 getProject().setProperty("ARCH", fpdParser.getAllArchForModule(moduleId));\r
878ddf1f 372 }\r
373\r
aca6c736 374 private void cleanupProperties() {\r
375 Project newProject = new Project();\r
376\r
377 Hashtable<String, String> passdownProperties = FrameworkBuildTask.originalProperties;\r
378 Iterator<String> iter = passdownProperties.keySet().iterator();\r
379 while (iter.hasNext()) {\r
380 String item = iter.next();\r
381 newProject.setProperty(item, passdownProperties.get(item));\r
382 }\r
383\r
384 newProject.setInputHandler(getProject().getInputHandler());\r
385\r
386 Iterator listenerIter = getProject().getBuildListeners().iterator();\r
387 while (listenerIter.hasNext()) {\r
388 newProject.addBuildListener((BuildListener) listenerIter.next());\r
389 }\r
390\r
391 getProject().initSubProject(newProject);\r
392\r
393 setProject(newProject);\r
394 }\r
878ddf1f 395\r
396 /**\r
a29c47e0 397 Set Module-Related information to properties.\r
82516887 398 \r
399 @param arch current build ARCH\r
878ddf1f 400 **/\r
a29c47e0 401 private void setModuleCommonProperties(String arch) {\r
878ddf1f 402 //\r
a29c47e0 403 // Prepare for all other common properties\r
404 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r
878ddf1f 405 //\r
a29c47e0 406 PackageIdentification packageId = moduleId.getPackage();\r
aca6c736 407 getProject().setProperty("PACKAGE", packageId.getName());\r
408 getProject().setProperty("PACKAGE_GUID", packageId.getGuid());\r
409 getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());\r
410 getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r
411 getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r
ff225cbb 412\r
a29c47e0 413 //\r
414 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r
415 // MODULE_DIR, MODULE_RELATIVE_DIR\r
416 //\r
aca6c736 417 getProject().setProperty("MODULE", moduleId.getName());\r
83fba802 418 String baseName = saq.getModuleOutputFileBasename();\r
a29c47e0 419 if (baseName == null) {\r
aca6c736 420 getProject().setProperty("BASE_NAME", moduleId.getName());\r
82516887 421 } else {\r
aca6c736 422 getProject().setProperty("BASE_NAME", baseName);\r
a29c47e0 423 }\r
aca6c736 424 getProject().setProperty("GUID", moduleId.getGuid());\r
425 getProject().setProperty("FILE_GUID", moduleId.getGuid());\r
426 getProject().setProperty("VERSION", moduleId.getVersion());\r
427 getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());\r
86f3fef0 428 File msaFile = moduleId.getMsaFile();\r
429 String msaFileName = msaFile.getName();\r
430 getProject().setProperty("MODULE_DIR", msaFile.getParent().replaceAll("(\\\\)", "/"));\r
431 getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/") \r
bc022470 432 + File.separatorChar + msaFileName.substring(0, msaFileName.lastIndexOf('.')));\r
ff225cbb 433\r
a29c47e0 434 //\r
435 // SUBSYSTEM\r
436 //\r
437 String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},\r
ff225cbb 438 { "SEC", "EFI_BOOT_SERVICE_DRIVER" },\r
439 { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r
440 { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },\r
a29c47e0 441 { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r
ff225cbb 442 { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
443 { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },\r
444 { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
445 { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
446 { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },\r
a29c47e0 447 { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
ff225cbb 448 { "UEFI_APPLICATION", "EFI_APPLICATION" },\r
449 { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };\r
450\r
a29c47e0 451 String subsystem = "EFI_BOOT_SERVICE_DRIVER";\r
452 for (int i = 0; i < subsystemMap.length; i++) {\r
453 if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {\r
454 subsystem = subsystemMap[i][1];\r
455 break ;\r
878ddf1f 456 }\r
457 }\r
aca6c736 458 getProject().setProperty("SUBSYSTEM", subsystem);\r
ff225cbb 459\r
a29c47e0 460 //\r
461 // ENTRYPOINT\r
462 //\r
463 if (arch.equalsIgnoreCase("EBC")) {\r
aca6c736 464 getProject().setProperty("ENTRYPOINT", "EfiStart");\r
82516887 465 } else {\r
aca6c736 466 getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");\r
878ddf1f 467 }\r
ff225cbb 468\r
aca6c736 469 getProject().setProperty("OBJECTS", "");\r
878ddf1f 470 }\r
471\r
a29c47e0 472 private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {\r
473 String[] cmd = GlobalData.getToolChainInfo().getCommands();\r
474 for ( int m = 0; m < cmd.length; m++) {\r
878ddf1f 475 //\r
a29c47e0 476 // Set cmd, like CC, DLINK\r
878ddf1f 477 //\r
a29c47e0 478 String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};\r
4a6a5026 479 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_PATH;\r
a29c47e0 480 String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);\r
4a6a5026 481 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME;\r
a29c47e0 482 String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);\r
1549f516 483 if (cmdName.length() == 0) {\r
fd6c41f5 484 EdkLog.log(this, EdkLog.EDK_VERBOSE, "Warning: " + cmd[m] + " hasn't been defined!");\r
485 getProject().setProperty(cmd[m], "");\r
1549f516 486 continue;\r
487 }\r
a29c47e0 488 File cmdFile = new File(cmdPath + File.separatorChar + cmdName);\r
aca6c736 489 getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));\r
ff225cbb 490\r
878ddf1f 491 //\r
a29c47e0 492 // set CC_FLAGS\r
878ddf1f 493 //\r
4a6a5026 494 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS;\r
a29c47e0 495 String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);\r
e04a8a9a 496 if (cmdFlags != null) \r
497 {\r
e04a8a9a 498 getProject().setProperty(cmd[m] + "_FLAGS", cmdFlags);\r
499 } \r
500 else \r
501 {\r
502 getProject().setProperty(cmd[m] + "_FLAGS", "");\r
503 }\r
504\r
878ddf1f 505 //\r
a29c47e0 506 // Set CC_EXT\r
878ddf1f 507 //\r
4a6a5026 508 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_EXT;\r
a29c47e0 509 String extName = GlobalData.getCommandSetting(key, fpdModuleId);\r
a29c47e0 510 if ( extName != null && ! extName.equalsIgnoreCase("")) {\r
aca6c736 511 getProject().setProperty(cmd[m] + "_EXT", extName);\r
82516887 512 } else {\r
aca6c736 513 getProject().setProperty(cmd[m] + "_EXT", "");\r
878ddf1f 514 }\r
ff225cbb 515\r
878ddf1f 516 //\r
a29c47e0 517 // set CC_FAMILY\r
878ddf1f 518 //\r
4a6a5026 519 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY;\r
a29c47e0 520 String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);\r
a29c47e0 521 if (toolChainFamily != null) {\r
aca6c736 522 getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);\r
878ddf1f 523 }\r
ff225cbb 524\r
878ddf1f 525 //\r
a29c47e0 526 // set CC_SPATH\r
878ddf1f 527 //\r
4a6a5026 528 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_SPATH;\r
a29c47e0 529 String spath = GlobalData.getCommandSetting(key, fpdModuleId);\r
a29c47e0 530 if (spath != null) {\r
aca6c736 531 getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));\r
82516887 532 } else {\r
aca6c736 533 getProject().setProperty(cmd[m] + "_SPATH", "");\r
878ddf1f 534 }\r
ff225cbb 535\r
878ddf1f 536 //\r
a29c47e0 537 // set CC_DPATH\r
878ddf1f 538 //\r
4a6a5026 539 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_DPATH;\r
a29c47e0 540 String dpath = GlobalData.getCommandSetting(key, fpdModuleId);\r
a29c47e0 541 if (dpath != null) {\r
aca6c736 542 getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));\r
82516887 543 } else {\r
aca6c736 544 getProject().setProperty(cmd[m] + "_DPATH", "");\r
878ddf1f 545 }\r
c639781e 546 \r
547 //\r
548 // Set CC_LIBPATH\r
549 //\r
550 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_LIBPATH;\r
551 String libpath = GlobalData.getCommandSetting(key, fpdModuleId);\r
552 if (libpath != null) {\r
553 getProject().setProperty(cmd[m] + "_LIBPATH", libpath.replaceAll("(\\\\)", "/"));\r
554 } else {\r
555 getProject().setProperty(cmd[m] + "_LIBPATH", "");\r
556 }\r
557 \r
558 //\r
559 // Set CC_INCLUDEPATH\r
560 //\r
561 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_INCLUDEPATH;\r
562 String includepath = GlobalData.getCommandSetting(key, fpdModuleId);\r
563 if (dpath != null) {\r
564 getProject().setProperty(cmd[m] + "_INCLUDEPATH", includepath.replaceAll("(\\\\)", "/"));\r
565 } else {\r
566 getProject().setProperty(cmd[m] + "_INCLUDEPATH", "");\r
567 }\r
878ddf1f 568 }\r
a29c47e0 569 }\r
ff225cbb 570\r
a29c47e0 571 public void setMsaFile(File msaFile) {\r
572 this.msaFile = msaFile;\r
878ddf1f 573 }\r
574\r
575 /**\r
ff225cbb 576 Method is for ANT to initialize MSA file.\r
577\r
a29c47e0 578 @param msaFilename MSA file name\r
878ddf1f 579 **/\r
a29c47e0 580 public void setMsaFile(String msaFilename) {\r
581 String moduleDir = getProject().getProperty("MODULE_DIR");\r
ff225cbb 582\r
a29c47e0 583 //\r
584 // If is Single Module Build, then use the Base Dir defined in build.xml\r
585 //\r
586 if (moduleDir == null) {\r
587 moduleDir = getProject().getBaseDir().getPath();\r
878ddf1f 588 }\r
a29c47e0 589 msaFile = new File(moduleDir + File.separatorChar + msaFilename);\r
590 }\r
ff225cbb 591\r
a29c47e0 592 public void addConfiguredModuleItem(ModuleItem moduleItem) {\r
593 PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());\r
594 ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());\r
595 moduleId.setPackage(packageId);\r
596 this.moduleId = moduleId;\r
597 }\r
ff225cbb 598\r
a29c47e0 599 /**\r
ff225cbb 600 Add a property.\r
601\r
a29c47e0 602 @param p property\r
603 **/\r
604 public void addProperty(Property p) {\r
605 properties.addElement(p);\r
606 }\r
607\r
608 public void setType(String type) {\r
609 this.type = type;\r
610 }\r
ff225cbb 611\r
892b0e7a 612 private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException {\r
a29c47e0 613 //\r
83fba802 614 // Call AutoGen to generate AutoGen.c and AutoGen.h\r
a29c47e0 615 //\r
2eb7d78d 616 AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch(), saq, parentId);\r
136adffc 617 autogen.genAutogen();\r
ff225cbb 618\r
a29c47e0 619 //\r
620 // Get compiler flags\r
621 //\r
82516887 622 try {\r
623 getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r
624 }\r
625 catch (EdkException ee) {\r
626 throw new BuildException(ee.getMessage());\r
627 }\r
628 \r
a29c47e0 629 //\r
630 // Prepare LIBS\r
631 //\r
83fba802 632 ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch());\r
a29c47e0 633 String propertyLibs = "";\r
634 for (int i = 0; i < libinstances.length; i++) {\r
498e9021 635 propertyLibs += getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib" + " ";\r
878ddf1f 636 }\r
aca6c736 637 getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r
ff225cbb 638\r
bf3a7173 639 //\r
640 // Get all includepath and set to INCLUDE_PATHS\r
641 //\r
642 String[] includes = prepareIncludePaths(fpdModuleId);\r
643 \r
a29c47e0 644 //\r
645 // if it is CUSTOM_BUILD\r
646 // then call the exist BaseName_build.xml directly.\r
647 //\r
648 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
d965d1f6 649 EdkLog.log(this, "Call user-defined " + moduleId.getName() + "_build.xml");\r
82516887 650 \r
651 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
652 antCall(antFilename, null);\r
653 \r
a29c47e0 654 return ;\r
878ddf1f 655 }\r
ff225cbb 656\r
878ddf1f 657 //\r
a29c47e0 658 // Generate ${BASE_NAME}_build.xml\r
659 // TBD\r
878ddf1f 660 //\r
83fba802 661 String ffsKeyword = saq.getModuleFfsKeyword();\r
662 ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId, includes, saq);\r
a29c47e0 663 String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
664 fileGenerator.genBuildFile(buildFilename);\r
ff225cbb 665\r
a29c47e0 666 //\r
667 // Ant call ${BASE_NAME}_build.xml\r
668 //\r
82516887 669 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
670 antCall(antFilename, null);\r
a29c47e0 671 }\r
ff225cbb 672\r
a29c47e0 673 private void applyClean(FpdModuleIdentification fpdModuleId){\r
674 //\r
675 // if it is CUSTOM_BUILD\r
676 // then call the exist BaseName_build.xml directly.\r
677 //\r
678 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
d965d1f6 679 EdkLog.log(this, "Calling user-defined " + moduleId.getName() + "_build.xml");\r
82516887 680 \r
681 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
682 antCall(antFilename, "clean");\r
683 \r
a29c47e0 684 return ;\r
878ddf1f 685 }\r
ff225cbb 686\r
82516887 687 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
688 antCall(antFilename, "clean");\r
a29c47e0 689 }\r
ff225cbb 690\r
a29c47e0 691 private void applyCleanall(FpdModuleIdentification fpdModuleId){\r
692 //\r
693 // if it is CUSTOM_BUILD\r
694 // then call the exist BaseName_build.xml directly.\r
695 //\r
696 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
d965d1f6 697 EdkLog.log(this, "Calling user-defined " + moduleId.getName() + "_build.xml");\r
82516887 698\r
699 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
700 antCall(antFilename, "cleanall");\r
701 \r
a29c47e0 702 return ;\r
878ddf1f 703 }\r
82516887 704 \r
705 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
706 antCall(antFilename, "cleanall");\r
707 }\r
ff225cbb 708\r
82516887 709 private void antCall(String antFilename, String target) {\r
a29c47e0 710 Ant ant = new Ant();\r
711 ant.setProject(getProject());\r
82516887 712 ant.setAntfile(antFilename);\r
713 if (target != null) {\r
714 ant.setTarget(target);\r
715 }\r
a29c47e0 716 ant.setInheritAll(true);\r
717 ant.init();\r
718 ant.execute();\r
878ddf1f 719 }\r
720\r
de4bb9f6 721 public void setSingleModuleBuild(boolean isSingleModuleBuild) {\r
722 this.isSingleModuleBuild = isSingleModuleBuild;\r
723 }\r
bf3a7173 724 \r
892b0e7a 725 private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) throws EdkException{\r
bf3a7173 726 //\r
727 // Prepare the includes: PackageDependencies and Output debug direactory\r
728 //\r
729 Set<String> includes = new LinkedHashSet<String>();\r
730 String arch = fpdModuleId.getArch();\r
731 \r
732 //\r
733 // WORKSPACE\r
734 //\r
735 includes.add("${WORKSPACE_DIR}" + File.separatorChar);\r
736 \r
737 //\r
738 // Module iteself\r
739 //\r
740 includes.add("${MODULE_DIR}");\r
741 includes.add("${MODULE_DIR}" + File.separatorChar + archDir(arch));\r
742 \r
743 //\r
744 // Packages in PackageDenpendencies\r
745 //\r
83fba802 746 PackageIdentification[] packageDependencies = saq.getDependencePkg(fpdModuleId.getArch());\r
bf3a7173 747 for (int i = 0; i < packageDependencies.length; i++) {\r
748 GlobalData.refreshPackageIdentification(packageDependencies[i]);\r
749 File packageFile = packageDependencies[i].getSpdFile();\r
750 includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
751 includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
752 }\r
753\r
754 //\r
755 // All Dependency Library Instance's PackageDependencies\r
756 //\r
83fba802 757 ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch());\r
bf3a7173 758 for (int i = 0; i < libinstances.length; i++) {\r
83fba802 759 saq.push(GlobalData.getDoc(libinstances[i], fpdModuleId.getArch()));\r
760 PackageIdentification[] libraryPackageDependencies = saq.getDependencePkg(fpdModuleId.getArch());\r
bf3a7173 761 for (int j = 0; j < libraryPackageDependencies.length; j++) {\r
762 GlobalData.refreshPackageIdentification(libraryPackageDependencies[j]);\r
763 File packageFile = libraryPackageDependencies[j].getSpdFile();\r
764 includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
765 includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
766 }\r
83fba802 767 saq.pop();\r
bf3a7173 768 }\r
769 \r
770 \r
771 //\r
772 // The package which the module belongs to\r
773 // TBD\r
774 includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include");\r
775 includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
776\r
777 //\r
778 // Debug files output directory\r
779 //\r
780 includes.add("${DEST_DIR_DEBUG}");\r
781 \r
782 //\r
783 // set to INCLUDE_PATHS property\r
784 //\r
785 Iterator<String> iter = includes.iterator();\r
786 StringBuffer includePaths = new StringBuffer();\r
787 while (iter.hasNext()) {\r
788 includePaths.append(iter.next());\r
789 includePaths.append("; ");\r
790 }\r
aca6c736 791 getProject().setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths.toString()).replaceAll("(\\\\)", "/"));\r
bf3a7173 792 \r
793 return includes.toArray(new String[includes.size()]);\r
794 }\r
795 \r
796 /**\r
797 Return the name of the directory that corresponds to the architecture.\r
798 This is a translation from the XML Schema tag to a directory that\r
799 corresponds to our directory name coding convention.\r
800 \r
801 **/\r
802 private String archDir(String arch) {\r
803 return arch.replaceFirst("X64", "x64")\r
804 .replaceFirst("IPF", "Ipf")\r
805 .replaceFirst("IA32", "Ia32")\r
806 .replaceFirst("ARM", "Arm")\r
807 .replaceFirst("EBC", "Ebc");\r
19bf6b15 808 }\r
809 \r
810 \r
811 public void setExternalProperties(Vector<Property> v) {\r
812 this.properties = v;\r
813 }\r
878ddf1f 814}\r