]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java
Remove dead code.
[mirror_edk2.git] / Tools / 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.Stack;
26 import java.util.Vector;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29
30 import org.apache.tools.ant.BuildException;
31 import org.apache.tools.ant.taskdefs.Ant;
32 import org.apache.tools.ant.taskdefs.Property;
33 import org.apache.xmlbeans.XmlObject;
34
35 import org.tianocore.common.exception.EdkException;
36 import org.tianocore.common.logger.EdkLog;
37 import org.tianocore.build.autogen.AutoGen;
38 import org.tianocore.build.fpd.FpdParserTask;
39 import org.tianocore.build.global.GenBuildLogger;
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
49 /**
50 <p>
51 <code>GenBuildTask</code> is an ANT task that can be used in ANT build
52 system. The main function of this task is to parse module's surface area,
53 then generate the corresponding <em>BaseName_build.xml</em> (the real ANT
54 build script) and call this to build the module. The whole process including:
55 1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances;
56 3. build all source files inlcude AutoGen.c; 4. generate sections;
57 5. generate FFS file if it is driver module while LIB file if it is Library module.
58 </p>
59
60 <p>
61 The usage is (take module <em>HelloWorld</em> for example):
62 </p>
63
64 <pre>
65 &lt;GenBuild
66 msaFilename=&quot;HelloWorld.msa&quot;/&gt;
67 processTo=&quot;ALL&quot;/&gt;
68 </pre>
69
70 <p><code>processTo</code> provides a way to customize the whole build process.
71 processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE.
72 Default is ALL, means whole
73 </p>
74
75 <p>
76 This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and
77 <em>AutoGen.h</em>. The task also parses the development environment
78 configuration files, such as collecting package information, setting compiler
79 flags and so on.
80 </p>
81
82
83 @since GenBuild 1.0
84 **/
85 public class GenBuildTask extends Ant {
86
87 ///
88 /// Module surface area file.
89 ///
90 File msaFile;
91
92 private String type = "all";
93
94 ///
95 /// Module's Identification.
96 ///
97 private ModuleIdentification moduleId;
98
99 private Vector<Property> properties = new Vector<Property>();
100
101 private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();
102
103 private boolean isSingleModuleBuild = false;
104
105 /**
106 Public construct method. It is necessary for ANT task.
107 **/
108 public GenBuildTask() {
109 }
110
111 /**
112
113 @throws BuildException
114 From module build, exception from module surface area invalid.
115 **/
116 public void execute() throws BuildException {
117 //
118 // set Logger
119 //
120 GenBuildLogger logger = new GenBuildLogger(getProject());
121 EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
122 EdkLog.setLogger(logger);
123
124 pushProperties();
125 //
126 // Enable all specified properties
127 //
128 Iterator<Property> iter = properties.iterator();
129 while (iter.hasNext()) {
130 Property item = iter.next();
131 getProject().setProperty(item.getName(), item.getValue());
132 }
133
134 //
135 // GenBuild should specify either msaFile or moduleGuid & packageGuid
136 //
137 if (msaFile == null ) {
138 String moduleGuid = getProject().getProperty("MODULE_GUID");
139 String moduleVersion = getProject().getProperty("MODULE_VERSION");
140 String packageGuid = getProject().getProperty("PACKAGE_GUID");
141 String packageVersion = getProject().getProperty("PACKAGE_VERSION");
142 if (moduleGuid == null || packageGuid == null) {
143 throw new BuildException("GenBuild parameter error.");
144 }
145 PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
146 moduleId = new ModuleIdentification(moduleGuid, moduleVersion);
147 moduleId.setPackage(packageId);
148 Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);
149 SurfaceAreaQuery.setDoc(doc);
150 moduleId = SurfaceAreaQuery.getMsaHeader();
151 } else {
152 Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);
153 SurfaceAreaQuery.setDoc(doc);
154 moduleId = SurfaceAreaQuery.getMsaHeader();
155 }
156 String[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED",null);
157 if (producedLibraryClasses.length == 0) {
158 moduleId.setLibrary(false);
159 } else {
160 moduleId.setLibrary(true);
161 }
162
163 //
164 // Judge whether it is single module build or not
165 //
166 if (isSingleModuleBuild) {
167 //
168 // Single Module build
169 //
170 prepareSingleModuleBuild();
171 } else {
172 //
173 // Platform build. Restore the platform related info
174 //
175 String filename = getProject().getProperty("PLATFORM_FILE");
176 PlatformIdentification platformId = GlobalData.getPlatform(filename);
177 getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
178 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
179
180 String packageGuid = getProject().getProperty("PACKAGE_GUID");
181 String packageVersion = getProject().getProperty("PACKAGE_VERSION");
182 PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
183 moduleId.setPackage(packageId);
184 }
185
186 //
187 // If single module : get arch from pass down, otherwise intersection MSA
188 // supported ARCHs and tools def
189 //
190 Set<String> archListSupByToolChain = new LinkedHashSet<String>();
191 String[] archs = GlobalData.getToolChainInfo().getArchs();
192
193 for (int i = 0; i < archs.length; i ++) {
194 archListSupByToolChain.add(archs[i]);
195 }
196
197 Set<String> archSet = new LinkedHashSet<String>();
198
199 if ( getProject().getProperty("ARCH") != null) {
200 String[] fpdArchList = getProject().getProperty("ARCH").split(" ");
201
202 for (int i = 0; i < fpdArchList.length; i++) {
203 if (archListSupByToolChain.contains(fpdArchList[i])) {
204 archSet.add(fpdArchList[i]);
205 }
206 }
207 } else {
208 archSet = archListSupByToolChain;
209 }
210
211 String[] archList = archSet.toArray(new String[archSet.size()]);
212
213 //
214 // Judge if arch is all supported by current module. If not, throw Exception.
215 //
216 List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs();
217 if (moduleSupportedArchs != null) {
218 for (int k = 0; k < archList.length; k++) {
219 if ( ! moduleSupportedArchs.contains(archList[k])) {
220 throw new BuildException("Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures.");
221 }
222 }
223 }
224
225 for (int k = 0; k < archList.length; k++) {
226
227 getProject().setProperty("ARCH", archList[k]);
228
229 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
230
231 //
232 // Whether the module is built before
233 //
234 if (moduleId.isLibrary() == false && GlobalData.hasFpdModuleSA(fpdModuleId) == false) {
235 System.out.println("\nWARNING: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");
236 continue;
237 } else if (GlobalData.isModuleBuilt(fpdModuleId)) {
238 return;
239 } else {
240 GlobalData.registerBuiltModule(fpdModuleId);
241 }
242
243 //
244 // For Every TOOLCHAIN, TARGET
245 //
246 String[] targetList = GlobalData.getToolChainInfo().getTargets();
247 for (int i = 0; i < targetList.length; i ++){
248 //
249 // Prepare for target related common properties
250 // TARGET
251 //
252 getProject().setProperty("TARGET", targetList[i]);
253 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
254 for(int j = 0; j < toolchainList.length; j ++){
255 //
256 // check if any tool is defined for current target + toolchain + arch
257 // don't do anything if no tools found
258 //
259 if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {
260 System.out.println("Warning: No build issued. No tools were found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");
261 continue;
262 }
263
264 //
265 // Prepare for toolchain related common properties
266 // TOOLCHAIN
267 //
268 getProject().setProperty("TOOLCHAIN", toolchainList[j]);
269
270 System.out.println("Build " + moduleId + " start >>>");
271 System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);
272 SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));
273
274 //
275 // Prepare for all other common properties
276 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
277 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
278 // MODULE_DIR, MODULE_RELATIVE_DIR
279 // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH
280 //
281 setModuleCommonProperties(archList[k]);
282
283 //
284 // OutputManage prepare for
285 // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
286 //
287 OutputManager.getInstance().update(getProject());
288
289 if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {
290 applyBuild(targetList[i], toolchainList[j], fpdModuleId);
291 } else if (type.equalsIgnoreCase("clean")) {
292 applyClean(fpdModuleId);
293 } else if (type.equalsIgnoreCase("cleanall")) {
294 applyCleanall(fpdModuleId);
295 }
296 }
297 }
298 }
299
300 popProperties();
301 }
302
303 /**
304 This method is used to prepare Platform-related information.
305
306 <p>In Single Module Build mode, platform-related information is not ready.
307 The method read the system environment variable <code>ACTIVE_PLATFORM</code>
308 and search in the Framework Database. Note that platform name in the Framework
309 Database must be unique. </p>
310
311 **/
312 private void prepareSingleModuleBuild(){
313 //
314 // Find out the package which the module belongs to
315 // TBD: Enhance it!!!!
316 //
317 PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);
318
319 moduleId.setPackage(packageId);
320
321 //
322 // Read ACTIVE_PLATFORM's FPD file
323 //
324 String filename = getProject().getProperty("PLATFORM_FILE");
325
326 if (filename == null){
327 throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!");
328 }
329
330 PlatformIdentification platformId = GlobalData.getPlatform(filename);
331
332 //
333 // Read FPD file (Call FpdParserTask's method)
334 //
335 FpdParserTask fpdParser = new FpdParserTask();
336 fpdParser.setProject(getProject());
337 fpdParser.parseFpdFile(platformId.getFpdFile());
338
339 //
340 // Prepare for Platform related common properties
341 // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
342 //
343 getProject().setProperty("PLATFORM", platformId.getName());
344 getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
345 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
346 }
347
348
349 /**
350 Set Module-Related information to properties.
351
352 @param arch current build ARCH
353 **/
354 private void setModuleCommonProperties(String arch) {
355 //
356 // Prepare for all other common properties
357 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
358 //
359 PackageIdentification packageId = moduleId.getPackage();
360 getProject().setProperty("PACKAGE", packageId.getName());
361 getProject().setProperty("PACKAGE_GUID", packageId.getGuid());
362 getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());
363 getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));
364 getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
365
366 //
367 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
368 // MODULE_DIR, MODULE_RELATIVE_DIR
369 //
370 getProject().setProperty("MODULE", moduleId.getName());
371 String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();
372 if (baseName == null) {
373 getProject().setProperty("BASE_NAME", moduleId.getName());
374 } else {
375 getProject().setProperty("BASE_NAME", baseName);
376 }
377 getProject().setProperty("GUID", moduleId.getGuid());
378 getProject().setProperty("FILE_GUID", moduleId.getGuid());
379 getProject().setProperty("VERSION", moduleId.getVersion());
380 getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());
381 getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
382 getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));
383
384 //
385 // SUBSYSTEM
386 //
387 String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},
388 { "SEC", "EFI_BOOT_SERVICE_DRIVER" },
389 { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },
390 { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },
391 { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },
392 { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
393 { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },
394 { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
395 { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
396 { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },
397 { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
398 { "UEFI_APPLICATION", "EFI_APPLICATION" },
399 { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };
400
401 String subsystem = "EFI_BOOT_SERVICE_DRIVER";
402 for (int i = 0; i < subsystemMap.length; i++) {
403 if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {
404 subsystem = subsystemMap[i][1];
405 break ;
406 }
407 }
408 getProject().setProperty("SUBSYSTEM", subsystem);
409
410 //
411 // ENTRYPOINT
412 //
413 if (arch.equalsIgnoreCase("EBC")) {
414 getProject().setProperty("ENTRYPOINT", "EfiStart");
415 } else {
416 getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");
417 }
418
419 getProject().setProperty("OBJECTS", "");
420 }
421
422 private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {
423 String[] cmd = GlobalData.getToolChainInfo().getCommands();
424 for ( int m = 0; m < cmd.length; m++) {
425 //
426 // Set cmd, like CC, DLINK
427 //
428 String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};
429 key[4] = "PATH";
430 String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);
431 key[4] = "NAME";
432 String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);
433 File cmdFile = new File(cmdPath + File.separatorChar + cmdName);
434 getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));
435
436 //
437 // set CC_FLAGS
438 //
439 key[4] = "FLAGS";
440 String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);
441 Set<String> addset = new LinkedHashSet<String>();
442 Set<String> subset = new LinkedHashSet<String>();
443 putFlagsToSet(addset, cmdFlags);
444 getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));
445
446 //
447 // Set CC_EXT
448 //
449 key[4] = "EXT";
450 String extName = GlobalData.getCommandSetting(key, fpdModuleId);
451 if ( extName != null && ! extName.equalsIgnoreCase("")) {
452 getProject().setProperty(cmd[m] + "_EXT", extName);
453 } else {
454 getProject().setProperty(cmd[m] + "_EXT", "");
455 }
456
457 //
458 // set CC_FAMILY
459 //
460 key[4] = "FAMILY";
461 String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);
462 if (toolChainFamily != null) {
463 getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);
464 }
465
466 //
467 // set CC_SPATH
468 //
469 key[4] = "SPATH";
470 String spath = GlobalData.getCommandSetting(key, fpdModuleId);
471 if (spath != null) {
472 getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));
473 } else {
474 getProject().setProperty(cmd[m] + "_SPATH", "");
475 }
476
477 //
478 // set CC_DPATH
479 //
480 key[4] = "DPATH";
481 String dpath = GlobalData.getCommandSetting(key, fpdModuleId);
482 if (dpath != null) {
483 getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));
484 } else {
485 getProject().setProperty(cmd[m] + "_DPATH", "");
486 }
487 }
488 }
489
490 public void setMsaFile(File msaFile) {
491 this.msaFile = msaFile;
492 }
493
494 /**
495 Method is for ANT to initialize MSA file.
496
497 @param msaFilename MSA file name
498 **/
499 public void setMsaFile(String msaFilename) {
500 String moduleDir = getProject().getProperty("MODULE_DIR");
501
502 //
503 // If is Single Module Build, then use the Base Dir defined in build.xml
504 //
505 if (moduleDir == null) {
506 moduleDir = getProject().getBaseDir().getPath();
507 }
508 msaFile = new File(moduleDir + File.separatorChar + msaFilename);
509 }
510
511 public void addConfiguredModuleItem(ModuleItem moduleItem) {
512 PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());
513 ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());
514 moduleId.setPackage(packageId);
515 this.moduleId = moduleId;
516 }
517
518 /**
519 Add a property.
520
521 @param p property
522 **/
523 public void addProperty(Property p) {
524 properties.addElement(p);
525 }
526
527 public void setType(String type) {
528 this.type = type;
529 }
530
531 private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws BuildException{
532 //
533 // AutoGen
534 //
535
536 AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());
537 autogen.genAutogen();
538
539
540 //
541 // Get compiler flags
542 //
543 try {
544 getCompilerFlags(buildTarget, buildTagname, fpdModuleId);
545 }
546 catch (EdkException ee) {
547 throw new BuildException(ee.getMessage());
548 }
549
550 //
551 // Prepare LIBS
552 //
553 ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());
554 String propertyLibs = "";
555 for (int i = 0; i < libinstances.length; i++) {
556 propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";
557 }
558 getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));
559
560 //
561 // if it is CUSTOM_BUILD
562 // then call the exist BaseName_build.xml directly.
563 //
564 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
565 GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");
566
567 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
568 antCall(antFilename, null);
569
570 return ;
571 }
572
573 //
574 // Generate ${BASE_NAME}_build.xml
575 // TBD
576 //
577 String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword();
578 ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId);
579 String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
580 fileGenerator.genBuildFile(buildFilename);
581
582 //
583 // Ant call ${BASE_NAME}_build.xml
584 //
585 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
586 antCall(antFilename, null);
587 }
588
589 private void applyClean(FpdModuleIdentification fpdModuleId){
590 //
591 // if it is CUSTOM_BUILD
592 // then call the exist BaseName_build.xml directly.
593 //
594 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
595 GlobalData.log.info("Calling user-defined " + moduleId.getName() + "_build.xml");
596
597 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
598 antCall(antFilename, "clean");
599
600 return ;
601 }
602
603 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
604 antCall(antFilename, "clean");
605 }
606
607 private void applyCleanall(FpdModuleIdentification fpdModuleId){
608 //
609 // if it is CUSTOM_BUILD
610 // then call the exist BaseName_build.xml directly.
611 //
612 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
613 GlobalData.log.info("Calling user-defined " + moduleId.getName() + "_build.xml");
614
615 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
616 antCall(antFilename, "cleanall");
617
618 return ;
619 }
620
621 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
622 antCall(antFilename, "cleanall");
623 }
624
625 private void antCall(String antFilename, String target) {
626 Ant ant = new Ant();
627 ant.setProject(getProject());
628 ant.setAntfile(antFilename);
629 if (target != null) {
630 ant.setTarget(target);
631 }
632 ant.setInheritAll(true);
633 ant.init();
634 ant.execute();
635 }
636
637
638 /**
639 Separate the string and instore in set.
640
641 <p> String is separated by Java Regulation Expression
642 "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
643
644 <p>For example: </p>
645
646 <pre>
647 "/nologo", "/W3", "/WX"
648 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
649 </pre>
650
651 @param set store the separated string
652 @param str string to separate
653 **/
654 private void putFlagsToSet(Set<String> set, String str) {
655 if (str == null || str.length() == 0) {
656 return;
657 }
658
659 Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
660 Matcher matcher = myPattern.matcher(str + " ");
661 while (matcher.find()) {
662 String item = str.substring(matcher.start(1), matcher.end(1));
663 set.add(item);
664 }
665 }
666
667 /**
668 Generate the final flags string will be used by compile command.
669
670 @param add the add flags set
671 @param sub the sub flags set
672 @return final flags after add set substract sub set
673 **/
674 private String getFlags(Set<String> add, Set<String> sub) {
675 String result = "";
676 add.removeAll(sub);
677 Iterator iter = add.iterator();
678 while (iter.hasNext()) {
679 String str = (String) iter.next();
680 result += str.substring(1, str.length() - 1) + " ";
681 }
682 return result;
683 }
684
685 private void pushProperties() {
686 backupPropertiesStack.push(getProject().getProperties());
687 }
688
689 private void popProperties() {
690 Hashtable backupProperties = backupPropertiesStack.pop();
691 Set keys = backupProperties.keySet();
692 Iterator iter = keys.iterator();
693 while (iter.hasNext()) {
694 String item = (String)iter.next();
695 getProject().setProperty(item, (String)backupProperties.get(item));
696 }
697 }
698
699 public void setSingleModuleBuild(boolean isSingleModuleBuild) {
700 this.isSingleModuleBuild = isSingleModuleBuild;
701 }
702 }