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