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
{
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("(\\\\)", "/");
161 File dbFile
= new File(workspaceDir
+ File
.separatorChar
+ workspaceDatabaseFile
);
163 FrameworkDatabaseDocument db
= (FrameworkDatabaseDocument
) XmlObject
.Factory
.parse(dbFile
);
165 // validate FrameworkDatabaseFile
167 // if (! db.validate()) {
168 // throw new Exception("Framework Database file [" + dbFile.getPath() + "] is invalid.");
173 List
<DbPathAndFilename
> packages
= db
.getFrameworkDatabase().getPackageList().getFilenameList();
175 Iterator iter
= packages
.iterator();
176 while (iter
.hasNext()) {
177 DbPathAndFilename dbPath
= (DbPathAndFilename
)iter
.next();
178 String fileName
= dbPath
.getStringValue();
179 Spd spd
= new Spd(new File(workspaceDir
+ File
.separatorChar
+ fileName
));
180 packageList
.add(spd
.getPackageId());
181 spdTable
.put(spd
.getPackageId(), spd
);
185 } catch (Exception e
) {
187 throw new Exception("Parse workspace Database [" + dbFile
.getPath() + "] Error.\n" + e
.getMessage());
192 Get the current WORKSPACE Directory.
194 @return current workspace directory
196 public synchronized static String
getWorkspacePath() {
202 Get the MSA file name with absolute path
204 public synchronized static File
getMsaFile(ModuleIdentification moduleId
) throws Exception
{
207 // TBD. Do only when package is null.
209 Iterator iter
= packageList
.iterator();
210 while (iter
.hasNext()) {
211 PackageIdentification packageId
= (PackageIdentification
)iter
.next();
212 Spd spd
= spdTable
.get(packageId
);
213 msaFile
= spd
.getModuleFile(moduleId
);
214 if (msaFile
!= null ) {
218 if (msaFile
== null){
219 throw new Exception("Can't find Module [" + moduleId
.getName() + "] in all packages. ");
226 public synchronized static PackageIdentification
getPackageForModule(ModuleIdentification moduleId
) {
228 // If package already defined in module
230 if (moduleId
.getPackage() != null) {
231 return moduleId
.getPackage();
234 PackageIdentification packageId
= null;
235 Iterator iter
= packageList
.iterator();
236 while (iter
.hasNext()) {
237 packageId
= (PackageIdentification
)iter
.next();
239 Spd spd
= spdTable
.get(packageId
);
240 if (spd
.getModuleFile(moduleId
) != null ) {
241 moduleId
.setPackage(packageId
);
245 if (packageId
== null){
254 Difference between build and parse: ToolChain and Target
256 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId
) {
257 return builtModules
.contains(moduleId
);
260 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId
) {
261 builtModules
.add(fpdModuleId
);
265 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId
, Map
<String
, XmlObject
> doc
) throws Exception
{
266 Map
<String
, XmlObject
> result
= new HashMap
<String
, XmlObject
>();
267 Set keySet
= doc
.keySet();
268 Iterator iter
= keySet
.iterator();
269 while (iter
.hasNext()){
270 String key
= (String
)iter
.next();
271 XmlObject item
= cloneXmlObject(doc
.get(key
), true);
272 result
.put(key
, item
);
274 fpdModuleSA
.put(fpdModuleId
, result
);
278 Query overrided module surface area information. If current is Package
279 or Platform build, also include the information from FPD file.
281 <p>Note that surface area parsing is incremental. That means the method will
282 only parse the MSA and MBD files if necessary. </p>
284 @param moduleName the base name of the module
285 @return the overrided module surface area information
287 MSA or MBD is not valid
289 public synchronized static Map
<String
, XmlObject
> getDoc(FpdModuleIdentification fpdModuleId
) throws Exception
{
290 if (parsedModules
.containsKey(fpdModuleId
)) {
291 return parsedModules
.get(fpdModuleId
);
293 Map
<String
, XmlObject
> doc
= new HashMap
<String
, XmlObject
>();
294 ModuleIdentification moduleId
= fpdModuleId
.getModule();
296 // First part: get the MSA files info
298 doc
= getNativeMsa(moduleId
);
301 // Second part: put build options
303 doc
.put("BuildOptions", fpdBuildOptions
);
306 // Third part: get Module info from FPD, such as Library instances, PCDs
308 if (fpdModuleSA
.containsKey(fpdModuleId
)){
310 // merge module info in FPD to final Doc
311 // For Library Module, do nothing here
313 doc
.putAll(fpdModuleSA
.get(fpdModuleId
));
315 parsedModules
.put(fpdModuleId
, doc
);
319 public synchronized static Map
<String
, XmlObject
> getDoc(ModuleIdentification moduleId
, String arch
) throws Exception
{
320 FpdModuleIdentification fpdModuleId
= new FpdModuleIdentification(moduleId
, arch
);
321 return getDoc(fpdModuleId
);
324 Query the native MSA information with module base name.
326 <p>Note that MSA parsing is incremental. That means the method will
327 only to parse the MSA files when never parsed before. </p>
329 @param moduleName the base name of the module
330 @return the native MSA information
332 MSA file is not valid
334 public synchronized static Map
<String
, XmlObject
> getNativeMsa(ModuleIdentification moduleId
) throws Exception
{
335 if (nativeMsa
.containsKey(moduleId
)) {
336 return nativeMsa
.get(moduleId
);
338 File msaFile
= getMsaFile(moduleId
);
339 Map
<String
, XmlObject
> msaMap
= getNativeMsa(msaFile
);
340 nativeMsa
.put(moduleId
, msaMap
);
344 public synchronized static Map
<String
, XmlObject
> getNativeMsa(File msaFile
) throws Exception
{
345 if (! msaFile
.exists()) {
346 throw new Exception("Surface Area file [" + msaFile
.getPath() + "] can't found.");
349 ModuleSurfaceAreaDocument doc
= (ModuleSurfaceAreaDocument
)XmlObject
.Factory
.parse(msaFile
);
351 // Validate File if they accord with XML Schema
353 // if ( ! doc.validate()){
354 // throw new Exception("Module Surface Area file [" + msaFile.getPath() + "] is invalid.");
359 ModuleSurfaceArea msa
= doc
.getModuleSurfaceArea();
360 Map
<String
, XmlObject
> msaMap
= new HashMap
<String
, XmlObject
>();
361 msaMap
.put("ModuleSurfaceArea", msa
);
362 msaMap
.put("MsaHeader", cloneXmlObject(msa
.getMsaHeader(), true));
363 msaMap
.put("LibraryClassDefinitions", cloneXmlObject(msa
.getLibraryClassDefinitions(), true));
364 msaMap
.put("SourceFiles", cloneXmlObject(msa
.getSourceFiles(), true));
365 msaMap
.put("PackageDependencies", cloneXmlObject(msa
.getPackageDependencies(), true));
366 msaMap
.put("Protocols", cloneXmlObject(msa
.getProtocols(), true));
367 msaMap
.put("PPIs", cloneXmlObject(msa
.getPPIs(), true));
368 msaMap
.put("Guids", cloneXmlObject(msa
.getGuids(), true));
369 msaMap
.put("Externs", cloneXmlObject(msa
.getExterns(), true));
372 catch (Exception ex
){
373 throw new Exception(ex
.getMessage());
377 public static Map
<String
, XmlObject
> getFpdBuildOptions() {
378 Map
<String
, XmlObject
> map
= new HashMap
<String
, XmlObject
>();
379 map
.put("BuildOptions", fpdBuildOptions
);
383 public static void setFpdBuildOptions(XmlObject fpdBuildOptions
) throws Exception
{
384 GlobalData
.fpdBuildOptions
= cloneXmlObject(fpdBuildOptions
, true);
387 public static XmlObject
getFpdDynamicPcds() {
388 return fpdDynamicPcds
;
391 public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds
) {
392 GlobalData
.fpdDynamicPcds
= fpdDynamicPcds
;
395 //////////////////////////////////////////////
396 //////////////////////////////////////////////
398 public static Set
<ModuleIdentification
> getModules(PackageIdentification packageId
){
399 Spd spd
= spdTable
.get(packageId
);
401 Set
<ModuleIdentification
> dummy
= new HashSet
<ModuleIdentification
>();
405 return spd
.getModules();
409 public synchronized static PlatformIdentification
getPlatform(String name
) throws Exception
{
410 Iterator iter
= platformList
.iterator();
411 while(iter
.hasNext()){
412 PlatformIdentification platformId
= (PlatformIdentification
)iter
.next();
413 if (platformId
.getName().equalsIgnoreCase(name
)) {
414 GlobalData
.log
.info("Platform: " + platformId
+ platformId
.getFpdFile());
418 throw new Exception("Can't find platform [" + name
+ "] in current workspace. ");
421 public synchronized static File
getPackageFile(PackageIdentification packageId
) throws Exception
{
422 Iterator iter
= packageList
.iterator();
423 while(iter
.hasNext()){
424 PackageIdentification packageItem
= (PackageIdentification
)iter
.next();
425 if (packageItem
.equals(packageId
)) {
426 packageId
.setName(packageItem
.getName());
427 return packageItem
.getSpdFile();
430 throw new Exception("Can't find " + packageId
+ " in current workspace. ");
433 public synchronized static File
getModuleFile(ModuleIdentification moduleId
) throws Exception
{
434 PackageIdentification packageId
= getPackageForModule(moduleId
);
435 moduleId
.setPackage(packageId
);
436 Spd spd
= spdTable
.get(packageId
);
437 return spd
.getModuleFile(moduleId
);
440 // expanded by FrameworkWizard
442 public synchronized static XmlObject
getModuleXmlObject(ModuleIdentification moduleId
) throws Exception
{
443 PackageIdentification packageId
= getPackageForModule(moduleId
);
444 moduleId
.setPackage(packageId
);
445 Spd spd
= spdTable
.get(packageId
);
446 return spd
.msaDocMap
.get(moduleId
);
449 public synchronized static XmlObject
getPackageXmlObject(PackageIdentification packageId
) {
450 Spd spd
= spdTable
.get(packageId
);
452 return spd
.spdDocMap
.get("PackageSurfaceArea");
457 public synchronized static Set
<PackageIdentification
> getPackageList(){
461 private static XmlObject
cloneXmlObject(XmlObject object
, boolean deep
) throws Exception
{
462 if ( object
== null) {
465 XmlObject result
= null;
467 result
= XmlObject
.Factory
.parse(object
.getDomNode()
469 } catch (Exception ex
) {
470 throw new Exception(ex
.getMessage());
475 ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
476 public static void setBuildToolChainFamilyOptions(Map
<String
, Object
> map
) {
477 toolChainFamilyOptions
= map
;
480 public static Map
<String
, Object
> getToolChainFamilyOptions() {
481 return toolChainFamilyOptions
;
484 public static void setBuildToolChainOptions(Map
<String
, Object
> map
) {
485 toolChainOptions
= map
;
488 public static Map
<String
, Object
> getToolChainOptions() {
489 return toolChainOptions
;
492 public static void setTargets(Set
<String
> targetSet
) {
493 GlobalData
.log
.info("TargetSet: " + targetSet
);
497 public static String
[] getTargets() {
498 return (String
[])targets
.toArray(new String
[targets
.size()]);
501 public static void setToolChains(Set
<String
> toolChainSet
) {
502 toolChains
= toolChainSet
;
505 public static String
[] getToolChains() {
506 String
[] toolChainList
= new String
[toolChains
.size()];
507 return (String
[])toolChains
.toArray(toolChainList
);
510 public static void setToolChainFamilies(Set
<String
> toolChainFamilySet
) {
511 toolChainFamilies
= toolChainFamilySet
;
514 public static void setToolChainFamiliyMap(Map
<String
, Set
<String
>> map
) {
516 Set<String> keys = map.keySet();
517 Iterator it = keys.iterator();
518 while (it.hasNext()) {
519 String toolchain = (String)it.next();
520 Set<String> familyMap = (Set<String>)map.get(toolchain);
521 Iterator fit = familyMap.iterator();
522 System.out.print(toolchain + ": ");
523 while (fit.hasNext()) {
524 System.out.print((String)fit.next() + " ");
526 System.out.println("");
529 toolChainFamilyMap
= map
;
532 public static String
[] getToolChainFamilies() {
533 String
[] toolChainFamilyList
= new String
[toolChainFamilies
.size()];
534 return (String
[])toolChainFamilies
.toArray(toolChainFamilyList
);
537 public static String
[] getToolChainFamilies(String toolChain
) {
538 Set
<String
> familySet
= (Set
<String
>)toolChainFamilyMap
.get(toolChain
);
539 String
[] toolChainFamilyList
= new String
[familySet
.size()];
540 return (String
[])familySet
.toArray(toolChainFamilyList
);
543 public static Set
<String
> getToolChainFamilySet(String toolChain
) {
544 return (Set
<String
>)toolChainFamilyMap
.get(toolChain
);
547 public static void setArchs(Set
<String
> archSet
) {
551 public static String
[] getArchs() {
552 String
[] archList
= new String
[archs
.size()];
553 return (String
[])archs
.toArray(archList
);
558 public static void SetCommandTypes(Set
<String
> commandTypeSet
) {
559 commandTypes
= commandTypeSet
;
564 public static void SetCommandTypes(Map
<String
, Set
<String
>> commandTypeMap
) {
565 toolChainCommandMap
= commandTypeMap
;
570 public static String
[] getCommandTypes() {
571 String
[] commandList
= new String
[commandTypes
.size()];
572 return (String
[])commandTypes
.toArray(commandList
);
577 public static String
[] getCommandTypes(String toolChain
) {
578 Set
<String
> commands
= (Set
<String
>)toolChainCommandMap
.get(toolChain
);
579 if (commands
== null) {
580 return new String
[0];
583 String
[] commandList
= new String
[commands
.size()];
584 return (String
[])commands
.toArray(commandList
);
589 public static String
getCommandSetting(String commandDescString
) {
590 return (String
)toolChainDefinitions
.get(commandDescString
);
595 public static void setToolChainDefinitions(Map
<String
, String
> def
) {
596 toolChainDefinitions
= def
;
599 public static Map
<String
, String
> getToolChainDefinitions() {
600 return toolChainDefinitions
;
605 final class KeyComparator
implements Comparator
<String
> {
606 public int compare(String x
, String y
) {
607 return x
.compareToIgnoreCase(y
);