]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java
978b11fe2b9f258c70a128bf4ed5cd5055752c22
[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.Vector;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.BuildListener;
31 import org.apache.tools.ant.Project;
32 import org.apache.tools.ant.taskdefs.Ant;
33 import org.apache.tools.ant.taskdefs.Property;
34 import org.apache.xmlbeans.XmlObject;
35
36 import org.tianocore.common.definitions.ToolDefinitions;
37 import org.tianocore.common.exception.EdkException;
38 import org.tianocore.build.autogen.AutoGen;
39 import org.tianocore.build.fpd.FpdParserTask;
40 import org.tianocore.build.global.GlobalData;
41 import org.tianocore.build.global.OutputManager;
42 import org.tianocore.build.global.SurfaceAreaQuery;
43 import org.tianocore.build.id.FpdModuleIdentification;
44 import org.tianocore.build.id.ModuleIdentification;
45 import org.tianocore.build.id.PackageIdentification;
46 import org.tianocore.build.id.PlatformIdentification;
47 import org.tianocore.build.tools.ModuleItem;
48
49 /**
50 <p>
51 <code>GenBuildTask</code> is an ANT task that can be used in ANT build
52 system.
53
54 <p>The main function of this task is to parse module's surface area (MSA),
55 then generate the corresponding <em>BaseName_build.xml</em> (the real ANT
56 build script) and call this to build the module. The whole process including:
57
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 msaFile="${PACKAGE_DIR}/Application/HelloWorld/HelloWorld.msa"
74 type="cleanall" /&gt;
75 </pre>
76
77 <p>
78 This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and
79 <em>AutoGen.h</em>.
80 </p>
81
82 <p>
83 This task will also set properties for current module, such as PACKAGE,
84 PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
85 (relative to Workspace), MODULE or BASE_NAME, GUID, VERSION, MODULE_DIR,
86 MODULE_RELATIVE_DIR (relative to Package), CONFIG_DIR, BIN_DIR,
87 DEST_DIR_DEBUG, DEST_DIR_OUTPUT, TARGET, ARCH, TOOLCHAIN, TOOLCHAIN_FAMILY,
88 SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH, all compiler command related
89 properties (CC, CC_FLAGS, CC_DPATH, CC_SPATH, CC_FAMILY, CC_EXT).
90 </p>
91
92 @since GenBuild 1.0
93 **/
94 public class GenBuildTask extends Ant {
95
96 ///
97 /// Module surface area file.
98 ///
99 File msaFile;
100
101 public ModuleIdentification parentId;
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 boolean isSingleModuleBuild = false;
113
114 private SurfaceAreaQuery saq = null;
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 if (!FrameworkBuildTask.multithread) {
129 cleanupProperties();
130 }
131
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 saq = new SurfaceAreaQuery(doc);
157 moduleId = saq.getMsaHeader();
158 } else {
159 Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);
160 saq = new SurfaceAreaQuery(doc);
161 moduleId = saq.getMsaHeader();
162 }
163 String[] producedLibraryClasses = saq.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 String packageGuid = getProject().getProperty("PACKAGE_GUID");
180 String packageVersion = getProject().getProperty("PACKAGE_VERSION");
181 PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
182 moduleId.setPackage(packageId);
183 }
184
185 //
186 // If single module : get arch from pass down, otherwise intersection MSA
187 // supported ARCHs and tools def
188 //
189 Set<String> archListSupByToolChain = new LinkedHashSet<String>();
190 String[] archs = GlobalData.getToolChainInfo().getArchs();
191
192 for (int i = 0; i < archs.length; i ++) {
193 archListSupByToolChain.add(archs[i]);
194 }
195
196 Set<String> archSet = new LinkedHashSet<String>();
197
198 if ( getProject().getProperty("ARCH") != null) {
199 String[] fpdArchList = getProject().getProperty("ARCH").split(" ");
200
201 for (int i = 0; i < fpdArchList.length; i++) {
202 if (archListSupByToolChain.contains(fpdArchList[i])) {
203 archSet.add(fpdArchList[i]);
204 }
205 }
206 } else {
207 archSet = archListSupByToolChain;
208 }
209
210 String[] archList = archSet.toArray(new String[archSet.size()]);
211
212 //
213 // Judge if arch is all supported by current module. If not, throw Exception.
214 //
215 List moduleSupportedArchs = saq.getModuleSupportedArchs();
216 if (moduleSupportedArchs != null) {
217 for (int k = 0; k < archList.length; k++) {
218 if ( ! moduleSupportedArchs.contains(archList[k])) {
219 throw new BuildException("Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures.");
220 }
221 }
222 }
223
224 for (int k = 0; k < archList.length; k++) {
225
226 getProject().setProperty("ARCH", archList[k]);
227
228 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
229
230 //
231 // Whether the module is built before
232 //
233 if (moduleId.isLibrary() == false && GlobalData.hasFpdModuleSA(fpdModuleId) == false) {
234 System.out.println("\nWARNING: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");
235 continue;
236 } else if (GlobalData.isModuleBuilt(fpdModuleId)) {
237 break;
238 } else {
239 GlobalData.registerBuiltModule(fpdModuleId);
240 }
241
242 //
243 // For Every TOOLCHAIN, TARGET
244 //
245 String[] targetList = GlobalData.getToolChainInfo().getTargets();
246 for (int i = 0; i < targetList.length; i ++){
247 //
248 // Prepare for target related common properties
249 // TARGET
250 //
251 getProject().setProperty("TARGET", targetList[i]);
252 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
253 for(int j = 0; j < toolchainList.length; j ++){
254 //
255 // check if any tool is defined for current target + toolchain + arch
256 // don't do anything if no tools found
257 //
258 if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {
259 System.out.println("Warning: No build issued. No tools were found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");
260 continue;
261 }
262
263 //
264 // Prepare for toolchain related common properties
265 // TOOLCHAIN
266 //
267 getProject().setProperty("TOOLCHAIN", toolchainList[j]);
268
269 System.out.println("Build " + moduleId + " start >>>");
270 System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);
271 saq.push(GlobalData.getDoc(fpdModuleId));
272
273 //
274 // Prepare for all other common properties
275 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
276 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
277 // MODULE_DIR, MODULE_RELATIVE_DIR
278 // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH
279 //
280 setModuleCommonProperties(archList[k]);
281
282 //
283 // OutputManage prepare for
284 // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
285 //
286 OutputManager.getInstance().update(getProject());
287
288 if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {
289 applyBuild(targetList[i], toolchainList[j], fpdModuleId);
290 } else if (type.equalsIgnoreCase("clean")) {
291 applyClean(fpdModuleId);
292 } else if (type.equalsIgnoreCase("cleanall")) {
293 applyCleanall(fpdModuleId);
294 }
295 }
296 }
297 }
298 }
299
300 /**
301 This method is used to prepare Platform-related information.
302
303 <p>In Single Module Build mode, platform-related information is not ready.
304 The method read the system environment variable <code>ACTIVE_PLATFORM</code>
305 and search in the Framework Database. Note that platform name in the Framework
306 Database must be unique. </p>
307
308 **/
309 private void prepareSingleModuleBuild(){
310 //
311 // Find out the package which the module belongs to
312 // TBD: Enhance it!!!!
313 //
314 PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);
315
316 moduleId.setPackage(packageId);
317
318 //
319 // Read ACTIVE_PLATFORM's FPD file
320 //
321 String filename = getProject().getProperty("PLATFORM_FILE");
322
323 if (filename == null){
324 throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!");
325 }
326
327 PlatformIdentification platformId = GlobalData.getPlatform(filename);
328
329 //
330 // Read FPD file (Call FpdParserTask's method)
331 //
332 FpdParserTask fpdParser = new FpdParserTask();
333 fpdParser.setProject(getProject());
334 fpdParser.parseFpdFile(platformId.getFpdFile());
335 getProject().setProperty("ARCH", fpdParser.getAllArchForModule(moduleId));
336 }
337
338 private void cleanupProperties() {
339 Project newProject = new Project();
340
341 Hashtable<String, String> passdownProperties = FrameworkBuildTask.originalProperties;
342 Iterator<String> iter = passdownProperties.keySet().iterator();
343 while (iter.hasNext()) {
344 String item = iter.next();
345 newProject.setProperty(item, passdownProperties.get(item));
346 }
347
348 newProject.setInputHandler(getProject().getInputHandler());
349
350 Iterator listenerIter = getProject().getBuildListeners().iterator();
351 while (listenerIter.hasNext()) {
352 newProject.addBuildListener((BuildListener) listenerIter.next());
353 }
354
355 getProject().initSubProject(newProject);
356
357 setProject(newProject);
358 }
359
360 /**
361 Set Module-Related information to properties.
362
363 @param arch current build ARCH
364 **/
365 private void setModuleCommonProperties(String arch) {
366 //
367 // Prepare for all other common properties
368 // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
369 //
370 PackageIdentification packageId = moduleId.getPackage();
371 getProject().setProperty("PACKAGE", packageId.getName());
372 getProject().setProperty("PACKAGE_GUID", packageId.getGuid());
373 getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());
374 getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));
375 getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
376
377 //
378 // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
379 // MODULE_DIR, MODULE_RELATIVE_DIR
380 //
381 getProject().setProperty("MODULE", moduleId.getName());
382 String baseName = saq.getModuleOutputFileBasename();
383 if (baseName == null) {
384 getProject().setProperty("BASE_NAME", moduleId.getName());
385 } else {
386 getProject().setProperty("BASE_NAME", baseName);
387 }
388 getProject().setProperty("GUID", moduleId.getGuid());
389 getProject().setProperty("FILE_GUID", moduleId.getGuid());
390 getProject().setProperty("VERSION", moduleId.getVersion());
391 getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());
392 getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
393 getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));
394
395 //
396 // SUBSYSTEM
397 //
398 String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},
399 { "SEC", "EFI_BOOT_SERVICE_DRIVER" },
400 { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },
401 { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },
402 { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },
403 { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
404 { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },
405 { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
406 { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
407 { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },
408 { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },
409 { "UEFI_APPLICATION", "EFI_APPLICATION" },
410 { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };
411
412 String subsystem = "EFI_BOOT_SERVICE_DRIVER";
413 for (int i = 0; i < subsystemMap.length; i++) {
414 if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {
415 subsystem = subsystemMap[i][1];
416 break ;
417 }
418 }
419 getProject().setProperty("SUBSYSTEM", subsystem);
420
421 //
422 // ENTRYPOINT
423 //
424 if (arch.equalsIgnoreCase("EBC")) {
425 getProject().setProperty("ENTRYPOINT", "EfiStart");
426 } else {
427 getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");
428 }
429
430 getProject().setProperty("OBJECTS", "");
431 }
432
433 private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {
434 String[] cmd = GlobalData.getToolChainInfo().getCommands();
435 for ( int m = 0; m < cmd.length; m++) {
436 //
437 // Set cmd, like CC, DLINK
438 //
439 String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};
440 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_PATH;
441 String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);
442 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME;
443 String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);
444 File cmdFile = new File(cmdPath + File.separatorChar + cmdName);
445 getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));
446
447 //
448 // set CC_FLAGS
449 //
450 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS;
451 String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);
452 Set<String> addset = new LinkedHashSet<String>();
453 Set<String> subset = new LinkedHashSet<String>();
454 putFlagsToSet(addset, cmdFlags);
455 getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));
456
457 //
458 // Set CC_EXT
459 //
460 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_EXT;
461 String extName = GlobalData.getCommandSetting(key, fpdModuleId);
462 if ( extName != null && ! extName.equalsIgnoreCase("")) {
463 getProject().setProperty(cmd[m] + "_EXT", extName);
464 } else {
465 getProject().setProperty(cmd[m] + "_EXT", "");
466 }
467
468 //
469 // set CC_FAMILY
470 //
471 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY;
472 String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);
473 if (toolChainFamily != null) {
474 getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);
475 }
476
477 //
478 // set CC_SPATH
479 //
480 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_SPATH;
481 String spath = GlobalData.getCommandSetting(key, fpdModuleId);
482 if (spath != null) {
483 getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));
484 } else {
485 getProject().setProperty(cmd[m] + "_SPATH", "");
486 }
487
488 //
489 // set CC_DPATH
490 //
491 key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_DPATH;
492 String dpath = GlobalData.getCommandSetting(key, fpdModuleId);
493 if (dpath != null) {
494 getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));
495 } else {
496 getProject().setProperty(cmd[m] + "_DPATH", "");
497 }
498 }
499 }
500
501 public void setMsaFile(File msaFile) {
502 this.msaFile = msaFile;
503 }
504
505 /**
506 Method is for ANT to initialize MSA file.
507
508 @param msaFilename MSA file name
509 **/
510 public void setMsaFile(String msaFilename) {
511 String moduleDir = getProject().getProperty("MODULE_DIR");
512
513 //
514 // If is Single Module Build, then use the Base Dir defined in build.xml
515 //
516 if (moduleDir == null) {
517 moduleDir = getProject().getBaseDir().getPath();
518 }
519 msaFile = new File(moduleDir + File.separatorChar + msaFilename);
520 }
521
522 public void addConfiguredModuleItem(ModuleItem moduleItem) {
523 PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());
524 ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());
525 moduleId.setPackage(packageId);
526 this.moduleId = moduleId;
527 }
528
529 /**
530 Add a property.
531
532 @param p property
533 **/
534 public void addProperty(Property p) {
535 properties.addElement(p);
536 }
537
538 public void setType(String type) {
539 this.type = type;
540 }
541
542 private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws BuildException{
543 //
544 // Call AutoGen to generate AutoGen.c and AutoGen.h
545 //
546 AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch(), saq);
547 autogen.genAutogen();
548
549 //
550 // Get compiler flags
551 //
552 try {
553 getCompilerFlags(buildTarget, buildTagname, fpdModuleId);
554 }
555 catch (EdkException ee) {
556 throw new BuildException(ee.getMessage());
557 }
558
559 //
560 // Prepare LIBS
561 //
562 ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch());
563 String propertyLibs = "";
564 for (int i = 0; i < libinstances.length; i++) {
565 propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";
566 }
567 getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));
568
569 //
570 // Get all includepath and set to INCLUDE_PATHS
571 //
572 String[] includes = prepareIncludePaths(fpdModuleId);
573
574 //
575 // if it is CUSTOM_BUILD
576 // then call the exist BaseName_build.xml directly.
577 //
578 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
579 System.out.println("Call user-defined " + moduleId.getName() + "_build.xml");
580
581 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
582 antCall(antFilename, null);
583
584 return ;
585 }
586
587 //
588 // Generate ${BASE_NAME}_build.xml
589 // TBD
590 //
591 String ffsKeyword = saq.getModuleFfsKeyword();
592 ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId, includes, saq);
593 String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
594 fileGenerator.genBuildFile(buildFilename);
595
596 //
597 // Ant call ${BASE_NAME}_build.xml
598 //
599 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
600 antCall(antFilename, null);
601 }
602
603 private void applyClean(FpdModuleIdentification fpdModuleId){
604 //
605 // if it is CUSTOM_BUILD
606 // then call the exist BaseName_build.xml directly.
607 //
608 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
609 System.out.println("Calling user-defined " + moduleId.getName() + "_build.xml");
610
611 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
612 antCall(antFilename, "clean");
613
614 return ;
615 }
616
617 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
618 antCall(antFilename, "clean");
619 }
620
621 private void applyCleanall(FpdModuleIdentification fpdModuleId){
622 //
623 // if it is CUSTOM_BUILD
624 // then call the exist BaseName_build.xml directly.
625 //
626 if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {
627 System.out.println("Calling user-defined " + moduleId.getName() + "_build.xml");
628
629 String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";
630 antCall(antFilename, "cleanall");
631
632 return ;
633 }
634
635 String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";
636 antCall(antFilename, "cleanall");
637 }
638
639 private void antCall(String antFilename, String target) {
640 Ant ant = new Ant();
641 ant.setProject(getProject());
642 ant.setAntfile(antFilename);
643 if (target != null) {
644 ant.setTarget(target);
645 }
646 ant.setInheritAll(true);
647 ant.init();
648 ant.execute();
649 }
650
651
652 /**
653 Separate the string and instore in set.
654
655 <p> String is separated by Java Regulation Expression
656 "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>
657
658 <p>For example: </p>
659
660 <pre>
661 "/nologo", "/W3", "/WX"
662 "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
663 </pre>
664
665 @param set store the separated string
666 @param str string to separate
667 **/
668 private void putFlagsToSet(Set<String> set, String str) {
669 if (str == null || str.length() == 0) {
670 return;
671 }
672
673 Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
674 Matcher matcher = myPattern.matcher(str + " ");
675 while (matcher.find()) {
676 String item = str.substring(matcher.start(1), matcher.end(1));
677 set.add(item);
678 }
679 }
680
681 /**
682 Generate the final flags string will be used by compile command.
683
684 @param add the add flags set
685 @param sub the sub flags set
686 @return final flags after add set substract sub set
687 **/
688 private String getFlags(Set<String> add, Set<String> sub) {
689 String result = "";
690 add.removeAll(sub);
691 Iterator iter = add.iterator();
692 while (iter.hasNext()) {
693 String str = (String) iter.next();
694 result += str.substring(1, str.length() - 1) + " ";
695 }
696 return result;
697 }
698
699 public void setSingleModuleBuild(boolean isSingleModuleBuild) {
700 this.isSingleModuleBuild = isSingleModuleBuild;
701 }
702
703 private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) {
704 //
705 // Prepare the includes: PackageDependencies and Output debug direactory
706 //
707 Set<String> includes = new LinkedHashSet<String>();
708 String arch = fpdModuleId.getArch();
709
710 //
711 // WORKSPACE
712 //
713 includes.add("${WORKSPACE_DIR}" + File.separatorChar);
714
715 //
716 // Module iteself
717 //
718 includes.add("${MODULE_DIR}");
719 includes.add("${MODULE_DIR}" + File.separatorChar + archDir(arch));
720
721 //
722 // Packages in PackageDenpendencies
723 //
724 PackageIdentification[] packageDependencies = saq.getDependencePkg(fpdModuleId.getArch());
725 for (int i = 0; i < packageDependencies.length; i++) {
726 GlobalData.refreshPackageIdentification(packageDependencies[i]);
727 File packageFile = packageDependencies[i].getSpdFile();
728 includes.add(packageFile.getParent() + File.separatorChar + "Include");
729 includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));
730 }
731
732 //
733 // All Dependency Library Instance's PackageDependencies
734 //
735 ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch());
736 for (int i = 0; i < libinstances.length; i++) {
737 saq.push(GlobalData.getDoc(libinstances[i], fpdModuleId.getArch()));
738 PackageIdentification[] libraryPackageDependencies = saq.getDependencePkg(fpdModuleId.getArch());
739 for (int j = 0; j < libraryPackageDependencies.length; j++) {
740 GlobalData.refreshPackageIdentification(libraryPackageDependencies[j]);
741 File packageFile = libraryPackageDependencies[j].getSpdFile();
742 includes.add(packageFile.getParent() + File.separatorChar + "Include");
743 includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));
744 }
745 saq.pop();
746 }
747
748
749 //
750 // The package which the module belongs to
751 // TBD
752 includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include");
753 includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));
754
755 //
756 // Debug files output directory
757 //
758 includes.add("${DEST_DIR_DEBUG}");
759
760 //
761 // set to INCLUDE_PATHS property
762 //
763 Iterator<String> iter = includes.iterator();
764 StringBuffer includePaths = new StringBuffer();
765 while (iter.hasNext()) {
766 includePaths.append(iter.next());
767 includePaths.append("; ");
768 }
769 getProject().setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths.toString()).replaceAll("(\\\\)", "/"));
770
771 return includes.toArray(new String[includes.size()]);
772 }
773
774 /**
775 Return the name of the directory that corresponds to the architecture.
776 This is a translation from the XML Schema tag to a directory that
777 corresponds to our directory name coding convention.
778
779 **/
780 private String archDir(String arch) {
781 return arch.replaceFirst("X64", "x64")
782 .replaceFirst("IPF", "Ipf")
783 .replaceFirst("IA32", "Ia32")
784 .replaceFirst("ARM", "Arm")
785 .replaceFirst("EBC", "Ebc");
786 }
787
788
789 public void setExternalProperties(Vector<Property> v) {
790 this.properties = v;
791 }
792 }