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
.frameworkwizard
.platform
.ui
.global
;
19 import org
.apache
.xmlbeans
.XmlObject
;
20 import org
.tianocore
.DbPathAndFilename
;
21 import org
.tianocore
.FrameworkDatabaseDocument
;
22 import org
.tianocore
.ModuleSurfaceAreaDocument
;
23 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
24 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.FpdModuleIdentification
;
25 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
26 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
27 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PlatformIdentification
;
30 import java
.util
.Comparator
;
31 import java
.util
.HashMap
;
32 import java
.util
.HashSet
;
33 import java
.util
.Iterator
;
34 import java
.util
.List
;
37 import java
.util
.logging
.Logger
;
40 GlobalData provide initializing, instoring, querying and update global data.
41 It is a bridge to intercommunicate between multiple component, such as AutoGen,
44 <p>Note that all global information are initialized incrementally. All data will
45 parse and record only of necessary during build time. </p>
49 public class GlobalData
{
52 public static Logger log
= Logger
.getAnonymousLogger();
53 public static KeyComparator comparator
= new KeyComparator();
55 /// Record current WORKSPACE Directory
57 private static String workspaceDir
= "";
60 /// Be used to ensure Global data will be initialized only once.
62 // private static boolean globalFlag = false;
65 /// Framework Database information: package list and platform list
67 private static Set
<PackageIdentification
> packageList
= new HashSet
<PackageIdentification
>();
69 private static Set
<PlatformIdentification
> platformList
= new HashSet
<PlatformIdentification
>();
72 /// Every detail SPD informations: Module list, Library class definition,
73 /// Package header file, GUID/PPI/Protocol definitions
75 private static final Map
<PackageIdentification
, Spd
> spdTable
= new HashMap
<PackageIdentification
, Spd
>();
78 /// Build informations are divided into three parts:
79 /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA
81 private static Map
<ModuleIdentification
, Map
<String
, XmlObject
>> nativeMsa
= new HashMap
<ModuleIdentification
, Map
<String
, XmlObject
>>();
83 private static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleSA
= new HashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
85 private static XmlObject fpdBuildOptions
;
87 private static XmlObject fpdDynamicPcds
;
90 /// Parsed modules list
92 private static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> parsedModules
= new HashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
95 /// built modules list with ARCH, TARGET, TOOLCHAIN
97 private static Set
<FpdModuleIdentification
> builtModules
= new HashSet
<FpdModuleIdentification
>();
100 /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
102 // private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();
105 /// build target + tool chain family/tag name + arch + command types + command options
107 private static Map
<String
, Object
> toolChainOptions
;
108 private static Map
<String
, Object
> toolChainFamilyOptions
;
109 private static Map
<String
, String
> toolChainDefinitions
;
113 private static Set
<String
> targets
;
117 private static Set
<String
> toolChainFamilies
;
121 private static Set
<String
> toolChains
;
123 /// keep track which toolchain family a toolchain tag belongs to
125 private static Map
<String
, Set
<String
>> toolChainFamilyMap
;
126 private static Map
<String
, Set
<String
>> toolChainCommandMap
;
129 /// list of Arch: EBC, ARM, IA32, X64, IPF, PPC
131 private static Set
<String
> archs
;
134 /// list of Command Type: CC, LIB, LINK, ASL, ASM, ASMLINK, PP
136 private static Set
<String
> commandTypes
;
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
146 Framework Dababase or SPD or MSA file is not valid
148 public synchronized static void initInfo(String workspaceDatabaseFile
, String workspaceDir
) throws Exception
{
151 // Backup workspace directory. It will be used by other method
153 GlobalData
.workspaceDir
= workspaceDir
.replaceAll("(\\\\)", "/");
154 File dbFile
= new File(workspaceDir
+ File
.separatorChar
+ workspaceDatabaseFile
);
156 FrameworkDatabaseDocument db
= (FrameworkDatabaseDocument
) XmlObject
.Factory
.parse(dbFile
);
158 // validate FrameworkDatabaseFile
160 // if (! db.validate()) {
161 // throw new Exception("Framework Database file [" + dbFile.getPath() + "] is invalid.");
166 List
<DbPathAndFilename
> packages
= db
.getFrameworkDatabase().getPackageList().getFilenameList();
168 Iterator iter
= packages
.iterator();
169 while (iter
.hasNext()) {
170 DbPathAndFilename dbPath
= (DbPathAndFilename
)iter
.next();
171 String fileName
= dbPath
.getStringValue();
172 Spd spd
= new Spd(new File(workspaceDir
+ File
.separatorChar
+ fileName
));
173 if (!packageList
.contains(spd
.getPackageId())) {
174 packageList
.add(spd
.getPackageId());
176 spdTable
.put(spd
.getPackageId(), spd
);
180 } catch (Exception e
) {
182 throw new Exception("Parse workspace Database [" + dbFile
.getPath() + "] Error.\n" + e
.getMessage());
187 Get the current WORKSPACE Directory.
189 @return current workspace directory
191 public synchronized static String
getWorkspacePath() {
197 Get the MSA file name with absolute path
199 public synchronized static File
getMsaFile(ModuleIdentification moduleId
) throws Exception
{
202 // TBD. Do only when package is null.
204 Iterator iter
= packageList
.iterator();
205 while (iter
.hasNext()) {
206 PackageIdentification packageId
= (PackageIdentification
)iter
.next();
207 Spd spd
= spdTable
.get(packageId
);
208 msaFile
= spd
.getModuleFile(moduleId
);
209 if (msaFile
!= null ) {
213 if (msaFile
== null){
214 throw new Exception("Can't find Module [" + moduleId
.getName() + "] in all packages. ");
221 public synchronized static PackageIdentification
getPackageForModule(ModuleIdentification moduleId
) {
223 // If package already defined in module
225 if (moduleId
.getPackage() != null) {
226 return moduleId
.getPackage();
229 PackageIdentification packageId
= null;
230 Iterator iter
= packageList
.iterator();
231 while (iter
.hasNext()) {
232 packageId
= (PackageIdentification
)iter
.next();
234 Spd spd
= spdTable
.get(packageId
);
235 if (spd
.getModuleFile(moduleId
) != null ) {
236 moduleId
.setPackage(packageId
);
240 if (packageId
== null){
249 Difference between build and parse: ToolChain and Target
251 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId
) {
252 return builtModules
.contains(moduleId
);
255 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId
) {
256 builtModules
.add(fpdModuleId
);
260 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId
, Map
<String
, XmlObject
> doc
) throws Exception
{
261 Map
<String
, XmlObject
> result
= new HashMap
<String
, XmlObject
>();
262 Set keySet
= doc
.keySet();
263 Iterator iter
= keySet
.iterator();
264 while (iter
.hasNext()){
265 String key
= (String
)iter
.next();
266 XmlObject item
= cloneXmlObject(doc
.get(key
), true);
267 result
.put(key
, item
);
269 fpdModuleSA
.put(fpdModuleId
, result
);
273 Query overrided module surface area information. If current is Package
274 or Platform build, also include the information from FPD file.
276 <p>Note that surface area parsing is incremental. That means the method will
277 only parse the MSA and MBD files if necessary. </p>
279 @param moduleName the base name of the module
280 @return the overrided module surface area information
282 MSA or MBD is not valid
284 public synchronized static Map
<String
, XmlObject
> getDoc(FpdModuleIdentification fpdModuleId
) throws Exception
{
285 if (parsedModules
.containsKey(fpdModuleId
)) {
286 return parsedModules
.get(fpdModuleId
);
288 Map
<String
, XmlObject
> doc
= new HashMap
<String
, XmlObject
>();
289 ModuleIdentification moduleId
= fpdModuleId
.getModule();
291 // First part: get the MSA files info
293 doc
= getNativeMsa(moduleId
);
296 // Second part: put build options
298 doc
.put("BuildOptions", fpdBuildOptions
);
301 // Third part: get Module info from FPD, such as Library instances, PCDs
303 if (fpdModuleSA
.containsKey(fpdModuleId
)){
305 // merge module info in FPD to final Doc
306 // For Library Module, do nothing here
308 doc
.putAll(fpdModuleSA
.get(fpdModuleId
));
310 parsedModules
.put(fpdModuleId
, doc
);
314 public synchronized static Map
<String
, XmlObject
> getDoc(ModuleIdentification moduleId
, String arch
) throws Exception
{
315 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, arch
);
316 return getDoc(fpdModuleId
);
319 Query the native MSA information with module base name.
321 <p>Note that MSA parsing is incremental. That means the method will
322 only to parse the MSA files when never parsed before. </p>
324 @param moduleName the base name of the module
325 @return the native MSA information
327 MSA file is not valid
329 public synchronized static Map
<String
, XmlObject
> getNativeMsa(ModuleIdentification moduleId
) throws Exception
{
330 if (nativeMsa
.containsKey(moduleId
)) {
331 return nativeMsa
.get(moduleId
);
333 File msaFile
= getMsaFile(moduleId
);
334 Map
<String
, XmlObject
> msaMap
= getNativeMsa(msaFile
);
335 nativeMsa
.put(moduleId
, msaMap
);
339 public synchronized static Map
<String
, XmlObject
> getNativeMsa(File msaFile
) throws Exception
{
342 ModuleSurfaceAreaDocument doc
= (ModuleSurfaceAreaDocument
)XmlObject
.Factory
.parse(msaFile
);
344 // Validate File if they accord with XML Schema
346 // if ( ! doc.validate()){
347 // throw new Exception("Module Surface Area file [" + msaFile.getPath() + "] is invalid.");
352 ModuleSurfaceArea msa
= doc
.getModuleSurfaceArea();
353 Map
<String
, XmlObject
> msaMap
= new HashMap
<String
, XmlObject
>();
354 msaMap
.put("ModuleSurfaceArea", msa
);
355 msaMap
.put("MsaHeader", cloneXmlObject(msa
.getMsaHeader(), true));
356 msaMap
.put("LibraryClassDefinitions", cloneXmlObject(msa
.getLibraryClassDefinitions(), true));
357 msaMap
.put("SourceFiles", cloneXmlObject(msa
.getSourceFiles(), true));
358 msaMap
.put("PackageDependencies", cloneXmlObject(msa
.getPackageDependencies(), true));
359 msaMap
.put("Protocols", cloneXmlObject(msa
.getProtocols(), true));
360 msaMap
.put("PPIs", cloneXmlObject(msa
.getPPIs(), true));
361 msaMap
.put("Guids", cloneXmlObject(msa
.getGuids(), true));
362 msaMap
.put("Externs", cloneXmlObject(msa
.getExterns(), true));
365 catch (Exception ex
){
366 throw new Exception(ex
.getMessage());
370 public static Map
<String
, XmlObject
> getFpdBuildOptions() {
371 Map
<String
, XmlObject
> map
= new HashMap
<String
, XmlObject
>();
372 map
.put("BuildOptions", fpdBuildOptions
);
376 public static void setFpdBuildOptions(XmlObject fpdBuildOptions
) throws Exception
{
377 GlobalData
.fpdBuildOptions
= cloneXmlObject(fpdBuildOptions
, true);
380 public static XmlObject
getFpdDynamicPcds() {
381 return fpdDynamicPcds
;
384 public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds
) {
385 GlobalData
.fpdDynamicPcds
= fpdDynamicPcds
;
388 //////////////////////////////////////////////
389 //////////////////////////////////////////////
391 public static Set
<ModuleIdentification
> getModules(PackageIdentification packageId
){
392 Spd spd
= spdTable
.get(packageId
);
394 Set
<ModuleIdentification
> dummy
= new HashSet
<ModuleIdentification
>();
398 return spd
.getModules();
402 public synchronized static PlatformIdentification
getPlatform(String name
) throws Exception
{
403 Iterator iter
= platformList
.iterator();
404 while(iter
.hasNext()){
405 PlatformIdentification platformId
= (PlatformIdentification
)iter
.next();
406 if (platformId
.getName().equalsIgnoreCase(name
)) {
407 GlobalData
.log
.info("Platform: " + platformId
+ platformId
.getFpdFile());
411 throw new Exception("Can't find platform [" + name
+ "] in current workspace. ");
414 public synchronized static File
getPackageFile(PackageIdentification packageId
) throws Exception
{
415 Iterator iter
= packageList
.iterator();
416 while(iter
.hasNext()){
417 PackageIdentification packageItem
= (PackageIdentification
)iter
.next();
418 if (packageItem
.equals(packageId
)) {
419 packageId
.setName(packageItem
.getName());
420 return packageItem
.getSpdFile();
423 throw new Exception("Can't find " + packageId
+ " in current workspace. ");
426 public synchronized static File
getModuleFile(ModuleIdentification moduleId
) throws Exception
{
427 PackageIdentification packageId
= getPackageForModule(moduleId
);
428 moduleId
.setPackage(packageId
);
429 Spd spd
= spdTable
.get(packageId
);
430 return spd
.getModuleFile(moduleId
);
433 // expanded by FrameworkWizard
435 public synchronized static XmlObject
getModuleXmlObject(ModuleIdentification moduleId
) throws Exception
{
436 PackageIdentification packageId
= getPackageForModule(moduleId
);
437 moduleId
.setPackage(packageId
);
438 Spd spd
= spdTable
.get(packageId
);
439 return spd
.msaDocMap
.get(moduleId
);
442 public synchronized static XmlObject
getPackageXmlObject(PackageIdentification packageId
) {
443 Spd spd
= spdTable
.get(packageId
);
445 return spd
.spdDocMap
.get("PackageSurfaceArea");
450 public synchronized static Set
<PackageIdentification
> getPackageList(){
454 private static XmlObject
cloneXmlObject(XmlObject object
, boolean deep
) throws Exception
{
455 if ( object
== null) {
458 XmlObject result
= null;
460 result
= XmlObject
.Factory
.parse(object
.getDomNode()
462 } catch (Exception ex
) {
463 throw new Exception(ex
.getMessage());
468 ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
469 public static void setBuildToolChainFamilyOptions(Map
<String
, Object
> map
) {
470 toolChainFamilyOptions
= map
;
473 public static Map
<String
, Object
> getToolChainFamilyOptions() {
474 return toolChainFamilyOptions
;
477 public static void setBuildToolChainOptions(Map
<String
, Object
> map
) {
478 toolChainOptions
= map
;
481 public static Map
<String
, Object
> getToolChainOptions() {
482 return toolChainOptions
;
485 public static void setTargets(Set
<String
> targetSet
) {
486 GlobalData
.log
.info("TargetSet: " + targetSet
);
490 public static String
[] getTargets() {
491 return (String
[])targets
.toArray(new String
[targets
.size()]);
494 public static void setToolChains(Set
<String
> toolChainSet
) {
495 toolChains
= toolChainSet
;
498 public static String
[] getToolChains() {
499 String
[] toolChainList
= new String
[toolChains
.size()];
500 return (String
[])toolChains
.toArray(toolChainList
);
503 public static void setToolChainFamilies(Set
<String
> toolChainFamilySet
) {
504 toolChainFamilies
= toolChainFamilySet
;
507 public static void setToolChainFamiliyMap(Map
<String
, Set
<String
>> map
) {
509 Set<String> keys = map.keySet();
510 Iterator it = keys.iterator();
511 while (it.hasNext()) {
512 String toolchain = (String)it.next();
513 Set<String> familyMap = (Set<String>)map.get(toolchain);
514 Iterator fit = familyMap.iterator();
515 System.out.print(toolchain + ": ");
516 while (fit.hasNext()) {
517 System.out.print((String)fit.next() + " ");
519 System.out.println("");
522 toolChainFamilyMap
= map
;
525 public static String
[] getToolChainFamilies() {
526 String
[] toolChainFamilyList
= new String
[toolChainFamilies
.size()];
527 return (String
[])toolChainFamilies
.toArray(toolChainFamilyList
);
530 public static String
[] getToolChainFamilies(String toolChain
) {
531 Set
<String
> familySet
= (Set
<String
>)toolChainFamilyMap
.get(toolChain
);
532 String
[] toolChainFamilyList
= new String
[familySet
.size()];
533 return (String
[])familySet
.toArray(toolChainFamilyList
);
536 public static Set
<String
> getToolChainFamilySet(String toolChain
) {
537 return (Set
<String
>)toolChainFamilyMap
.get(toolChain
);
540 public static void setArchs(Set
<String
> archSet
) {
544 public static String
[] getArchs() {
545 String
[] archList
= new String
[archs
.size()];
546 return (String
[])archs
.toArray(archList
);
551 public static void SetCommandTypes(Set
<String
> commandTypeSet
) {
552 commandTypes
= commandTypeSet
;
557 public static void SetCommandTypes(Map
<String
, Set
<String
>> commandTypeMap
) {
558 toolChainCommandMap
= commandTypeMap
;
563 public static String
[] getCommandTypes() {
564 String
[] commandList
= new String
[commandTypes
.size()];
565 return (String
[])commandTypes
.toArray(commandList
);
570 public static String
[] getCommandTypes(String toolChain
) {
571 Set
<String
> commands
= (Set
<String
>)toolChainCommandMap
.get(toolChain
);
572 if (commands
== null) {
573 return new String
[0];
576 String
[] commandList
= new String
[commands
.size()];
577 return (String
[])commands
.toArray(commandList
);
582 public static String
getCommandSetting(String commandDescString
) {
583 return (String
)toolChainDefinitions
.get(commandDescString
);
588 public static void setToolChainDefinitions(Map
<String
, String
> def
) {
589 toolChainDefinitions
= def
;
592 public static Map
<String
, String
> getToolChainDefinitions() {
593 return toolChainDefinitions
;
598 final class KeyComparator
implements Comparator
<String
> {
599 public int compare(String x
, String y
) {
600 return x
.compareToIgnoreCase(y
);