4 GlobalData provide initializing, instoring, querying and update global data.
5 It is a bridge to intercommunicate between multiple component, such as AutoGen,
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 package org
.tianocore
.build
.global
;
20 import java
.io
.IOException
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collection
;
23 import java
.util
.HashMap
;
24 import java
.util
.HashSet
;
25 import java
.util
.Iterator
;
26 import java
.util
.List
;
30 import org
.apache
.xmlbeans
.XmlException
;
31 import org
.apache
.xmlbeans
.XmlObject
;
32 import org
.apache
.xmlbeans
.XmlOptions
;
33 import org
.tianocore
.DbPathAndFilename
;
34 import org
.tianocore
.FrameworkDatabaseDocument
;
35 import org
.tianocore
.ModuleSurfaceAreaDocument
;
36 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
37 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
38 import org
.tianocore
.build
.id
.ModuleIdentification
;
39 import org
.tianocore
.build
.id
.PackageIdentification
;
40 import org
.tianocore
.build
.id
.PlatformIdentification
;
41 import org
.tianocore
.build
.toolchain
.ToolChainConfig
;
42 import org
.tianocore
.build
.toolchain
.ToolChainElement
;
43 import org
.tianocore
.build
.toolchain
.ToolChainInfo
;
44 import org
.tianocore
.build
.toolchain
.ToolChainKey
;
45 import org
.tianocore
.build
.toolchain
.ToolChainMap
;
46 import org
.tianocore
.common
.definitions
.ToolDefinitions
;
47 import org
.tianocore
.common
.exception
.EdkException
;
48 import org
.tianocore
.common
.logger
.EdkLog
;
49 import org
.tianocore
.pcd
.entity
.MemoryDatabaseManager
;
52 GlobalData provide initializing, instoring, querying and update global data.
53 It is a bridge to intercommunicate between multiple component, such as AutoGen,
56 <p>Note that all global information are initialized incrementally. All data will
57 parse and record only of necessary during build time. </p>
61 public class GlobalData
{
63 /// Record current WORKSPACE Directory
65 private static String workspaceDir
= "";
68 /// Be used to ensure Global data will be initialized only once.
70 private static boolean globalFlag
= false;
73 /// Framework Database information: package list and platform list
75 private static Set
<PackageIdentification
> packageList
= new HashSet
<PackageIdentification
>();
77 private static Set
<PlatformIdentification
> platformList
= new HashSet
<PlatformIdentification
>();
80 /// Every detail SPD informations: Module list, Library class definition,
81 /// Package header file, GUID/PPI/Protocol definitions
83 private static final Map
<PackageIdentification
, Spd
> spdTable
= new HashMap
<PackageIdentification
, Spd
>();
86 /// Build informations are divided into three parts:
87 /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA
89 private static Map
<ModuleIdentification
, Map
<String
, XmlObject
>> nativeMsa
= new HashMap
<ModuleIdentification
, Map
<String
, XmlObject
>>();
91 private static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleSA
= new HashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
93 private static Map
<String
, XmlObject
> fpdBuildOptionsMap
= new HashMap
<String
, XmlObject
>();
95 private static XmlObject fpdBuildOptions
;
97 private static XmlObject fpdDynamicPcds
;
100 /// Parsed modules list
102 private static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> parsedModules
= new HashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
105 /// built modules list with ARCH, TARGET, TOOLCHAIN
107 private static Set
<FpdModuleIdentification
> builtModules
= new HashSet
<FpdModuleIdentification
>();
110 /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
112 private static final MemoryDatabaseManager pcdDbManager
= new MemoryDatabaseManager();
115 /// build target + tool chain family/tag name + arch + command types + command options
119 /// toolsDef - build tool program information
120 /// fpdBuildOption - all modules's build options for tool tag or tool chain families
121 /// moduleSaBuildOption - build options for a specific module
123 private static ToolChainConfig toolsDef
;
125 private static ToolChainInfo toolChainInfo
;
126 private static ToolChainInfo toolChainEnvInfo
;
127 private static ToolChainInfo toolChainPlatformInfo
;
129 private static ToolChainMap platformToolChainOption
;
130 private static ToolChainMap platformToolChainFamilyOption
;
132 private static Map
<FpdModuleIdentification
, ToolChainMap
> moduleToolChainOption
= new HashMap
<FpdModuleIdentification
, ToolChainMap
>();
133 private static Map
<FpdModuleIdentification
, ToolChainMap
> moduleToolChainFamilyOption
= new HashMap
<FpdModuleIdentification
, ToolChainMap
>();
135 private static Map
<ModuleIdentification
, ToolChainMap
> msaBuildOption
= new HashMap
<ModuleIdentification
, ToolChainMap
>();
136 private static Map
<ModuleIdentification
, ToolChainMap
> msaFamilyBuildOption
= new HashMap
<ModuleIdentification
, ToolChainMap
>();
139 Parse framework database (DB) and all SPD files listed in DB to initialize
140 the environment for next build. This method will only be executed only once
141 in the whole build process.
143 @param workspaceDatabaseFile the file name of framework database
144 @param workspaceDir current workspace directory path
145 @throws BuildException
146 Framework Dababase or SPD or MSA file is not valid
148 public synchronized static void initInfo(String workspaceDatabaseFile
, String workspaceDir
, String toolsDefFilename
) throws EdkException
{
150 // ensure this method will be revoked only once
158 // Backup workspace directory. It will be used by other method
160 GlobalData
.workspaceDir
= workspaceDir
.replaceAll("(\\\\)", "/");
163 // Parse tools definition file
166 // If ToolChain has been set up before, do nothing.
167 // CONF dir + tools definition file name
169 File toolsDefFile
= new File(workspaceDir
+ File
.separatorChar
+ toolsDefFilename
);
170 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, "Using tool definition file [" + toolsDefFile
.getPath() + "].");
171 toolsDef
= new ToolChainConfig(toolsDefFile
);
174 // Parse Framework Database
176 File dbFile
= new File(workspaceDir
+ File
.separatorChar
+ workspaceDatabaseFile
);
177 FrameworkDatabaseDocument db
= null;
179 db
= (FrameworkDatabaseDocument
)parseXmlFile(dbFile
);
183 if (db
.getFrameworkDatabase().getPackageList() != null ) {
184 List
<DbPathAndFilename
> packages
= db
.getFrameworkDatabase().getPackageList().getFilenameList();
185 Iterator
<DbPathAndFilename
> iter
= packages
.iterator();
186 while (iter
.hasNext()) {
187 String fileName
= iter
.next().getStringValue().trim();
188 Spd spd
= new Spd(new File(workspaceDir
+ File
.separatorChar
+ fileName
));
189 packageList
.add(spd
.getPackageId());
191 // Report warning if existing two packages with same GUID and Version
193 if (spdTable
.containsKey(spd
.getPackageId())) {
197 EdkLog
.log("Init", EdkLog
.EDK_WARNING
, "Warning: Existing two packages with same GUID and Version. They are ... " + spd
.getPackageId().getSpdFile().getPath());
199 spdTable
.put(spd
.getPackageId(), spd
);
202 } catch(IOException ex
) {
203 EdkException edkException
= new EdkException("Parse of WORKSPACE Database file [" + dbFile
.getPath() + "] failed!\n" + ex
.getMessage());
204 edkException
.setStackTrace(ex
.getStackTrace());
206 } catch(XmlException ex
) {
207 EdkException edkException
= new EdkException("Parse of WORKSPACE Database file [" + dbFile
.getPath() + "] failed!\n" + ex
.getMessage());
208 edkException
.setStackTrace(ex
.getStackTrace());
217 if (db
.getFrameworkDatabase().getPlatformList() != null) {
218 List
<DbPathAndFilename
> platforms
= db
.getFrameworkDatabase().getPlatformList().getFilenameList();
219 Iterator
<DbPathAndFilename
> iter
= platforms
.iterator();
220 while (iter
.hasNext()) {
221 String fileName
= iter
.next().getStringValue().trim();
222 fpdFile
= new File(workspaceDir
+ File
.separatorChar
+ fileName
);
223 if ( !fpdFile
.exists() ) {
224 throw new EdkException("Platform file [" + fpdFile
.getPath() + "] not exists. ");
226 XmlObject fpdDoc
= parseXmlFile(fpdFile
);
228 // We can change Map to XmlObject
230 Map
<String
, XmlObject
> fpdDocMap
= new HashMap
<String
, XmlObject
>();
231 fpdDocMap
.put("PlatformSurfaceArea", fpdDoc
);
232 SurfaceAreaQuery saq
= new SurfaceAreaQuery(fpdDocMap
);
233 PlatformIdentification platformId
= saq
.getFpdHeader();
234 platformId
.setFpdFile(fpdFile
);
236 // Report warning if existing two platfrom with same GUID and Version
238 if (platformList
.contains(platformId
)) {
242 EdkLog
.log("Init", EdkLog
.EDK_WARNING
, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile
.getPath());
244 platformList
.add(platformId
);
247 } catch(IOException ex
) {
248 EdkException edkException
= new EdkException("Parse of platform definition file [" + fpdFile
.getPath() + "] failed!\n" + ex
.getMessage());
249 edkException
.setStackTrace(ex
.getStackTrace());
251 } catch(XmlException ex
) {
252 EdkException edkException
= new EdkException("Parse of platform definition file [" + fpdFile
.getPath() + "] failed!\n" + ex
.getMessage());
253 edkException
.setStackTrace(ex
.getStackTrace());
259 Get the current WORKSPACE Directory.
261 @return current workspace directory
263 public synchronized static String
getWorkspacePath() {
269 Get the MSA file name with absolute path
271 public synchronized static File
getMsaFile(ModuleIdentification moduleId
) throws EdkException
{
274 // TBD. Do only when package is null.
276 Iterator iter
= packageList
.iterator();
277 while (iter
.hasNext()) {
278 PackageIdentification packageId
= (PackageIdentification
)iter
.next();
279 Spd spd
= spdTable
.get(packageId
);
280 msaFile
= spd
.getModuleFile(moduleId
);
281 if (msaFile
!= null ) {
285 if (msaFile
== null){
286 throw new EdkException("Can't find Module [" + moduleId
.getName() + "] in any SPD package!");
292 public synchronized static PackageIdentification
getPackageForModule(ModuleIdentification moduleId
) throws EdkException
{
294 // If package already defined in module
296 if (moduleId
.getPackage() != null) {
297 return moduleId
.getPackage();
300 PackageIdentification packageId
= null;
301 Iterator iter
= packageList
.iterator();
302 while (iter
.hasNext()) {
303 packageId
= (PackageIdentification
)iter
.next();
304 moduleId
.setPackage(packageId
);
305 Spd spd
= spdTable
.get(packageId
);
306 File tempMsaFile
= null;
307 if ((tempMsaFile
= spd
.getModuleFile(moduleId
)) != null ) {
308 if (tempMsaFile
.getParent().equalsIgnoreCase(moduleId
.getMsaFile().getParent())) {
314 if (packageId
== null){
315 throw new EdkException("Can't find Module [" + moduleId
.getName() + "] in any SPD package!");
322 Difference between build and parse: ToolChain and Target
324 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId
) {
325 return builtModules
.contains(moduleId
);
328 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId
) {
329 builtModules
.add(fpdModuleId
);
333 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId
, Map
<String
, XmlObject
> doc
) throws EdkException
{
334 Map
<String
, XmlObject
> result
= new HashMap
<String
, XmlObject
>();
335 Set keySet
= doc
.keySet();
336 Iterator iter
= keySet
.iterator();
337 while (iter
.hasNext()){
338 String key
= (String
)iter
.next();
339 XmlObject item
= cloneXmlObject(doc
.get(key
), true);
340 result
.put(key
, item
);
342 fpdModuleSA
.put(fpdModuleId
, result
);
345 public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId
) {
346 return fpdModuleSA
.containsKey(fpdModuleId
);
350 Query module surface area information.
352 <p>Note that surface area parsing is incremental. That means the method will
353 only parse the MSA files if necessary. </p>
355 @param fpdModuleId Module ID with arch
356 @return ModuleSA info and MSA info for fpdModuleId
357 @throws BuildException Can't find MSA
359 public synchronized static Map
<String
, XmlObject
> getDoc(FpdModuleIdentification fpdModuleId
) throws EdkException
{
360 if (parsedModules
.containsKey(fpdModuleId
)) {
361 return parsedModules
.get(fpdModuleId
);
363 Map
<String
, XmlObject
> doc
= new HashMap
<String
, XmlObject
>();
364 ModuleIdentification moduleId
= fpdModuleId
.getModule();
366 // First part: get the MSA files info
368 doc
.putAll(getNativeMsa(moduleId
));
371 // Second part: put build options
373 doc
.put("BuildOptions", fpdBuildOptions
);
376 // Third part: get Module info from FPD, such as Library instances, PCDs
378 if (fpdModuleSA
.containsKey(fpdModuleId
)){
380 // merge module info in FPD to final Doc
381 // For Library Module, do nothing here
383 doc
.putAll(fpdModuleSA
.get(fpdModuleId
));
385 parsedModules
.put(fpdModuleId
, doc
);
389 public synchronized static Map
<String
, XmlObject
> getDoc(ModuleIdentification moduleId
, String arch
) throws EdkException
{
390 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, arch
);
391 return getDoc(fpdModuleId
);
395 Query the native MSA information with module base name.
397 <p>Note that MSA parsing is incremental. That means the method will
398 only to parse the MSA files when never parsed before. </p>
400 @param moduleName the base name of the module
401 @return the native MSA information
402 @throws BuildException
403 MSA file is not valid
405 public synchronized static Map
<String
, XmlObject
> getNativeMsa(ModuleIdentification moduleId
) throws EdkException
{
406 if (nativeMsa
.containsKey(moduleId
)) {
407 return nativeMsa
.get(moduleId
);
409 File msaFile
= getMsaFile(moduleId
);
410 Map
<String
, XmlObject
> msaMap
= getNativeMsa(msaFile
);
411 nativeMsa
.put(moduleId
, msaMap
);
415 public synchronized static Map
<String
, XmlObject
> getNativeMsa(File msaFile
) throws EdkException
{
416 if (!msaFile
.exists()) {
417 throw new EdkException("Module Surface Area file [" + msaFile
.getPath() + "] can't be found!");
420 ModuleSurfaceAreaDocument doc
= (ModuleSurfaceAreaDocument
)parseXmlFile(msaFile
);
424 ModuleSurfaceArea msa
= doc
.getModuleSurfaceArea();
425 Map
<String
, XmlObject
> msaMap
= new HashMap
<String
, XmlObject
>();
426 msaMap
.put("MsaHeader", cloneXmlObject(msa
.getMsaHeader(), true));
427 msaMap
.put("ModuleDefinitions", cloneXmlObject(msa
.getModuleDefinitions(), true));
428 msaMap
.put("LibraryClassDefinitions", cloneXmlObject(msa
.getLibraryClassDefinitions(), true));
429 msaMap
.put("SourceFiles", cloneXmlObject(msa
.getSourceFiles(), true));
430 msaMap
.put("PackageDependencies", cloneXmlObject(msa
.getPackageDependencies(), true));
431 msaMap
.put("Protocols", cloneXmlObject(msa
.getProtocols(), true));
432 msaMap
.put("PPIs", cloneXmlObject(msa
.getPPIs(), true));
433 msaMap
.put("Guids", cloneXmlObject(msa
.getGuids(), true));
434 msaMap
.put("Externs", cloneXmlObject(msa
.getExterns(), true));
435 msaMap
.put("PcdCoded", cloneXmlObject(msa
.getPcdCoded(), true));
436 msaMap
.put("ModuleBuildOptions", cloneXmlObject(msa
.getModuleBuildOptions(), true));
438 } catch(IOException ex
) {
439 EdkException edkException
= new EdkException("Parse of MSA file [" + msaFile
.getPath() + "] failed!\n" + ex
.getMessage());
440 edkException
.setStackTrace(ex
.getStackTrace());
442 } catch(XmlException ex
) {
443 EdkException edkException
= new EdkException("Parse of MSA file [" + msaFile
.getPath() + "] failed!\n" + ex
.getMessage());
444 edkException
.setStackTrace(ex
.getStackTrace());
449 public static Map
<String
, XmlObject
> getFpdBuildOptionsMap() {
450 return fpdBuildOptionsMap
;
453 public static void setFpdBuildOptions(XmlObject fpdBuildOptions
) throws EdkException
{
454 GlobalData
.fpdBuildOptions
= cloneXmlObject(fpdBuildOptions
, true);
455 fpdBuildOptionsMap
.put("BuildOptions", GlobalData
.fpdBuildOptions
);
458 public static XmlObject
getFpdDynamicPcds() {
459 return fpdDynamicPcds
;
462 public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds
) {
463 GlobalData
.fpdDynamicPcds
= fpdDynamicPcds
;
466 public static Set
<ModuleIdentification
> getModules(PackageIdentification packageId
){
467 Spd spd
= spdTable
.get(packageId
);
469 Set
<ModuleIdentification
> dummy
= new HashSet
<ModuleIdentification
>();
472 return spd
.getModules();
477 * The header file path is relative to workspace dir
479 public static String
[] getLibraryClassHeaderFiles(
480 PackageIdentification
[] packages
, String name
) throws EdkException
{
481 if (packages
== null) {
482 // throw Exception or not????
483 return new String
[0];
485 String
[] result
= null;
486 for (int i
= 0; i
< packages
.length
; i
++) {
487 Spd spd
= spdTable
.get(packages
[i
]);
489 // If find one package defined the library class
491 if ((result
= spd
.getLibClassIncluder(name
)) != null) {
496 // If can't find library class declaration in every package
498 throw new EdkException("Can not find library class [" + name
499 + "] declaration in any SPD package!");
503 * The header file path is relative to workspace dir
505 public static String
getPackageHeaderFiles(PackageIdentification packages
,
507 if (packages
== null) {
508 return new String("");
510 Spd spd
= spdTable
.get(packages
);
512 // If can't find package header file, skip it
516 if ((temp
= spd
.getPackageIncluder(moduleType
)) != null) {
528 * return two values: {cName, GuidValue}
530 public static String
[] getGuid(List
<PackageIdentification
> packages
, String name
) {
531 if (packages
== null) {
532 // throw Exception or not????
533 return new String
[0];
535 String
[] result
= null;
536 Iterator item
= packages
.iterator();
537 while (item
.hasNext()){
538 Spd spd
= spdTable
.get(item
.next());
540 // If find one package defined the GUID
542 if ((result
= spd
.getGuid(name
)) != null) {
551 * return two values: {cName, GuidValue}
553 public static String
[] getPpiGuid(List
<PackageIdentification
> packages
,
555 if (packages
== null) {
556 return new String
[0];
558 String
[] result
= null;
559 Iterator item
= packages
.iterator();
560 while (item
.hasNext()){
561 Spd spd
= spdTable
.get(item
.next());
563 // If find one package defined the Ppi GUID
565 if ((result
= spd
.getPpi(name
)) != null) {
573 * return two values: {cName, GuidValue}
575 public static String
[] getProtocolGuid(List
<PackageIdentification
> packages
,
577 if (packages
== null) {
578 return new String
[0];
580 String
[] result
= null;
581 Iterator item
= packages
.iterator();
582 while (item
.hasNext()){
583 Spd spd
= spdTable
.get(item
.next());
585 // If find one package defined the protocol GUID
587 if ((result
= spd
.getProtocol(name
))!= null){
595 public synchronized static PlatformIdentification
getPlatformByName(String name
) throws EdkException
{
596 Iterator iter
= platformList
.iterator();
597 while(iter
.hasNext()){
598 PlatformIdentification platformId
= (PlatformIdentification
)iter
.next();
599 if (platformId
.getName().equalsIgnoreCase(name
)) {
603 throw new EdkException("Can't find platform [" + name
+ "] in the current WORKSPACE database!");
606 public synchronized static PlatformIdentification
getPlatform(String filename
) throws EdkException
{
607 File file
= new File(workspaceDir
+ File
.separatorChar
+ filename
);
608 Iterator iter
= platformList
.iterator();
609 while(iter
.hasNext()){
610 PlatformIdentification platformId
= (PlatformIdentification
)iter
.next();
611 if (platformId
.getFpdFile().getPath().equalsIgnoreCase(file
.getPath())) {
615 throw new EdkException("Can't find platform file [" + filename
+ "] in the current WORKSPACE database!");
618 public synchronized static PackageIdentification
refreshPackageIdentification(PackageIdentification packageId
) throws EdkException
{
619 Iterator iter
= packageList
.iterator();
620 while(iter
.hasNext()){
621 PackageIdentification packageItem
= (PackageIdentification
)iter
.next();
622 if (packageItem
.equals(packageId
)) {
623 packageId
.setName(packageItem
.getName());
624 packageId
.setSpdFile(packageItem
.getSpdFile());
628 throw new EdkException("Can't find package GUID value " + packageId
.toGuidString() + " in the current workspace!");
631 public synchronized static ModuleIdentification
refreshModuleIdentification(ModuleIdentification moduleId
) throws EdkException
{
632 PackageIdentification packageId
= getPackageForModule(moduleId
);
633 moduleId
.setPackage(packageId
);
634 Spd spd
= spdTable
.get(packageId
);
636 throw new EdkException("Can't find package GUID value " + packageId
.toGuidString() + " in the current workspace!");
638 Set
<ModuleIdentification
> modules
= spd
.getModules();
639 Iterator
<ModuleIdentification
> iter
= modules
.iterator();
640 while (iter
.hasNext()) {
641 ModuleIdentification item
= iter
.next();
642 if (item
.equals(moduleId
)) {
643 moduleId
.setName(item
.getName());
644 moduleId
.setModuleType(item
.getModuleType());
645 moduleId
.setMsaFile(item
.getMsaFile());
649 throw new EdkException("Can't find module GUID value " + moduleId
.toGuidString() + " in " + packageId
+ " under the current workspace!");
652 public synchronized static Set
<PackageIdentification
> getPackageList(){
657 BUGBUG: It is a walk around method. If do not clone, can't query info with
660 @param object XmlObject
661 @param deep flag for deep clone
662 @return XmlObject after clone
663 @throws BuildException parse original XmlObject error.
665 private static XmlObject
cloneXmlObject(XmlObject object
, boolean deep
) throws EdkException
{
666 if ( object
== null) {
669 XmlObject result
= null;
671 result
= XmlObject
.Factory
.parse(object
.getDomNode()
673 } catch (XmlException ex
) {
674 EdkException edkException
= new EdkException(ex
.getMessage());
675 edkException
.setStackTrace(ex
.getStackTrace());
682 /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
684 public synchronized static ToolChainInfo
getToolChainInfo() {
685 if (toolChainInfo
== null) {
686 toolChainInfo
= toolsDef
.getConfigInfo().intersection(toolChainEnvInfo
);
687 if (toolChainPlatformInfo
!= null) {
688 toolChainInfo
= toolChainInfo
.intersection(toolChainPlatformInfo
);
690 toolChainInfo
.addCommands(toolsDef
.getConfigInfo().getCommands());
691 toolChainInfo
.normalize();
692 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, "Current build tool chain information summary: ");
693 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, toolChainInfo
+ "");
695 return toolChainInfo
;
698 public static void setPlatformToolChainFamilyOption(ToolChainMap map
) {
699 platformToolChainFamilyOption
= map
;
702 public static void setPlatformToolChainOption(ToolChainMap map
) {
703 platformToolChainOption
= map
;
706 public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId
,
707 ToolChainMap toolChainOption
) {
708 moduleToolChainOption
.put(fpdModuleId
, toolChainOption
);
711 public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId
,
712 ToolChainMap toolChainOption
) {
713 moduleToolChainFamilyOption
.put(fpdModuleId
, toolChainOption
);
716 public static void addMsaBuildOption(ModuleIdentification moduleId
,
717 ToolChainMap toolChainOption
) {
718 msaBuildOption
.put(moduleId
, toolChainOption
);
721 public static void addMsaFamilyBuildOption(ModuleIdentification moduleId
,
722 ToolChainMap toolChainOption
) {
723 msaFamilyBuildOption
.put(moduleId
, toolChainOption
);
726 public static boolean isCommandSet(String target
, String toolchain
, String arch
) {
727 String
[] commands
= getToolChainInfo().getCommands();
729 for (int i
= 0; i
< commands
.length
; ++i
) {
730 String cmdName
= toolsDef
.getConfig().get(new String
[] {target
, toolchain
, arch
, commands
[i
], ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_NAME
});
731 if (cmdName
!= null && cmdName
.length() != 0) {
740 Except FLAGS, all attribute are from TOOLS_DEF file.
742 For FLAGS, information from four places, they are:
745 2. MSA <BuildOptions>/<Options>
746 3. FPD <BuildOptions>/<Options>
747 4. FPD <FrameworkModules>/<ModuleSaBuildOptions>/<Options>
750 @param commandDescription Key: TARGET, TAGNAME, ARCH, COMMANDTYPE, ATTRIBUTE
751 @param fpdModuleId Module Identification with Arch
752 @return The corresponding String
753 @throws EdkException If build option definition error
755 public synchronized static String
getCommandSetting(String
[] commandDescription
, FpdModuleIdentification fpdModuleId
) throws EdkException
{
756 ToolChainKey toolChainKey
= new ToolChainKey(commandDescription
);
757 ToolChainMap toolChainConfig
= toolsDef
.getConfig();
758 String setting
= null;
761 // Default in tools_def.txt
763 setting
= toolChainConfig
.get(toolChainKey
);
764 if (setting
== null) {
767 if (!commandDescription
[ToolChainElement
.ATTRIBUTE
.value
].equals(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
)) {
772 // Tool's option can be in .fpd and/or .msa file
775 ToolChainMap option
= null;
776 ToolChainKey toolChainFamilyKey
= new ToolChainKey(commandDescription
);
778 toolChainFamilyKey
.setKey(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FAMILY
, ToolChainElement
.ATTRIBUTE
.value
);
779 String family
= toolChainConfig
.get(toolChainFamilyKey
);
780 toolChainFamilyKey
.setKey(family
, ToolChainElement
.TOOLCHAIN
.value
);
781 toolChainFamilyKey
.setKey(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
, ToolChainElement
.ATTRIBUTE
.value
);
784 // MSA's tool chain family option
786 option
= msaFamilyBuildOption
.get(fpdModuleId
.getModule());
787 if (option
!= null && (optionString
= option
.get(toolChainFamilyKey
)) != null) {
788 setting
+= (" " + optionString
);
792 // MSA's tool chain option
794 option
= msaBuildOption
.get(fpdModuleId
.getModule());
795 if (option
!= null && (optionString
= option
.get(toolChainKey
)) != null) {
796 setting
+= (" " + optionString
);
800 // Platform's tool chain family option
802 optionString
= platformToolChainFamilyOption
.get(toolChainFamilyKey
);
803 if (optionString
!= null) {
804 setting
+= (" " + optionString
);
808 // Platform's tool chain tag option
810 optionString
= platformToolChainOption
.get(toolChainKey
);
811 if (optionString
!= null) {
812 setting
+= (" " + optionString
);
816 // Module's tool chain family option
818 option
= moduleToolChainFamilyOption
.get(fpdModuleId
);
819 if (option
!= null && (optionString
= option
.get(toolChainFamilyKey
)) != null) {
820 setting
+= (" " + optionString
);
824 // Module's tool chain tag option
826 option
= moduleToolChainOption
.get(fpdModuleId
);
827 if (option
!= null && (optionString
= option
.get(toolChainKey
)) != null) {
828 setting
+= (" " + optionString
);
834 public static void setToolChainEnvInfo(ToolChainInfo envInfo
) {
835 toolChainEnvInfo
= envInfo
;
837 public static void setToolChainPlatformInfo(ToolChainInfo platformInfo
) {
838 toolChainPlatformInfo
= platformInfo
;
844 public synchronized static MemoryDatabaseManager
getPCDMemoryDBManager() {
849 // For PCD get tokenSpaceGUid
851 public synchronized static String
getGuidInfoFromCname(String cName
){
852 String cNameGuid
= null;
854 Set set
= spdTable
.keySet();
855 Iterator iter
= set
.iterator();
861 while (iter
.hasNext()){
862 Spd spd
= (Spd
) spdTable
.get(iter
.next());
863 guid
= spd
.getGuidFromCname(cName
);
875 public synchronized static Map
<FpdModuleIdentification
, XmlObject
>
876 getFpdModuleSaXmlObject(String xmlObjectName
) {
877 Set
<FpdModuleIdentification
> fpdModuleSASet
= fpdModuleSA
.keySet();
878 Iterator item
= fpdModuleSASet
.iterator();
881 Map
<FpdModuleIdentification
, XmlObject
> SAPcdBuildDef
= new HashMap
<FpdModuleIdentification
, XmlObject
>();
882 Map
<String
, XmlObject
> SANode
= new HashMap
<String
, XmlObject
>();
883 FpdModuleIdentification moduleId
;
884 while (item
.hasNext()) {
886 moduleId
= (FpdModuleIdentification
) item
.next();
887 SANode
= fpdModuleSA
.get(moduleId
);
889 if (SANode
.get(xmlObjectName
)!= null){
890 SAPcdBuildDef
.put(moduleId
,
891 (XmlObject
) SANode
.get(xmlObjectName
));
894 } catch (Exception e
){
895 EdkLog
.log(EdkLog
.EDK_INFO
, e
.getMessage());
898 return SAPcdBuildDef
;
901 public synchronized static Map
<FpdModuleIdentification
,XmlObject
> getFpdPcdBuildDefinitions() {
902 Map
<FpdModuleIdentification
,XmlObject
> pcdBuildDef
= getFpdModuleSaXmlObject ("PcdBuildDefinition");
907 public static XmlObject
parseXmlFile(File xmlFile
) throws IOException
, XmlException
{
908 Collection errors
= new ArrayList();
909 XmlOptions opt
= new XmlOptions();
911 opt
.setLoadLineNumbers();
912 opt
.setLoadMessageDigest();
913 opt
.setErrorListener(errors
);
915 XmlObject doc
= XmlObject
.Factory
.parse(xmlFile
, opt
);
917 // Validate File if they accord with XML Schema
919 if (!doc
.validate(opt
)){
920 StringBuilder errorMessage
= new StringBuilder(1024);
921 for (Iterator it
= errors
.iterator(); it
.hasNext(); ) {
922 errorMessage
.append(it
.next());
923 errorMessage
.append("\n");
925 throw new XmlException(errorMessage
.toString());