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
.LinkedHashSet
;
27 import java
.util
.List
;
31 import org
.apache
.tools
.ant
.Project
;
32 import org
.apache
.xmlbeans
.XmlException
;
33 import org
.apache
.xmlbeans
.XmlObject
;
34 import org
.apache
.xmlbeans
.XmlOptions
;
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
;
48 import org
.tianocore
.common
.definitions
.ToolDefinitions
;
49 import org
.tianocore
.common
.exception
.EdkException
;
50 import org
.tianocore
.common
.logger
.EdkLog
;
51 import org
.tianocore
.pcd
.entity
.MemoryDatabaseManager
;
54 GlobalData provide initializing, instoring, querying and update global data.
55 It is a bridge to intercommunicate between multiple component, such as AutoGen,
58 <p>Note that all global information are initialized incrementally. All data will
59 parse and record only of necessary during build time. </p>
63 public class GlobalData
{
65 /// Record current WORKSPACE Directory
67 private static String workspaceDir
= "";
70 /// Be used to ensure Global data will be initialized only once.
72 private static boolean globalFlag
= false;
75 /// Framework Database information: package list and platform list
77 private static Set
<PackageIdentification
> packageList
= new HashSet
<PackageIdentification
>();
79 private static Set
<PlatformIdentification
> platformList
= new HashSet
<PlatformIdentification
>();
82 /// Every detail SPD informations: Module list, Library class definition,
83 /// Package header file, GUID/PPI/Protocol definitions
85 private static final Map
<PackageIdentification
, Spd
> spdTable
= new HashMap
<PackageIdentification
, Spd
>();
88 /// Build informations are divided into three parts:
89 /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA
91 private static Map
<ModuleIdentification
, Map
<String
, XmlObject
>> nativeMsa
= new HashMap
<ModuleIdentification
, Map
<String
, XmlObject
>>();
93 private static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleSA
= new HashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
95 private static Map
<String
, XmlObject
> fpdBuildOptionsMap
= new HashMap
<String
, XmlObject
>();
97 private static XmlObject fpdBuildOptions
;
99 private static XmlObject fpdDynamicPcds
;
102 /// Parsed modules list
104 private static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> parsedModules
= new HashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
107 /// built modules list with ARCH, TARGET, TOOLCHAIN
109 private static Set
<FpdModuleIdentification
> builtModules
= new HashSet
<FpdModuleIdentification
>();
112 /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
114 private static final MemoryDatabaseManager pcdDbManager
= new MemoryDatabaseManager();
117 /// build target + tool chain family/tag name + arch + command types + command options
121 /// toolsDef - build tool program information
122 /// fpdBuildOption - all modules's build options for tool tag or tool chain families
123 /// moduleSaBuildOption - build options for a specific module
125 private static ToolChainConfig toolsDef
;
127 private static ToolChainInfo toolChainInfo
;
128 private static ToolChainInfo toolChainEnvInfo
;
129 private static ToolChainInfo toolChainPlatformInfo
;
131 private static ToolChainMap platformToolChainOption
;
132 private static ToolChainMap platformToolChainFamilyOption
;
134 private static Map
<FpdModuleIdentification
, ToolChainMap
> moduleToolChainOption
= new HashMap
<FpdModuleIdentification
, ToolChainMap
>();
135 private static Map
<FpdModuleIdentification
, ToolChainMap
> moduleToolChainFamilyOption
= new HashMap
<FpdModuleIdentification
, ToolChainMap
>();
137 private static Map
<ModuleIdentification
, ToolChainMap
> msaBuildOption
= new HashMap
<ModuleIdentification
, ToolChainMap
>();
138 private static Map
<ModuleIdentification
, ToolChainMap
> msaFamilyBuildOption
= new HashMap
<ModuleIdentification
, ToolChainMap
>();
141 Parse framework database (DB) and all SPD files listed in DB to initialize
142 the environment for next build. This method will only be executed only once
143 in the whole build process.
145 @param workspaceDatabaseFile the file name of framework database
146 @param workspaceDir current workspace directory path
147 @throws BuildException
148 Framework Dababase or SPD or MSA file is not valid
150 public synchronized static void initInfo(Project prj
, String workspaceDatabaseFile
, String workspaceDir
, String toolsDefFilename
) throws EdkException
{
152 // ensure this method will be revoked only once
160 // Backup workspace directory. It will be used by other method
162 GlobalData
.workspaceDir
= workspaceDir
.replaceAll("(\\\\)", "/");
165 // Parse tools definition file
168 // If ToolChain has been set up before, do nothing.
169 // CONF dir + tools definition file name
171 File toolsDefFile
= new File(workspaceDir
+ File
.separatorChar
+ toolsDefFilename
);
172 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, "Using tool definition file [" + toolsDefFile
.getPath() + "].");
173 toolsDef
= new ToolChainConfig(prj
, toolsDefFile
);
176 // Parse Framework Database
178 File dbFile
= new File(workspaceDir
+ File
.separatorChar
+ workspaceDatabaseFile
);
179 FrameworkDatabaseDocument db
= null;
181 db
= (FrameworkDatabaseDocument
)parseXmlFile(dbFile
);
185 if (db
.getFrameworkDatabase().getPackageList() != null ) {
186 List
<DbPathAndFilename
> packages
= db
.getFrameworkDatabase().getPackageList().getFilenameList();
187 Iterator
<DbPathAndFilename
> iter
= packages
.iterator();
188 while (iter
.hasNext()) {
189 String fileName
= iter
.next().getStringValue().trim();
190 Spd spd
= new Spd(new File(workspaceDir
+ File
.separatorChar
+ fileName
));
191 packageList
.add(spd
.getPackageId());
193 // Report warning if existing two packages with same GUID and Version
195 if (spdTable
.containsKey(spd
.getPackageId())) {
199 EdkLog
.log("Init", EdkLog
.EDK_WARNING
, "Warning: Existing two packages with same GUID and Version. They are ... " + spd
.getPackageId().getSpdFile().getPath());
201 spdTable
.put(spd
.getPackageId(), spd
);
204 } catch(IOException ex
) {
205 EdkException edkException
= new EdkException("Parse of WORKSPACE Database file [" + dbFile
.getPath() + "] failed!\n" + ex
.getMessage());
206 edkException
.setStackTrace(ex
.getStackTrace());
208 } catch(XmlException ex
) {
209 EdkException edkException
= new EdkException("Parse of WORKSPACE Database file [" + dbFile
.getPath() + "] failed!\n" + ex
.getMessage());
210 edkException
.setStackTrace(ex
.getStackTrace());
219 if (db
.getFrameworkDatabase().getPlatformList() != null) {
220 List
<DbPathAndFilename
> platforms
= db
.getFrameworkDatabase().getPlatformList().getFilenameList();
221 Iterator
<DbPathAndFilename
> iter
= platforms
.iterator();
222 while (iter
.hasNext()) {
223 String fileName
= iter
.next().getStringValue().trim();
224 fpdFile
= new File(workspaceDir
+ File
.separatorChar
+ fileName
);
225 if ( !fpdFile
.exists() ) {
226 throw new EdkException("Platform file [" + fpdFile
.getPath() + "] not exists. ");
228 XmlObject fpdDoc
= parseXmlFile(fpdFile
);
230 // We can change Map to XmlObject
232 Map
<String
, XmlObject
> fpdDocMap
= new HashMap
<String
, XmlObject
>();
233 fpdDocMap
.put("PlatformSurfaceArea", fpdDoc
);
234 SurfaceAreaQuery saq
= new SurfaceAreaQuery(fpdDocMap
);
235 PlatformIdentification platformId
= saq
.getFpdHeader();
236 platformId
.setFpdFile(fpdFile
);
238 // Report warning if existing two platfrom with same GUID and Version
240 if (platformList
.contains(platformId
)) {
244 EdkLog
.log("Init", EdkLog
.EDK_WARNING
, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile
.getPath());
246 platformList
.add(platformId
);
249 } catch(IOException ex
) {
250 EdkException edkException
= new EdkException("Parse of platform definition file [" + fpdFile
.getPath() + "] failed!\n" + ex
.getMessage());
251 edkException
.setStackTrace(ex
.getStackTrace());
253 } catch(XmlException ex
) {
254 EdkException edkException
= new EdkException("Parse of platform definition file [" + fpdFile
.getPath() + "] failed!\n" + ex
.getMessage());
255 edkException
.setStackTrace(ex
.getStackTrace());
261 Get the current WORKSPACE Directory.
263 @return current workspace directory
265 public synchronized static String
getWorkspacePath() {
271 Get the MSA file name with absolute path
273 public synchronized static File
getMsaFile(ModuleIdentification moduleId
) throws EdkException
{
276 // TBD. Do only when package is null.
278 Iterator iter
= packageList
.iterator();
279 while (iter
.hasNext()) {
280 PackageIdentification packageId
= (PackageIdentification
)iter
.next();
281 Spd spd
= spdTable
.get(packageId
);
282 msaFile
= spd
.getModuleFile(moduleId
);
283 if (msaFile
!= null ) {
287 if (msaFile
== null){
288 throw new EdkException("Can't find Module [" + moduleId
.getName() + "] in any SPD package!");
294 public synchronized static PackageIdentification
getPackageForModule(ModuleIdentification moduleId
) throws EdkException
{
296 // If package already defined in module
298 if (moduleId
.getPackage() != null) {
299 return moduleId
.getPackage();
302 PackageIdentification packageId
= null;
303 Iterator iter
= packageList
.iterator();
304 while (iter
.hasNext()) {
305 PackageIdentification pid
= (PackageIdentification
)iter
.next();
306 moduleId
.setPackage(pid
);
307 Spd spd
= spdTable
.get(pid
);
308 File tempMsaFile
= null;
309 if ((tempMsaFile
= spd
.getModuleFile(moduleId
)) != null ) {
310 if (tempMsaFile
.getParent().equalsIgnoreCase(moduleId
.getMsaFile().getParent())) {
317 if (packageId
== null){
318 throw new EdkException("Can't find Module [" + moduleId
.getName() + "] in any package!");
325 Difference between build and parse: ToolChain and Target
327 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId
) {
328 return builtModules
.contains(moduleId
);
331 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId
) {
332 builtModules
.add(fpdModuleId
);
336 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId
, Map
<String
, XmlObject
> doc
) throws EdkException
{
337 Map
<String
, XmlObject
> result
= new HashMap
<String
, XmlObject
>();
338 Set keySet
= doc
.keySet();
339 Iterator iter
= keySet
.iterator();
340 while (iter
.hasNext()){
341 String key
= (String
)iter
.next();
342 XmlObject item
= cloneXmlObject(doc
.get(key
), true);
343 result
.put(key
, item
);
345 fpdModuleSA
.put(fpdModuleId
, result
);
348 public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId
) {
349 return fpdModuleSA
.containsKey(fpdModuleId
);
353 Query module surface area information.
355 <p>Note that surface area parsing is incremental. That means the method will
356 only parse the MSA files if necessary. </p>
358 @param fpdModuleId Module ID with arch
359 @return ModuleSA info and MSA info for fpdModuleId
360 @throws BuildException Can't find MSA
362 public synchronized static Map
<String
, XmlObject
> getDoc(FpdModuleIdentification fpdModuleId
) throws EdkException
{
363 if (parsedModules
.containsKey(fpdModuleId
)) {
364 return parsedModules
.get(fpdModuleId
);
366 Map
<String
, XmlObject
> doc
= new HashMap
<String
, XmlObject
>();
367 ModuleIdentification moduleId
= fpdModuleId
.getModule();
369 // First part: get the MSA files info
371 doc
.putAll(getNativeMsa(moduleId
));
374 // Second part: put build options
376 doc
.put("BuildOptions", fpdBuildOptions
);
379 // Third part: get Module info from FPD, such as Library instances, PCDs
381 if (fpdModuleSA
.containsKey(fpdModuleId
)){
383 // merge module info in FPD to final Doc
384 // For Library Module, do nothing here
386 doc
.putAll(fpdModuleSA
.get(fpdModuleId
));
388 parsedModules
.put(fpdModuleId
, doc
);
392 public synchronized static Map
<String
, XmlObject
> getDoc(ModuleIdentification moduleId
, String arch
) throws EdkException
{
393 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, arch
);
394 return getDoc(fpdModuleId
);
398 Query the native MSA information with module base name.
400 <p>Note that MSA parsing is incremental. That means the method will
401 only to parse the MSA files when never parsed before. </p>
403 @param moduleName the base name of the module
404 @return the native MSA information
405 @throws BuildException
406 MSA file is not valid
408 public synchronized static Map
<String
, XmlObject
> getNativeMsa(ModuleIdentification moduleId
) throws EdkException
{
409 if (nativeMsa
.containsKey(moduleId
)) {
410 return nativeMsa
.get(moduleId
);
412 File msaFile
= getMsaFile(moduleId
);
413 Map
<String
, XmlObject
> msaMap
= getNativeMsa(msaFile
);
414 nativeMsa
.put(moduleId
, msaMap
);
418 public synchronized static Map
<String
, XmlObject
> getNativeMsa(File msaFile
) throws EdkException
{
419 if (!msaFile
.exists()) {
420 throw new EdkException("Module Surface Area file [" + msaFile
.getPath() + "] can't be found!");
423 ModuleSurfaceAreaDocument doc
= (ModuleSurfaceAreaDocument
)parseXmlFile(msaFile
);
427 ModuleSurfaceArea msa
= doc
.getModuleSurfaceArea();
428 Map
<String
, XmlObject
> msaMap
= new HashMap
<String
, XmlObject
>();
429 msaMap
.put("MsaHeader", cloneXmlObject(msa
.getMsaHeader(), true));
430 msaMap
.put("ModuleDefinitions", cloneXmlObject(msa
.getModuleDefinitions(), true));
431 msaMap
.put("LibraryClassDefinitions", cloneXmlObject(msa
.getLibraryClassDefinitions(), true));
432 msaMap
.put("SourceFiles", cloneXmlObject(msa
.getSourceFiles(), true));
433 msaMap
.put("PackageDependencies", cloneXmlObject(msa
.getPackageDependencies(), true));
434 msaMap
.put("Protocols", cloneXmlObject(msa
.getProtocols(), true));
435 msaMap
.put("PPIs", cloneXmlObject(msa
.getPPIs(), true));
436 msaMap
.put("Guids", cloneXmlObject(msa
.getGuids(), true));
437 msaMap
.put("Externs", cloneXmlObject(msa
.getExterns(), true));
438 msaMap
.put("PcdCoded", cloneXmlObject(msa
.getPcdCoded(), true));
439 msaMap
.put("ModuleBuildOptions", cloneXmlObject(msa
.getModuleBuildOptions(), true));
441 } catch(IOException ex
) {
442 EdkException edkException
= new EdkException("Parse of MSA file [" + msaFile
.getPath() + "] failed!\n" + ex
.getMessage());
443 edkException
.setStackTrace(ex
.getStackTrace());
445 } catch(XmlException ex
) {
446 EdkException edkException
= new EdkException("Parse of MSA file [" + msaFile
.getPath() + "] failed!\n" + ex
.getMessage());
447 edkException
.setStackTrace(ex
.getStackTrace());
452 public static Map
<String
, XmlObject
> getFpdBuildOptionsMap() {
453 return fpdBuildOptionsMap
;
456 public static void setFpdBuildOptions(XmlObject fpdBuildOptions
) throws EdkException
{
457 GlobalData
.fpdBuildOptions
= cloneXmlObject(fpdBuildOptions
, true);
458 fpdBuildOptionsMap
.put("BuildOptions", GlobalData
.fpdBuildOptions
);
461 public static XmlObject
getFpdDynamicPcds() {
462 return fpdDynamicPcds
;
465 public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds
) {
466 GlobalData
.fpdDynamicPcds
= fpdDynamicPcds
;
469 public static Set
<ModuleIdentification
> getModules(PackageIdentification packageId
){
470 Spd spd
= spdTable
.get(packageId
);
472 Set
<ModuleIdentification
> dummy
= new HashSet
<ModuleIdentification
>();
475 return spd
.getModules();
480 * The header file path is relative to workspace dir
482 public static String
[] getLibraryClassHeaderFiles(
483 PackageIdentification
[] packages
, String name
) throws EdkException
{
484 if (packages
== null) {
485 // throw Exception or not????
486 return new String
[0];
488 String
[] result
= null;
489 for (int i
= 0; i
< packages
.length
; i
++) {
490 Spd spd
= spdTable
.get(packages
[i
]);
492 // If find one package defined the library class
494 if ((result
= spd
.getLibClassIncluder(name
)) != null) {
499 // If can't find library class declaration in every package
501 throw new EdkException("Can not find library class [" + name
502 + "] declaration in any SPD package!");
506 * The header file path is relative to workspace dir
508 public static String
getPackageHeaderFiles(PackageIdentification packages
,
510 if (packages
== null) {
511 return new String("");
513 Spd spd
= spdTable
.get(packages
);
515 // If can't find package header file, skip it
519 if ((temp
= spd
.getPackageIncluder(moduleType
)) != null) {
531 * return two values: {cName, GuidValue}
533 public static String
[] getGuid(List
<PackageIdentification
> packages
, String name
) {
534 if (packages
== null) {
535 // throw Exception or not????
536 return new String
[0];
538 String
[] result
= null;
539 Iterator item
= packages
.iterator();
540 while (item
.hasNext()){
541 Spd spd
= spdTable
.get(item
.next());
543 // If find one package defined the GUID
545 if ((result
= spd
.getGuid(name
)) != null) {
554 * return two values: {cName, GuidValue}
556 public static String
[] getPpiGuid(List
<PackageIdentification
> packages
,
558 if (packages
== null) {
559 return new String
[0];
561 String
[] result
= null;
562 Iterator item
= packages
.iterator();
563 while (item
.hasNext()){
564 Spd spd
= spdTable
.get(item
.next());
566 // If find one package defined the Ppi GUID
568 if ((result
= spd
.getPpi(name
)) != null) {
576 * return two values: {cName, GuidValue}
578 public static String
[] getProtocolGuid(List
<PackageIdentification
> packages
,
580 if (packages
== null) {
581 return new String
[0];
583 String
[] result
= null;
584 Iterator item
= packages
.iterator();
585 while (item
.hasNext()){
586 Spd spd
= spdTable
.get(item
.next());
588 // If find one package defined the protocol GUID
590 if ((result
= spd
.getProtocol(name
))!= null){
598 public synchronized static PlatformIdentification
getPlatformByName(String name
) throws EdkException
{
599 Iterator iter
= platformList
.iterator();
600 while(iter
.hasNext()){
601 PlatformIdentification platformId
= (PlatformIdentification
)iter
.next();
602 if (platformId
.getName().equalsIgnoreCase(name
)) {
606 throw new EdkException("Can't find platform [" + name
+ "] in the current WORKSPACE database!");
609 public synchronized static PlatformIdentification
getPlatform(String filename
) throws EdkException
{
610 File file
= new File(workspaceDir
+ File
.separatorChar
+ filename
);
611 Iterator iter
= platformList
.iterator();
612 while(iter
.hasNext()){
613 PlatformIdentification platformId
= (PlatformIdentification
)iter
.next();
614 if (platformId
.getFpdFile().getPath().equalsIgnoreCase(file
.getPath())) {
618 throw new EdkException("Can't find platform file [" + filename
+ "] in the current WORKSPACE database!");
621 public synchronized static PackageIdentification
refreshPackageIdentification(PackageIdentification packageId
) throws EdkException
{
622 Iterator iter
= packageList
.iterator();
623 while(iter
.hasNext()){
624 PackageIdentification packageItem
= (PackageIdentification
)iter
.next();
625 if (packageItem
.equals(packageId
)) {
626 packageId
.setName(packageItem
.getName());
627 packageId
.setSpdFile(packageItem
.getSpdFile());
631 throw new EdkException("Can't find package GUID value " + packageId
.toGuidString() + " in the current workspace!");
634 public synchronized static ModuleIdentification
refreshModuleIdentification(ModuleIdentification moduleId
) throws EdkException
{
635 PackageIdentification packageId
= getPackageForModule(moduleId
);
636 moduleId
.setPackage(packageId
);
637 Spd spd
= spdTable
.get(packageId
);
639 throw new EdkException("Can't find package GUID value " + packageId
.toGuidString() + " in the current workspace!");
641 Set
<ModuleIdentification
> modules
= spd
.getModules();
642 Iterator
<ModuleIdentification
> iter
= modules
.iterator();
643 while (iter
.hasNext()) {
644 ModuleIdentification item
= iter
.next();
645 if (item
.equals(moduleId
)) {
646 moduleId
.setName(item
.getName());
647 moduleId
.setModuleType(item
.getModuleType());
648 moduleId
.setMsaFile(item
.getMsaFile());
652 throw new EdkException("Can't find " + moduleId
+ " under the current workspace!");
655 public synchronized static Set
<PackageIdentification
> getPackageList(){
660 BUGBUG: It is a walk around method. If do not clone, can't query info with
663 @param object XmlObject
664 @param deep flag for deep clone
665 @return XmlObject after clone
666 @throws BuildException parse original XmlObject error.
668 private static XmlObject
cloneXmlObject(XmlObject object
, boolean deep
) throws EdkException
{
669 if ( object
== null) {
672 XmlObject result
= null;
674 result
= XmlObject
.Factory
.parse(object
.getDomNode()
676 } catch (XmlException ex
) {
677 EdkException edkException
= new EdkException(ex
.getMessage());
678 edkException
.setStackTrace(ex
.getStackTrace());
685 /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
687 public synchronized static ToolChainInfo
getToolChainInfo() {
688 if (toolChainInfo
== null) {
689 toolChainInfo
= toolsDef
.getConfigInfo().intersection(toolChainEnvInfo
);
690 if (toolChainPlatformInfo
!= null) {
691 toolChainInfo
= toolChainInfo
.intersection(toolChainPlatformInfo
);
693 toolChainInfo
.addCommands(toolsDef
.getConfigInfo().getCommands());
694 toolChainInfo
.normalize();
696 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, "Current build tool chain information summary: ");
697 EdkLog
.log("Init", EdkLog
.EDK_ALWAYS
, toolChainInfo
+ "");
699 return toolChainInfo
;
702 public static void setPlatformToolChainFamilyOption(ToolChainMap map
) {
703 platformToolChainFamilyOption
= map
;
706 public static void setPlatformToolChainOption(ToolChainMap map
) {
707 platformToolChainOption
= map
;
710 public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId
,
711 ToolChainMap toolChainOption
) {
712 moduleToolChainOption
.put(fpdModuleId
, toolChainOption
);
715 public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId
,
716 ToolChainMap toolChainOption
) {
717 moduleToolChainFamilyOption
.put(fpdModuleId
, toolChainOption
);
720 public static void addMsaBuildOption(ModuleIdentification moduleId
,
721 ToolChainMap toolChainOption
) {
722 msaBuildOption
.put(moduleId
, toolChainOption
);
725 public static void addMsaFamilyBuildOption(ModuleIdentification moduleId
,
726 ToolChainMap toolChainOption
) {
727 msaFamilyBuildOption
.put(moduleId
, toolChainOption
);
730 public static boolean isCommandSet(String target
, String toolchain
, String arch
) throws EdkException
{
731 String
[] commands
= getToolChainInfo().getCommands();
733 for (int i
= 0; i
< commands
.length
; ++i
) {
734 String cmdName
= toolsDef
.getConfig().get(new String
[] {target
, toolchain
, arch
, commands
[i
], ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_NAME
});
735 if (cmdName
!= null && cmdName
.length() != 0) {
744 Except FLAGS, all attribute are from TOOLS_DEF file.
746 For FLAGS, information from four places, they are:
749 2. MSA <BuildOptions>/<Options>
750 3. FPD <BuildOptions>/<Options>
751 4. FPD <FrameworkModules>/<ModuleSaBuildOptions>/<Options>
754 @param commandDescription Key: TARGET, TAGNAME, ARCH, COMMANDTYPE, ATTRIBUTE
755 @param fpdModuleId Module Identification with Arch
756 @return The corresponding String
757 @throws EdkException If build option definition error
759 public synchronized static String
getCommandSetting(String
[] commandDescription
, FpdModuleIdentification fpdModuleId
) throws EdkException
{
760 ToolChainKey toolChainKey
= new ToolChainKey(commandDescription
);
761 ToolChainMap toolChainConfig
= toolsDef
.getConfig();
762 String setting
= null;
765 // Default in tools_def.txt
767 setting
= toolChainConfig
.get(toolChainKey
);
768 if (setting
== null) {
771 if (!commandDescription
[ToolChainElement
.ATTRIBUTE
.value
].equals(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
)) {
775 Set
<String
> flagSet
= new LinkedHashSet
<String
>();
776 flagSet
.add(setting
);
779 // Tool's option can be in .fpd and/or .msa file
782 ToolChainMap option
= null;
783 ToolChainKey toolChainFamilyKey
= new ToolChainKey(commandDescription
);
785 toolChainFamilyKey
.setKey(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FAMILY
, ToolChainElement
.ATTRIBUTE
.value
);
786 String family
= toolChainConfig
.get(toolChainFamilyKey
);
787 toolChainFamilyKey
.setKey(family
, ToolChainElement
.TOOLCHAIN
.value
);
788 toolChainFamilyKey
.setKey(ToolDefinitions
.TOOLS_DEF_ATTRIBUTE_FLAGS
, ToolChainElement
.ATTRIBUTE
.value
);
791 // MSA's tool chain family option
793 option
= msaFamilyBuildOption
.get(fpdModuleId
.getModule());
794 if (option
!= null && (optionString
= option
.get(toolChainFamilyKey
)) != null) {
795 flagSet
.add(optionString
);
799 // MSA's tool chain option
801 option
= msaBuildOption
.get(fpdModuleId
.getModule());
802 if (option
!= null && (optionString
= option
.get(toolChainKey
)) != null) {
803 flagSet
.add(optionString
);
807 // Platform's tool chain family option
809 optionString
= platformToolChainFamilyOption
.get(toolChainFamilyKey
);
810 if (optionString
!= null) {
811 flagSet
.add(optionString
);
815 // Platform's tool chain tag option
817 optionString
= platformToolChainOption
.get(toolChainKey
);
818 if (optionString
!= null) {
819 flagSet
.add(optionString
);
823 // Module's tool chain family option
825 option
= moduleToolChainFamilyOption
.get(fpdModuleId
);
826 if (option
!= null && (optionString
= option
.get(toolChainFamilyKey
)) != null) {
827 flagSet
.add(optionString
);
831 // Module's tool chain tag option
833 option
= moduleToolChainOption
.get(fpdModuleId
);
834 if (option
!= null && (optionString
= option
.get(toolChainKey
)) != null) {
835 flagSet
.add(optionString
);
839 for(Iterator
<String
> iter
= flagSet
.iterator(); iter
.hasNext();) {
840 setting
+= iter
.next() +" ";
845 public static void setToolChainEnvInfo(ToolChainInfo envInfo
) {
846 toolChainEnvInfo
= envInfo
;
848 public static void setToolChainPlatformInfo(ToolChainInfo platformInfo
) {
849 toolChainPlatformInfo
= platformInfo
;
855 public synchronized static MemoryDatabaseManager
getPCDMemoryDBManager() {
860 // For PCD get tokenSpaceGUid
862 public synchronized static String
getGuidInfoFromCname(String cName
){
863 String cNameGuid
= null;
865 Set set
= spdTable
.keySet();
866 Iterator iter
= set
.iterator();
872 while (iter
.hasNext()){
873 Spd spd
= (Spd
) spdTable
.get(iter
.next());
874 guid
= spd
.getGuidFromCname(cName
);
886 public synchronized static Map
<FpdModuleIdentification
, XmlObject
>
887 getFpdModuleSaXmlObject(String xmlObjectName
) {
888 Set
<FpdModuleIdentification
> fpdModuleSASet
= fpdModuleSA
.keySet();
889 Iterator item
= fpdModuleSASet
.iterator();
892 Map
<FpdModuleIdentification
, XmlObject
> SAPcdBuildDef
= new HashMap
<FpdModuleIdentification
, XmlObject
>();
893 Map
<String
, XmlObject
> SANode
= new HashMap
<String
, XmlObject
>();
894 FpdModuleIdentification moduleId
;
895 while (item
.hasNext()) {
897 moduleId
= (FpdModuleIdentification
) item
.next();
898 SANode
= fpdModuleSA
.get(moduleId
);
900 if (SANode
.get(xmlObjectName
)!= null){
901 SAPcdBuildDef
.put(moduleId
,
902 (XmlObject
) SANode
.get(xmlObjectName
));
905 } catch (Exception e
){
906 EdkLog
.log(EdkLog
.EDK_INFO
, e
.getMessage());
909 return SAPcdBuildDef
;
912 public synchronized static Map
<FpdModuleIdentification
,XmlObject
> getFpdPcdBuildDefinitions() {
913 Map
<FpdModuleIdentification
,XmlObject
> pcdBuildDef
= getFpdModuleSaXmlObject ("PcdBuildDefinition");
918 public static XmlObject
parseXmlFile(File xmlFile
) throws IOException
, XmlException
{
919 Collection errors
= new ArrayList();
920 XmlOptions opt
= new XmlOptions();
922 opt
.setLoadLineNumbers();
923 opt
.setLoadMessageDigest();
924 opt
.setErrorListener(errors
);
926 XmlObject doc
= XmlObject
.Factory
.parse(xmlFile
, opt
);
928 // Validate File if they accord with XML Schema
930 if (!doc
.validate(opt
)){
931 StringBuilder errorMessage
= new StringBuilder(1024);
932 for (Iterator it
= errors
.iterator(); it
.hasNext(); ) {
933 errorMessage
.append(it
.next());
934 errorMessage
.append("\n");
936 throw new XmlException(errorMessage
.toString());