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