]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java
Fix a bug that can't add library MSA specific build option.
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / fpd / FpdParserTask.java
1 /** @file
2 This file is ANT task FpdParserTask.
3
4 FpdParserTask is used to parse FPD (Framework Platform Description) and generate
5 build.out.xml. It is for Package or Platform build use.
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.fpd;
17
18 import java.io.BufferedWriter;
19 import java.io.File;
20 import java.io.FileWriter;
21 import java.io.IOException;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.LinkedHashMap;
25 import java.util.LinkedHashSet;
26 import java.util.Map;
27 import java.util.Set;
28 import java.util.Vector;
29
30 import org.apache.tools.ant.BuildException;
31 import org.apache.tools.ant.Task;
32 import org.apache.tools.ant.taskdefs.Ant;
33 import org.apache.tools.ant.taskdefs.Property;
34 import org.apache.xmlbeans.XmlException;
35 import org.apache.xmlbeans.XmlObject;
36
37 import org.tianocore.common.definitions.EdkDefinitions;
38 import org.tianocore.common.definitions.ToolDefinitions;
39 import org.tianocore.common.exception.EdkException;
40 import org.tianocore.common.logger.EdkLog;
41 import org.tianocore.build.FrameworkBuildTask;
42 import org.tianocore.build.global.GlobalData;
43 import org.tianocore.build.global.OutputManager;
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.pcd.action.PlatformPcdPreprocessActionForBuilding;
50 import org.tianocore.build.toolchain.ToolChainElement;
51 import org.tianocore.build.toolchain.ToolChainMap;
52 import org.tianocore.build.toolchain.ToolChainInfo;
53 import org.w3c.dom.NamedNodeMap;
54 import org.w3c.dom.Node;
55 import org.w3c.dom.NodeList;
56
57 /**
58 <code>FpdParserTask</code> is an ANT task. The main function is parsing Framework
59 Platform Descritpion (FPD) XML file and generating its ANT build script for
60 corresponding platform.
61
62 <p>The task sets global properties PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
63 and BUILD_DIR. </p>
64
65 <p>The task generates ${PLATFORM}_build.xml file which will be called by top level
66 build.xml. The task also generate Fv.inf files (File is for Tool GenFvImage). </p>
67
68 <p>FpdParserTask task stores all FPD information to GlobalData. And parse
69 tools definition file to set up compiler options for different Target and
70 different ToolChainTag. </p>
71
72 <p>The method parseFpdFile is also prepared for single module build. </p>
73
74 @since GenBuild 1.0
75 **/
76 public class FpdParserTask extends Task {
77
78 private File fpdFile = null;
79
80 PlatformIdentification platformId;
81
82 private String type;
83
84 ///
85 /// Mapping from modules identification to out put file name
86 ///
87 Map<FpdModuleIdentification, String> outfiles = new LinkedHashMap<FpdModuleIdentification, String>();
88
89 ///
90 /// Mapping from FV name to its modules
91 ///
92 Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();
93
94 ///
95 /// FpdParserTask can specify some ANT properties.
96 ///
97 private Vector<Property> properties = new Vector<Property>();
98
99 SurfaceAreaQuery saq = null;
100
101 boolean isUnified = true;
102
103 /**
104 Public construct method. It is necessary for ANT task.
105 **/
106 public FpdParserTask() {
107 }
108
109 /**
110 ANT task's entry method. The main steps is described as following:
111
112 <ul>
113 <li>Initialize global information (Framework DB, SPD files and all MSA files
114 listed in SPD). This step will execute only once in whole build process;</li>
115 <li>Parse specified FPD file; </li>
116 <li>Generate FV.inf files; </li>
117 <li>Generate PlatformName_build.xml file for Flatform build; </li>
118 <li>Collect PCD information. </li>
119 </ul>
120
121 @throws BuildException
122 Surface area is not valid.
123 **/
124 public void execute() throws BuildException {
125 this.setTaskName("FpdParser");
126
127 //
128 // Parse FPD file
129 //
130 parseFpdFile();
131
132 //
133 // Prepare BUILD_DIR
134 //
135 isUnified = OutputManager.getInstance().prepareBuildDir(getProject());
136
137 String buildDir = getProject().getProperty("BUILD_DIR");
138 //
139 // For every Target and ToolChain
140 //
141 String[] targetList = GlobalData.getToolChainInfo().getTargets();
142 for (int i = 0; i < targetList.length; i++) {
143 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
144 for(int j = 0; j < toolchainList.length; j++) {
145 //
146 // Prepare FV_DIR
147 //
148 String ffsCommonDir = buildDir + File.separatorChar
149 + targetList[i] + "_"
150 + toolchainList[j];
151 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");
152 fvDir.mkdirs();
153 getProject().setProperty("FV_DIR", fvDir.getPath().replaceAll("(\\\\)", "/"));
154
155 //
156 // Gen Fv.inf files
157 //
158 genFvInfFiles(ffsCommonDir);
159 }
160 }
161
162 //
163 // Gen build.xml
164 //
165 String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";
166 PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);
167 fileGenerator.genBuildFile();
168
169 //
170 // Ant call ${PLATFORM}_build.xml
171 //
172 Ant ant = new Ant();
173 ant.setProject(getProject());
174 ant.setAntfile(platformBuildFile);
175 ant.setTarget(type);
176 ant.setInheritAll(true);
177 ant.init();
178 ant.execute();
179 }
180
181 /**
182 Generate Fv.inf files. The Fv.inf file is composed with four
183 parts: Options, Attributes, Components and Files. The Fv.inf files
184 will be under FV_DIR.
185
186 @throws BuildException
187 File write FV.inf files error.
188 **/
189 void genFvInfFiles(String ffsCommonDir) throws BuildException {
190 String[] validFv = saq.getFpdValidImageNames();
191 for (int i = 0; i < validFv.length; i++) {
192 //
193 // Get all global variables from FPD and set them to properties
194 //
195 String[][] globalVariables = saq.getFpdGlobalVariable();
196 for (int j = 0; j < globalVariables.length; j++) {
197 getProject().setProperty(globalVariables[j][0], globalVariables[j][1]);
198 }
199
200 getProject().setProperty("FV_FILENAME", validFv[i]);
201
202 File fvFile = new File(getProject().replaceProperties( getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".inf"));
203 if (fvFile.exists() && (fvFile.lastModified() >= fpdFile.lastModified())) {
204 //
205 // don't re-generate FV.inf if fpd has not been changed
206 //
207 continue;
208 }
209 fvFile.getParentFile().mkdirs();
210
211 try {
212 FileWriter fw = new FileWriter(fvFile);
213 BufferedWriter bw = new BufferedWriter(fw);
214
215 //
216 // Options
217 //
218 String[][] options = saq.getFpdOptions(validFv[i]);
219 if (options.length > 0) {
220 bw.write("[options]");
221 bw.newLine();
222 for (int j = 0; j < options.length; j++) {
223 StringBuffer str = new StringBuffer(100);
224 str.append(options[j][0]);
225 while (str.length() < 40) {
226 str.append(' ');
227 }
228 str.append("= ");
229 str.append(options[j][1]);
230 bw.write(getProject().replaceProperties(str.toString()));
231 bw.newLine();
232 }
233 bw.newLine();
234 }
235
236 //
237 // Attributes;
238 //
239 String[][] attributes = saq.getFpdAttributes(validFv[i]);
240 if (attributes.length > 0) {
241 bw.write("[attributes]");
242 bw.newLine();
243 for (int j = 0; j < attributes.length; j++) {
244 StringBuffer str = new StringBuffer(100);
245 str.append(attributes[j][0]);
246 while (str.length() < 40) {
247 str.append(' ');
248 }
249 str.append("= ");
250 str.append(attributes[j][1]);
251 bw.write(getProject().replaceProperties(str.toString()));
252 bw.newLine();
253 }
254 bw.newLine();
255 }
256
257 //
258 // Components
259 //
260 String[][] components = saq.getFpdComponents(validFv[i]);
261 if (components.length > 0) {
262 bw.write("[components]");
263 bw.newLine();
264 for (int j = 0; j < components.length; j++) {
265 StringBuffer str = new StringBuffer(100);
266 str.append(components[j][0]);
267 while (str.length() < 40) {
268 str.append(' ');
269 }
270 str.append("= ");
271 str.append(components[j][1]);
272 bw.write(getProject().replaceProperties(str.toString()));
273 bw.newLine();
274 }
275 bw.newLine();
276 }
277
278 //
279 // Files
280 //
281 Set<FpdModuleIdentification> moduleSeqSet = getModuleSequenceForFv(validFv[i]);
282
283 Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i]);
284
285 FpdModuleIdentification[] files = null;
286
287 if (moduleSeqSet == null) {
288 if (filesSet != null) {
289 files = filesSet.toArray(new FpdModuleIdentification[filesSet.size()]);
290 }
291 } else if (filesSet == null) {
292 if (moduleSeqSet.size() != 0) {
293 throw new BuildException("Can not find any modules belongs to FV[" + validFv[i] + "], but listed some in BuildOptions.UserExtensions[@UserID='IMAGES' @Identifier='1']");
294 }
295 } else {
296 //
297 // if moduleSeqSet and filesSet is inconsistent, report error
298 //
299 if(moduleSeqSet.size() != filesSet.size()){
300 throw new BuildException("Modules for FV[" + validFv[i] + "] defined in FrameworkModules and in BuildOptions.UserExtensions[@UserID='IMAGES' @Identifier='1'] are inconsistent. ");
301 } else {
302 //
303 // whether all modules in moduleSeqSet listed in filesSet
304 //
305 Iterator<FpdModuleIdentification> iter = moduleSeqSet.iterator();
306 while (iter.hasNext()) {
307 FpdModuleIdentification item = iter.next();
308 if (!filesSet.contains(item)) {
309 throw new BuildException("Can not find " + item + " belongs to FV[" + validFv[i] + "]");
310 }
311 }
312 }
313
314 files = moduleSeqSet.toArray(new FpdModuleIdentification[moduleSeqSet.size()]);
315 }
316
317
318 if (files != null) {
319 bw.write("[files]");
320 bw.newLine();
321 for (int j = 0; j < files.length; j++) {
322 String str = ffsCommonDir + File.separatorChar + outfiles.get(files[j]);
323 bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));
324 bw.newLine();
325 }
326 }
327 bw.flush();
328 bw.close();
329 fw.close();
330 } catch (IOException ex) {
331 BuildException buildException = new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + ex.getMessage());
332 buildException.setStackTrace(ex.getStackTrace());
333 throw buildException;
334 } catch (EdkException ex) {
335 BuildException buildException = new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + ex.getMessage());
336 buildException.setStackTrace(ex.getStackTrace());
337 throw buildException;
338 }
339 }
340 }
341
342 /**
343 This method is used for Single Module Build.
344
345 @throws BuildException
346 FPD file is not valid.
347 **/
348 public void parseFpdFile(File fpdFile) throws BuildException, EdkException {
349 this.fpdFile = fpdFile;
350 parseFpdFile();
351
352 //
353 // Call Platform_build.xml prebuild firstly in stand-alone build
354 // Prepare BUILD_DIR
355 //
356 isUnified = OutputManager.getInstance().prepareBuildDir(getProject());
357
358 String buildDir = getProject().getProperty("BUILD_DIR");
359 //
360 // For every Target and ToolChain
361 //
362 String[] targetList = GlobalData.getToolChainInfo().getTargets();
363 for (int i = 0; i < targetList.length; i++) {
364 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
365 for(int j = 0; j < toolchainList.length; j++) {
366 //
367 // Prepare FV_DIR
368 //
369 String ffsCommonDir = buildDir + File.separatorChar
370 + targetList[i] + "_"
371 + toolchainList[j];
372 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");
373 fvDir.mkdirs();
374 }
375 }
376
377 String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";
378 PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);
379 fileGenerator.genBuildFile();
380
381 Ant ant = new Ant();
382 ant.setProject(getProject());
383 ant.setAntfile(platformBuildFile);
384 ant.setTarget("prebuild");
385 ant.setInheritAll(true);
386 ant.init();
387 ant.execute();
388 }
389
390 /**
391 Parse FPD file.
392
393 @throws BuildException
394 FPD file is not valid.
395 **/
396 void parseFpdFile() throws BuildException {
397 try {
398 XmlObject doc = XmlObject.Factory.parse(fpdFile);
399
400 if (!doc.validate()) {
401 throw new BuildException("Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");
402 }
403
404 Map<String, XmlObject> map = new HashMap<String, XmlObject>();
405 map.put("PlatformSurfaceArea", doc);
406 saq = new SurfaceAreaQuery(map);
407
408 //
409 // Initialize
410 //
411 platformId = saq.getFpdHeader();
412 platformId.setFpdFile(fpdFile);
413 getProject().setProperty("PLATFORM", platformId.getName());
414 getProject().setProperty("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));
415 getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
416 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
417
418 if( !FrameworkBuildTask.multithread) {
419 FrameworkBuildTask.originalProperties.put("PLATFORM", platformId.getName());
420 FrameworkBuildTask.originalProperties.put("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));
421 FrameworkBuildTask.originalProperties.put("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
422 FrameworkBuildTask.originalProperties.put("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
423 }
424
425 //
426 // Build mode. User-defined output dir.
427 //
428 String buildMode = saq.getFpdIntermediateDirectories();
429 String userDefinedOutputDir = saq.getFpdOutputDirectory();
430
431 OutputManager.getInstance().setup(userDefinedOutputDir, buildMode);
432
433 //
434 // TBD. Deal PCD and BuildOption related Info
435 //
436 GlobalData.setFpdBuildOptions(saq.getFpdBuildOptions());
437
438 GlobalData.setToolChainPlatformInfo(saq.getFpdToolChainInfo());
439
440 //
441 // Parse all list modules SA
442 //
443 parseModuleSAFiles();
444
445 //
446 // TBD. Deal PCD and BuildOption related Info
447 //
448 parseToolChainFamilyOptions();
449 parseToolChainOptions();
450
451 //
452 // check if the tool chain is valid or not
453 //
454 checkToolChain();
455
456 saq.push(map);
457
458 //
459 // Pcd Collection. Call CollectPCDAction to collect pcd info.
460 //
461 PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();
462 ca.perform(platformId.getFpdFile().getPath());
463 } catch (IOException ex) {
464 BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());
465 buildException.setStackTrace(ex.getStackTrace());
466 throw buildException;
467 } catch (XmlException ex) {
468 BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());
469 buildException.setStackTrace(ex.getStackTrace());
470 throw buildException;
471 } catch (EdkException ex) {
472 BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());
473 buildException.setStackTrace(ex.getStackTrace());
474 throw buildException;
475 }
476 }
477
478 /**
479 Parse all modules listed in FPD file.
480 **/
481 void parseModuleSAFiles() throws EdkException{
482 Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = saq.getFpdModules();
483
484 //
485 // For every Module lists in FPD file.
486 //
487 Set<FpdModuleIdentification> keys = moduleSAs.keySet();
488 Iterator iter = keys.iterator();
489 while (iter.hasNext()) {
490 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();
491
492 //
493 // Judge if Module is existed?
494 // TBD
495 GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId));
496
497 //
498 // Put fpdModuleId to the corresponding FV
499 //
500 saq.push(GlobalData.getDoc(fpdModuleId));
501 String fvBinding = saq.getModuleFvBindingKeyword();
502
503 fpdModuleId.setFvBinding(fvBinding);
504 updateFvs(fvBinding, fpdModuleId);
505
506 //
507 // Prepare for out put file name
508 //
509 ModuleIdentification moduleId = fpdModuleId.getModule();
510
511 String baseName = saq.getModuleOutputFileBasename();
512
513 if (baseName == null) {
514 baseName = moduleId.getName();
515 }
516 outfiles.put(fpdModuleId, fpdModuleId.getArch() + File.separatorChar
517 + moduleId.getGuid() + "-" + baseName
518 + getSuffix(moduleId.getModuleType()));
519
520 //
521 // parse module build options, if any
522 //
523 GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));
524 GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));
525
526 //
527 // parse MSA build options
528 //
529 GlobalData.addMsaBuildOption(moduleId, parseMsaBuildOptions(false));
530 GlobalData.addMsaFamilyBuildOption(moduleId, parseMsaBuildOptions(true));
531
532 ModuleIdentification[] libraryInstances = saq.getLibraryInstance(null);
533 for (int i = 0; i < libraryInstances.length; i++) {
534 saq.push(GlobalData.getDoc(libraryInstances[i], fpdModuleId.getArch()));
535 GlobalData.addMsaBuildOption(libraryInstances[i], parseMsaBuildOptions(false));
536 GlobalData.addMsaFamilyBuildOption(libraryInstances[i], parseMsaBuildOptions(true));
537 saq.pop();
538 }
539
540 saq.pop();
541 }
542 }
543
544 ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {
545 String[][] options = saq.getModuleBuildOptions(toolChainFamilyFlag);
546 if (options == null || options.length == 0) {
547 return new ToolChainMap();
548 }
549 return parseOptions(options);
550 }
551
552 private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException {
553 String[][] options = saq.getPlatformBuildOptions(toolChainFamilyFlag);
554 if (options == null || options.length == 0) {
555 return new ToolChainMap();
556 }
557 return parseOptions(options);
558 }
559
560 ToolChainMap parseMsaBuildOptions(boolean toolChainFamilyFlag) throws EdkException {
561 String[][] options = saq.getMsaBuildOptions(toolChainFamilyFlag);
562 if (options == null || options.length == 0) {
563 return new ToolChainMap();
564 }
565 return parseOptions(options);
566 }
567
568 private ToolChainMap parseOptions(String[][] options) throws EdkException {
569 ToolChainMap map = new ToolChainMap();
570 int flagIndex = ToolChainElement.ATTRIBUTE.value;
571
572 for (int i = 0; i < options.length; ++i) {
573 String flagString = options[i][flagIndex];
574 if (flagString == null) {
575 flagString = "";
576 }
577 options[i][flagIndex] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS;
578 map.put(options[i], flagString.trim());
579 }
580
581 return map;
582 }
583
584 private void parseToolChainFamilyOptions() throws EdkException {
585 GlobalData.setPlatformToolChainFamilyOption(parsePlatformBuildOptions(true));
586 }
587
588 private void parseToolChainOptions() throws EdkException {
589 GlobalData.setPlatformToolChainOption(parsePlatformBuildOptions(false));
590 }
591
592 /**
593 Add the current module to corresponding FV.
594
595 @param fvName current FV name
596 @param moduleName current module identification
597 **/
598 void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) {
599 if (fvName == null || fvName.trim().length() == 0) {
600 fvName = "NULL";
601 }
602 String[] fvNameArray = fvName.split("[, \t]+");
603 for (int i = 0; i < fvNameArray.length; i++) {
604 //
605 // Put module to corresponding fvName
606 //
607 if (fvs.containsKey(fvNameArray[i])) {
608 Set<FpdModuleIdentification> set = fvs.get(fvNameArray[i]);
609 set.add(fpdModuleId);
610 } else {
611 Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();
612 set.add(fpdModuleId);
613 fvs.put(fvNameArray[i], set);
614 }
615 }
616 }
617
618 /**
619 Get the suffix based on module type. Current relationship are listed:
620
621 <pre>
622 <b>ModuleType</b> <b>Suffix</b>
623 BASE .FFS
624 SEC .SEC
625 PEI_CORE .PEI
626 PEIM .PEI
627 DXE_CORE .DXE
628 DXE_DRIVER .DXE
629 DXE_RUNTIME_DRIVER .DXE
630 DXE_SAL_DRIVER .DXE
631 DXE_SMM_DRIVER .DXE
632 TOOL .FFS
633 UEFI_DRIVER .DXE
634 UEFI_APPLICATION .APP
635 USER_DEFINED .FFS
636 </pre>
637
638 @param moduleType module type
639 @return
640 @throws BuildException
641 If module type is null
642 **/
643 public static String getSuffix(String moduleType) throws BuildException {
644 if (moduleType == null) {
645 throw new BuildException("Module type is not specified.");
646 }
647
648 String[][] suffix = EdkDefinitions.ModuleTypeExtensions;
649
650 for (int i = 0; i < suffix.length; i++) {
651 if (suffix[i][0].equalsIgnoreCase(moduleType)) {
652 return suffix[i][1];
653 }
654 }
655 //
656 // Default is '.FFS'
657 //
658 return ".FFS";
659 }
660 /**
661 Add a property.
662
663 @param p property
664 **/
665 public void addProperty(Property p) {
666 properties.addElement(p);
667 }
668
669 public void setFpdFile(File fpdFile) {
670 this.fpdFile = fpdFile;
671 }
672
673 public void setType(String type) {
674 this.type = type;
675 }
676
677 public String getAllArchForModule(ModuleIdentification moduleId) {
678 String archs = "";
679 Iterator<FpdModuleIdentification> iter = outfiles.keySet().iterator();
680 while (iter.hasNext()) {
681 FpdModuleIdentification fpdModuleId = iter.next();
682
683 if (fpdModuleId.getModule().equals(moduleId)) {
684 archs += fpdModuleId.getArch() + " ";
685 }
686 }
687
688 return archs;
689 }
690
691 private Set<FpdModuleIdentification> getModuleSequenceForFv(String fvName) throws EdkException {
692 Node node = saq.getFpdModuleSequence(fvName);
693 Set<FpdModuleIdentification> result = new LinkedHashSet<FpdModuleIdentification>();
694
695 if ( node == null) {
696 EdkLog.log(this, EdkLog.EDK_WARNING, "FV[" + fvName + "] does not specify module sequence in FPD. Assuming present sequence as default sequence in FV. ");
697 return null;
698 } else {
699 NodeList childNodes = node.getChildNodes();
700 for (int i = 0; i < childNodes.getLength(); i++) {
701 Node childItem = childNodes.item(i);
702 if (childItem.getNodeType() == Node.ELEMENT_NODE) {
703 //
704 // Find child elements "IncludeModules"
705 //
706 if (childItem.getNodeName().compareTo("IncludeModules") == 0) {
707 //
708 // result will be updated
709 //
710 processNodes(childItem, result);
711 } else if (childItem.getNodeName().compareTo("FvName") == 0) {
712
713 } else if (childItem.getNodeName().compareTo("InfFileName") == 0) {
714
715 } else {
716 //
717 // Report Warning
718 //
719 EdkLog.log(this, EdkLog.EDK_WARNING, "Unrecognised element " + childItem.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='IMAGES' Identifier='1']");
720 }
721 }
722 }
723 }
724
725 return result;
726 }
727
728 private void processNodes(Node node, Set<FpdModuleIdentification> result) throws EdkException {
729 //
730 // Found out all elements "Module"
731 //
732 NodeList childNodes = node.getChildNodes();
733 for (int j = 0; j < childNodes.getLength(); j++) {
734 Node childItem = childNodes.item(j);
735 if (childItem.getNodeType() == Node.ELEMENT_NODE) {
736 if (childItem.getNodeName().compareTo("Module") == 0) {
737 String moduleGuid = null;
738 String moduleVersion = null;
739 String packageGuid = null;
740 String packageVersion = null;
741 String arch = null;
742
743 NamedNodeMap attr = childItem.getAttributes();
744 for (int i = 0; i < attr.getLength(); i++) {
745 Node attrItem = attr.item(i);
746 if (attrItem.getNodeName().compareTo("ModuleGuid") == 0) {
747 moduleGuid = attrItem.getNodeValue();
748 } else if (attrItem.getNodeName().compareTo("ModuleVersion") == 0) {
749 moduleVersion = attrItem.getNodeValue();
750 } else if (attrItem.getNodeName().compareTo("PackageGuid") == 0) {
751 packageGuid = attrItem.getNodeValue();
752 } else if (attrItem.getNodeName().compareTo("PackageVersion") == 0) {
753 packageVersion = attrItem.getNodeValue();
754 } else if (attrItem.getNodeName().compareTo("Arch") == 0) {
755 arch = attrItem.getNodeValue();
756 } else {
757 //
758 // Report warning
759 //
760 EdkLog.log(this, EdkLog.EDK_WARNING, "Unrecognised attribute " + attrItem.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='IMAGES' Identifier='1'].IncludeModules.Module");
761 }
762 }
763
764 PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
765 GlobalData.refreshPackageIdentification(packageId);
766
767 ModuleIdentification moduleId = new ModuleIdentification(moduleGuid, moduleVersion);
768 moduleId.setPackage(packageId);
769 GlobalData.refreshModuleIdentification(moduleId);
770
771 if (arch == null) {
772 throw new EdkException("Attribute [Arch] is required for element FPD.BuildOptions.UserExtensions[UserID='IMAGES' Identifier='1'].IncludeModules.Module. ");
773 }
774
775 result.add(new FpdModuleIdentification(moduleId, arch));
776 } else {
777 //
778 // Report Warning
779 //
780 EdkLog.log(this, EdkLog.EDK_WARNING, "Unrecognised element " + childItem.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='IMAGES' Identifier='1'].IncludeModules");
781 }
782 }
783 }
784 }
785
786
787 private void checkToolChain() throws EdkException {
788 ToolChainInfo toolChainInfo = GlobalData.getToolChainInfo();
789
790 if (toolChainInfo.getTargets().length == 0) {
791 throw new EdkException("No valid target found! "+
792 "Please check the TARGET definition in Tools/Conf/target.txt, "+
793 "or the <BuildTarget>, <BuildOptions> in the FPD file.");
794 }
795
796 if (toolChainInfo.getTagnames().length == 0) {
797 throw new EdkException("No valid tool chain found! "+
798 "Please check the TOOL_CHAIN_TAG definition in Tools/Conf/target.txt, "+
799 "or the <BuildOptions> in the FPD file.");
800 }
801
802 if (toolChainInfo.getArchs().length == 0) {
803 throw new EdkException("No valid architecture found! "+
804 "Please check the TARGET_ARCH definition in Tools/Conf/target.txt, "+
805 "or the <SupportedArchitectures>, <BuildOptions> in the FPD file.");
806 }
807
808 if (toolChainInfo.getCommands().length == 0) {
809 throw new EdkException("No valid COMMAND found! Please check the tool chain definitions "+
810 "in Tools/Conf/tools_def.txt.");
811 }
812 }
813 }