]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java
Enhance Arch check.
[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.ArrayList;
20 import java.util.Hashtable;
21 import java.util.Iterator;
22 import java.util.LinkedHashSet;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.Stack;
27 import java.util.Vector;
28 import java.util.regex.Matcher;
29 import java.util.regex.Pattern;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.taskdefs.Ant;
33 import org.apache.tools.ant.taskdefs.Property;
34 import org.apache.xmlbeans.XmlObject;
35
36 import org.tianocore.build.autogen.AutoGen;
37 import org.tianocore.build.fpd.FpdParserTask;
38 import org.tianocore.build.global.GenBuildLogger;
39 import org.tianocore.build.global.GlobalData;
40 import org.tianocore.build.global.OutputManager;
41 import org.tianocore.build.global.SurfaceAreaQuery;
42 import org.tianocore.build.id.FpdModuleIdentification;
43 import org.tianocore.build.id.ModuleIdentification;
44 import org.tianocore.build.id.PackageIdentification;
45 import org.tianocore.build.id.PlatformIdentification;
46 import org.tianocore.build.tools.ModuleItem;
47 import org.tianocore.exception.EdkException;
48 import org.tianocore.logger.EdkLog;
49
50 /**
51 <p>
52 <code>GenBuildTask</code> is an ANT task that can be used in ANT build
53 system. The main function of this task is to parse module's surface area,
54 then generate the corresponding <em>BaseName_build.xml</em> (the real ANT
55 build script) and call this to build the module. The whole process including:
56 1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances;
57 3. build all source files inlcude AutoGen.c; 4. generate sections;
58 5. generate FFS file if it is driver module while LIB file if it is Library module.
59 </p>
60
61 <p>
62 The usage is (take module <em>HelloWorld</em> for example):
63 </p>
64
65 <pre>
66 &lt;GenBuild
67 msaFilename=&quot;HelloWorld.msa&quot;/&gt;
68 processTo=&quot;ALL&quot;/&gt;
69 </pre>
70
71 <p><code>processTo</code> provides a way to customize the whole build process.
72 processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE.
73 Default is ALL, means whole
74 </p>
75
76 <p>
77 This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and
78 <em>AutoGen.h</em>. The task also parses the development environment
79 configuration files, such as collecting package information, setting compiler
80 flags and so on.
81 </p>
82
83
84 @since GenBuild 1.0
85 **/
86 public class GenBuildTask extends Ant {
87
88 ///
89 /// Module surface area file.
90 ///
91 File msaFile;
92
93 ///
94 ///
95 ///
96 private String type = "all"; // = "build";
97
98 ///
99 /// Module's Identification.
100 ///
101 private ModuleIdentification moduleId;
102
103 private Vector<Property> properties = new Vector<Property>();
104
105 private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();
106
107 private boolean isSingleModuleBuild = false;
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",null);
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 (isSingleModuleBuild) {
174 //
175 // Single Module build
176 //
177 prepareSingleModuleBuild();
178 }
179 else {
180 //
181 // Platform build. Restore the platform related info
182 //
183 String filename = getProject().getProperty("PLATFORM_FILE");
184 PlatformIdentification platformId = GlobalData.getPlatform(filename);
185 getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
186 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
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 Set<String> archListSupByToolChain = new LinkedHashSet<String>();
199 String[] archs = GlobalData.getToolChainInfo().getArchs();
200
201 for (int i = 0; i < archs.length; i ++) {
202 archListSupByToolChain.add(archs[i]);
203 }
204
205 Set<String> archSet = new LinkedHashSet<String>();
206
207 if ( getProject().getProperty("ARCH") != null) {
208 String[] fpdArchList = getProject().getProperty("ARCH").split(" ");
209
210 for (int i = 0; i < fpdArchList.length; i++) {
211 if (archListSupByToolChain.contains(fpdArchList[i])) {
212 archSet.add(fpdArchList[i]);
213 }
214 }
215 }
216 else {
217 archSet = archListSupByToolChain;
218 }
219
220 String[] archList = archSet.toArray(new String[archSet.size()]);
221
222 //
223 // Judge if arch is all supported by current module. If not, throw Exception.
224 //
225 List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs();
226 if (moduleSupportedArchs != null) {
227 for (int k = 0; k < archList.length; k++) {
228 if ( ! moduleSupportedArchs.contains(archList[k])) {
229 throw new BuildException("ARCH [" + archList[k] + "] is not supported by " + moduleId + ". " + moduleId + " only supports [" + moduleSupportedArchs + "].");
230 }
231 }
232 }
233
234 for (int k = 0; k < archList.length; k++) {
235
236 getProject().setProperty("ARCH", archList[k]);
237
238 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
239
240 //
241 // Whether the module is built before
242 //
243 if (GlobalData.isModuleBuilt(fpdModuleId)) {
244 return ;
245 }
246 else {
247 GlobalData.registerBuiltModule(fpdModuleId);
248 }
249
250 //
251 // For Every TOOLCHAIN, TARGET
252 //
253 String[] targetList = GlobalData.getToolChainInfo().getTargets();
254 for (int i = 0; i < targetList.length; i ++){
255 //
256 // Prepare for target related common properties
257 // TARGET
258 //
259 getProject().setProperty("TARGET", targetList[i]);
260 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
261 for(int j = 0; j < toolchainList.length; j ++){
262 //
263 // check if any tool is defined for current target + toolchain + arch
264 // don't do anything if no tools found
265 //
266 if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {
267 System.out.println("Warning: No build issued. No tools found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");
268 continue;
269 }
270
271 //
272 // Prepare for toolchain related common properties
273 // TOOLCHAIN
274 //
275 getProject().setProperty("TOOLCHAIN", toolchainList[j]);
276
277 System.out.println("Build " + moduleId + " start >>>");
278 System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);
279 SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));
280
281 //
282 // Prepare for all other common properties
283 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
284 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
285 // MODULE_DIR, MODULE_RELATIVE_DIR
286 // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH
287 // LIBS, OBJECTS, SDB_FILES
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 //
432 // LIBS, OBJECTS, SDB_FILES
433 //
434 getProject().setProperty("OBJECTS", "");
435 getProject().setProperty("SDB_FILES", "");
436 getProject().setProperty("LIBS", "");
437 }
438
439 private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {
440 String[] cmd = GlobalData.getToolChainInfo().getCommands();
441 for ( int m = 0; m < cmd.length; m++) {
442 //
443 // Set cmd, like CC, DLINK
444 //
445 String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};
446 key[4] = "PATH";
447 String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);
448 key[4] = "NAME";
449 String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);
450 File cmdFile = new File(cmdPath + File.separatorChar + cmdName);
451 getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));
452
453 //
454 // set CC_FLAGS
455 //
456 key[4] = "FLAGS";
457 String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);
458 Set<String> addset = new LinkedHashSet<String>();
459 Set<String> subset = new LinkedHashSet<String>();
460 putFlagsToSet(addset, cmdFlags);
461 getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));
462
463 //
464 // Set CC_EXT
465 //
466 key[4] = "EXT";
467 String extName = GlobalData.getCommandSetting(key, fpdModuleId);
468 if ( extName != null && ! extName.equalsIgnoreCase("")) {
469 getProject().setProperty(cmd[m] + "_EXT", extName);
470 }
471 else {
472 getProject().setProperty(cmd[m] + "_EXT", "");
473 }
474
475 //
476 // set CC_FAMILY
477 //
478 key[4] = "FAMILY";
479 String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);
480 if (toolChainFamily != null) {
481 getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);
482 }
483
484 //
485 // set CC_SPATH
486 //
487 key[4] = "SPATH";
488 String spath = GlobalData.getCommandSetting(key, fpdModuleId);
489 if (spath != null) {
490 getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));
491 }
492 else {
493 getProject().setProperty(cmd[m] + "_SPATH", "");
494 }
495
496 //
497 // set CC_DPATH
498 //
499 key[4] = "DPATH";
500 String dpath = GlobalData.getCommandSetting(key, fpdModuleId);
501 if (dpath != null) {
502 getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));
503 }
504 else {
505 getProject().setProperty(cmd[m] + "_DPATH", "");
506 }
507 }
508 }
509
510 public void setMsaFile(File msaFile) {
511 this.msaFile = msaFile;
512 }
513
514 /**
515 Method is for ANT to initialize MSA file.
516
517 @param msaFilename MSA file name
518 **/
519 public void setMsaFile(String msaFilename) {
520 String moduleDir = getProject().getProperty("MODULE_DIR");
521
522 //
523 // If is Single Module Build, then use the Base Dir defined in build.xml
524 //
525 if (moduleDir == null) {
526 moduleDir = getProject().getBaseDir().getPath();
527 }
528 msaFile = new File(moduleDir + File.separatorChar + msaFilename);
529 }
530
531 public void addConfiguredModuleItem(ModuleItem moduleItem) {
532 PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());
533 ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());
534 moduleId.setPackage(packageId);
535 this.moduleId = moduleId;
536 }
537
538 /**
539 Add a property.
540
541 @param p property
542 **/
543 public void addProperty(Property p) {
544 properties.addElement(p);
545 }
546
547 public void setType(String type) {
548 this.type = type;
549 }
550
551 private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException{
552 //
553 // AutoGen
554 //
555
556 AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());
557 autogen.genAutogen();
558
559
560 //
561 // Get compiler flags
562 //
563 getCompilerFlags(buildTarget, buildTagname, fpdModuleId);
564
565 //
566 // Prepare LIBS
567 //
568 ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());
569 String propertyLibs = "";
570 for (int i = 0; i < libinstances.length; i++) {
571 propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";
572 }
573 getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));
574
575 //
576 // if it is CUSTOM_BUILD
577 // then call the exist BaseName_build.xml directly.
578 //
579 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
580 GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");
581 Ant ant = new Ant();
582 ant.setProject(getProject());
583 ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");
584 ant.setInheritAll(true);
585 ant.init();
586 ant.execute();
587 return ;
588 }
589
590 //
591 // Generate ${BASE_NAME}_build.xml
592 // TBD
593 //
594 String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword();
595 ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId);
596 String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
597 fileGenerator.genBuildFile(buildFilename);
598
599 //
600 // Ant call ${BASE_NAME}_build.xml
601 //
602 Ant ant = new Ant();
603 ant.setProject(getProject());
604 ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");
605 ant.setInheritAll(true);
606 ant.init();
607 ant.execute();
608 }
609
610 private void applyClean(FpdModuleIdentification fpdModuleId){
611 //
612 // if it is CUSTOM_BUILD
613 // then call the exist BaseName_build.xml directly.
614 //
615 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
616 GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");
617 Ant ant = new Ant();
618 ant.setProject(getProject());
619 ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");
620 ant.setTarget("clean");
621 ant.setInheritAll(true);
622 ant.init();
623 ant.execute();
624 return ;
625 }
626
627 Ant ant = new Ant();
628 ant.setProject(getProject());
629 ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");
630 ant.setTarget("clean");
631 ant.setInheritAll(true);
632 ant.init();
633 ant.execute();
634
635 //
636 // Delete current module's DEST_DIR_OUTPUT
637 // TBD
638 }
639
640 private void applyCleanall(FpdModuleIdentification fpdModuleId){
641 //
642 // if it is CUSTOM_BUILD
643 // then call the exist BaseName_build.xml directly.
644 //
645 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
646 GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");
647 Ant ant = new Ant();
648 ant.setProject(getProject());
649 ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");
650 ant.setTarget("cleanall");
651 ant.setInheritAll(true);
652 ant.init();
653 ant.execute();
654 return ;
655 }
656
657 Ant ant = new Ant();
658 ant.setProject(getProject());
659 ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");
660 ant.setTarget("cleanall");
661 ant.setInheritAll(true);
662 ant.init();
663 ant.execute();
664
665 //
666 // Delete current module's DEST_DIR_OUTPUT
667 // TBD
668 }
669
670
671
672
673 /**
674 Separate the string and instore in set.
675
676 <p> String is separated by Java Regulation Expression
677 "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
678
679 <p>For example: </p>
680
681 <pre>
682 "/nologo", "/W3", "/WX"
683 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
684 </pre>
685
686 @param set store the separated string
687 @param str string to separate
688 **/
689 private void putFlagsToSet(Set<String> set, String str) {
690 if (str == null || str.length() == 0) {
691 return;
692 }
693
694 Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
695 Matcher matcher = myPattern.matcher(str + " ");
696 while (matcher.find()) {
697 String item = str.substring(matcher.start(1), matcher.end(1));
698 set.add(item);
699 }
700 }
701
702 /**
703 Generate the final flags string will be used by compile command.
704
705 @param add the add flags set
706 @param sub the sub flags set
707 @return final flags after add set substract sub set
708 **/
709 private String getFlags(Set<String> add, Set<String> sub) {
710 String result = "";
711 add.removeAll(sub);
712 Iterator iter = add.iterator();
713 while (iter.hasNext()) {
714 String str = (String) iter.next();
715 result += str.substring(1, str.length() - 1) + " ";
716 }
717 return result;
718 }
719
720 /**
721 Generate the flags string with original format. The format is defined by
722 Java Regulation Expression "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
723
724 <p>For example: </p>
725
726 <pre>
727 "/nologo", "/W3", "/WX"
728 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
729 </pre>
730
731 @param add the add flags set
732 @param sub the sub flags set
733 @return flags with original format
734 **/
735 private String getRawFlags(Set<String> add, Set<String> sub) {
736 String result = null;
737 add.removeAll(sub);
738 Iterator iter = add.iterator();
739 while (iter.hasNext()) {
740 String str = (String) iter.next();
741 result += "\"" + str.substring(1, str.length() - 1) + "\", ";
742 }
743 return result;
744 }
745
746 private String parseOptionString(String optionString, Set<String> addSet, Set<String> subSet) {
747 boolean overrideOption = false;
748 Pattern pattern = Pattern.compile("ADD\\.\\[(.+)\\]");
749 Matcher matcher = pattern.matcher(optionString);
750
751 while (matcher.find()) {
752 overrideOption = true;
753 String addOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();
754 putFlagsToSet(addSet, addOption);
755
756 }
757
758 pattern = Pattern.compile("SUB\\.\\[(.+)\\]");
759 matcher = pattern.matcher(optionString);
760
761 while (matcher.find()) {
762 overrideOption = true;
763 String subOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();
764 putFlagsToSet(subSet, subOption);
765 }
766
767 if (overrideOption == true) {
768 return null;
769 }
770
771 return optionString;
772 }
773
774 private void pushProperties() {
775 backupPropertiesStack.push(getProject().getProperties());
776 }
777
778 private void popProperties() {
779 Hashtable backupProperties = backupPropertiesStack.pop();
780 Set keys = backupProperties.keySet();
781 Iterator iter = keys.iterator();
782 while (iter.hasNext()) {
783 String item = (String)iter.next();
784 getProject().setProperty(item, (String)backupProperties.get(item));
785 }
786 }
787
788 public void setSingleModuleBuild(boolean isSingleModuleBuild) {
789 this.isSingleModuleBuild = isSingleModuleBuild;
790 }
791 }