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 public ModuleIdentification parentId
;
103 private String type
= "all";
106 /// Module's Identification.
108 private ModuleIdentification moduleId
;
110 private Vector
<Property
> properties
= new Vector
<Property
>();
112 private boolean isSingleModuleBuild
= false;
114 private SurfaceAreaQuery saq
= null;
117 Public construct method. It is necessary for ANT task.
119 public GenBuildTask() {
124 @throws BuildException
125 From module build, exception from module surface area invalid.
127 public void execute() throws BuildException
{
131 GenBuildLogger logger
= new GenBuildLogger(getProject());
132 EdkLog
.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
133 EdkLog
.setLogger(logger
);
135 PropertyManager
.setProject(getProject());
136 PropertyManager
.save();
138 // Enable all specified properties
140 Iterator
<Property
> iter
= properties
.iterator();
141 while (iter
.hasNext()) {
142 Property item
= iter
.next();
143 PropertyManager
.setProperty(item
.getName(), item
.getValue());
147 // GenBuild should specify either msaFile or moduleGuid & packageGuid
149 if (msaFile
== null ) {
150 String moduleGuid
= getProject().getProperty("MODULE_GUID");
151 String moduleVersion
= getProject().getProperty("MODULE_VERSION");
152 String packageGuid
= getProject().getProperty("PACKAGE_GUID");
153 String packageVersion
= getProject().getProperty("PACKAGE_VERSION");
154 if (moduleGuid
== null || packageGuid
== null) {
155 throw new BuildException("GenBuild parameter error.");
157 PackageIdentification packageId
= new PackageIdentification(packageGuid
, packageVersion
);
158 moduleId
= new ModuleIdentification(moduleGuid
, moduleVersion
);
159 moduleId
.setPackage(packageId
);
160 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(moduleId
);
161 saq
= new SurfaceAreaQuery(doc
);
162 moduleId
= saq
.getMsaHeader();
164 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(msaFile
);
165 saq
= new SurfaceAreaQuery(doc
);
166 moduleId
= saq
.getMsaHeader();
168 String
[] producedLibraryClasses
= saq
.getLibraryClasses("ALWAYS_PRODUCED",null);
169 if (producedLibraryClasses
.length
== 0) {
170 moduleId
.setLibrary(false);
172 moduleId
.setLibrary(true);
176 // Judge whether it is single module build or not
178 if (isSingleModuleBuild
) {
180 // Single Module build
182 prepareSingleModuleBuild();
185 // Platform build. Restore the platform related info
187 String filename
= getProject().getProperty("PLATFORM_FILE");
188 PlatformIdentification platformId
= GlobalData
.getPlatform(filename
);
189 PropertyManager
.setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
190 PropertyManager
.setProperty("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
192 String packageGuid
= getProject().getProperty("PACKAGE_GUID");
193 String packageVersion
= getProject().getProperty("PACKAGE_VERSION");
194 PackageIdentification packageId
= new PackageIdentification(packageGuid
, packageVersion
);
195 moduleId
.setPackage(packageId
);
199 // If single module : get arch from pass down, otherwise intersection MSA
200 // supported ARCHs and tools def
202 Set
<String
> archListSupByToolChain
= new LinkedHashSet
<String
>();
203 String
[] archs
= GlobalData
.getToolChainInfo().getArchs();
205 for (int i
= 0; i
< archs
.length
; i
++) {
206 archListSupByToolChain
.add(archs
[i
]);
209 Set
<String
> archSet
= new LinkedHashSet
<String
>();
211 if ( getProject().getProperty("ARCH") != null) {
212 String
[] fpdArchList
= getProject().getProperty("ARCH").split(" ");
214 for (int i
= 0; i
< fpdArchList
.length
; i
++) {
215 if (archListSupByToolChain
.contains(fpdArchList
[i
])) {
216 archSet
.add(fpdArchList
[i
]);
220 archSet
= archListSupByToolChain
;
223 String
[] archList
= archSet
.toArray(new String
[archSet
.size()]);
226 // Judge if arch is all supported by current module. If not, throw Exception.
228 List moduleSupportedArchs
= saq
.getModuleSupportedArchs();
229 if (moduleSupportedArchs
!= null) {
230 for (int k
= 0; k
< archList
.length
; k
++) {
231 if ( ! moduleSupportedArchs
.contains(archList
[k
])) {
232 throw new BuildException("Specified architecture [" + archList
[k
] + "] is not supported by " + moduleId
+ ". The module " + moduleId
+ " only supports [" + moduleSupportedArchs
+ "] architectures.");
237 for (int k
= 0; k
< archList
.length
; k
++) {
239 PropertyManager
.setProperty("ARCH", archList
[k
]);
241 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, archList
[k
]);
244 // Whether the module is built before
246 if (moduleId
.isLibrary() == false && GlobalData
.hasFpdModuleSA(fpdModuleId
) == false) {
247 System
.out
.println("\nWARNING: " + moduleId
+ " for " + archList
[k
] + " was not found in current platform FPD file!\n");
249 } else if (GlobalData
.isModuleBuilt(fpdModuleId
)) {
252 GlobalData
.registerBuiltModule(fpdModuleId
);
256 // For Every TOOLCHAIN, TARGET
258 String
[] targetList
= GlobalData
.getToolChainInfo().getTargets();
259 for (int i
= 0; i
< targetList
.length
; i
++){
261 // Prepare for target related common properties
264 PropertyManager
.setProperty("TARGET", targetList
[i
]);
265 String
[] toolchainList
= GlobalData
.getToolChainInfo().getTagnames();
266 for(int j
= 0; j
< toolchainList
.length
; j
++){
268 // check if any tool is defined for current target + toolchain + arch
269 // don't do anything if no tools found
271 if (GlobalData
.isCommandSet(targetList
[i
], toolchainList
[j
], archList
[k
]) == false) {
272 System
.out
.println("Warning: No build issued. No tools were found for [target=" + targetList
[i
] + " toolchain=" + toolchainList
[j
] + " arch=" + archList
[k
] + "]\n");
277 // Prepare for toolchain related common properties
280 PropertyManager
.setProperty("TOOLCHAIN", toolchainList
[j
]);
282 System
.out
.println("Build " + moduleId
+ " start >>>");
283 System
.out
.println("Target: " + targetList
[i
] + " Tagname: " + toolchainList
[j
] + " Arch: " + archList
[k
]);
284 saq
.push(GlobalData
.getDoc(fpdModuleId
));
287 // Prepare for all other common properties
288 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
289 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
290 // MODULE_DIR, MODULE_RELATIVE_DIR
291 // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH
293 setModuleCommonProperties(archList
[k
]);
296 // OutputManage prepare for
297 // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
299 OutputManager
.getInstance().update(getProject());
301 if (type
.equalsIgnoreCase("all") || type
.equalsIgnoreCase("build")) {
302 applyBuild(targetList
[i
], toolchainList
[j
], fpdModuleId
);
303 } else if (type
.equalsIgnoreCase("clean")) {
304 applyClean(fpdModuleId
);
305 } else if (type
.equalsIgnoreCase("cleanall")) {
306 applyCleanall(fpdModuleId
);
312 PropertyManager
.restore();
316 This method is used to prepare Platform-related information.
318 <p>In Single Module Build mode, platform-related information is not ready.
319 The method read the system environment variable <code>ACTIVE_PLATFORM</code>
320 and search in the Framework Database. Note that platform name in the Framework
321 Database must be unique. </p>
324 private void prepareSingleModuleBuild(){
326 // Find out the package which the module belongs to
327 // TBD: Enhance it!!!!
329 PackageIdentification packageId
= GlobalData
.getPackageForModule(moduleId
);
331 moduleId
.setPackage(packageId
);
334 // Read ACTIVE_PLATFORM's FPD file
336 String filename
= getProject().getProperty("PLATFORM_FILE");
338 if (filename
== null){
339 throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!");
342 PlatformIdentification platformId
= GlobalData
.getPlatform(filename
);
345 // Read FPD file (Call FpdParserTask's method)
347 FpdParserTask fpdParser
= new FpdParserTask();
348 fpdParser
.setProject(getProject());
349 fpdParser
.parseFpdFile(platformId
.getFpdFile());
350 PropertyManager
.setProperty("ARCH", fpdParser
.getAllArchForModule(moduleId
));
353 // Prepare for Platform related common properties
354 // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
356 PropertyManager
.setProperty("PLATFORM", platformId
.getName());
357 PropertyManager
.setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
358 PropertyManager
.setProperty("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
363 Set Module-Related information to properties.
365 @param arch current build ARCH
367 private void setModuleCommonProperties(String arch
) {
369 // Prepare for all other common properties
370 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
372 PackageIdentification packageId
= moduleId
.getPackage();
373 PropertyManager
.setProperty("PACKAGE", packageId
.getName());
374 PropertyManager
.setProperty("PACKAGE_GUID", packageId
.getGuid());
375 PropertyManager
.setProperty("PACKAGE_VERSION", packageId
.getVersion());
376 PropertyManager
.setProperty("PACKAGE_DIR", packageId
.getPackageDir().replaceAll("(\\\\)", "/"));
377 PropertyManager
.setProperty("PACKAGE_RELATIVE_DIR", packageId
.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
380 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
381 // MODULE_DIR, MODULE_RELATIVE_DIR
383 PropertyManager
.setProperty("MODULE", moduleId
.getName());
384 String baseName
= saq
.getModuleOutputFileBasename();
385 if (baseName
== null) {
386 PropertyManager
.setProperty("BASE_NAME", moduleId
.getName());
388 PropertyManager
.setProperty("BASE_NAME", baseName
);
390 PropertyManager
.setProperty("GUID", moduleId
.getGuid());
391 PropertyManager
.setProperty("FILE_GUID", moduleId
.getGuid());
392 PropertyManager
.setProperty("VERSION", moduleId
.getVersion());
393 PropertyManager
.setProperty("MODULE_TYPE", moduleId
.getModuleType());
394 PropertyManager
.setProperty("MODULE_DIR", moduleId
.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
395 PropertyManager
.setProperty("MODULE_RELATIVE_DIR", moduleId
.getModuleRelativePath().replaceAll("(\\\\)", "/"));
400 String
[][] subsystemMap
= { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},
401 { "SEC", "EFI_BOOT_SERVICE_DRIVER" },
402 { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },
403 { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },
404 { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },
405 { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
406 { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },
407 { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
408 { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
409 { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },
410 { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
411 { "UEFI_APPLICATION", "EFI_APPLICATION" },
412 { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };
414 String subsystem
= "EFI_BOOT_SERVICE_DRIVER";
415 for (int i
= 0; i
< subsystemMap
.length
; i
++) {
416 if (moduleId
.getModuleType().equalsIgnoreCase(subsystemMap
[i
][0])) {
417 subsystem
= subsystemMap
[i
][1];
421 PropertyManager
.setProperty("SUBSYSTEM", subsystem
);
426 if (arch
.equalsIgnoreCase("EBC")) {
427 PropertyManager
.setProperty("ENTRYPOINT", "EfiStart");
429 PropertyManager
.setProperty("ENTRYPOINT", "_ModuleEntryPoint");
432 PropertyManager
.setProperty("OBJECTS", "");
435 private void getCompilerFlags(String target
, String toolchain
, FpdModuleIdentification fpdModuleId
) throws EdkException
{
436 String
[] cmd
= GlobalData
.getToolChainInfo().getCommands();
437 for ( int m
= 0; m
< cmd
.length
; m
++) {
439 // Set cmd, like CC, DLINK
441 String
[] key
= new String
[]{target
, toolchain
, fpdModuleId
.getArch(), cmd
[m
], null};
442 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_PATH
;
443 String cmdPath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
444 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_NAME
;
445 String cmdName
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
446 File cmdFile
= new File(cmdPath
+ File
.separatorChar
+ cmdName
);
447 PropertyManager
.setProperty(cmd
[m
], cmdFile
.getPath().replaceAll("(\\\\)", "/"));
452 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
;
453 String cmdFlags
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
454 Set
<String
> addset
= new LinkedHashSet
<String
>();
455 Set
<String
> subset
= new LinkedHashSet
<String
>();
456 putFlagsToSet(addset
, cmdFlags
);
457 PropertyManager
.setProperty(cmd
[m
] + "_FLAGS", getProject().replaceProperties(getFlags(addset
, subset
)));
462 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_EXT
;
463 String extName
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
464 if ( extName
!= null && ! extName
.equalsIgnoreCase("")) {
465 PropertyManager
.setProperty(cmd
[m
] + "_EXT", extName
);
467 PropertyManager
.setProperty(cmd
[m
] + "_EXT", "");
473 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FAMILY
;
474 String toolChainFamily
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
475 if (toolChainFamily
!= null) {
476 PropertyManager
.setProperty(cmd
[m
] + "_FAMILY", toolChainFamily
);
482 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_SPATH
;
483 String spath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
485 PropertyManager
.setProperty(cmd
[m
] + "_SPATH", spath
.replaceAll("(\\\\)", "/"));
487 PropertyManager
.setProperty(cmd
[m
] + "_SPATH", "");
493 key
[4] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_DPATH
;
494 String dpath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
496 PropertyManager
.setProperty(cmd
[m
] + "_DPATH", dpath
.replaceAll("(\\\\)", "/"));
498 PropertyManager
.setProperty(cmd
[m
] + "_DPATH", "");
503 public void setMsaFile(File msaFile
) {
504 this.msaFile
= msaFile
;
508 Method is for ANT to initialize MSA file.
510 @param msaFilename MSA file name
512 public void setMsaFile(String msaFilename
) {
513 String moduleDir
= getProject().getProperty("MODULE_DIR");
516 // If is Single Module Build, then use the Base Dir defined in build.xml
518 if (moduleDir
== null) {
519 moduleDir
= getProject().getBaseDir().getPath();
521 msaFile
= new File(moduleDir
+ File
.separatorChar
+ msaFilename
);
524 public void addConfiguredModuleItem(ModuleItem moduleItem
) {
525 PackageIdentification packageId
= new PackageIdentification(moduleItem
.getPackageGuid(), moduleItem
.getPackageVersion());
526 ModuleIdentification moduleId
= new ModuleIdentification(moduleItem
.getModuleGuid(), moduleItem
.getModuleVersion());
527 moduleId
.setPackage(packageId
);
528 this.moduleId
= moduleId
;
536 public void addProperty(Property p
) {
537 properties
.addElement(p
);
540 public void setType(String type
) {
544 private void applyBuild(String buildTarget
, String buildTagname
, FpdModuleIdentification fpdModuleId
) throws BuildException
{
546 // Call AutoGen to generate AutoGen.c and AutoGen.h
548 AutoGen autogen
= new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId
.getModule(),fpdModuleId
.getArch(), saq
);
549 autogen
.genAutogen();
552 // Get compiler flags
555 getCompilerFlags(buildTarget
, buildTagname
, fpdModuleId
);
557 catch (EdkException ee
) {
558 throw new BuildException(ee
.getMessage());
564 ModuleIdentification
[] libinstances
= saq
.getLibraryInstance(fpdModuleId
.getArch());
565 String propertyLibs
= "";
566 for (int i
= 0; i
< libinstances
.length
; i
++) {
567 propertyLibs
+= " " + getProject().getProperty("BIN_DIR") + File
.separatorChar
+ libinstances
[i
].getName() + ".lib";
569 PropertyManager
.setProperty("LIBS", propertyLibs
.replaceAll("(\\\\)", "/"));
572 // Get all includepath and set to INCLUDE_PATHS
574 String
[] includes
= prepareIncludePaths(fpdModuleId
);
577 // if it is CUSTOM_BUILD
578 // then call the exist BaseName_build.xml directly.
580 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
581 System
.out
.println("Call user-defined " + moduleId
.getName() + "_build.xml");
583 String antFilename
= getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
584 antCall(antFilename
, null);
590 // Generate ${BASE_NAME}_build.xml
593 String ffsKeyword
= saq
.getModuleFfsKeyword();
594 ModuleBuildFileGenerator fileGenerator
= new ModuleBuildFileGenerator(getProject(), ffsKeyword
, fpdModuleId
, includes
, saq
);
595 String buildFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
596 fileGenerator
.genBuildFile(buildFilename
);
599 // Ant call ${BASE_NAME}_build.xml
601 String antFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
602 antCall(antFilename
, null);
605 private void applyClean(FpdModuleIdentification fpdModuleId
){
607 // if it is CUSTOM_BUILD
608 // then call the exist BaseName_build.xml directly.
610 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
611 System
.out
.println("Calling user-defined " + moduleId
.getName() + "_build.xml");
613 String antFilename
= getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
614 antCall(antFilename
, "clean");
619 String antFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
620 antCall(antFilename
, "clean");
623 private void applyCleanall(FpdModuleIdentification fpdModuleId
){
625 // if it is CUSTOM_BUILD
626 // then call the exist BaseName_build.xml directly.
628 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
629 System
.out
.println("Calling user-defined " + moduleId
.getName() + "_build.xml");
631 String antFilename
= getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
632 antCall(antFilename
, "cleanall");
637 String antFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
638 antCall(antFilename
, "cleanall");
641 private void antCall(String antFilename
, String target
) {
643 ant
.setProject(getProject());
644 ant
.setAntfile(antFilename
);
645 if (target
!= null) {
646 ant
.setTarget(target
);
648 ant
.setInheritAll(true);
655 Separate the string and instore in set.
657 <p> String is separated by Java Regulation Expression
658 "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
663 "/nologo", "/W3", "/WX"
664 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
667 @param set store the separated string
668 @param str string to separate
670 private void putFlagsToSet(Set
<String
> set
, String str
) {
671 if (str
== null || str
.length() == 0) {
675 Pattern myPattern
= Pattern
.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
676 Matcher matcher
= myPattern
.matcher(str
+ " ");
677 while (matcher
.find()) {
678 String item
= str
.substring(matcher
.start(1), matcher
.end(1));
684 Generate the final flags string will be used by compile command.
686 @param add the add flags set
687 @param sub the sub flags set
688 @return final flags after add set substract sub set
690 private String
getFlags(Set
<String
> add
, Set
<String
> sub
) {
693 Iterator iter
= add
.iterator();
694 while (iter
.hasNext()) {
695 String str
= (String
) iter
.next();
696 result
+= str
.substring(1, str
.length() - 1) + " ";
701 public void setSingleModuleBuild(boolean isSingleModuleBuild
) {
702 this.isSingleModuleBuild
= isSingleModuleBuild
;
705 private String
[] prepareIncludePaths(FpdModuleIdentification fpdModuleId
) {
707 // Prepare the includes: PackageDependencies and Output debug direactory
709 Set
<String
> includes
= new LinkedHashSet
<String
>();
710 String arch
= fpdModuleId
.getArch();
715 includes
.add("${WORKSPACE_DIR}" + File
.separatorChar
);
720 includes
.add("${MODULE_DIR}");
721 includes
.add("${MODULE_DIR}" + File
.separatorChar
+ archDir(arch
));
724 // Packages in PackageDenpendencies
726 PackageIdentification
[] packageDependencies
= saq
.getDependencePkg(fpdModuleId
.getArch());
727 for (int i
= 0; i
< packageDependencies
.length
; i
++) {
728 GlobalData
.refreshPackageIdentification(packageDependencies
[i
]);
729 File packageFile
= packageDependencies
[i
].getSpdFile();
730 includes
.add(packageFile
.getParent() + File
.separatorChar
+ "Include");
731 includes
.add(packageFile
.getParent() + File
.separatorChar
+ "Include" + File
.separatorChar
+ archDir(arch
));
735 // All Dependency Library Instance's PackageDependencies
737 ModuleIdentification
[] libinstances
= saq
.getLibraryInstance(fpdModuleId
.getArch());
738 for (int i
= 0; i
< libinstances
.length
; i
++) {
739 saq
.push(GlobalData
.getDoc(libinstances
[i
], fpdModuleId
.getArch()));
740 PackageIdentification
[] libraryPackageDependencies
= saq
.getDependencePkg(fpdModuleId
.getArch());
741 for (int j
= 0; j
< libraryPackageDependencies
.length
; j
++) {
742 GlobalData
.refreshPackageIdentification(libraryPackageDependencies
[j
]);
743 File packageFile
= libraryPackageDependencies
[j
].getSpdFile();
744 includes
.add(packageFile
.getParent() + File
.separatorChar
+ "Include");
745 includes
.add(packageFile
.getParent() + File
.separatorChar
+ "Include" + File
.separatorChar
+ archDir(arch
));
752 // The package which the module belongs to
754 includes
.add(fpdModuleId
.getModule().getPackage().getPackageDir() + File
.separatorChar
+ "Include");
755 includes
.add(fpdModuleId
.getModule().getPackage().getPackageDir() + File
.separatorChar
+ "Include" + File
.separatorChar
+ archDir(arch
));
758 // Debug files output directory
760 includes
.add("${DEST_DIR_DEBUG}");
763 // set to INCLUDE_PATHS property
765 Iterator
<String
> iter
= includes
.iterator();
766 StringBuffer includePaths
= new StringBuffer();
767 while (iter
.hasNext()) {
768 includePaths
.append(iter
.next());
769 includePaths
.append("; ");
771 PropertyManager
.setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths
.toString()).replaceAll("(\\\\)", "/"));
773 return includes
.toArray(new String
[includes
.size()]);
777 Return the name of the directory that corresponds to the architecture.
778 This is a translation from the XML Schema tag to a directory that
779 corresponds to our directory name coding convention.
782 private String
archDir(String arch
) {
783 return arch
.replaceFirst("X64", "x64")
784 .replaceFirst("IPF", "Ipf")
785 .replaceFirst("IA32", "Ia32")
786 .replaceFirst("ARM", "Arm")
787 .replaceFirst("EBC", "Ebc");
791 public void setExternalProperties(Vector
<Property
> v
) {