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