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
.ArrayList
;
20 import java
.util
.Hashtable
;
21 import java
.util
.Iterator
;
22 import java
.util
.LinkedHashSet
;
23 import java
.util
.List
;
26 import java
.util
.Stack
;
27 import java
.util
.Vector
;
28 import java
.util
.regex
.Matcher
;
29 import java
.util
.regex
.Pattern
;
31 import org
.apache
.tools
.ant
.BuildException
;
32 import org
.apache
.tools
.ant
.taskdefs
.Ant
;
33 import org
.apache
.tools
.ant
.taskdefs
.Property
;
34 import org
.apache
.xmlbeans
.XmlObject
;
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
.SurfaceAreaQuery
;
42 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
43 import org
.tianocore
.build
.id
.ModuleIdentification
;
44 import org
.tianocore
.build
.id
.PackageIdentification
;
45 import org
.tianocore
.build
.id
.PlatformIdentification
;
46 import org
.tianocore
.build
.tools
.ModuleItem
;
47 import org
.tianocore
.exception
.EdkException
;
48 import org
.tianocore
.logger
.EdkLog
;
52 <code>GenBuildTask</code> is an ANT task that can be used in ANT build
53 system. The main function of this task is to parse module's surface area,
54 then generate the corresponding <em>BaseName_build.xml</em> (the real ANT
55 build script) and call this to build the module. The whole process including:
56 1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances;
57 3. build all source files inlcude AutoGen.c; 4. generate sections;
58 5. generate FFS file if it is driver module while LIB file if it is Library module.
62 The usage is (take module <em>HelloWorld</em> for example):
67 msaFilename="HelloWorld.msa"/>
68 processTo="ALL"/>
71 <p><code>processTo</code> provides a way to customize the whole build process.
72 processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE.
73 Default is ALL, means whole
77 This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and
78 <em>AutoGen.h</em>. The task also parses the development environment
79 configuration files, such as collecting package information, setting compiler
86 public class GenBuildTask
extends Ant
{
89 /// Module surface area file.
96 private String type
= "all"; // = "build";
99 /// Module's Identification.
101 private ModuleIdentification moduleId
;
103 private Vector
<Property
> properties
= new Vector
<Property
>();
105 private static Stack
<Hashtable
> backupPropertiesStack
= new Stack
<Hashtable
>();
107 private boolean isSingleModuleBuild
= false;
110 Public construct method. It is necessary for ANT task.
112 public GenBuildTask() {
117 @throws BuildException
118 From module build, exception from module surface area invalid.
120 public void execute() throws BuildException
{
124 GenBuildLogger logger
= new GenBuildLogger(getProject());
125 EdkLog
.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
126 EdkLog
.setLogger(logger
);
131 // Enable all specified properties
133 Iterator
<Property
> iter
= properties
.iterator();
134 while (iter
.hasNext()) {
135 Property item
= iter
.next();
136 getProject().setProperty(item
.getName(), item
.getValue());
140 // GenBuild should specify either msaFile or moduleGuid & packageGuid
142 if (msaFile
== null ) {
143 String moduleGuid
= getProject().getProperty("MODULE_GUID");
144 String moduleVersion
= getProject().getProperty("MODULE_VERSION");
145 String packageGuid
= getProject().getProperty("PACKAGE_GUID");
146 String packageVersion
= getProject().getProperty("PACKAGE_VERSION");
147 if (moduleGuid
== null || packageGuid
== null) {
148 throw new BuildException("GenBuild parameters error. ");
150 PackageIdentification packageId
= new PackageIdentification(packageGuid
, packageVersion
);
151 moduleId
= new ModuleIdentification(moduleGuid
, moduleVersion
);
152 moduleId
.setPackage(packageId
);
153 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(moduleId
);
154 SurfaceAreaQuery
.setDoc(doc
);
155 moduleId
= SurfaceAreaQuery
.getMsaHeader();
158 Map
<String
, XmlObject
> doc
= GlobalData
.getNativeMsa(msaFile
);
159 SurfaceAreaQuery
.setDoc(doc
);
160 moduleId
= SurfaceAreaQuery
.getMsaHeader();
162 String
[] producedLibraryClasses
= SurfaceAreaQuery
.getLibraryClasses("ALWAYS_PRODUCED",null);
163 if (producedLibraryClasses
.length
== 0) {
164 moduleId
.setLibrary(false);
167 moduleId
.setLibrary(true);
171 // Judge whether it is single module build or not
173 if (isSingleModuleBuild
) {
175 // Single Module build
177 prepareSingleModuleBuild();
181 // Platform build. Restore the platform related info
183 String filename
= getProject().getProperty("PLATFORM_FILE");
184 PlatformIdentification platformId
= GlobalData
.getPlatform(filename
);
185 getProject().setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
186 getProject().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 : intersection MSA supported ARCHs and tools def!!
196 // else, get arch from pass down
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
]);
217 archSet
= archListSupByToolChain
;
220 String
[] archList
= archSet
.toArray(new String
[archSet
.size()]);
223 // Judge if arch is all supported by current module. If not, throw Exception.
225 List moduleSupportedArchs
= SurfaceAreaQuery
.getModuleSupportedArchs();
226 if (moduleSupportedArchs
!= null) {
227 for (int k
= 0; k
< archList
.length
; k
++) {
228 if ( ! moduleSupportedArchs
.contains(archList
[k
])) {
229 throw new BuildException("ARCH [" + archList
[k
] + "] is not supported by " + moduleId
+ ". " + moduleId
+ " only supports [" + moduleSupportedArchs
+ "].");
234 for (int k
= 0; k
< archList
.length
; k
++) {
236 getProject().setProperty("ARCH", archList
[k
]);
238 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, archList
[k
]);
241 // Whether the module is built before
243 if (moduleId
.isLibrary() == false && GlobalData
.hasFpdModuleSA(fpdModuleId
) == false) {
244 System
.out
.println("\nWARNING: " + moduleId
+ " for " + archList
[k
] + " is not found in current platform\n");
246 } else if (GlobalData
.isModuleBuilt(fpdModuleId
)) {
249 GlobalData
.registerBuiltModule(fpdModuleId
);
253 // For Every TOOLCHAIN, TARGET
255 String
[] targetList
= GlobalData
.getToolChainInfo().getTargets();
256 for (int i
= 0; i
< targetList
.length
; i
++){
258 // Prepare for target related common properties
261 getProject().setProperty("TARGET", targetList
[i
]);
262 String
[] toolchainList
= GlobalData
.getToolChainInfo().getTagnames();
263 for(int j
= 0; j
< toolchainList
.length
; j
++){
265 // check if any tool is defined for current target + toolchain + arch
266 // don't do anything if no tools found
268 if (GlobalData
.isCommandSet(targetList
[i
], toolchainList
[j
], archList
[k
]) == false) {
269 System
.out
.println("Warning: No build issued. No tools found for [target=" + targetList
[i
] + " toolchain=" + toolchainList
[j
] + " arch=" + archList
[k
] + "]\n");
274 // Prepare for toolchain related common properties
277 getProject().setProperty("TOOLCHAIN", toolchainList
[j
]);
279 System
.out
.println("Build " + moduleId
+ " start >>>");
280 System
.out
.println("Target: " + targetList
[i
] + " Tagname: " + toolchainList
[j
] + " Arch: " + archList
[k
]);
281 SurfaceAreaQuery
.setDoc(GlobalData
.getDoc(fpdModuleId
));
284 // Prepare for all other common properties
285 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
286 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
287 // MODULE_DIR, MODULE_RELATIVE_DIR
288 // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH
289 // LIBS, OBJECTS, SDB_FILES
291 setModuleCommonProperties(archList
[k
]);
294 // OutputManage prepare for
295 // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
297 OutputManager
.getInstance().update(getProject());
299 if (type
.equalsIgnoreCase("all") || type
.equalsIgnoreCase("build")) {
300 applyBuild(targetList
[i
], toolchainList
[j
], fpdModuleId
);
302 else if (type
.equalsIgnoreCase("clean")) {
303 applyClean(fpdModuleId
);
305 else if (type
.equalsIgnoreCase("cleanall")) {
306 applyCleanall(fpdModuleId
);
312 }catch (Exception e
){
313 throw new BuildException(e
.getMessage());
318 This method is used to prepare Platform-related information.
320 <p>In Single Module Build mode, platform-related information is not ready.
321 The method read the system environment variable <code>ACTIVE_PLATFORM</code>
322 and search in the Framework Database. Note that platform name in the Framework
323 Database must be unique. </p>
326 private void prepareSingleModuleBuild(){
328 // Find out the package which the module belongs to
329 // TBD: Enhance it!!!!
331 PackageIdentification packageId
= GlobalData
.getPackageForModule(moduleId
);
333 moduleId
.setPackage(packageId
);
336 // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)
338 String filename
= getProject().getProperty("PLATFORM_FILE");
340 if (filename
== null){
341 throw new BuildException("Plese set ACTIVE_PLATFORM if you want to build a single module. ");
344 PlatformIdentification platformId
= GlobalData
.getPlatform(filename
);
349 FpdParserTask fpdParser
= new FpdParserTask();
350 fpdParser
.setProject(getProject());
351 fpdParser
.parseFpdFile(platformId
.getFpdFile());
354 // Prepare for Platform related common properties
355 // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
357 getProject().setProperty("PLATFORM", platformId
.getName());
358 getProject().setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
359 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
364 Set Module-Related information to properties.
366 private void setModuleCommonProperties(String arch
) {
368 // Prepare for all other common properties
369 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
371 PackageIdentification packageId
= moduleId
.getPackage();
372 getProject().setProperty("PACKAGE", packageId
.getName());
373 getProject().setProperty("PACKAGE_GUID", packageId
.getGuid());
374 getProject().setProperty("PACKAGE_VERSION", packageId
.getVersion());
375 getProject().setProperty("PACKAGE_DIR", packageId
.getPackageDir().replaceAll("(\\\\)", "/"));
376 getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId
.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
379 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
380 // MODULE_DIR, MODULE_RELATIVE_DIR
382 getProject().setProperty("MODULE", moduleId
.getName());
383 String baseName
= SurfaceAreaQuery
.getModuleOutputFileBasename();
384 if (baseName
== null) {
385 getProject().setProperty("BASE_NAME", moduleId
.getName());
388 getProject().setProperty("BASE_NAME", baseName
);
390 getProject().setProperty("GUID", moduleId
.getGuid());
391 getProject().setProperty("FILE_GUID", moduleId
.getGuid());
392 getProject().setProperty("VERSION", moduleId
.getVersion());
393 getProject().setProperty("MODULE_TYPE", moduleId
.getModuleType());
394 getProject().setProperty("MODULE_DIR", moduleId
.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
395 getProject().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 getProject().setProperty("SUBSYSTEM", subsystem
);
426 if (arch
.equalsIgnoreCase("EBC")) {
427 getProject().setProperty("ENTRYPOINT", "EfiStart");
430 getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");
434 // LIBS, OBJECTS, SDB_FILES
436 getProject().setProperty("OBJECTS", "");
437 getProject().setProperty("SDB_FILES", "");
438 getProject().setProperty("LIBS", "");
441 private void getCompilerFlags(String target
, String toolchain
, FpdModuleIdentification fpdModuleId
) throws EdkException
{
442 String
[] cmd
= GlobalData
.getToolChainInfo().getCommands();
443 for ( int m
= 0; m
< cmd
.length
; m
++) {
445 // Set cmd, like CC, DLINK
447 String
[] key
= new String
[]{target
, toolchain
, fpdModuleId
.getArch(), cmd
[m
], null};
449 String cmdPath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
451 String cmdName
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
452 File cmdFile
= new File(cmdPath
+ File
.separatorChar
+ cmdName
);
453 getProject().setProperty(cmd
[m
], cmdFile
.getPath().replaceAll("(\\\\)", "/"));
459 String cmdFlags
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
460 Set
<String
> addset
= new LinkedHashSet
<String
>();
461 Set
<String
> subset
= new LinkedHashSet
<String
>();
462 putFlagsToSet(addset
, cmdFlags
);
463 getProject().setProperty(cmd
[m
] + "_FLAGS", getProject().replaceProperties(getFlags(addset
, subset
)));
469 String extName
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
470 if ( extName
!= null && ! extName
.equalsIgnoreCase("")) {
471 getProject().setProperty(cmd
[m
] + "_EXT", extName
);
474 getProject().setProperty(cmd
[m
] + "_EXT", "");
481 String toolChainFamily
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
482 if (toolChainFamily
!= null) {
483 getProject().setProperty(cmd
[m
] + "_FAMILY", toolChainFamily
);
490 String spath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
492 getProject().setProperty(cmd
[m
] + "_SPATH", spath
.replaceAll("(\\\\)", "/"));
495 getProject().setProperty(cmd
[m
] + "_SPATH", "");
502 String dpath
= GlobalData
.getCommandSetting(key
, fpdModuleId
);
504 getProject().setProperty(cmd
[m
] + "_DPATH", dpath
.replaceAll("(\\\\)", "/"));
507 getProject().setProperty(cmd
[m
] + "_DPATH", "");
512 public void setMsaFile(File msaFile
) {
513 this.msaFile
= msaFile
;
517 Method is for ANT to initialize MSA file.
519 @param msaFilename MSA file name
521 public void setMsaFile(String msaFilename
) {
522 String moduleDir
= getProject().getProperty("MODULE_DIR");
525 // If is Single Module Build, then use the Base Dir defined in build.xml
527 if (moduleDir
== null) {
528 moduleDir
= getProject().getBaseDir().getPath();
530 msaFile
= new File(moduleDir
+ File
.separatorChar
+ msaFilename
);
533 public void addConfiguredModuleItem(ModuleItem moduleItem
) {
534 PackageIdentification packageId
= new PackageIdentification(moduleItem
.getPackageGuid(), moduleItem
.getPackageVersion());
535 ModuleIdentification moduleId
= new ModuleIdentification(moduleItem
.getModuleGuid(), moduleItem
.getModuleVersion());
536 moduleId
.setPackage(packageId
);
537 this.moduleId
= moduleId
;
545 public void addProperty(Property p
) {
546 properties
.addElement(p
);
549 public void setType(String type
) {
553 private void applyBuild(String buildTarget
, String buildTagname
, FpdModuleIdentification fpdModuleId
) throws EdkException
{
558 AutoGen autogen
= new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId
.getModule(),fpdModuleId
.getArch());
559 autogen
.genAutogen();
563 // Get compiler flags
565 getCompilerFlags(buildTarget
, buildTagname
, fpdModuleId
);
570 ModuleIdentification
[] libinstances
= SurfaceAreaQuery
.getLibraryInstance(fpdModuleId
.getArch());
571 String propertyLibs
= "";
572 for (int i
= 0; i
< libinstances
.length
; i
++) {
573 propertyLibs
+= " " + getProject().getProperty("BIN_DIR") + File
.separatorChar
+ libinstances
[i
].getName() + ".lib";
575 getProject().setProperty("LIBS", propertyLibs
.replaceAll("(\\\\)", "/"));
578 // if it is CUSTOM_BUILD
579 // then call the exist BaseName_build.xml directly.
581 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
582 GlobalData
.log
.info("Call user-defined " + moduleId
.getName() + "_build.xml");
584 ant
.setProject(getProject());
585 ant
.setAntfile(getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml");
586 ant
.setInheritAll(true);
593 // Generate ${BASE_NAME}_build.xml
596 String ffsKeyword
= SurfaceAreaQuery
.getModuleFfsKeyword();
597 ModuleBuildFileGenerator fileGenerator
= new ModuleBuildFileGenerator(getProject(), ffsKeyword
, fpdModuleId
);
598 String buildFilename
= getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml";
599 fileGenerator
.genBuildFile(buildFilename
);
602 // Ant call ${BASE_NAME}_build.xml
605 ant
.setProject(getProject());
606 ant
.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml");
607 ant
.setInheritAll(true);
612 private void applyClean(FpdModuleIdentification fpdModuleId
){
614 // if it is CUSTOM_BUILD
615 // then call the exist BaseName_build.xml directly.
617 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
618 GlobalData
.log
.info("Call user-defined " + moduleId
.getName() + "_build.xml");
620 ant
.setProject(getProject());
621 ant
.setAntfile(getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml");
622 ant
.setTarget("clean");
623 ant
.setInheritAll(true);
630 ant
.setProject(getProject());
631 ant
.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml");
632 ant
.setTarget("clean");
633 ant
.setInheritAll(true);
638 // Delete current module's DEST_DIR_OUTPUT
642 private void applyCleanall(FpdModuleIdentification fpdModuleId
){
644 // if it is CUSTOM_BUILD
645 // then call the exist BaseName_build.xml directly.
647 if (moduleId
.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
648 GlobalData
.log
.info("Call user-defined " + moduleId
.getName() + "_build.xml");
650 ant
.setProject(getProject());
651 ant
.setAntfile(getProject().getProperty("MODULE_DIR") + File
.separatorChar
+ moduleId
.getName() + "_build.xml");
652 ant
.setTarget("cleanall");
653 ant
.setInheritAll(true);
660 ant
.setProject(getProject());
661 ant
.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File
.separatorChar
+ moduleId
.getName() + "_build.xml");
662 ant
.setTarget("cleanall");
663 ant
.setInheritAll(true);
668 // Delete current module's DEST_DIR_OUTPUT
676 Separate the string and instore in set.
678 <p> String is separated by Java Regulation Expression
679 "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
684 "/nologo", "/W3", "/WX"
685 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
688 @param set store the separated string
689 @param str string to separate
691 private void putFlagsToSet(Set
<String
> set
, String str
) {
692 if (str
== null || str
.length() == 0) {
696 Pattern myPattern
= Pattern
.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
697 Matcher matcher
= myPattern
.matcher(str
+ " ");
698 while (matcher
.find()) {
699 String item
= str
.substring(matcher
.start(1), matcher
.end(1));
705 Generate the final flags string will be used by compile command.
707 @param add the add flags set
708 @param sub the sub flags set
709 @return final flags after add set substract sub set
711 private String
getFlags(Set
<String
> add
, Set
<String
> sub
) {
714 Iterator iter
= add
.iterator();
715 while (iter
.hasNext()) {
716 String str
= (String
) iter
.next();
717 result
+= str
.substring(1, str
.length() - 1) + " ";
723 Generate the flags string with original format. The format is defined by
724 Java Regulation Expression "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
729 "/nologo", "/W3", "/WX"
730 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
733 @param add the add flags set
734 @param sub the sub flags set
735 @return flags with original format
737 private String
getRawFlags(Set
<String
> add
, Set
<String
> sub
) {
738 String result
= null;
740 Iterator iter
= add
.iterator();
741 while (iter
.hasNext()) {
742 String str
= (String
) iter
.next();
743 result
+= "\"" + str
.substring(1, str
.length() - 1) + "\", ";
748 private String
parseOptionString(String optionString
, Set
<String
> addSet
, Set
<String
> subSet
) {
749 boolean overrideOption
= false;
750 Pattern pattern
= Pattern
.compile("ADD\\.\\[(.+)\\]");
751 Matcher matcher
= pattern
.matcher(optionString
);
753 while (matcher
.find()) {
754 overrideOption
= true;
755 String addOption
= optionString
.substring(matcher
.start(1), matcher
.end(1)).trim();
756 putFlagsToSet(addSet
, addOption
);
760 pattern
= Pattern
.compile("SUB\\.\\[(.+)\\]");
761 matcher
= pattern
.matcher(optionString
);
763 while (matcher
.find()) {
764 overrideOption
= true;
765 String subOption
= optionString
.substring(matcher
.start(1), matcher
.end(1)).trim();
766 putFlagsToSet(subSet
, subOption
);
769 if (overrideOption
== true) {
776 private void pushProperties() {
777 backupPropertiesStack
.push(getProject().getProperties());
780 private void popProperties() {
781 Hashtable backupProperties
= backupPropertiesStack
.pop();
782 Set keys
= backupProperties
.keySet();
783 Iterator iter
= keys
.iterator();
784 while (iter
.hasNext()) {
785 String item
= (String
)iter
.next();
786 getProject().setProperty(item
, (String
)backupProperties
.get(item
));
790 public void setSingleModuleBuild(boolean isSingleModuleBuild
) {
791 this.isSingleModuleBuild
= isSingleModuleBuild
;