2 This file is ANT task GenBuild.
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.
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
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.
16 package org
.tianocore
.build
;
19 import java
.util
.Iterator
;
20 import java
.util
.LinkedHashSet
;
21 import java
.util
.List
;
24 import java
.util
.Vector
;
25 import java
.util
.regex
.Matcher
;
26 import java
.util
.regex
.Pattern
;
28 import org
.apache
.tools
.ant
.BuildException
;
29 import org
.apache
.tools
.ant
.taskdefs
.Ant
;
30 import org
.apache
.tools
.ant
.taskdefs
.Property
;
31 import org
.apache
.xmlbeans
.XmlObject
;
33 import org
.tianocore
.common
.definitions
.ToolDefinitions
;
34 import org
.tianocore
.common
.exception
.EdkException
;
35 import org
.tianocore
.common
.logger
.EdkLog
;
36 import org
.tianocore
.build
.autogen
.AutoGen
;
37 import org
.tianocore
.build
.fpd
.FpdParserTask
;
38 import org
.tianocore
.build
.global
.GenBuildLogger
;
39 import org
.tianocore
.build
.global
.GlobalData
;
40 import org
.tianocore
.build
.global
.OutputManager
;
41 import org
.tianocore
.build
.global
.PropertyManager
;
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
;
51 <code>GenBuildTask</code> is an ANT task that can be used in ANT build
54 <p>The main function of this task is to parse module's surface area (MSA),
55 then generate the corresponding <em>BaseName_build.xml</em> (the real ANT
56 build script) and call this to build the module. The whole process including:
59 1. generate AutoGen.c and AutoGen.h;
60 2. build all dependent library instances;
61 3. build all source files inlcude AutoGen.c;
63 5. generate FFS file if it is driver module while LIB file if it is Library module.
68 The usage is (take module <em>HelloWorld</em> for example):
73 msaFile="${PACKAGE_DIR}/Application/HelloWorld/HelloWorld.msa"
78 This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and
83 This task will also set properties for current module, such as PACKAGE,
84 PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
85 (relative to Workspace), MODULE or BASE_NAME, GUID, VERSION, MODULE_DIR,
86 MODULE_RELATIVE_DIR (relative to Package), CONFIG_DIR, BIN_DIR,
87 DEST_DIR_DEBUG, DEST_DIR_OUTPUT, TARGET, ARCH, TOOLCHAIN, TOOLCHAIN_FAMILY,
88 SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH, all compiler command related
89 properties (CC, CC_FLAGS, CC_DPATH, CC_SPATH, CC_FAMILY, CC_EXT).
94 public class GenBuildTask
extends Ant
{
97 /// Module surface area file.
101 private String type
= "all";
104 /// Module's Identification.
106 private ModuleIdentification moduleId
;
108 private Vector
<Property
> properties
= new Vector
<Property
>();
110 private boolean isSingleModuleBuild
= false;
113 Public construct method. It is necessary for ANT task.
115 public GenBuildTask() {
120 @throws BuildException
121 From module build, exception from module surface area invalid.
123 public void execute() throws BuildException
{
127 GenBuildLogger logger
= new GenBuildLogger(getProject());
128 EdkLog
.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
129 EdkLog
.setLogger(logger
);
131 PropertyManager
.setProject(getProject());
132 PropertyManager
.save();
134 // Enable all specified properties
136 Iterator
<Property
> iter
= properties
.iterator();
137 while (iter
.hasNext()) {
138 Property item
= iter
.next();
139 PropertyManager
.setProperty(item
.getName(), item
.getValue());
143 // GenBuild should specify either msaFile or moduleGuid & packageGuid
145 if (msaFile
== null ) {
146 String moduleGuid
= getProject().getProperty("MODULE_GUID");
147 String moduleVersion
= getProject().getProperty("MODULE_VERSION");
148 String packageGuid
= getProject().getProperty("PACKAGE_GUID");
149 String packageVersion
= getProject().getProperty("PACKAGE_VERSION");
150 if (moduleGuid
== null || packageGuid
== null) {
151 throw new BuildException("GenBuild parameter error.");
153 PackageIdentification packageId
= new PackageIdentification(packageGuid
, packageVersion
);
154 moduleId
= new ModuleIdentification(moduleGuid
, moduleVersion
);
155 moduleId
.setPackage(packageId
);
156 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(moduleId
);
157 SurfaceAreaQuery
.setDoc(doc
);
158 moduleId
= SurfaceAreaQuery
.getMsaHeader();
160 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(msaFile
);
161 SurfaceAreaQuery
.setDoc(doc
);
162 moduleId
= SurfaceAreaQuery
.getMsaHeader();
164 String
[] producedLibraryClasses
= SurfaceAreaQuery
.getLibraryClasses("ALWAYS_PRODUCED",null);
165 if (producedLibraryClasses
.length
== 0) {
166 moduleId
.setLibrary(false);
168 moduleId
.setLibrary(true);
172 // Judge whether it is single module build or not
174 if (isSingleModuleBuild
) {
176 // Single Module build
178 prepareSingleModuleBuild();
181 // Platform build. Restore the platform related info
183 String filename
= getProject().getProperty("PLATFORM_FILE");
184 PlatformIdentification platformId
= GlobalData
.getPlatform(filename
);
185 PropertyManager
.setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
186 PropertyManager
.setProperty("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
188 String packageGuid
= getProject().getProperty("PACKAGE_GUID");
189 String packageVersion
= getProject().getProperty("PACKAGE_VERSION");
190 PackageIdentification packageId
= new PackageIdentification(packageGuid
, packageVersion
);
191 moduleId
.setPackage(packageId
);
195 // If single module : get arch from pass down, otherwise intersection MSA
196 // supported ARCHs and tools def
198 Set
<String
> archListSupByToolChain
= new LinkedHashSet
<String
>();
199 String
[] archs
= GlobalData
.getToolChainInfo().getArchs();
201 for (int i
= 0; i
< archs
.length
; i
++) {
202 archListSupByToolChain
.add(archs
[i
]);
205 Set
<String
> archSet
= new LinkedHashSet
<String
>();
207 if ( getProject().getProperty("ARCH") != null) {
208 String
[] fpdArchList
= getProject().getProperty("ARCH").split(" ");
210 for (int i
= 0; i
< fpdArchList
.length
; i
++) {
211 if (archListSupByToolChain
.contains(fpdArchList
[i
])) {
212 archSet
.add(fpdArchList
[i
]);
216 archSet
= archListSupByToolChain
;
219 String
[] archList
= archSet
.toArray(new String
[archSet
.size()]);
222 // Judge if arch is all supported by current module. If not, throw Exception.
224 List moduleSupportedArchs
= SurfaceAreaQuery
.getModuleSupportedArchs();
225 if (moduleSupportedArchs
!= null) {
226 for (int k
= 0; k
< archList
.length
; k
++) {
227 if ( ! moduleSupportedArchs
.contains(archList
[k
])) {
228 throw new BuildException("Specified architecture [" + archList
[k
] + "] is not supported by " + moduleId
+ ". The module " + moduleId
+ " only supports [" + moduleSupportedArchs
+ "] architectures.");
233 for (int k
= 0; k
< archList
.length
; k
++) {
235 PropertyManager
.setProperty("ARCH", archList
[k
]);
237 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, archList
[k
]);
240 // Whether the module is built before
242 if (moduleId
.isLibrary() == false && GlobalData
.hasFpdModuleSA(fpdModuleId
) == false) {
243 System
.out
.println("\nWARNING: " + moduleId
+ " for " + archList
[k
] + " was not found in current platform FPD file!\n");
245 } else if (GlobalData
.isModuleBuilt(fpdModuleId
)) {
248 GlobalData
.registerBuiltModule(fpdModuleId
);
252 // For Every TOOLCHAIN, TARGET
254 String
[] targetList
= GlobalData
.getToolChainInfo().getTargets();
255 for (int i
= 0; i
< targetList
.length
; i
++){
257 // Prepare for target related common properties
260 PropertyManager
.setProperty("TARGET", targetList
[i
]);
261 String
[] toolchainList
= GlobalData
.getToolChainInfo().getTagnames();
262 for(int j
= 0; j
< toolchainList
.length
; j
++){
264 // check if any tool is defined for current target + toolchain + arch
265 // don't do anything if no tools found
267 if (GlobalData
.isCommandSet(targetList
[i
], toolchainList
[j
], archList
[k
]) == false) {
268 System
.out
.println("Warning: No build issued. No tools were found for [target=" + targetList
[i
] + " toolchain=" + toolchainList
[j
] + " arch=" + archList
[k
] + "]\n");
273 // Prepare for toolchain related common properties
276 PropertyManager
.setProperty("TOOLCHAIN", toolchainList
[j
]);
278 System
.out
.println("Build " + moduleId
+ " start >>>");
279 System
.out
.println("Target: " + targetList
[i
] + " Tagname: " + toolchainList
[j
] + " Arch: " + archList
[k
]);
280 SurfaceAreaQuery
.setDoc(GlobalData
.getDoc(fpdModuleId
));
283 // Prepare for all other common properties
284 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
285 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
286 // MODULE_DIR, MODULE_RELATIVE_DIR
287 // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH
289 setModuleCommonProperties(archList
[k
]);
292 // OutputManage prepare for
293 // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
295 OutputManager
.getInstance().update(getProject());
297 if (type
.equalsIgnoreCase("all") || type
.equalsIgnoreCase("build")) {
298 applyBuild(targetList
[i
], toolchainList
[j
], fpdModuleId
);
299 } else if (type
.equalsIgnoreCase("clean")) {
300 applyClean(fpdModuleId
);
301 } else if (type
.equalsIgnoreCase("cleanall")) {
302 applyCleanall(fpdModuleId
);
308 PropertyManager
.restore();
312 This method is used to prepare Platform-related information.
314 <p>In Single Module Build mode, platform-related information is not ready.
315 The method read the system environment variable <code>ACTIVE_PLATFORM</code>
316 and search in the Framework Database. Note that platform name in the Framework
317 Database must be unique. </p>
320 private void prepareSingleModuleBuild(){
322 // Find out the package which the module belongs to
323 // TBD: Enhance it!!!!
325 PackageIdentification packageId
= GlobalData
.getPackageForModule(moduleId
);
327 moduleId
.setPackage(packageId
);
330 // Read ACTIVE_PLATFORM's FPD file
332 String filename
= getProject().getProperty("PLATFORM_FILE");
334 if (filename
== null){
335 throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!");
338 PlatformIdentification platformId
= GlobalData
.getPlatform(filename
);
341 // Read FPD file (Call FpdParserTask's method)
343 FpdParserTask fpdParser
= new FpdParserTask();
344 fpdParser
.setProject(getProject());
345 fpdParser
.parseFpdFile(platformId
.getFpdFile());
346 PropertyManager
.setProperty("ARCH", fpdParser
.getAllArchForModule(moduleId
));
349 // Prepare for Platform related common properties
350 // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
352 PropertyManager
.setProperty("PLATFORM", platformId
.getName());
353 PropertyManager
.setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
354 PropertyManager
.setProperty("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
359 Set Module-Related information to properties.
361 @param arch current build ARCH
363 private void setModuleCommonProperties(String arch
) {
365 // Prepare for all other common properties
366 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
368 PackageIdentification packageId
= moduleId
.getPackage();
369 PropertyManager
.setProperty("PACKAGE", packageId
.getName());
370 PropertyManager
.setProperty("PACKAGE_GUID", packageId
.getGuid());
371 PropertyManager
.setProperty("PACKAGE_VERSION", packageId
.getVersion());
372 PropertyManager
.setProperty("PACKAGE_DIR", packageId
.getPackageDir().replaceAll("(\\\\)", "/"));
373 PropertyManager
.setProperty("PACKAGE_RELATIVE_DIR", packageId
.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
376 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
377 // MODULE_DIR, MODULE_RELATIVE_DIR
379 PropertyManager
.setProperty("MODULE", moduleId
.getName());
380 String baseName
= SurfaceAreaQuery
.getModuleOutputFileBasename();
381 if (baseName
== null) {
382 PropertyManager
.setProperty("BASE_NAME", moduleId
.getName());
384 PropertyManager
.setProperty("BASE_NAME", baseName
);
386 PropertyManager
.setProperty("GUID", moduleId
.getGuid());
387 PropertyManager
.setProperty("FILE_GUID", moduleId
.getGuid());
388 PropertyManager
.setProperty("VERSION", moduleId
.getVersion());
389 PropertyManager
.setProperty("MODULE_TYPE", moduleId
.getModuleType());
390 PropertyManager
.setProperty("MODULE_DIR", moduleId
.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
391 PropertyManager
.setProperty("MODULE_RELATIVE_DIR", moduleId
.getModuleRelativePath().replaceAll("(\\\\)", "/"));
396 String
[][] subsystemMap
= { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},
397 { "SEC", "EFI_BOOT_SERVICE_DRIVER" },
398 { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },
399 { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },
400 { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },
401 { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
402 { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },
403 { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
404 { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
405 { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },
406 { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
407 { "UEFI_APPLICATION", "EFI_APPLICATION" },
408 { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };
410 String subsystem
= "EFI_BOOT_SERVICE_DRIVER";
411 for (int i
= 0; i
< subsystemMap
.length
; i
++) {
412 if (moduleId
.getModuleType().equalsIgnoreCase(subsystemMap
[i
][0])) {
413 subsystem
= subsystemMap
[i
][1];
417 PropertyManager
.setProperty("SUBSYSTEM", subsystem
);
422 if (arch
.equalsIgnoreCase("EBC")) {
423 PropertyManager
.setProperty("ENTRYPOINT", "EfiStart");
425 PropertyManager
.setProperty("ENTRYPOINT", "_ModuleEntryPoint");
428 PropertyManager
.setProperty("OBJECTS", "");
431 private void getCompilerFlags(String target
, String toolchain
, FpdModuleIdentification fpdModuleId
) throws EdkException
{
432 String
[] cmd
= GlobalData
.getToolChainInfo().getCommands();
433 for ( int m
= 0; m
< cmd
.length
; m
++) {
435 // Set cmd, like CC, DLINK
437 String
[] key
= new String
[]{target
, toolchain
, fpdModuleId
.getArch(), cmd
[m
], null};
438 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_PATH
;
439 String cmdPath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
440 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_NAME
;
441 String cmdName
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
442 File cmdFile
= new File(cmdPath
+ File
.separatorChar
+ cmdName
);
443 PropertyManager
.setProperty(cmd
[m
], cmdFile
.getPath().replaceAll("(\\\\)", "/"));
448 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
;
449 String cmdFlags
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
450 Set
<String
> addset
= new LinkedHashSet
<String
>();
451 Set
<String
> subset
= new LinkedHashSet
<String
>();
452 putFlagsToSet(addset
, cmdFlags
);
453 PropertyManager
.setProperty(cmd
[m
] + "_FLAGS", getProject().replaceProperties(getFlags(addset
, subset
)));
458 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_EXT
;
459 String extName
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
460 if ( extName
!= null && ! extName
.equalsIgnoreCase("")) {
461 PropertyManager
.setProperty(cmd
[m
] + "_EXT", extName
);
463 PropertyManager
.setProperty(cmd
[m
] + "_EXT", "");
469 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FAMILY
;
470 String toolChainFamily
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
471 if (toolChainFamily
!= null) {
472 PropertyManager
.setProperty(cmd
[m
] + "_FAMILY", toolChainFamily
);
478 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_SPATH
;
479 String spath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
481 PropertyManager
.setProperty(cmd
[m
] + "_SPATH", spath
.replaceAll("(\\\\)", "/"));
483 PropertyManager
.setProperty(cmd
[m
] + "_SPATH", "");
489 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_DPATH
;
490 String dpath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
492 PropertyManager
.setProperty(cmd
[m
] + "_DPATH", dpath
.replaceAll("(\\\\)", "/"));
494 PropertyManager
.setProperty(cmd
[m
] + "_DPATH", "");
499 public void setMsaFile(File msaFile
) {
500 this.msaFile
= msaFile
;
504 Method is for ANT to initialize MSA file.
506 @param msaFilename MSA file name
508 public void setMsaFile(String msaFilename
) {
509 String moduleDir
= getProject().getProperty("MODULE_DIR");
512 // If is Single Module Build, then use the Base Dir defined in build.xml
514 if (moduleDir
== null) {
515 moduleDir
= getProject().getBaseDir().getPath();
517 msaFile
= new File(moduleDir
+ File
.separatorChar
+ msaFilename
);
520 public void addConfiguredModuleItem(ModuleItem moduleItem
) {
521 PackageIdentification packageId
= new PackageIdentification(moduleItem
.getPackageGuid(), moduleItem
.getPackageVersion());
522 ModuleIdentification moduleId
= new ModuleIdentification(moduleItem
.getModuleGuid(), moduleItem
.getModuleVersion());
523 moduleId
.setPackage(packageId
);
524 this.moduleId
= moduleId
;
532 public void addProperty(Property p
) {
533 properties
.addElement(p
);
536 public void setType(String type
) {
540 private void applyBuild(String buildTarget
, String buildTagname
, FpdModuleIdentification fpdModuleId
) throws BuildException
{
545 AutoGen autogen
= new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId
.getModule(),fpdModuleId
.getArch());
546 autogen
.genAutogen();
550 // Get compiler flags
553 getCompilerFlags(buildTarget
, buildTagname
, fpdModuleId
);
555 catch (EdkException ee
) {
556 throw new BuildException(ee
.getMessage());
562 ModuleIdentification
[] libinstances
= SurfaceAreaQuery
.getLibraryInstance(fpdModuleId
.getArch());
563 String propertyLibs
= "";
564 for (int i
= 0; i
< libinstances
.length
; i
++) {
565 propertyLibs
+= " " + getProject().getProperty("BIN_DIR") + File
.separatorChar
+ libinstances
[i
].getName() + ".lib";
567 PropertyManager
.setProperty("LIBS", propertyLibs
.replaceAll("(\\\\)", "/"));
570 // Get all includepath and set to INCLUDE_PATHS
572 String
[] includes
= prepareIncludePaths(fpdModuleId
);
575 // if it is CUSTOM_BUILD
576 // then call the exist BaseName_build.xml directly.
578 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
579 System
.out
.println("Call user-defined " + moduleId
.getName() + "_build.xml");
581 String antFilename
= getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
582 antCall(antFilename
, null);
588 // Generate ${BASE_NAME}_build.xml
591 String ffsKeyword
= SurfaceAreaQuery
.getModuleFfsKeyword();
592 ModuleBuildFileGenerator fileGenerator
= new ModuleBuildFileGenerator(getProject(), ffsKeyword
, fpdModuleId
, includes
);
593 String buildFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
594 fileGenerator
.genBuildFile(buildFilename
);
597 // Ant call ${BASE_NAME}_build.xml
599 String antFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
600 antCall(antFilename
, null);
603 private void applyClean(FpdModuleIdentification fpdModuleId
){
605 // if it is CUSTOM_BUILD
606 // then call the exist BaseName_build.xml directly.
608 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
609 System
.out
.println("Calling user-defined " + moduleId
.getName() + "_build.xml");
611 String antFilename
= getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
612 antCall(antFilename
, "clean");
617 String antFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
618 antCall(antFilename
, "clean");
621 private void applyCleanall(FpdModuleIdentification fpdModuleId
){
623 // if it is CUSTOM_BUILD
624 // then call the exist BaseName_build.xml directly.
626 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
627 System
.out
.println("Calling user-defined " + moduleId
.getName() + "_build.xml");
629 String antFilename
= getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
630 antCall(antFilename
, "cleanall");
635 String antFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
636 antCall(antFilename
, "cleanall");
639 private void antCall(String antFilename
, String target
) {
641 ant
.setProject(getProject());
642 ant
.setAntfile(antFilename
);
643 if (target
!= null) {
644 ant
.setTarget(target
);
646 ant
.setInheritAll(true);
653 Separate the string and instore in set.
655 <p> String is separated by Java Regulation Expression
656 "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
661 "/nologo", "/W3", "/WX"
662 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
665 @param set store the separated string
666 @param str string to separate
668 private void putFlagsToSet(Set
<String
> set
, String str
) {
669 if (str
== null || str
.length() == 0) {
673 Pattern myPattern
= Pattern
.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
674 Matcher matcher
= myPattern
.matcher(str
+ " ");
675 while (matcher
.find()) {
676 String item
= str
.substring(matcher
.start(1), matcher
.end(1));
682 Generate the final flags string will be used by compile command.
684 @param add the add flags set
685 @param sub the sub flags set
686 @return final flags after add set substract sub set
688 private String
getFlags(Set
<String
> add
, Set
<String
> sub
) {
691 Iterator iter
= add
.iterator();
692 while (iter
.hasNext()) {
693 String str
= (String
) iter
.next();
694 result
+= str
.substring(1, str
.length() - 1) + " ";
699 public void setSingleModuleBuild(boolean isSingleModuleBuild
) {
700 this.isSingleModuleBuild
= isSingleModuleBuild
;
703 private String
[] prepareIncludePaths(FpdModuleIdentification fpdModuleId
) {
705 // Prepare the includes: PackageDependencies and Output debug direactory
707 Set
<String
> includes
= new LinkedHashSet
<String
>();
708 String arch
= fpdModuleId
.getArch();
713 includes
.add("${WORKSPACE_DIR}" + File
.separatorChar
);
718 includes
.add("${MODULE_DIR}");
719 includes
.add("${MODULE_DIR}" + File
.separatorChar
+ archDir(arch
));
722 // Packages in PackageDenpendencies
724 PackageIdentification
[] packageDependencies
= SurfaceAreaQuery
.getDependencePkg(fpdModuleId
.getArch());
725 for (int i
= 0; i
< packageDependencies
.length
; i
++) {
726 GlobalData
.refreshPackageIdentification(packageDependencies
[i
]);
727 File packageFile
= packageDependencies
[i
].getSpdFile();
728 includes
.add(packageFile
.getParent() + File
.separatorChar
+ "Include");
729 includes
.add(packageFile
.getParent() + File
.separatorChar
+ "Include" + File
.separatorChar
+ archDir(arch
));
733 // All Dependency Library Instance's PackageDependencies
735 ModuleIdentification
[] libinstances
= SurfaceAreaQuery
.getLibraryInstance(fpdModuleId
.getArch());
736 for (int i
= 0; i
< libinstances
.length
; i
++) {
737 SurfaceAreaQuery
.push(GlobalData
.getDoc(libinstances
[i
], fpdModuleId
.getArch()));
738 PackageIdentification
[] libraryPackageDependencies
= SurfaceAreaQuery
.getDependencePkg(fpdModuleId
.getArch());
739 for (int j
= 0; j
< libraryPackageDependencies
.length
; j
++) {
740 GlobalData
.refreshPackageIdentification(libraryPackageDependencies
[j
]);
741 File packageFile
= libraryPackageDependencies
[j
].getSpdFile();
742 includes
.add(packageFile
.getParent() + File
.separatorChar
+ "Include");
743 includes
.add(packageFile
.getParent() + File
.separatorChar
+ "Include" + File
.separatorChar
+ archDir(arch
));
745 SurfaceAreaQuery
.pop();
750 // The package which the module belongs to
752 includes
.add(fpdModuleId
.getModule().getPackage().getPackageDir() + File
.separatorChar
+ "Include");
753 includes
.add(fpdModuleId
.getModule().getPackage().getPackageDir() + File
.separatorChar
+ "Include" + File
.separatorChar
+ archDir(arch
));
756 // Debug files output directory
758 includes
.add("${DEST_DIR_DEBUG}");
761 // set to INCLUDE_PATHS property
763 Iterator
<String
> iter
= includes
.iterator();
764 StringBuffer includePaths
= new StringBuffer();
765 while (iter
.hasNext()) {
766 includePaths
.append(iter
.next());
767 includePaths
.append("; ");
769 PropertyManager
.setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths
.toString()).replaceAll("(\\\\)", "/"));
771 return includes
.toArray(new String
[includes
.size()]);
775 Return the name of the directory that corresponds to the architecture.
776 This is a translation from the XML Schema tag to a directory that
777 corresponds to our directory name coding convention.
780 private String
archDir(String arch
) {
781 return arch
.replaceFirst("X64", "x64")
782 .replaceFirst("IPF", "Ipf")
783 .replaceFirst("IA32", "Ia32")
784 .replaceFirst("ARM", "Arm")
785 .replaceFirst("EBC", "Ebc");