2 This file is ANT task FpdParserTask.
4 FpdParserTask is used to parse FPD (Framework Platform Description) and generate
5 build.out.xml. It is for Package or Platform build use.
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
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.
16 package org
.tianocore
.build
.fpd
;
18 import java
.io
.BufferedWriter
;
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
;
28 import java
.util
.Vector
;
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
;
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
;
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.
62 <p>The task sets global properties PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
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>
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>
72 <p>The method parseFpdFile is also prepared for single module build. </p>
76 public class FpdParserTask
extends Task
{
78 private File fpdFile
= null;
80 PlatformIdentification platformId
;
85 /// Mapping from modules identification to out put file name
87 Map
<FpdModuleIdentification
, String
> outfiles
= new LinkedHashMap
<FpdModuleIdentification
, String
>();
90 /// Mapping from FV name to its modules
92 Map
<String
, Set
<FpdModuleIdentification
>> fvs
= new HashMap
<String
, Set
<FpdModuleIdentification
>>();
95 /// Mapping from FV apriori file to its type (PEI or DXE)
97 Map
<String
, String
> aprioriType
= new HashMap
<String
, String
>();
100 /// FpdParserTask can specify some ANT properties.
102 private Vector
<Property
> properties
= new Vector
<Property
>();
104 SurfaceAreaQuery saq
= null;
106 boolean isUnified
= true;
108 public static String PEI_APRIORI_GUID
= "1b45cc0a-156a-428a-af62-49864da0e6e6";
110 public static String DXE_APRIORI_GUID
= "fc510ee7-ffdc-11d4-bd41-0080c73c8881";
113 Public construct method. It is necessary for ANT task.
115 public FpdParserTask() {
119 ANT task's entry method. The main steps is described as following:
122 <li>Initialize global information (Framework DB, SPD files and all MSA files
123 listed in SPD). This step will execute only once in whole build process;</li>
124 <li>Parse specified FPD file; </li>
125 <li>Generate FV.inf files; </li>
126 <li>Generate PlatformName_build.xml file for Flatform build; </li>
127 <li>Collect PCD information. </li>
130 @throws BuildException
131 Surface area is not valid.
133 public void execute() throws BuildException
{
134 this.setTaskName("FpdParser");
144 isUnified
= OutputManager
.getInstance().prepareBuildDir(getProject());
146 String buildDir
= getProject().getProperty("BUILD_DIR");
148 // For every Target and ToolChain
150 String
[] targetList
= GlobalData
.getToolChainInfo().getTargets();
151 for (int i
= 0; i
< targetList
.length
; i
++) {
152 String
[] toolchainList
= GlobalData
.getToolChainInfo().getTagnames();
153 for(int j
= 0; j
< toolchainList
.length
; j
++) {
157 String ffsCommonDir
= buildDir
+ File
.separatorChar
158 + targetList
[i
] + "_"
160 File fvDir
= new File(ffsCommonDir
+ File
.separatorChar
+ "FV");
162 getProject().setProperty("FV_DIR", fvDir
.getPath().replaceAll("(\\\\)", "/"));
167 genFvInfFiles(ffsCommonDir
);
174 String platformBuildFile
= buildDir
+ File
.separatorChar
+ platformId
.getName() + "_build.xml";
175 PlatformBuildFileGenerator fileGenerator
= new PlatformBuildFileGenerator(getProject(), outfiles
, fvs
, isUnified
, saq
, platformBuildFile
, aprioriType
);
176 fileGenerator
.genBuildFile();
179 // Ant call ${PLATFORM}_build.xml
182 ant
.setProject(getProject());
183 ant
.setAntfile(platformBuildFile
);
185 ant
.setInheritAll(true);
191 Generate Fv.inf files. The Fv.inf file is composed with four
192 parts: Options, Attributes, Components and Files. The Fv.inf files
193 will be under FV_DIR.
195 @throws BuildException
196 File write FV.inf files error.
198 void genFvInfFiles(String ffsCommonDir
) throws BuildException
{
199 String
[] validFv
= saq
.getFpdValidImageNames();
200 for (int i
= 0; i
< validFv
.length
; i
++) {
202 // Get all global variables from FPD and set them to properties
204 String
[][] globalVariables
= saq
.getFpdGlobalVariable();
205 for (int j
= 0; j
< globalVariables
.length
; j
++) {
206 getProject().setProperty(globalVariables
[j
][0], globalVariables
[j
][1]);
209 getProject().setProperty("FV_FILENAME", validFv
[i
]);
211 File fvFile
= new File(getProject().replaceProperties( getProject().getProperty("FV_DIR") + File
.separatorChar
+ validFv
[i
] + ".inf"));
212 if (fvFile
.exists() && (fvFile
.lastModified() >= fpdFile
.lastModified())) {
214 // don't re-generate FV.inf if fpd has not been changed
218 fvFile
.getParentFile().mkdirs();
221 FileWriter fw
= new FileWriter(fvFile
);
222 BufferedWriter bw
= new BufferedWriter(fw
);
227 String
[][] options
= saq
.getFpdOptions(validFv
[i
]);
228 if (options
.length
> 0) {
229 bw
.write("[options]");
231 for (int j
= 0; j
< options
.length
; j
++) {
232 StringBuffer str
= new StringBuffer(100);
233 str
.append(options
[j
][0]);
234 while (str
.length() < 40) {
238 str
.append(options
[j
][1]);
239 bw
.write(getProject().replaceProperties(str
.toString()));
248 String
[][] attributes
= saq
.getFpdAttributes(validFv
[i
]);
249 if (attributes
.length
> 0) {
250 bw
.write("[attributes]");
252 for (int j
= 0; j
< attributes
.length
; j
++) {
253 StringBuffer str
= new StringBuffer(100);
254 str
.append(attributes
[j
][0]);
255 while (str
.length() < 40) {
259 str
.append(attributes
[j
][1]);
260 bw
.write(getProject().replaceProperties(str
.toString()));
269 String
[][] components
= saq
.getFpdComponents(validFv
[i
]);
270 if (components
.length
> 0) {
271 bw
.write("[components]");
273 for (int j
= 0; j
< components
.length
; j
++) {
274 StringBuffer str
= new StringBuffer(100);
275 str
.append(components
[j
][0]);
276 while (str
.length() < 40) {
280 str
.append(components
[j
][1]);
281 bw
.write(getProject().replaceProperties(str
.toString()));
290 Set
<FpdModuleIdentification
> moduleSeqSet
= getModuleSequenceForFv(validFv
[i
]);
292 Set
<FpdModuleIdentification
> filesSet
= fvs
.get(validFv
[i
]);
294 FpdModuleIdentification
[] files
= null;
296 if (moduleSeqSet
== null) {
297 if (filesSet
!= null) {
298 files
= filesSet
.toArray(new FpdModuleIdentification
[filesSet
.size()]);
300 } else if (filesSet
== null) {
301 if (moduleSeqSet
.size() != 0) {
302 throw new BuildException("Can not find any modules belongs to FV[" + validFv
[i
] + "], but listed some in BuildOptions.UserExtensions[@UserID='IMAGES' @Identifier='1']");
306 // if moduleSeqSet and filesSet is inconsistent, report error
308 if(moduleSeqSet
.size() != filesSet
.size()){
309 throw new BuildException("Modules for FV[" + validFv
[i
] + "] defined in FrameworkModules and in BuildOptions.UserExtensions[@UserID='IMAGES' @Identifier='1'] are inconsistent. ");
312 // whether all modules in moduleSeqSet listed in filesSet
314 Iterator
<FpdModuleIdentification
> iter
= moduleSeqSet
.iterator();
315 while (iter
.hasNext()) {
316 FpdModuleIdentification item
= iter
.next();
317 if (!filesSet
.contains(item
)) {
318 throw new BuildException("Can not find " + item
+ " belongs to FV[" + validFv
[i
] + "]");
323 files
= moduleSeqSet
.toArray(new FpdModuleIdentification
[moduleSeqSet
.size()]);
331 Set
<FpdModuleIdentification
> modules
= null;
333 if ( (modules
= getPeiApriori(validFv
[i
])) != null) {
335 // Special GUID - validFv[i].FFS
337 String str
= ffsCommonDir
+ File
.separatorChar
+ "FV" + File
.separatorChar
+ PEI_APRIORI_GUID
+ "-" + validFv
[i
] + ".FFS";
338 bw
.write(getProject().replaceProperties("EFI_FILE_NAME = " + str
));
341 File aprioriFile
= new File(getProject().getProperty("FV_DIR") + File
.separatorChar
+ validFv
[i
] + ".apr");
342 aprioriType
.put(validFv
[i
], PEI_APRIORI_GUID
);
343 genAprioriFile(modules
, aprioriFile
);
344 } else if((modules
= getDxeApriori(validFv
[i
])) != null) {
346 // Special GUID - validFv[i].FFS
348 String str
= ffsCommonDir
+ File
.separatorChar
+ "FV" + File
.separatorChar
+ DXE_APRIORI_GUID
+ "-" + validFv
[i
] + ".FFS";
349 bw
.write(getProject().replaceProperties("EFI_FILE_NAME = " + str
));
352 File aprioriFile
= new File(getProject().getProperty("FV_DIR") + File
.separatorChar
+ validFv
[i
] + ".apr");
353 aprioriType
.put(validFv
[i
], DXE_APRIORI_GUID
);
354 genAprioriFile(modules
, aprioriFile
);
357 for (int j
= 0; j
< files
.length
; j
++) {
358 String str
= ffsCommonDir
+ File
.separatorChar
+ outfiles
.get(files
[j
]);
359 bw
.write(getProject().replaceProperties("EFI_FILE_NAME = " + str
));
366 } catch (IOException ex
) {
367 BuildException buildException
= new BuildException("Generation of the FV file [" + fvFile
.getPath() + "] failed!\n" + ex
.getMessage());
368 buildException
.setStackTrace(ex
.getStackTrace());
369 throw buildException
;
370 } catch (EdkException ex
) {
371 BuildException buildException
= new BuildException("Generation of the FV file [" + fvFile
.getPath() + "] failed!\n" + ex
.getMessage());
372 buildException
.setStackTrace(ex
.getStackTrace());
373 throw buildException
;
379 This method is used for Single Module Build.
381 @throws BuildException
382 FPD file is not valid.
384 public void parseFpdFile(File fpdFile
) throws BuildException
, EdkException
{
385 this.fpdFile
= fpdFile
;
389 // Call Platform_build.xml prebuild firstly in stand-alone build
392 isUnified
= OutputManager
.getInstance().prepareBuildDir(getProject());
394 String buildDir
= getProject().getProperty("BUILD_DIR");
396 // For every Target and ToolChain
398 String
[] targetList
= GlobalData
.getToolChainInfo().getTargets();
399 for (int i
= 0; i
< targetList
.length
; i
++) {
400 String
[] toolchainList
= GlobalData
.getToolChainInfo().getTagnames();
401 for(int j
= 0; j
< toolchainList
.length
; j
++) {
405 String ffsCommonDir
= buildDir
+ File
.separatorChar
406 + targetList
[i
] + "_"
408 File fvDir
= new File(ffsCommonDir
+ File
.separatorChar
+ "FV");
413 String platformBuildFile
= buildDir
+ File
.separatorChar
+ platformId
.getName() + "_build.xml";
414 PlatformBuildFileGenerator fileGenerator
= new PlatformBuildFileGenerator(getProject(), outfiles
, fvs
, isUnified
, saq
, platformBuildFile
, aprioriType
);
415 fileGenerator
.genBuildFile();
418 ant
.setProject(getProject());
419 ant
.setAntfile(platformBuildFile
);
420 ant
.setTarget("prebuild");
421 ant
.setInheritAll(true);
429 @throws BuildException
430 FPD file is not valid.
432 void parseFpdFile() throws BuildException
{
434 XmlObject doc
= XmlObject
.Factory
.parse(fpdFile
);
436 if (!doc
.validate()) {
437 throw new BuildException("Platform Surface Area file [" + fpdFile
.getPath() + "] format is invalid!");
440 Map
<String
, XmlObject
> map
= new HashMap
<String
, XmlObject
>();
441 map
.put("PlatformSurfaceArea", doc
);
442 saq
= new SurfaceAreaQuery(map
);
447 platformId
= saq
.getFpdHeader();
448 platformId
.setFpdFile(fpdFile
);
449 getProject().setProperty("PLATFORM", platformId
.getName());
450 getProject().setProperty("PLATFORM_FILE", platformId
.getRelativeFpdFile().replaceAll("(\\\\)", "/"));
451 getProject().setProperty("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
452 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
454 if( !FrameworkBuildTask
.multithread
) {
455 FrameworkBuildTask
.originalProperties
.put("PLATFORM", platformId
.getName());
456 FrameworkBuildTask
.originalProperties
.put("PLATFORM_FILE", platformId
.getRelativeFpdFile().replaceAll("(\\\\)", "/"));
457 FrameworkBuildTask
.originalProperties
.put("PLATFORM_DIR", platformId
.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
458 FrameworkBuildTask
.originalProperties
.put("PLATFORM_RELATIVE_DIR", platformId
.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
462 // Build mode. User-defined output dir.
464 String buildMode
= saq
.getFpdIntermediateDirectories();
465 String userDefinedOutputDir
= saq
.getFpdOutputDirectory();
467 OutputManager
.getInstance().setup(userDefinedOutputDir
, buildMode
);
470 // TBD. Deal PCD and BuildOption related Info
472 GlobalData
.setFpdBuildOptions(saq
.getFpdBuildOptions());
474 GlobalData
.setToolChainPlatformInfo(saq
.getFpdToolChainInfo());
477 // Parse all list modules SA
479 parseModuleSAFiles();
482 // TBD. Deal PCD and BuildOption related Info
484 parseToolChainFamilyOptions();
485 parseToolChainOptions();
488 // check if the tool chain is valid or not
495 // Pcd Collection. Call CollectPCDAction to collect pcd info.
497 PlatformPcdPreprocessActionForBuilding ca
= new PlatformPcdPreprocessActionForBuilding();
498 ca
.perform(platformId
.getFpdFile().getPath());
499 } catch (IOException ex
) {
500 BuildException buildException
= new BuildException("Parsing of the FPD file [" + fpdFile
.getPath() + "] failed!\n" + ex
.getMessage());
501 buildException
.setStackTrace(ex
.getStackTrace());
502 throw buildException
;
503 } catch (XmlException ex
) {
504 BuildException buildException
= new BuildException("Parsing of the FPD file [" + fpdFile
.getPath() + "] failed!\n" + ex
.getMessage());
505 buildException
.setStackTrace(ex
.getStackTrace());
506 throw buildException
;
507 } catch (EdkException ex
) {
508 BuildException buildException
= new BuildException("Parsing of the FPD file [" + fpdFile
.getPath() + "] failed!\n" + ex
.getMessage());
509 buildException
.setStackTrace(ex
.getStackTrace());
510 throw buildException
;
515 Parse all modules listed in FPD file.
517 void parseModuleSAFiles() throws EdkException
{
518 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> moduleSAs
= saq
.getFpdModules();
521 // For every Module lists in FPD file.
523 Set
<FpdModuleIdentification
> keys
= moduleSAs
.keySet();
524 Iterator iter
= keys
.iterator();
525 while (iter
.hasNext()) {
526 FpdModuleIdentification fpdModuleId
= (FpdModuleIdentification
) iter
.next();
529 // Judge if Module is existed?
531 GlobalData
.registerFpdModuleSA(fpdModuleId
, moduleSAs
.get(fpdModuleId
));
534 // Put fpdModuleId to the corresponding FV
536 saq
.push(GlobalData
.getDoc(fpdModuleId
));
537 String fvBinding
= saq
.getModuleFvBindingKeyword();
539 fpdModuleId
.setFvBinding(fvBinding
);
540 updateFvs(fvBinding
, fpdModuleId
);
543 // Prepare for out put file name
545 ModuleIdentification moduleId
= fpdModuleId
.getModule();
547 String baseName
= saq
.getModuleOutputFileBasename();
549 if (baseName
== null) {
550 baseName
= moduleId
.getName();
552 outfiles
.put(fpdModuleId
, fpdModuleId
.getArch() + File
.separatorChar
553 + moduleId
.getGuid() + "-" + baseName
554 + getSuffix(moduleId
.getModuleType()));
557 // parse module build options, if any
559 GlobalData
.addModuleToolChainOption(fpdModuleId
, parseModuleBuildOptions(false));
560 GlobalData
.addModuleToolChainFamilyOption(fpdModuleId
, parseModuleBuildOptions(true));
563 // parse MSA build options
565 GlobalData
.addMsaBuildOption(moduleId
, parseMsaBuildOptions(false));
566 GlobalData
.addMsaFamilyBuildOption(moduleId
, parseMsaBuildOptions(true));
568 ModuleIdentification
[] libraryInstances
= saq
.getLibraryInstance(null);
569 for (int i
= 0; i
< libraryInstances
.length
; i
++) {
570 saq
.push(GlobalData
.getDoc(libraryInstances
[i
], fpdModuleId
.getArch()));
571 GlobalData
.addMsaBuildOption(libraryInstances
[i
], parseMsaBuildOptions(false));
572 GlobalData
.addMsaFamilyBuildOption(libraryInstances
[i
], parseMsaBuildOptions(true));
580 ToolChainMap
parseModuleBuildOptions(boolean toolChainFamilyFlag
) throws EdkException
{
581 String
[][] options
= saq
.getModuleBuildOptions(toolChainFamilyFlag
);
582 if (options
== null || options
.length
== 0) {
583 return new ToolChainMap();
585 return parseOptions(options
);
588 private ToolChainMap
parsePlatformBuildOptions(boolean toolChainFamilyFlag
) throws EdkException
{
589 String
[][] options
= saq
.getPlatformBuildOptions(toolChainFamilyFlag
);
590 if (options
== null || options
.length
== 0) {
591 return new ToolChainMap();
593 return parseOptions(options
);
596 ToolChainMap
parseMsaBuildOptions(boolean toolChainFamilyFlag
) throws EdkException
{
597 String
[][] options
= saq
.getMsaBuildOptions(toolChainFamilyFlag
);
598 if (options
== null || options
.length
== 0) {
599 return new ToolChainMap();
601 return parseOptions(options
);
604 private ToolChainMap
parseOptions(String
[][] options
) throws EdkException
{
605 ToolChainMap map
= new ToolChainMap();
606 int flagIndex
= ToolChainElement
.ATTRIBUTE
.value
;
608 for (int i
= 0; i
< options
.length
; ++i
) {
609 String flagString
= options
[i
][flagIndex
];
610 if (flagString
== null) {
613 options
[i
][flagIndex
] = ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
;
614 map
.put(options
[i
], flagString
.trim());
620 private void parseToolChainFamilyOptions() throws EdkException
{
621 GlobalData
.setPlatformToolChainFamilyOption(parsePlatformBuildOptions(true));
624 private void parseToolChainOptions() throws EdkException
{
625 GlobalData
.setPlatformToolChainOption(parsePlatformBuildOptions(false));
629 Add the current module to corresponding FV.
631 @param fvName current FV name
632 @param moduleName current module identification
634 void updateFvs(String fvName
, FpdModuleIdentification fpdModuleId
) {
635 if (fvName
== null || fvName
.trim().length() == 0) {
638 String
[] fvNameArray
= fvName
.split("[, \t]+");
639 for (int i
= 0; i
< fvNameArray
.length
; i
++) {
641 // Put module to corresponding fvName
643 if (fvs
.containsKey(fvNameArray
[i
])) {
644 Set
<FpdModuleIdentification
> set
= fvs
.get(fvNameArray
[i
]);
645 set
.add(fpdModuleId
);
647 Set
<FpdModuleIdentification
> set
= new LinkedHashSet
<FpdModuleIdentification
>();
648 set
.add(fpdModuleId
);
649 fvs
.put(fvNameArray
[i
], set
);
655 Get the suffix based on module type. Current relationship are listed:
658 <b>ModuleType</b> <b>Suffix</b>
665 DXE_RUNTIME_DRIVER .DXE
670 UEFI_APPLICATION .APP
674 @param moduleType module type
676 @throws BuildException
677 If module type is null
679 public static String
getSuffix(String moduleType
) throws BuildException
{
680 if (moduleType
== null) {
681 throw new BuildException("Module type is not specified.");
684 String
[][] suffix
= EdkDefinitions
.ModuleTypeExtensions
;
686 for (int i
= 0; i
< suffix
.length
; i
++) {
687 if (suffix
[i
][0].equalsIgnoreCase(moduleType
)) {
701 public void addProperty(Property p
) {
702 properties
.addElement(p
);
705 public void setFpdFile(File fpdFile
) {
706 this.fpdFile
= fpdFile
;
709 public void setType(String type
) {
713 public String
getAllArchForModule(ModuleIdentification moduleId
) {
715 Iterator
<FpdModuleIdentification
> iter
= outfiles
.keySet().iterator();
716 while (iter
.hasNext()) {
717 FpdModuleIdentification fpdModuleId
= iter
.next();
719 if (fpdModuleId
.getModule().equals(moduleId
)) {
720 archs
+= fpdModuleId
.getArch() + " ";
727 private void genAprioriFile(Set
<FpdModuleIdentification
> modules
, File file
) {
729 FileWriter fw
= new FileWriter(file
);
730 BufferedWriter bw
= new BufferedWriter(fw
);
732 Iterator
<FpdModuleIdentification
> iter
= modules
.iterator();
733 while(iter
.hasNext()) {
734 bw
.write(iter
.next().getModule().getGuid());
741 } catch (IOException ex
) {
742 BuildException buildException
= new BuildException("Generation of the Apriori file [" + file
.getPath() + "] failed!\n" + ex
.getMessage());
743 buildException
.setStackTrace(ex
.getStackTrace());
744 throw buildException
;
748 private Set
<FpdModuleIdentification
> getPeiApriori(String fvName
) throws EdkException
{
749 Node node
= saq
.getPeiApriori(fvName
);
750 Set
<FpdModuleIdentification
> result
= new LinkedHashSet
<FpdModuleIdentification
>();
755 NodeList childNodes
= node
.getChildNodes();
756 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
757 Node childItem
= childNodes
.item(i
);
758 if (childItem
.getNodeType() == Node
.ELEMENT_NODE
) {
760 // Find child elements "IncludeModules"
762 if (childItem
.getNodeName().compareTo("IncludeModules") == 0) {
764 // result will be updated
766 processNodes(childItem
, result
);
767 } else if (childItem
.getNodeName().compareTo("FvName") == 0) {
769 } else if (childItem
.getNodeName().compareTo("InfFileName") == 0) {
775 EdkLog
.log(this, EdkLog
.EDK_WARNING
, "Unrecognised element " + childItem
.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='APRIORI' Identifier='0']");
783 private Set
<FpdModuleIdentification
> getDxeApriori(String fvName
) throws EdkException
{
784 Node node
= saq
.getDxeApriori(fvName
);
785 Set
<FpdModuleIdentification
> result
= new LinkedHashSet
<FpdModuleIdentification
>();
790 NodeList childNodes
= node
.getChildNodes();
791 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
792 Node childItem
= childNodes
.item(i
);
793 if (childItem
.getNodeType() == Node
.ELEMENT_NODE
) {
795 // Find child elements "IncludeModules"
797 if (childItem
.getNodeName().compareTo("IncludeModules") == 0) {
799 // result will be updated
801 processNodes(childItem
, result
);
802 } else if (childItem
.getNodeName().compareTo("FvName") == 0) {
804 } else if (childItem
.getNodeName().compareTo("InfFileName") == 0) {
810 EdkLog
.log(this, EdkLog
.EDK_WARNING
, "Unrecognised element " + childItem
.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='APRIORI' Identifier='1']");
818 private Set
<FpdModuleIdentification
> getModuleSequenceForFv(String fvName
) throws EdkException
{
819 Node node
= saq
.getFpdModuleSequence(fvName
);
820 Set
<FpdModuleIdentification
> result
= new LinkedHashSet
<FpdModuleIdentification
>();
823 EdkLog
.log(this, EdkLog
.EDK_WARNING
, "FV[" + fvName
+ "] does not specify module sequence in FPD. Assuming present sequence as default sequence in FV. ");
826 NodeList childNodes
= node
.getChildNodes();
827 for (int i
= 0; i
< childNodes
.getLength(); i
++) {
828 Node childItem
= childNodes
.item(i
);
829 if (childItem
.getNodeType() == Node
.ELEMENT_NODE
) {
831 // Find child elements "IncludeModules"
833 if (childItem
.getNodeName().compareTo("IncludeModules") == 0) {
835 // result will be updated
837 processNodes(childItem
, result
);
838 } else if (childItem
.getNodeName().compareTo("FvName") == 0) {
840 } else if (childItem
.getNodeName().compareTo("InfFileName") == 0) {
846 EdkLog
.log(this, EdkLog
.EDK_WARNING
, "Unrecognised element " + childItem
.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='IMAGES' Identifier='1']");
855 private void processNodes(Node node
, Set
<FpdModuleIdentification
> result
) throws EdkException
{
857 // Found out all elements "Module"
859 NodeList childNodes
= node
.getChildNodes();
860 for (int j
= 0; j
< childNodes
.getLength(); j
++) {
861 Node childItem
= childNodes
.item(j
);
862 if (childItem
.getNodeType() == Node
.ELEMENT_NODE
) {
863 if (childItem
.getNodeName().compareTo("Module") == 0) {
864 String moduleGuid
= null;
865 String moduleVersion
= null;
866 String packageGuid
= null;
867 String packageVersion
= null;
870 NamedNodeMap attr
= childItem
.getAttributes();
871 for (int i
= 0; i
< attr
.getLength(); i
++) {
872 Node attrItem
= attr
.item(i
);
873 if (attrItem
.getNodeName().compareTo("ModuleGuid") == 0) {
874 moduleGuid
= attrItem
.getNodeValue();
875 } else if (attrItem
.getNodeName().compareTo("ModuleVersion") == 0) {
876 moduleVersion
= attrItem
.getNodeValue();
877 } else if (attrItem
.getNodeName().compareTo("PackageGuid") == 0) {
878 packageGuid
= attrItem
.getNodeValue();
879 } else if (attrItem
.getNodeName().compareTo("PackageVersion") == 0) {
880 packageVersion
= attrItem
.getNodeValue();
881 } else if (attrItem
.getNodeName().compareTo("Arch") == 0) {
882 arch
= attrItem
.getNodeValue();
887 EdkLog
.log(this, EdkLog
.EDK_WARNING
, "Unrecognised attribute " + attrItem
.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='IMAGES' Identifier='1'].IncludeModules.Module");
891 PackageIdentification packageId
= new PackageIdentification(packageGuid
, packageVersion
);
892 GlobalData
.refreshPackageIdentification(packageId
);
894 ModuleIdentification moduleId
= new ModuleIdentification(moduleGuid
, moduleVersion
);
895 moduleId
.setPackage(packageId
);
896 GlobalData
.refreshModuleIdentification(moduleId
);
899 throw new EdkException("Attribute [Arch] is required for element FPD.BuildOptions.UserExtensions[UserID='IMAGES' Identifier='1'].IncludeModules.Module. ");
902 result
.add(new FpdModuleIdentification(moduleId
, arch
));
907 EdkLog
.log(this, EdkLog
.EDK_WARNING
, "Unrecognised element " + childItem
.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='IMAGES' Identifier='1'].IncludeModules");
914 private void checkToolChain() throws EdkException
{
915 ToolChainInfo toolChainInfo
= GlobalData
.getToolChainInfo();
917 if (toolChainInfo
.getTargets().length
== 0) {
918 throw new EdkException("No valid target found! "+
919 "Please check the TARGET definition in Tools/Conf/target.txt, "+
920 "or the <BuildTarget>, <BuildOptions> in the FPD file.");
923 if (toolChainInfo
.getTagnames().length
== 0) {
924 throw new EdkException("No valid tool chain found! "+
925 "Please check the TOOL_CHAIN_TAG definition in Tools/Conf/target.txt, "+
926 "or the <BuildOptions> in the FPD file.");
929 if (toolChainInfo
.getArchs().length
== 0) {
930 throw new EdkException("No valid architecture found! "+
931 "Please check the TARGET_ARCH definition in Tools/Conf/target.txt, "+
932 "or the <SupportedArchitectures>, <BuildOptions> in the FPD file.");
935 if (toolChainInfo
.getCommands().length
== 0) {
936 throw new EdkException("No valid COMMAND found! Please check the tool chain definitions "+
937 "in Tools/Conf/tools_def.txt.");