Add class header to FrameworkBuildTask. Remove some unused code from top level build...
[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 <pre>
59 1. generate AutoGen.c and AutoGen.h;
60 2. build all dependent library instances;
61 3. build all source files inlcude AutoGen.c;
62 4. generate sections;
63 5. generate FFS file if it is driver module while LIB file if it is Library module.
64 </pre>
65
66
67 <p>
68 The usage is (take module <em>HelloWorld</em> for example):
69 </p>
70
71 <pre>
72 &lt;GenBuild
73 msaFilename=&quot;HelloWorld.msa&quot;/&gt;
74 processTo=&quot;ALL&quot;/&gt;
75 </pre>
76
77 <p><code>processTo</code> provides a way to customize the whole build process.
78 processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE.
79 Default is ALL, means whole
80 </p>
81
82 <p>
83 This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and
84 <em>AutoGen.h</em>. The task also parses the development environment
85 configuration files, such as collecting package information, setting compiler
86 flags and so on.
87 </p>
88
89
90 @since GenBuild 1.0
91 **/
92 public class GenBuildTask extends Ant {
93
94 ///
95 /// Module surface area file.
96 ///
97 File msaFile;
98
99 private String type = "all";
100
101 ///
102 /// Module's Identification.
103 ///
104 private ModuleIdentification moduleId;
105
106 private Vector<Property> properties = new Vector<Property>();
107
108 private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();
109
110 private boolean isSingleModuleBuild = false;
111
112 /**
113 Public construct method. It is necessary for ANT task.
114 **/
115 public GenBuildTask() {
116 }
117
118 /**
119
120 @throws BuildException
121 From module build, exception from module surface area invalid.
122 **/
123 public void execute() throws BuildException {
124 //
125 // set Logger
126 //
127 GenBuildLogger logger = new GenBuildLogger(getProject());
128 EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
129 EdkLog.setLogger(logger);
130
131 pushProperties();
132 //
133 // Enable all specified properties
134 //
135 Iterator<Property> iter = properties.iterator();
136 while (iter.hasNext()) {
137 Property item = iter.next();
138 getProject().setProperty(item.getName(), item.getValue());
139 }
140
141 //
142 // GenBuild should specify either msaFile or moduleGuid & packageGuid
143 //
144 if (msaFile == null ) {
145 String moduleGuid = getProject().getProperty("MODULE_GUID");
146 String moduleVersion = getProject().getProperty("MODULE_VERSION");
147 String packageGuid = getProject().getProperty("PACKAGE_GUID");
148 String packageVersion = getProject().getProperty("PACKAGE_VERSION");
149 if (moduleGuid == null || packageGuid == null) {
150 throw new BuildException("GenBuild parameter error.");
151 }
152 PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
153 moduleId = new ModuleIdentification(moduleGuid, moduleVersion);
154 moduleId.setPackage(packageId);
155 Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);
156 SurfaceAreaQuery.setDoc(doc);
157 moduleId = SurfaceAreaQuery.getMsaHeader();
158 } else {
159 Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);
160 SurfaceAreaQuery.setDoc(doc);
161 moduleId = SurfaceAreaQuery.getMsaHeader();
162 }
163 String[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED",null);
164 if (producedLibraryClasses.length == 0) {
165 moduleId.setLibrary(false);
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 } 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 : get arch from pass down, otherwise intersection MSA
195 // supported ARCHs and tools def
196 //
197 Set<String> archListSupByToolChain = new LinkedHashSet<String>();
198 String[] archs = GlobalData.getToolChainInfo().getArchs();
199
200 for (int i = 0; i < archs.length; i ++) {
201 archListSupByToolChain.add(archs[i]);
202 }
203
204 Set<String> archSet = new LinkedHashSet<String>();
205
206 if ( getProject().getProperty("ARCH") != null) {
207 String[] fpdArchList = getProject().getProperty("ARCH").split(" ");
208
209 for (int i = 0; i < fpdArchList.length; i++) {
210 if (archListSupByToolChain.contains(fpdArchList[i])) {
211 archSet.add(fpdArchList[i]);
212 }
213 }
214 } else {
215 archSet = archListSupByToolChain;
216 }
217
218 String[] archList = archSet.toArray(new String[archSet.size()]);
219
220 //
221 // Judge if arch is all supported by current module. If not, throw Exception.
222 //
223 List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs();
224 if (moduleSupportedArchs != null) {
225 for (int k = 0; k < archList.length; k++) {
226 if ( ! moduleSupportedArchs.contains(archList[k])) {
227 throw new BuildException("Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures.");
228 }
229 }
230 }
231
232 for (int k = 0; k < archList.length; k++) {
233
234 getProject().setProperty("ARCH", archList[k]);
235
236 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
237
238 //
239 // Whether the module is built before
240 //
241 if (moduleId.isLibrary() == false && GlobalData.hasFpdModuleSA(fpdModuleId) == false) {
242 System.out.println("\nWARNING: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");
243 continue;
244 } else if (GlobalData.isModuleBuilt(fpdModuleId)) {
245 return;
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 were 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 //
288 setModuleCommonProperties(archList[k]);
289
290 //
291 // OutputManage prepare for
292 // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
293 //
294 OutputManager.getInstance().update(getProject());
295
296 if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {
297 applyBuild(targetList[i], toolchainList[j], fpdModuleId);
298 } else if (type.equalsIgnoreCase("clean")) {
299 applyClean(fpdModuleId);
300 } else if (type.equalsIgnoreCase("cleanall")) {
301 applyCleanall(fpdModuleId);
302 }
303 }
304 }
305 }
306
307 popProperties();
308 }
309
310 /**
311 This method is used to prepare Platform-related information.
312
313 <p>In Single Module Build mode, platform-related information is not ready.
314 The method read the system environment variable <code>ACTIVE_PLATFORM</code>
315 and search in the Framework Database. Note that platform name in the Framework
316 Database must be unique. </p>
317
318 **/
319 private void prepareSingleModuleBuild(){
320 //
321 // Find out the package which the module belongs to
322 // TBD: Enhance it!!!!
323 //
324 PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);
325
326 moduleId.setPackage(packageId);
327
328 //
329 // Read ACTIVE_PLATFORM's FPD file
330 //
331 String filename = getProject().getProperty("PLATFORM_FILE");
332
333 if (filename == null){
334 throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!");
335 }
336
337 PlatformIdentification platformId = GlobalData.getPlatform(filename);
338
339 //
340 // Read FPD file (Call FpdParserTask's method)
341 //
342 FpdParserTask fpdParser = new FpdParserTask();
343 fpdParser.setProject(getProject());
344 fpdParser.parseFpdFile(platformId.getFpdFile());
345
346 //
347 // Prepare for Platform related common properties
348 // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
349 //
350 getProject().setProperty("PLATFORM", platformId.getName());
351 getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
352 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
353 }
354
355
356 /**
357 Set Module-Related information to properties.
358
359 @param arch current build ARCH
360 **/
361 private void setModuleCommonProperties(String arch) {
362 //
363 // Prepare for all other common properties
364 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
365 //
366 PackageIdentification packageId = moduleId.getPackage();
367 getProject().setProperty("PACKAGE", packageId.getName());
368 getProject().setProperty("PACKAGE_GUID", packageId.getGuid());
369 getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());
370 getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));
371 getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
372
373 //
374 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
375 // MODULE_DIR, MODULE_RELATIVE_DIR
376 //
377 getProject().setProperty("MODULE", moduleId.getName());
378 String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();
379 if (baseName == null) {
380 getProject().setProperty("BASE_NAME", moduleId.getName());
381 } else {
382 getProject().setProperty("BASE_NAME", baseName);
383 }
384 getProject().setProperty("GUID", moduleId.getGuid());
385 getProject().setProperty("FILE_GUID", moduleId.getGuid());
386 getProject().setProperty("VERSION", moduleId.getVersion());
387 getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());
388 getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
389 getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));
390
391 //
392 // SUBSYSTEM
393 //
394 String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},
395 { "SEC", "EFI_BOOT_SERVICE_DRIVER" },
396 { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },
397 { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },
398 { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },
399 { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
400 { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },
401 { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
402 { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
403 { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },
404 { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
405 { "UEFI_APPLICATION", "EFI_APPLICATION" },
406 { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };
407
408 String subsystem = "EFI_BOOT_SERVICE_DRIVER";
409 for (int i = 0; i < subsystemMap.length; i++) {
410 if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {
411 subsystem = subsystemMap[i][1];
412 break ;
413 }
414 }
415 getProject().setProperty("SUBSYSTEM", subsystem);
416
417 //
418 // ENTRYPOINT
419 //
420 if (arch.equalsIgnoreCase("EBC")) {
421 getProject().setProperty("ENTRYPOINT", "EfiStart");
422 } else {
423 getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");
424 }
425
426 getProject().setProperty("OBJECTS", "");
427 }
428
429 private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {
430 String[] cmd = GlobalData.getToolChainInfo().getCommands();
431 for ( int m = 0; m < cmd.length; m++) {
432 //
433 // Set cmd, like CC, DLINK
434 //
435 String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};
436 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_PATH;
437 String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);
438 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME;
439 String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);
440 File cmdFile = new File(cmdPath + File.separatorChar + cmdName);
441 getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));
442
443 //
444 // set CC_FLAGS
445 //
446 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS;
447 String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);
448 Set<String> addset = new LinkedHashSet<String>();
449 Set<String> subset = new LinkedHashSet<String>();
450 putFlagsToSet(addset, cmdFlags);
451 getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));
452
453 //
454 // Set CC_EXT
455 //
456 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_EXT;
457 String extName = GlobalData.getCommandSetting(key, fpdModuleId);
458 if ( extName != null && ! extName.equalsIgnoreCase("")) {
459 getProject().setProperty(cmd[m] + "_EXT", extName);
460 } else {
461 getProject().setProperty(cmd[m] + "_EXT", "");
462 }
463
464 //
465 // set CC_FAMILY
466 //
467 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY;
468 String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);
469 if (toolChainFamily != null) {
470 getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);
471 }
472
473 //
474 // set CC_SPATH
475 //
476 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_SPATH;
477 String spath = GlobalData.getCommandSetting(key, fpdModuleId);
478 if (spath != null) {
479 getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));
480 } else {
481 getProject().setProperty(cmd[m] + "_SPATH", "");
482 }
483
484 //
485 // set CC_DPATH
486 //
487 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_DPATH;
488 String dpath = GlobalData.getCommandSetting(key, fpdModuleId);
489 if (dpath != null) {
490 getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));
491 } else {
492 getProject().setProperty(cmd[m] + "_DPATH", "");
493 }
494 }
495 }
496
497 public void setMsaFile(File msaFile) {
498 this.msaFile = msaFile;
499 }
500
501 /**
502 Method is for ANT to initialize MSA file.
503
504 @param msaFilename MSA file name
505 **/
506 public void setMsaFile(String msaFilename) {
507 String moduleDir = getProject().getProperty("MODULE_DIR");
508
509 //
510 // If is Single Module Build, then use the Base Dir defined in build.xml
511 //
512 if (moduleDir == null) {
513 moduleDir = getProject().getBaseDir().getPath();
514 }
515 msaFile = new File(moduleDir + File.separatorChar + msaFilename);
516 }
517
518 public void addConfiguredModuleItem(ModuleItem moduleItem) {
519 PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());
520 ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());
521 moduleId.setPackage(packageId);
522 this.moduleId = moduleId;
523 }
524
525 /**
526 Add a property.
527
528 @param p property
529 **/
530 public void addProperty(Property p) {
531 properties.addElement(p);
532 }
533
534 public void setType(String type) {
535 this.type = type;
536 }
537
538 private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws BuildException{
539 //
540 // AutoGen
541 //
542
543 AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());
544 autogen.genAutogen();
545
546
547 //
548 // Get compiler flags
549 //
550 try {
551 getCompilerFlags(buildTarget, buildTagname, fpdModuleId);
552 }
553 catch (EdkException ee) {
554 throw new BuildException(ee.getMessage());
555 }
556
557 //
558 // Prepare LIBS
559 //
560 ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());
561 String propertyLibs = "";
562 for (int i = 0; i < libinstances.length; i++) {
563 propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";
564 }
565 getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));
566
567 //
568 // if it is CUSTOM_BUILD
569 // then call the exist BaseName_build.xml directly.
570 //
571 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
572 GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");
573
574 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
575 antCall(antFilename, null);
576
577 return ;
578 }
579
580 //
581 // Generate ${BASE_NAME}_build.xml
582 // TBD
583 //
584 String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword();
585 ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId);
586 String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
587 fileGenerator.genBuildFile(buildFilename);
588
589 //
590 // Ant call ${BASE_NAME}_build.xml
591 //
592 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
593 antCall(antFilename, null);
594 }
595
596 private void applyClean(FpdModuleIdentification fpdModuleId){
597 //
598 // if it is CUSTOM_BUILD
599 // then call the exist BaseName_build.xml directly.
600 //
601 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
602 GlobalData.log.info("Calling user-defined " + moduleId.getName() + "_build.xml");
603
604 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
605 antCall(antFilename, "clean");
606
607 return ;
608 }
609
610 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
611 antCall(antFilename, "clean");
612 }
613
614 private void applyCleanall(FpdModuleIdentification fpdModuleId){
615 //
616 // if it is CUSTOM_BUILD
617 // then call the exist BaseName_build.xml directly.
618 //
619 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
620 GlobalData.log.info("Calling user-defined " + moduleId.getName() + "_build.xml");
621
622 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
623 antCall(antFilename, "cleanall");
624
625 return ;
626 }
627
628 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
629 antCall(antFilename, "cleanall");
630 }
631
632 private void antCall(String antFilename, String target) {
633 Ant ant = new Ant();
634 ant.setProject(getProject());
635 ant.setAntfile(antFilename);
636 if (target != null) {
637 ant.setTarget(target);
638 }
639 ant.setInheritAll(true);
640 ant.init();
641 ant.execute();
642 }
643
644
645 /**
646 Separate the string and instore in set.
647
648 <p> String is separated by Java Regulation Expression
649 "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
650
651 <p>For example: </p>
652
653 <pre>
654 "/nologo", "/W3", "/WX"
655 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
656 </pre>
657
658 @param set store the separated string
659 @param str string to separate
660 **/
661 private void putFlagsToSet(Set<String> set, String str) {
662 if (str == null || str.length() == 0) {
663 return;
664 }
665
666 Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
667 Matcher matcher = myPattern.matcher(str + " ");
668 while (matcher.find()) {
669 String item = str.substring(matcher.start(1), matcher.end(1));
670 set.add(item);
671 }
672 }
673
674 /**
675 Generate the final flags string will be used by compile command.
676
677 @param add the add flags set
678 @param sub the sub flags set
679 @return final flags after add set substract sub set
680 **/
681 private String getFlags(Set<String> add, Set<String> sub) {
682 String result = "";
683 add.removeAll(sub);
684 Iterator iter = add.iterator();
685 while (iter.hasNext()) {
686 String str = (String) iter.next();
687 result += str.substring(1, str.length() - 1) + " ";
688 }
689 return result;
690 }
691
692 private void pushProperties() {
693 backupPropertiesStack.push(getProject().getProperties());
694 }
695
696 private void popProperties() {
697 Hashtable backupProperties = backupPropertiesStack.pop();
698 Set keys = backupProperties.keySet();
699 Iterator iter = keys.iterator();
700 while (iter.hasNext()) {
701 String item = (String)iter.next();
702 getProject().setProperty(item, (String)backupProperties.get(item));
703 }
704 }
705
706 public void setSingleModuleBuild(boolean isSingleModuleBuild) {
707 this.isSingleModuleBuild = isSingleModuleBuild;
708 }
709 }