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