]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java
bac506abfa3f0161ff999a6c096b326474b77f2a
[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 String[] archList = new String[0];
198 if ( getProject().getProperty("ARCH") != null ) {
199 archList = getProject().getProperty("ARCH").split(" ");
200 }
201 else {
202 archList = GlobalData.getToolChainInfo().getArchs();
203 }
204
205
206 //
207 // Judge if arch is all supported by current module. If not, throw Exception.
208 //
209 List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs();
210 if (moduleSupportedArchs != null) {
211 for (int k = 0; k < archList.length; k++) {
212 if ( ! moduleSupportedArchs.contains(archList[k])) {
213 throw new BuildException("ARCH [" + archList[k] + "] is not supported by " + moduleId + ". " + moduleId + " only supports [" + moduleSupportedArchs + "].");
214 }
215 }
216 }
217
218 for (int k = 0; k < archList.length; k++) {
219 getProject().setProperty("ARCH", archList[k]);
220
221 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
222
223 //
224 // Whether the module is built before
225 //
226 if (GlobalData.isModuleBuilt(fpdModuleId)) {
227 return ;
228 }
229 else {
230 GlobalData.registerBuiltModule(fpdModuleId);
231 }
232
233 //
234 // For Every TOOLCHAIN, TARGET
235 //
236 String[] targetList = GlobalData.getToolChainInfo().getTargets();
237 for (int i = 0; i < targetList.length; i ++){
238 //
239 // Prepare for target related common properties
240 // TARGET
241 //
242 getProject().setProperty("TARGET", targetList[i]);
243 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
244 for(int j = 0; j < toolchainList.length; j ++){
245 //
246 // check if any tool is defined for current target + toolchain + arch
247 // don't do anything if no tools found
248 //
249 if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {
250 System.out.println("Warning: No build issued. No tools found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");
251 continue;
252 }
253
254 //
255 // Prepare for toolchain related common properties
256 // TOOLCHAIN
257 //
258 getProject().setProperty("TOOLCHAIN", toolchainList[j]);
259
260 System.out.println("Build " + moduleId + " start >>>");
261 System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);
262 SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));
263
264 //
265 // Prepare for all other common properties
266 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
267 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
268 // MODULE_DIR, MODULE_RELATIVE_DIR
269 // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH
270 // LIBS, OBJECTS, SDB_FILES
271 //
272 setModuleCommonProperties(archList[k]);
273
274 //
275 // OutputManage prepare for
276 // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
277 //
278 OutputManager.getInstance().update(getProject());
279
280 if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {
281 applyBuild(targetList[i], toolchainList[j], fpdModuleId);
282 }
283 else if (type.equalsIgnoreCase("clean")) {
284 applyClean(fpdModuleId);
285 }
286 else if (type.equalsIgnoreCase("cleanall")) {
287 applyCleanall(fpdModuleId);
288 }
289 }
290 }
291 }
292 popProperties();
293 }catch (Exception e){
294 throw new BuildException(e.getMessage());
295 }
296 }
297
298 /**
299 This method is used to prepare Platform-related information.
300
301 <p>In Single Module Build mode, platform-related information is not ready.
302 The method read the system environment variable <code>ACTIVE_PLATFORM</code>
303 and search in the Framework Database. Note that platform name in the Framework
304 Database must be unique. </p>
305
306 **/
307 private void prepareSingleModuleBuild(){
308 //
309 // Find out the package which the module belongs to
310 // TBD: Enhance it!!!!
311 //
312 PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);
313
314 moduleId.setPackage(packageId);
315
316 //
317 // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)
318 //
319 String filename = getProject().getProperty("PLATFORM_FILE");
320
321 if (filename == null){
322 throw new BuildException("Plese set ACTIVE_PLATFORM if you want to build a single module. ");
323 }
324
325 PlatformIdentification platformId = GlobalData.getPlatform(filename);
326
327 //
328 // Read FPD file
329 //
330 FpdParserTask fpdParser = new FpdParserTask();
331 fpdParser.setProject(getProject());
332 fpdParser.parseFpdFile(platformId.getFpdFile());
333
334 //
335 // Prepare for Platform related common properties
336 // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
337 //
338 getProject().setProperty("PLATFORM", platformId.getName());
339 getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
340 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
341 }
342
343
344 /**
345 Set Module-Related information to properties.
346 **/
347 private void setModuleCommonProperties(String arch) {
348 //
349 // Prepare for all other common properties
350 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
351 //
352 PackageIdentification packageId = moduleId.getPackage();
353 getProject().setProperty("PACKAGE", packageId.getName());
354 getProject().setProperty("PACKAGE_GUID", packageId.getGuid());
355 getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());
356 getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));
357 getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
358
359 //
360 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
361 // MODULE_DIR, MODULE_RELATIVE_DIR
362 //
363 getProject().setProperty("MODULE", moduleId.getName());
364 String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();
365 if (baseName == null) {
366 getProject().setProperty("BASE_NAME", moduleId.getName());
367 }
368 else {
369 getProject().setProperty("BASE_NAME", baseName);
370 }
371 getProject().setProperty("GUID", moduleId.getGuid());
372 getProject().setProperty("FILE_GUID", moduleId.getGuid());
373 getProject().setProperty("VERSION", moduleId.getVersion());
374 getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());
375 getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
376 getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));
377
378 //
379 // SUBSYSTEM
380 //
381 String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},
382 { "SEC", "EFI_BOOT_SERVICE_DRIVER" },
383 { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },
384 { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },
385 { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },
386 { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
387 { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },
388 { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
389 { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
390 { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },
391 { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
392 { "UEFI_APPLICATION", "EFI_APPLICATION" },
393 { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };
394
395 String subsystem = "EFI_BOOT_SERVICE_DRIVER";
396 for (int i = 0; i < subsystemMap.length; i++) {
397 if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {
398 subsystem = subsystemMap[i][1];
399 break ;
400 }
401 }
402 getProject().setProperty("SUBSYSTEM", subsystem);
403
404 //
405 // ENTRYPOINT
406 //
407 if (arch.equalsIgnoreCase("EBC")) {
408 getProject().setProperty("ENTRYPOINT", "EfiStart");
409 }
410 else {
411 getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");
412 }
413
414 //
415 // LIBS, OBJECTS, SDB_FILES
416 //
417 getProject().setProperty("OBJECTS", "");
418 getProject().setProperty("SDB_FILES", "");
419 getProject().setProperty("LIBS", "");
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 }
454 else {
455 getProject().setProperty(cmd[m] + "_EXT", "");
456 }
457
458 //
459 // set CC_FAMILY
460 //
461 key[4] = "FAMILY";
462 String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);
463 if (toolChainFamily != null) {
464 getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);
465 }
466
467 //
468 // set CC_SPATH
469 //
470 key[4] = "SPATH";
471 String spath = GlobalData.getCommandSetting(key, fpdModuleId);
472 if (spath != null) {
473 getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));
474 }
475 else {
476 getProject().setProperty(cmd[m] + "_SPATH", "");
477 }
478
479 //
480 // set CC_DPATH
481 //
482 key[4] = "DPATH";
483 String dpath = GlobalData.getCommandSetting(key, fpdModuleId);
484 if (dpath != null) {
485 getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));
486 }
487 else {
488 getProject().setProperty(cmd[m] + "_DPATH", "");
489 }
490 }
491 }
492
493 public void setMsaFile(File msaFile) {
494 this.msaFile = msaFile;
495 }
496
497 /**
498 Method is for ANT to initialize MSA file.
499
500 @param msaFilename MSA file name
501 **/
502 public void setMsaFile(String msaFilename) {
503 String moduleDir = getProject().getProperty("MODULE_DIR");
504
505 //
506 // If is Single Module Build, then use the Base Dir defined in build.xml
507 //
508 if (moduleDir == null) {
509 moduleDir = getProject().getBaseDir().getPath();
510 }
511 msaFile = new File(moduleDir + File.separatorChar + msaFilename);
512 }
513
514 public void addConfiguredModuleItem(ModuleItem moduleItem) {
515 PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());
516 ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());
517 moduleId.setPackage(packageId);
518 this.moduleId = moduleId;
519 }
520
521 /**
522 Add a property.
523
524 @param p property
525 **/
526 public void addProperty(Property p) {
527 properties.addElement(p);
528 }
529
530 public void setType(String type) {
531 this.type = type;
532 }
533
534 private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException{
535 //
536 // AutoGen
537 //
538
539 AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());
540 autogen.genAutogen();
541
542
543 //
544 // Get compiler flags
545 //
546 getCompilerFlags(buildTarget, buildTagname, fpdModuleId);
547
548 //
549 // Prepare LIBS
550 //
551 ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());
552 String propertyLibs = "";
553 for (int i = 0; i < libinstances.length; i++) {
554 propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";
555 }
556 getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));
557
558 //
559 // if it is CUSTOM_BUILD
560 // then call the exist BaseName_build.xml directly.
561 //
562 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
563 GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");
564 Ant ant = new Ant();
565 ant.setProject(getProject());
566 ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");
567 ant.setInheritAll(true);
568 ant.init();
569 ant.execute();
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 Ant ant = new Ant();
586 ant.setProject(getProject());
587 ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");
588 ant.setInheritAll(true);
589 ant.init();
590 ant.execute();
591 }
592
593 private void applyClean(FpdModuleIdentification fpdModuleId){
594 //
595 // if it is CUSTOM_BUILD
596 // then call the exist BaseName_build.xml directly.
597 //
598 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
599 GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");
600 Ant ant = new Ant();
601 ant.setProject(getProject());
602 ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");
603 ant.setTarget("clean");
604 ant.setInheritAll(true);
605 ant.init();
606 ant.execute();
607 return ;
608 }
609
610 Ant ant = new Ant();
611 ant.setProject(getProject());
612 ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");
613 ant.setTarget("clean");
614 ant.setInheritAll(true);
615 ant.init();
616 ant.execute();
617
618 //
619 // Delete current module's DEST_DIR_OUTPUT
620 // TBD
621 }
622
623 private void applyCleanall(FpdModuleIdentification fpdModuleId){
624 //
625 // if it is CUSTOM_BUILD
626 // then call the exist BaseName_build.xml directly.
627 //
628 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
629 GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");
630 Ant ant = new Ant();
631 ant.setProject(getProject());
632 ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");
633 ant.setTarget("cleanall");
634 ant.setInheritAll(true);
635 ant.init();
636 ant.execute();
637 return ;
638 }
639
640 Ant ant = new Ant();
641 ant.setProject(getProject());
642 ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");
643 ant.setTarget("cleanall");
644 ant.setInheritAll(true);
645 ant.init();
646 ant.execute();
647
648 //
649 // Delete current module's DEST_DIR_OUTPUT
650 // TBD
651 }
652
653
654
655
656 /**
657 Separate the string and instore in set.
658
659 <p> String is separated by Java Regulation Expression
660 "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
661
662 <p>For example: </p>
663
664 <pre>
665 "/nologo", "/W3", "/WX"
666 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
667 </pre>
668
669 @param set store the separated string
670 @param str string to separate
671 **/
672 private void putFlagsToSet(Set<String> set, String str) {
673 if (str == null || str.length() == 0) {
674 return;
675 }
676
677 Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
678 Matcher matcher = myPattern.matcher(str + " ");
679 while (matcher.find()) {
680 String item = str.substring(matcher.start(1), matcher.end(1));
681 set.add(item);
682 }
683 }
684
685 /**
686 Generate the final flags string will be used by compile command.
687
688 @param add the add flags set
689 @param sub the sub flags set
690 @return final flags after add set substract sub set
691 **/
692 private String getFlags(Set<String> add, Set<String> sub) {
693 String result = "";
694 add.removeAll(sub);
695 Iterator iter = add.iterator();
696 while (iter.hasNext()) {
697 String str = (String) iter.next();
698 result += str.substring(1, str.length() - 1) + " ";
699 }
700 return result;
701 }
702
703 /**
704 Generate the flags string with original format. The format is defined by
705 Java Regulation Expression "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
706
707 <p>For example: </p>
708
709 <pre>
710 "/nologo", "/W3", "/WX"
711 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
712 </pre>
713
714 @param add the add flags set
715 @param sub the sub flags set
716 @return flags with original format
717 **/
718 private String getRawFlags(Set<String> add, Set<String> sub) {
719 String result = null;
720 add.removeAll(sub);
721 Iterator iter = add.iterator();
722 while (iter.hasNext()) {
723 String str = (String) iter.next();
724 result += "\"" + str.substring(1, str.length() - 1) + "\", ";
725 }
726 return result;
727 }
728
729 private String parseOptionString(String optionString, Set<String> addSet, Set<String> subSet) {
730 boolean overrideOption = false;
731 Pattern pattern = Pattern.compile("ADD\\.\\[(.+)\\]");
732 Matcher matcher = pattern.matcher(optionString);
733
734 while (matcher.find()) {
735 overrideOption = true;
736 String addOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();
737 putFlagsToSet(addSet, addOption);
738
739 }
740
741 pattern = Pattern.compile("SUB\\.\\[(.+)\\]");
742 matcher = pattern.matcher(optionString);
743
744 while (matcher.find()) {
745 overrideOption = true;
746 String subOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();
747 putFlagsToSet(subSet, subOption);
748 }
749
750 if (overrideOption == true) {
751 return null;
752 }
753
754 return optionString;
755 }
756
757 private void pushProperties() {
758 backupPropertiesStack.push(getProject().getProperties());
759 }
760
761 private void popProperties() {
762 Hashtable backupProperties = backupPropertiesStack.pop();
763 Set keys = backupProperties.keySet();
764 Iterator iter = keys.iterator();
765 while (iter.hasNext()) {
766 String item = (String)iter.next();
767 getProject().setProperty(item, (String)backupProperties.get(item));
768 }
769 }
770
771 public void setSingleModuleBuild(boolean isSingleModuleBuild) {
772 this.isSingleModuleBuild = isSingleModuleBuild;
773 }
774 }