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