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
.HashMap
;
22 import java
.util
.HashSet
;
23 import java
.util
.Iterator
;
24 import java
.util
.List
;
28 import org
.apache
.xmlbeans
.XmlException
;
29 import org
.apache
.xmlbeans
.XmlObject
;
31 import org
.tianocore
.common
.definitions
.ToolDefinitions
;
32 import org
.tianocore
.common
.exception
.EdkException
;
33 import org
.tianocore
.common
.logger
.EdkLog
;
34 import org
.tianocore
.pcd
.entity
.MemoryDatabaseManager
;
35 import org
.tianocore
.DbPathAndFilename
;
36 import org
.tianocore
.FrameworkDatabaseDocument
;
37 import org
.tianocore
.ModuleSurfaceAreaDocument
;
38 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
39 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
40 import org
.tianocore
.build
.id
.ModuleIdentification
;
41 import org
.tianocore
.build
.id
.PackageIdentification
;
42 import org
.tianocore
.build
.id
.PlatformIdentification
;
43 import org
.tianocore
.build
.toolchain
.ToolChainConfig
;
44 import org
.tianocore
.build
.toolchain
.ToolChainElement
;
45 import org
.tianocore
.build
.toolchain
.ToolChainInfo
;
46 import org
.tianocore
.build
.toolchain
.ToolChainKey
;
47 import org
.tianocore
.build
.toolchain
.ToolChainMap
;
50 GlobalData provide initializing, instoring, querying and update global data.
51 It is a bridge to intercommunicate between multiple component, such as AutoGen,
54 <p>Note that all global information are initialized incrementally. All data will
55 parse and record only of necessary during build time. </p>
59 public class GlobalData
{
61 /// Record current WORKSPACE Directory
63 private static String workspaceDir
= "";
66 /// Be used to ensure Global data will be initialized only once.
68 private static boolean globalFlag
= false;
71 /// Framework Database information: package list and platform list
73 private static Set
<PackageIdentification
> packageList
= new HashSet
<PackageIdentification
>();
75 private static Set
<PlatformIdentification
> platformList
= new HashSet
<PlatformIdentification
>();
78 /// Every detail SPD informations: Module list, Library class definition,
79 /// Package header file, GUID/PPI/Protocol definitions
81 private static final Map
<PackageIdentification
, Spd
> spdTable
= new HashMap
<PackageIdentification
, Spd
>();
84 /// Build informations are divided into three parts:
85 /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA
87 private static Map
<ModuleIdentification
, Map
<String
, XmlObject
>> nativeMsa
= new HashMap
<ModuleIdentification
, Map
<String
, XmlObject
>>();
89 private static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleSA
= new HashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
91 private static Map
<String
, XmlObject
> fpdBuildOptionsMap
= new HashMap
<String
, XmlObject
>();
93 private static XmlObject fpdBuildOptions
;
95 private static XmlObject fpdDynamicPcds
;
98 /// Parsed modules list
100 private static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> parsedModules
= new HashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
103 /// built modules list with ARCH, TARGET, TOOLCHAIN
105 private static Set
<FpdModuleIdentification
> builtModules
= new HashSet
<FpdModuleIdentification
>();
108 /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
110 private static final MemoryDatabaseManager pcdDbManager
= new MemoryDatabaseManager();
113 /// build target + tool chain family/tag name + arch + command types + command options
117 /// toolsDef - build tool program information
118 /// fpdBuildOption - all modules's build options for tool tag or tool chain families
119 /// moduleSaBuildOption - build options for a specific module
121 private static ToolChainConfig toolsDef
;
123 private static ToolChainInfo toolChainInfo
;
124 private static ToolChainInfo toolChainEnvInfo
;
125 private static ToolChainInfo toolChainPlatformInfo
;
127 private static ToolChainMap platformToolChainOption
;
128 private static ToolChainMap platformToolChainFamilyOption
;
130 private static Map
<FpdModuleIdentification
, ToolChainMap
> moduleToolChainOption
= new HashMap
<FpdModuleIdentification
, ToolChainMap
>();
131 private static Map
<FpdModuleIdentification
, ToolChainMap
> moduleToolChainFamilyOption
= new HashMap
<FpdModuleIdentification
, ToolChainMap
>();
133 private static Map
<ModuleIdentification
, ToolChainMap
> msaBuildOption
= new HashMap
<ModuleIdentification
, ToolChainMap
>();
134 private static Map
<ModuleIdentification
, ToolChainMap
> msaFamilyBuildOption
= new HashMap
<ModuleIdentification
, ToolChainMap
>();
136 // private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");
138 Parse framework database (DB) and all SPD files listed in DB to initialize
139 the environment for next build. This method will only be executed only once
140 in the whole build process.
142 @param workspaceDatabaseFile the file name of framework database
143 @param workspaceDir current workspace directory path
144 @throws BuildException
145 Framework Dababase or SPD or MSA file is not valid
147 public synchronized static void initInfo(String workspaceDatabaseFile
, String workspaceDir
, String toolsDefFilename
) throws EdkException
{
149 // ensure this method will be revoked only once
157 // Backup workspace directory. It will be used by other method
159 GlobalData
.workspaceDir
= workspaceDir
.replaceAll("(\\\\)", "/");
162 // Parse tools definition file
165 // If ToolChain has been set up before, do nothing.
166 // CONF dir + tools definition file name
168 File toolsDefFile
= new File(workspaceDir
+ File
.separatorChar
+ toolsDefFilename
);
169 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, "Using tool definition file [" + toolsDefFile
.getPath() + "].");
170 toolsDef
= new ToolChainConfig(toolsDefFile
);
173 // Parse Framework Database
175 File dbFile
= new File(workspaceDir
+ File
.separatorChar
+ workspaceDatabaseFile
);
177 FrameworkDatabaseDocument db
= (FrameworkDatabaseDocument
) XmlObject
.Factory
.parse(dbFile
);
179 // validate FrameworkDatabaseFile
181 if (!db
.validate()) {
182 throw new EdkException("Framework Database file [" + dbFile
.getPath() + "] format is invalid!");
187 if (db
.getFrameworkDatabase().getPackageList() != null ) {
188 List
<DbPathAndFilename
> packages
= db
.getFrameworkDatabase().getPackageList().getFilenameList();
189 Iterator
<DbPathAndFilename
> iter
= packages
.iterator();
190 while (iter
.hasNext()) {
191 String fileName
= iter
.next().getStringValue().trim();
192 Spd spd
= new Spd(new File(workspaceDir
+ File
.separatorChar
+ fileName
));
193 packageList
.add(spd
.getPackageId());
195 // Report warning if existing two packages with same GUID and Version
197 if (spdTable
.containsKey(spd
.getPackageId())) {
201 EdkLog
.log("Init", EdkLog
.EDK_WARNING
, "Warning: Existing two packages with same GUID and Version. They are ... " + spd
.getPackageId().getSpdFile().getPath());
203 spdTable
.put(spd
.getPackageId(), spd
);
210 if (db
.getFrameworkDatabase().getPlatformList() != null) {
211 List
<DbPathAndFilename
> platforms
= db
.getFrameworkDatabase().getPlatformList().getFilenameList();
212 Iterator
<DbPathAndFilename
> iter
= platforms
.iterator();
213 while (iter
.hasNext()) {
214 String fileName
= iter
.next().getStringValue().trim();
215 File fpdFile
= new File(workspaceDir
+ File
.separatorChar
+ fileName
);
216 if ( !fpdFile
.exists() ) {
217 throw new EdkException("Platform file [" + fpdFile
.getPath() + "] not exists. ");
219 XmlObject fpdDoc
= XmlObject
.Factory
.parse(fpdFile
);
221 // Verify FPD file, if is invalid, throw Exception
223 if (!fpdDoc
.validate()) {
224 throw new EdkException("Framework Platform Surface Area file [" + fpdFile
.getPath() + "] format is invalid!");
227 // We can change Map to XmlObject
229 Map
<String
, XmlObject
> fpdDocMap
= new HashMap
<String
, XmlObject
>();
230 fpdDocMap
.put("PlatformSurfaceArea", fpdDoc
);
231 SurfaceAreaQuery saq
= new SurfaceAreaQuery(fpdDocMap
);
232 PlatformIdentification platformId
= saq
.getFpdHeader();
233 platformId
.setFpdFile(fpdFile
);
235 // Report warning if existing two platfrom with same GUID and Version
237 if (platformList
.contains(platformId
)) {
241 EdkLog
.log("Init", EdkLog
.EDK_WARNING
, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile
.getPath());
243 platformList
.add(platformId
);
246 } catch(IOException ex
) {
247 EdkException edkException
= new EdkException("Parse WORKSPACE Database file [" + dbFile
.getPath() + "] Error.\n" + ex
.getMessage());
248 edkException
.setStackTrace(ex
.getStackTrace());
250 } catch(XmlException ex
) {
251 EdkException edkException
= new EdkException("Parse WORKSPACE Database file [" + dbFile
.getPath() + "] Error.\n" + ex
.getMessage());
252 edkException
.setStackTrace(ex
.getStackTrace());
258 Get the current WORKSPACE Directory.
260 @return current workspace directory
262 public synchronized static String
getWorkspacePath() {
268 Get the MSA file name with absolute path
270 public synchronized static File
getMsaFile(ModuleIdentification moduleId
) throws EdkException
{
273 // TBD. Do only when package is null.
275 Iterator iter
= packageList
.iterator();
276 while (iter
.hasNext()) {
277 PackageIdentification packageId
= (PackageIdentification
)iter
.next();
278 Spd spd
= spdTable
.get(packageId
);
279 msaFile
= spd
.getModuleFile(moduleId
);
280 if (msaFile
!= null ) {
284 if (msaFile
== null){
285 throw new EdkException("Can't find Module [" + moduleId
.getName() + "] in any SPD package!");
291 public synchronized static PackageIdentification
getPackageForModule(ModuleIdentification moduleId
) throws EdkException
{
293 // If package already defined in module
295 if (moduleId
.getPackage() != null) {
296 return moduleId
.getPackage();
299 PackageIdentification packageId
= null;
300 Iterator iter
= packageList
.iterator();
301 while (iter
.hasNext()) {
302 packageId
= (PackageIdentification
)iter
.next();
303 moduleId
.setPackage(packageId
);
304 Spd spd
= spdTable
.get(packageId
);
305 File tempMsaFile
= null;
306 if ((tempMsaFile
= spd
.getModuleFile(moduleId
)) != null ) {
307 if (tempMsaFile
.getParent().equalsIgnoreCase(moduleId
.getMsaFile().getParent())) {
313 if (packageId
== null){
314 throw new EdkException("Can't find Module [" + moduleId
.getName() + "] in any SPD package!");
321 Difference between build and parse: ToolChain and Target
323 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId
) {
324 return builtModules
.contains(moduleId
);
327 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId
) {
328 builtModules
.add(fpdModuleId
);
332 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId
, Map
<String
, XmlObject
> doc
) throws EdkException
{
333 Map
<String
, XmlObject
> result
= new HashMap
<String
, XmlObject
>();
334 Set keySet
= doc
.keySet();
335 Iterator iter
= keySet
.iterator();
336 while (iter
.hasNext()){
337 String key
= (String
)iter
.next();
338 XmlObject item
= cloneXmlObject(doc
.get(key
), true);
339 result
.put(key
, item
);
341 fpdModuleSA
.put(fpdModuleId
, result
);
344 public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId
) {
345 return fpdModuleSA
.containsKey(fpdModuleId
);
349 Query module surface area information.
351 <p>Note that surface area parsing is incremental. That means the method will
352 only parse the MSA files if necessary. </p>
354 @param fpdModuleId Module ID with arch
355 @return ModuleSA info and MSA info for fpdModuleId
356 @throws BuildException Can't find MSA
358 public synchronized static Map
<String
, XmlObject
> getDoc(FpdModuleIdentification fpdModuleId
) throws EdkException
{
359 if (parsedModules
.containsKey(fpdModuleId
)) {
360 return parsedModules
.get(fpdModuleId
);
362 Map
<String
, XmlObject
> doc
= new HashMap
<String
, XmlObject
>();
363 ModuleIdentification moduleId
= fpdModuleId
.getModule();
365 // First part: get the MSA files info
367 doc
.putAll(getNativeMsa(moduleId
));
370 // Second part: put build options
372 doc
.put("BuildOptions", fpdBuildOptions
);
375 // Third part: get Module info from FPD, such as Library instances, PCDs
377 if (fpdModuleSA
.containsKey(fpdModuleId
)){
379 // merge module info in FPD to final Doc
380 // For Library Module, do nothing here
382 doc
.putAll(fpdModuleSA
.get(fpdModuleId
));
384 parsedModules
.put(fpdModuleId
, doc
);
388 public synchronized static Map
<String
, XmlObject
> getDoc(ModuleIdentification moduleId
, String arch
) throws EdkException
{
389 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, arch
);
390 return getDoc(fpdModuleId
);
394 Query the native MSA information with module base name.
396 <p>Note that MSA parsing is incremental. That means the method will
397 only to parse the MSA files when never parsed before. </p>
399 @param moduleName the base name of the module
400 @return the native MSA information
401 @throws BuildException
402 MSA file is not valid
404 public synchronized static Map
<String
, XmlObject
> getNativeMsa(ModuleIdentification moduleId
) throws EdkException
{
405 if (nativeMsa
.containsKey(moduleId
)) {
406 return nativeMsa
.get(moduleId
);
408 File msaFile
= getMsaFile(moduleId
);
409 Map
<String
, XmlObject
> msaMap
= getNativeMsa(msaFile
);
410 nativeMsa
.put(moduleId
, msaMap
);
414 public synchronized static Map
<String
, XmlObject
> getNativeMsa(File msaFile
) throws EdkException
{
415 if (!msaFile
.exists()) {
416 throw new EdkException("Module Surface Area file [" + msaFile
.getPath() + "] can't be found!");
419 ModuleSurfaceAreaDocument doc
= (ModuleSurfaceAreaDocument
)XmlObject
.Factory
.parse(msaFile
);
421 // Validate File if they accord with XML Schema
423 if ( !doc
.validate()){
424 throw new EdkException("Module Surface Area file [" + msaFile
.getPath() + "] format is invalid!");
429 ModuleSurfaceArea msa
= doc
.getModuleSurfaceArea();
430 Map
<String
, XmlObject
> msaMap
= new HashMap
<String
, XmlObject
>();
431 msaMap
.put("MsaHeader", cloneXmlObject(msa
.getMsaHeader(), true));
432 msaMap
.put("ModuleDefinitions", cloneXmlObject(msa
.getModuleDefinitions(), true));
433 msaMap
.put("LibraryClassDefinitions", cloneXmlObject(msa
.getLibraryClassDefinitions(), true));
434 msaMap
.put("SourceFiles", cloneXmlObject(msa
.getSourceFiles(), true));
435 msaMap
.put("PackageDependencies", cloneXmlObject(msa
.getPackageDependencies(), true));
436 msaMap
.put("Protocols", cloneXmlObject(msa
.getProtocols(), true));
437 msaMap
.put("PPIs", cloneXmlObject(msa
.getPPIs(), true));
438 msaMap
.put("Guids", cloneXmlObject(msa
.getGuids(), true));
439 msaMap
.put("Externs", cloneXmlObject(msa
.getExterns(), true));
440 msaMap
.put("PcdCoded", cloneXmlObject(msa
.getPcdCoded(), true));
441 msaMap
.put("ModuleBuildOptions", cloneXmlObject(msa
.getModuleBuildOptions(), true));
443 } catch(IOException ex
) {
444 EdkException edkException
= new EdkException("Parsing MSA file [" + msaFile
.getPath() + "] error. \n" + ex
.getMessage());
445 edkException
.setStackTrace(ex
.getStackTrace());
447 } catch(XmlException ex
) {
448 EdkException edkException
= new EdkException("Parsing MSA file [" + msaFile
.getPath() + "] error. \n" + ex
.getMessage());
449 edkException
.setStackTrace(ex
.getStackTrace());
454 public static Map
<String
, XmlObject
> getFpdBuildOptionsMap() {
455 return fpdBuildOptionsMap
;
458 public static void setFpdBuildOptions(XmlObject fpdBuildOptions
) throws EdkException
{
459 GlobalData
.fpdBuildOptions
= cloneXmlObject(fpdBuildOptions
, true);
460 fpdBuildOptionsMap
.put("BuildOptions", GlobalData
.fpdBuildOptions
);
463 public static XmlObject
getFpdDynamicPcds() {
464 return fpdDynamicPcds
;
467 public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds
) {
468 GlobalData
.fpdDynamicPcds
= fpdDynamicPcds
;
471 public static Set
<ModuleIdentification
> getModules(PackageIdentification packageId
){
472 Spd spd
= spdTable
.get(packageId
);
474 Set
<ModuleIdentification
> dummy
= new HashSet
<ModuleIdentification
>();
477 return spd
.getModules();
482 * The header file path is relative to workspace dir
484 public static String
[] getLibraryClassHeaderFiles(
485 PackageIdentification
[] packages
, String name
) throws EdkException
{
486 if (packages
== null) {
487 // throw Exception or not????
488 return new String
[0];
490 String
[] result
= null;
491 for (int i
= 0; i
< packages
.length
; i
++) {
492 Spd spd
= spdTable
.get(packages
[i
]);
494 // If find one package defined the library class
496 if ((result
= spd
.getLibClassIncluder(name
)) != null) {
501 // If can't find library class declaration in every package
503 throw new EdkException("Can not find library class [" + name
504 + "] declaration in any SPD package!");
508 * The header file path is relative to workspace dir
510 public static String
getPackageHeaderFiles(PackageIdentification packages
,
512 if (packages
== null) {
513 return new String("");
515 Spd spd
= spdTable
.get(packages
);
517 // If can't find package header file, skip it
521 if ((temp
= spd
.getPackageIncluder(moduleType
)) != null) {
533 * return two values: {cName, GuidValue}
535 public static String
[] getGuid(List
<PackageIdentification
> packages
, String name
) {
536 if (packages
== null) {
537 // throw Exception or not????
538 return new String
[0];
540 String
[] result
= null;
541 Iterator item
= packages
.iterator();
542 while (item
.hasNext()){
543 Spd spd
= spdTable
.get(item
.next());
545 // If find one package defined the GUID
547 if ((result
= spd
.getGuid(name
)) != null) {
556 * return two values: {cName, GuidValue}
558 public static String
[] getPpiGuid(List
<PackageIdentification
> packages
,
560 if (packages
== null) {
561 return new String
[0];
563 String
[] result
= null;
564 Iterator item
= packages
.iterator();
565 while (item
.hasNext()){
566 Spd spd
= spdTable
.get(item
.next());
568 // If find one package defined the Ppi GUID
570 if ((result
= spd
.getPpi(name
)) != null) {
578 * return two values: {cName, GuidValue}
580 public static String
[] getProtocolGuid(List
<PackageIdentification
> packages
,
582 if (packages
== null) {
583 return new String
[0];
585 String
[] result
= null;
586 Iterator item
= packages
.iterator();
587 while (item
.hasNext()){
588 Spd spd
= spdTable
.get(item
.next());
590 // If find one package defined the protocol GUID
592 if ((result
= spd
.getProtocol(name
))!= null){
600 public synchronized static PlatformIdentification
getPlatformByName(String name
) throws EdkException
{
601 Iterator iter
= platformList
.iterator();
602 while(iter
.hasNext()){
603 PlatformIdentification platformId
= (PlatformIdentification
)iter
.next();
604 if (platformId
.getName().equalsIgnoreCase(name
)) {
608 throw new EdkException("Can't find platform [" + name
+ "] in the current WORKSPACE database!");
611 public synchronized static PlatformIdentification
getPlatform(String filename
) throws EdkException
{
612 File file
= new File(workspaceDir
+ File
.separatorChar
+ filename
);
613 Iterator iter
= platformList
.iterator();
614 while(iter
.hasNext()){
615 PlatformIdentification platformId
= (PlatformIdentification
)iter
.next();
616 if (platformId
.getFpdFile().getPath().equalsIgnoreCase(file
.getPath())) {
620 throw new EdkException("Can't find platform file [" + filename
+ "] in the current WORKSPACE database!");
623 public synchronized static PackageIdentification
refreshPackageIdentification(PackageIdentification packageId
) throws EdkException
{
624 Iterator iter
= packageList
.iterator();
625 while(iter
.hasNext()){
626 PackageIdentification packageItem
= (PackageIdentification
)iter
.next();
627 if (packageItem
.equals(packageId
)) {
628 packageId
.setName(packageItem
.getName());
629 packageId
.setSpdFile(packageItem
.getSpdFile());
633 throw new EdkException("Can't find package GUID value " + packageId
.toGuidString() + " in the current workspace!");
636 public synchronized static ModuleIdentification
refreshModuleIdentification(ModuleIdentification moduleId
) throws EdkException
{
637 PackageIdentification packageId
= getPackageForModule(moduleId
);
638 moduleId
.setPackage(packageId
);
639 Spd spd
= spdTable
.get(packageId
);
641 throw new EdkException("Can't find package GUID value " + packageId
.toGuidString() + " in the current workspace!");
643 Set
<ModuleIdentification
> modules
= spd
.getModules();
644 Iterator
<ModuleIdentification
> iter
= modules
.iterator();
645 while (iter
.hasNext()) {
646 ModuleIdentification item
= iter
.next();
647 if (item
.equals(moduleId
)) {
648 moduleId
.setName(item
.getName());
649 moduleId
.setModuleType(item
.getModuleType());
650 moduleId
.setMsaFile(item
.getMsaFile());
654 throw new EdkException("Can't find module GUID value " + moduleId
.toGuidString() + " in " + packageId
+ " under the current workspace!");
657 public synchronized static Set
<PackageIdentification
> getPackageList(){
662 BUGBUG: It is a walk around method. If do not clone, can't query info with
665 @param object XmlObject
666 @param deep flag for deep clone
667 @return XmlObject after clone
668 @throws BuildException parse original XmlObject error.
670 private static XmlObject
cloneXmlObject(XmlObject object
, boolean deep
) throws EdkException
{
671 if ( object
== null) {
674 XmlObject result
= null;
676 result
= XmlObject
.Factory
.parse(object
.getDomNode()
678 } catch (XmlException ex
) {
679 EdkException edkException
= new EdkException(ex
.getMessage());
680 edkException
.setStackTrace(ex
.getStackTrace());
687 /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
689 public synchronized static ToolChainInfo
getToolChainInfo() {
690 if (toolChainInfo
== null) {
691 toolChainInfo
= toolsDef
.getConfigInfo().intersection(toolChainEnvInfo
);
692 if (toolChainPlatformInfo
!= null) {
693 toolChainInfo
= toolChainInfo
.intersection(toolChainPlatformInfo
);
695 toolChainInfo
.addCommands(toolsDef
.getConfigInfo().getCommands());
696 toolChainInfo
.normalize();
697 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, "Current build tool chain information summary: ");
698 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, toolChainInfo
+ "");
700 return toolChainInfo
;
703 public static void setPlatformToolChainFamilyOption(ToolChainMap map
) {
704 platformToolChainFamilyOption
= map
;
707 public static void setPlatformToolChainOption(ToolChainMap map
) {
708 platformToolChainOption
= map
;
711 public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId
,
712 ToolChainMap toolChainOption
) {
713 moduleToolChainOption
.put(fpdModuleId
, toolChainOption
);
716 public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId
,
717 ToolChainMap toolChainOption
) {
718 moduleToolChainFamilyOption
.put(fpdModuleId
, toolChainOption
);
721 public static void addMsaBuildOption(ModuleIdentification moduleId
,
722 ToolChainMap toolChainOption
) {
723 msaBuildOption
.put(moduleId
, toolChainOption
);
726 public static void addMsaFamilyBuildOption(ModuleIdentification moduleId
,
727 ToolChainMap toolChainOption
) {
728 msaFamilyBuildOption
.put(moduleId
, toolChainOption
);
731 public static boolean isCommandSet(String target
, String toolchain
, String arch
) {
732 String
[] commands
= getToolChainInfo().getCommands();
734 for (int i
= 0; i
< commands
.length
; ++i
) {
735 String cmdName
= toolsDef
.getConfig().get(new String
[] {target
, toolchain
, arch
, commands
[i
], ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_NAME
});
736 if (cmdName
!= null && cmdName
.length() != 0) {
745 Except FLAGS, all attribute are from TOOLS_DEF file.
747 For FLAGS, information from four places, they are:
750 2. MSA <BuildOptions>/<Options>
751 3. FPD <BuildOptions>/<Options>
752 4. FPD <FrameworkModules>/<ModuleSaBuildOptions>/<Options>
755 @param commandDescription Key: TARGET, TAGNAME, ARCH, COMMANDTYPE, ATTRIBUTE
756 @param fpdModuleId Module Identification with Arch
757 @return The corresponding String
758 @throws EdkException If build option definition error
760 public synchronized static String
getCommandSetting(String
[] commandDescription
, FpdModuleIdentification fpdModuleId
) throws EdkException
{
761 ToolChainKey toolChainKey
= new ToolChainKey(commandDescription
);
762 ToolChainMap toolChainConfig
= toolsDef
.getConfig();
763 String setting
= null;
766 // Default in tools_def.txt
768 setting
= toolChainConfig
.get(toolChainKey
);
769 if (setting
== null) {
772 if (!commandDescription
[ToolChainElement
.ATTRIBUTE
.value
].equals(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
)) {
777 // Tool's option can be in .fpd and/or .msa file
780 ToolChainMap option
= null;
781 ToolChainKey toolChainFamilyKey
= new ToolChainKey(commandDescription
);
783 toolChainFamilyKey
.setKey(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FAMILY
, ToolChainElement
.ATTRIBUTE
.value
);
784 String family
= toolChainConfig
.get(toolChainFamilyKey
);
785 toolChainFamilyKey
.setKey(family
, ToolChainElement
.TOOLCHAIN
.value
);
786 toolChainFamilyKey
.setKey(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
, ToolChainElement
.ATTRIBUTE
.value
);
789 // MSA's tool chain family option
791 option
= msaFamilyBuildOption
.get(fpdModuleId
.getModule());
792 if (option
!= null && (optionString
= option
.get(toolChainFamilyKey
)) != null) {
793 setting
+= (" " + optionString
);
797 // MSA's tool chain option
799 option
= msaBuildOption
.get(fpdModuleId
.getModule());
800 if (option
!= null && (optionString
= option
.get(toolChainKey
)) != null) {
801 setting
+= (" " + optionString
);
805 // Platform's tool chain family option
807 optionString
= platformToolChainFamilyOption
.get(toolChainFamilyKey
);
808 if (optionString
!= null) {
809 setting
+= (" " + optionString
);
813 // Platform's tool chain tag option
815 optionString
= platformToolChainOption
.get(toolChainKey
);
816 if (optionString
!= null) {
817 setting
+= (" " + optionString
);
821 // Module's tool chain family option
823 option
= moduleToolChainFamilyOption
.get(fpdModuleId
);
824 if (option
!= null && (optionString
= option
.get(toolChainFamilyKey
)) != null) {
825 setting
+= (" " + optionString
);
829 // Module's tool chain tag option
831 option
= moduleToolChainOption
.get(fpdModuleId
);
832 if (option
!= null && (optionString
= option
.get(toolChainKey
)) != null) {
833 setting
+= (" " + optionString
);
839 public static void setToolChainEnvInfo(ToolChainInfo envInfo
) {
840 toolChainEnvInfo
= envInfo
;
842 public static void setToolChainPlatformInfo(ToolChainInfo platformInfo
) {
843 toolChainPlatformInfo
= platformInfo
;
849 public synchronized static MemoryDatabaseManager
getPCDMemoryDBManager() {
854 // For PCD get tokenSpaceGUid
856 public synchronized static String
getGuidInfoFromCname(String cName
){
857 String cNameGuid
= null;
859 Set set
= spdTable
.keySet();
860 Iterator iter
= set
.iterator();
866 while (iter
.hasNext()){
867 Spd spd
= (Spd
) spdTable
.get(iter
.next());
868 guid
= spd
.getGuidFromCname(cName
);
880 public synchronized static Map
<FpdModuleIdentification
, XmlObject
>
881 getFpdModuleSaXmlObject(String xmlObjectName
) {
882 Set
<FpdModuleIdentification
> fpdModuleSASet
= fpdModuleSA
.keySet();
883 Iterator item
= fpdModuleSASet
.iterator();
886 Map
<FpdModuleIdentification
, XmlObject
> SAPcdBuildDef
= new HashMap
<FpdModuleIdentification
, XmlObject
>();
887 Map
<String
, XmlObject
> SANode
= new HashMap
<String
, XmlObject
>();
888 FpdModuleIdentification moduleId
;
889 while (item
.hasNext()) {
891 moduleId
= (FpdModuleIdentification
) item
.next();
892 SANode
= fpdModuleSA
.get(moduleId
);
894 if (SANode
.get(xmlObjectName
)!= null){
895 SAPcdBuildDef
.put(moduleId
,
896 (XmlObject
) SANode
.get(xmlObjectName
));
899 } catch (Exception e
){
900 EdkLog
.log(EdkLog
.EDK_INFO
, e
.getMessage());
903 return SAPcdBuildDef
;
906 public synchronized static Map
<FpdModuleIdentification
,XmlObject
> getFpdPcdBuildDefinitions() {
907 Map
<FpdModuleIdentification
,XmlObject
> pcdBuildDef
= getFpdModuleSaXmlObject ("PcdBuildDefinition");