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