]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
Change GenBuildLogger format.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / GlobalData.java
index 75c637ffe1dea8f74edf1fb1dddf33c16e358674..4a7b56fc49eb13b1aad0d046ea96862cf75330cc 100644 (file)
@@ -1,10 +1,10 @@
 /** @file\r
 /** @file\r
-  GlobalData class. \r
-  \r
+  GlobalData class.\r
+\r
   GlobalData provide initializing, instoring, querying and update global data.\r
   It is a bridge to intercommunicate between multiple component, such as AutoGen,\r
   GlobalData provide initializing, instoring, querying and update global data.\r
   It is a bridge to intercommunicate between multiple component, such as AutoGen,\r
-  PCD and so on.   \r
\r
+  PCD and so on.\r
+\r
 Copyright (c) 2006, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 Copyright (c) 2006, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -16,64 +16,60 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.build.global;\r
 \r
 **/\r
 package org.tianocore.build.global;\r
 \r
+import java.io.File;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
+\r
+import org.tianocore.common.exception.EdkException;\r
+import org.tianocore.common.logger.EdkLog;\r
+import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.DbPathAndFilename;\r
 import org.tianocore.FrameworkDatabaseDocument;\r
 import org.tianocore.ModuleSurfaceAreaDocument;\r
 import org.tianocore.DbPathAndFilename;\r
 import org.tianocore.FrameworkDatabaseDocument;\r
 import org.tianocore.ModuleSurfaceAreaDocument;\r
-import org.tianocore.PcdBuildDefinitionDocument;\r
 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
-import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.build.toolchain.ToolChainAttribute;\r
 import org.tianocore.build.toolchain.ToolChainConfig;\r
 import org.tianocore.build.toolchain.ToolChainElement;\r
 import org.tianocore.build.toolchain.ToolChainInfo;\r
 import org.tianocore.build.toolchain.ToolChainKey;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
 import org.tianocore.build.toolchain.ToolChainAttribute;\r
 import org.tianocore.build.toolchain.ToolChainConfig;\r
 import org.tianocore.build.toolchain.ToolChainElement;\r
 import org.tianocore.build.toolchain.ToolChainInfo;\r
 import org.tianocore.build.toolchain.ToolChainKey;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
-import org.tianocore.exception.EdkException;\r
-import org.tianocore.logger.EdkLog;\r
-\r
-import java.io.File;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.logging.Logger;\r
 \r
 /**\r
   GlobalData provide initializing, instoring, querying and update global data.\r
   It is a bridge to intercommunicate between multiple component, such as AutoGen,\r
 \r
 /**\r
   GlobalData provide initializing, instoring, querying and update global data.\r
   It is a bridge to intercommunicate between multiple component, such as AutoGen,\r
-  PCD and so on. \r
-  \r
-  <p>Note that all global information are initialized incrementally. All data will \r
+  PCD and so on.\r
+\r
+  <p>Note that all global information are initialized incrementally. All data will\r
   parse and record only of necessary during build time. </p>\r
   parse and record only of necessary during build time. </p>\r
-  \r
+\r
   @since GenBuild 1.0\r
 **/\r
 public class GlobalData {\r
   @since GenBuild 1.0\r
 **/\r
 public class GlobalData {\r
-\r
-    public static Logger log = Logger.getAnonymousLogger();\r
-    \r
     ///\r
     /// Record current WORKSPACE Directory\r
     ///\r
     private static String workspaceDir = "";\r
     ///\r
     /// Record current WORKSPACE Directory\r
     ///\r
     private static String workspaceDir = "";\r
-    \r
+\r
     ///\r
     /// Be used to ensure Global data will be initialized only once.\r
     ///\r
     private static boolean globalFlag = false;\r
     ///\r
     /// Be used to ensure Global data will be initialized only once.\r
     ///\r
     private static boolean globalFlag = false;\r
-    \r
+\r
     ///\r
     /// Framework Database information: package list and platform list\r
     ///\r
     ///\r
     /// Framework Database information: package list and platform list\r
     ///\r
-    private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>();  \r
+    private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>();\r
 \r
     private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();\r
 \r
 \r
     private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();\r
 \r
@@ -91,24 +87,26 @@ public class GlobalData {
 \r
     private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
 \r
 \r
     private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
 \r
+    private static Map<String, XmlObject> fpdBuildOptionsMap = new HashMap<String, XmlObject>();\r
+    \r
     private static XmlObject fpdBuildOptions;\r
 \r
     private static XmlObject fpdDynamicPcds;\r
     private static XmlObject fpdBuildOptions;\r
 \r
     private static XmlObject fpdDynamicPcds;\r
-    \r
+\r
     ///\r
     /// Parsed modules list\r
     ///\r
     private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
     ///\r
     /// Parsed modules list\r
     ///\r
     private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
-    \r
+\r
     ///\r
     /// built modules list with ARCH, TARGET, TOOLCHAIN\r
     ///\r
     private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();\r
     ///\r
     /// built modules list with ARCH, TARGET, TOOLCHAIN\r
     ///\r
     private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();\r
-    \r
+\r
     ///\r
     /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r
     ///\r
     ///\r
     /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r
     ///\r
-//    private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r
+    private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r
 \r
     ///\r
     /// build target + tool chain family/tag name + arch + command types + command options\r
 \r
     ///\r
     /// build target + tool chain family/tag name + arch + command types + command options\r
@@ -118,7 +116,7 @@ public class GlobalData {
     /// toolsDef - build tool program information\r
     /// fpdBuildOption - all modules's build options for tool tag or tool chain families\r
     /// moduleSaBuildOption - build options for a specific module\r
     /// toolsDef - build tool program information\r
     /// fpdBuildOption - all modules's build options for tool tag or tool chain families\r
     /// moduleSaBuildOption - build options for a specific module\r
-    /// \r
+    ///\r
     private static ToolChainConfig toolsDef;\r
 \r
     private static ToolChainInfo toolChainInfo;\r
     private static ToolChainConfig toolsDef;\r
 \r
     private static ToolChainInfo toolChainInfo;\r
@@ -131,21 +129,17 @@ public class GlobalData {
     private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
     private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
 \r
     private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
     private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
 \r
-    private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r
-\r
-    \r
-\r
     /**\r
       Parse framework database (DB) and all SPD files listed in DB to initialize\r
       the environment for next build. This method will only be executed only once\r
     /**\r
       Parse framework database (DB) and all SPD files listed in DB to initialize\r
       the environment for next build. This method will only be executed only once\r
-      in the whole build process.  \r
-    \r
+      in the whole build process.\r
+\r
       @param workspaceDatabaseFile the file name of framework database\r
       @param workspaceDir current workspace directory path\r
       @throws BuildException\r
             Framework Dababase or SPD or MSA file is not valid\r
     **/\r
       @param workspaceDatabaseFile the file name of framework database\r
       @param workspaceDir current workspace directory path\r
       @throws BuildException\r
             Framework Dababase or SPD or MSA file is not valid\r
     **/\r
-    public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename) throws BuildException {\r
+    public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws BuildException {\r
         //\r
         // ensure this method will be revoked only once\r
         //\r
         //\r
         // ensure this method will be revoked only once\r
         //\r
@@ -153,12 +147,12 @@ public class GlobalData {
             return;\r
         }\r
         globalFlag = true;\r
             return;\r
         }\r
         globalFlag = true;\r
-        \r
-        //\r
+\r
+               //\r
         // Backup workspace directory. It will be used by other method\r
         //\r
         GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r
         // Backup workspace directory. It will be used by other method\r
         //\r
         GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r
-        \r
+\r
         //\r
         // Parse tools definition file\r
         //\r
         //\r
         // Parse tools definition file\r
         //\r
@@ -167,9 +161,13 @@ public class GlobalData {
         // CONF dir + tools definition file name\r
         //\r
         File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r
         // CONF dir + tools definition file name\r
         //\r
         File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r
-        System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. ");\r
-        toolsDef = new ToolChainConfig(toolsDefFile);\r
-        \r
+        EdkLog.log("Init", "Using tool definiton file [" + toolsDefFile.getPath() + "].");\r
+        try {\r
+            toolsDef = new ToolChainConfig(toolsDefFile);\r
+        } catch (Exception e) {\r
+            throw new BuildException(e.getMessage());\r
+        }\r
+\r
         //\r
         // Parse Framework Database\r
         //\r
         //\r
         // Parse Framework Database\r
         //\r
@@ -179,8 +177,8 @@ public class GlobalData {
             //\r
             // validate FrameworkDatabaseFile\r
             //\r
             //\r
             // validate FrameworkDatabaseFile\r
             //\r
-            if (! db.validate()) {\r
-                throw new BuildException("Framework Database file [" + dbFile.getPath() + "] is invalid.");\r
+            if (!db.validate()) {\r
+                throw new BuildException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r
             }\r
             //\r
             // Get package list\r
             }\r
             //\r
             // Get package list\r
@@ -189,7 +187,7 @@ public class GlobalData {
                 List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();\r
                 Iterator<DbPathAndFilename> iter = packages.iterator();\r
                 while (iter.hasNext()) {\r
                 List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();\r
                 Iterator<DbPathAndFilename> iter = packages.iterator();\r
                 while (iter.hasNext()) {\r
-                    String fileName = iter.next().getStringValue();\r
+                    String fileName = iter.next().getStringValue().trim();\r
                     Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));\r
                     packageList.add(spd.getPackageId());\r
                     spdTable.put(spd.getPackageId(), spd);\r
                     Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));\r
                     packageList.add(spd.getPackageId());\r
                     spdTable.put(spd.getPackageId(), spd);\r
@@ -203,17 +201,17 @@ public class GlobalData {
                 List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();\r
                 Iterator<DbPathAndFilename> iter = platforms.iterator();\r
                 while (iter.hasNext()) {\r
                 List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();\r
                 Iterator<DbPathAndFilename> iter = platforms.iterator();\r
                 while (iter.hasNext()) {\r
-                    String fileName = iter.next().getStringValue();\r
+                    String fileName = iter.next().getStringValue().trim();\r
                     File fpdFile = new File(workspaceDir + File.separatorChar + fileName);\r
                     File fpdFile = new File(workspaceDir + File.separatorChar + fileName);\r
-                    if ( ! fpdFile.exists() ) {\r
+                    if ( !fpdFile.exists() ) {\r
                         throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r
                     }\r
                     XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);\r
                     //\r
                     // Verify FPD file, if is invalid, throw Exception\r
                     //\r
                         throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r
                     }\r
                     XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);\r
                     //\r
                     // Verify FPD file, if is invalid, throw Exception\r
                     //\r
-                    if (! fpdDoc.validate()) {\r
-                        throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] is invalid. ");\r
+                    if (!fpdDoc.validate()) {\r
+                        throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r
                     }\r
                     //\r
                     // We can change Map to XmlObject\r
                     }\r
                     //\r
                     // We can change Map to XmlObject\r
@@ -223,21 +221,20 @@ public class GlobalData {
                     //\r
                     Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();\r
                     fpdDocMap.put("PlatformSurfaceArea", fpdDoc);\r
                     //\r
                     Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();\r
                     fpdDocMap.put("PlatformSurfaceArea", fpdDoc);\r
-                    SurfaceAreaQuery.setDoc(fpdDocMap);\r
-                    PlatformIdentification platformId = SurfaceAreaQuery.getFpdHeader();\r
+                    SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap);\r
+                    PlatformIdentification platformId = saq.getFpdHeader();\r
                     platformId.setFpdFile(fpdFile);\r
                     platformList.add(platformId);\r
                 }\r
             }\r
         } catch (Exception e) {\r
                     platformId.setFpdFile(fpdFile);\r
                     platformList.add(platformId);\r
                 }\r
             }\r
         } catch (Exception e) {\r
-            e.printStackTrace();\r
-            throw new BuildException("Parse workspace Database [" + dbFile.getPath() + "] Error.\n" + e.getMessage());\r
+            throw new BuildException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + e.getMessage());\r
         }\r
     }\r
         }\r
     }\r
-    \r
+\r
     /**\r
     /**\r
-      Get the current WORKSPACE Directory. \r
-      \r
+      Get the current WORKSPACE Directory.\r
+\r
       @return current workspace directory\r
     **/\r
     public synchronized static String getWorkspacePath() {\r
       @return current workspace directory\r
     **/\r
     public synchronized static String getWorkspacePath() {\r
@@ -251,7 +248,7 @@ public class GlobalData {
     public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {\r
         File msaFile = null;\r
         //\r
     public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {\r
         File msaFile = null;\r
         //\r
-        // TBD. Do only when package is null. \r
+        // TBD. Do only when package is null.\r
         //\r
         Iterator iter = packageList.iterator();\r
         while (iter.hasNext()) {\r
         //\r
         Iterator iter = packageList.iterator();\r
         while (iter.hasNext()) {\r
@@ -263,9 +260,8 @@ public class GlobalData {
             }\r
         }\r
         if (msaFile == null){\r
             }\r
         }\r
         if (msaFile == null){\r
-            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");\r
-        }\r
-        else {\r
+            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
+        } else {\r
             return msaFile;\r
         }\r
     }\r
             return msaFile;\r
         }\r
     }\r
@@ -277,7 +273,7 @@ public class GlobalData {
         if (moduleId.getPackage() != null) {\r
             return moduleId.getPackage();\r
         }\r
         if (moduleId.getPackage() != null) {\r
             return moduleId.getPackage();\r
         }\r
-        \r
+\r
         PackageIdentification packageId = null;\r
         Iterator iter = packageList.iterator();\r
         while (iter.hasNext()) {\r
         PackageIdentification packageId = null;\r
         Iterator iter = packageList.iterator();\r
         while (iter.hasNext()) {\r
@@ -289,25 +285,24 @@ public class GlobalData {
             }\r
         }\r
         if (packageId == null){\r
             }\r
         }\r
         if (packageId == null){\r
-            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");\r
-        }\r
-        else {\r
+            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
+        } else {\r
             return packageId;\r
         }\r
     }\r
             return packageId;\r
         }\r
     }\r
-    \r
+\r
     /**\r
       Difference between build and parse: ToolChain and Target\r
     **/\r
     public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {\r
         return builtModules.contains(moduleId);\r
     }\r
     /**\r
       Difference between build and parse: ToolChain and Target\r
     **/\r
     public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {\r
         return builtModules.contains(moduleId);\r
     }\r
-    \r
+\r
     public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {\r
         builtModules.add(fpdModuleId);\r
     }\r
 \r
     public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {\r
         builtModules.add(fpdModuleId);\r
     }\r
 \r
-    \r
+\r
     public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) {\r
         Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r
         Set keySet = doc.keySet();\r
     public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) {\r
         Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r
         Set keySet = doc.keySet();\r
@@ -319,18 +314,20 @@ public class GlobalData {
         }\r
         fpdModuleSA.put(fpdModuleId, result);\r
     }\r
         }\r
         fpdModuleSA.put(fpdModuleId, result);\r
     }\r
-    \r
+\r
+    public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) {\r
+        return fpdModuleSA.containsKey(fpdModuleId);\r
+    }\r
+\r
     /**\r
     /**\r
-      Query overrided module surface area information. If current is Package\r
-      or Platform build, also include the information from FPD file. \r
-      \r
-      <p>Note that surface area parsing is incremental. That means the method will \r
-      only parse the MSA and MBD files if necessary. </p>\r
+      Query module surface area information.\r
+\r
+      <p>Note that surface area parsing is incremental. That means the method will\r
+      only parse the MSA files if necessary. </p>\r
     \r
     \r
-      @param moduleName the base name of the module\r
-      @return the overrided module surface area information\r
-      @throws BuildException\r
-              MSA or MBD is not valid\r
+      @param fpdModuleId Module ID with arch\r
+      @return ModuleSA info and MSA info for fpdModuleId\r
+      @throws BuildException Can't find MSA\r
     **/\r
     public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {\r
         if (parsedModules.containsKey(fpdModuleId)) {\r
     **/\r
     public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {\r
         if (parsedModules.containsKey(fpdModuleId)) {\r
@@ -342,12 +339,12 @@ public class GlobalData {
         // First part: get the MSA files info\r
         //\r
         doc.putAll(getNativeMsa(moduleId));\r
         // First part: get the MSA files info\r
         //\r
         doc.putAll(getNativeMsa(moduleId));\r
-        \r
+\r
         //\r
         // Second part: put build options\r
         //\r
         doc.put("BuildOptions", fpdBuildOptions);\r
         //\r
         // Second part: put build options\r
         //\r
         doc.put("BuildOptions", fpdBuildOptions);\r
-        \r
+\r
         //\r
         // Third part: get Module info from FPD, such as Library instances, PCDs\r
         //\r
         //\r
         // Third part: get Module info from FPD, such as Library instances, PCDs\r
         //\r
@@ -367,11 +364,11 @@ public class GlobalData {
         return getDoc(fpdModuleId);\r
     }\r
     /**\r
         return getDoc(fpdModuleId);\r
     }\r
     /**\r
-      Query the native MSA information with module base name. \r
-      \r
-      <p>Note that MSA parsing is incremental. That means the method will \r
+      Query the native MSA information with module base name.\r
+\r
+      <p>Note that MSA parsing is incremental. That means the method will\r
       only to parse the MSA files when never parsed before. </p>\r
       only to parse the MSA files when never parsed before. </p>\r
-      \r
+\r
       @param moduleName the base name of the module\r
       @return the native MSA information\r
       @throws BuildException\r
       @param moduleName the base name of the module\r
       @return the native MSA information\r
       @throws BuildException\r
@@ -386,18 +383,18 @@ public class GlobalData {
         nativeMsa.put(moduleId, msaMap);\r
         return msaMap;\r
     }\r
         nativeMsa.put(moduleId, msaMap);\r
         return msaMap;\r
     }\r
-    \r
+\r
     public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {\r
     public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {\r
-        if (! msaFile.exists()) {\r
-            throw new BuildException("Surface Area file [" + msaFile.getPath() + "] can't found.");\r
+        if (!msaFile.exists()) {\r
+            throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");\r
         }\r
         try {\r
             ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r
             //\r
             // Validate File if they accord with XML Schema\r
             //\r
         }\r
         try {\r
             ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r
             //\r
             // Validate File if they accord with XML Schema\r
             //\r
-            if ( ! doc.validate()){\r
-                throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] is invalid.");\r
+            if ( !doc.validate()){\r
+                throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r
             }\r
             //\r
             // parse MSA file\r
             }\r
             //\r
             // parse MSA file\r
@@ -417,18 +414,17 @@ public class GlobalData {
             return msaMap;\r
         }\r
         catch (Exception ex){\r
             return msaMap;\r
         }\r
         catch (Exception ex){\r
-            throw new BuildException(ex.getMessage());\r
+            throw new BuildException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage() );\r
         }\r
     }\r
         }\r
     }\r
-    \r
-    public static Map<String, XmlObject> getFpdBuildOptions() {\r
-        Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-        map.put("BuildOptions", fpdBuildOptions);\r
-        return map;\r
+\r
+    public static Map<String, XmlObject> getFpdBuildOptionsMap() {\r
+        return fpdBuildOptionsMap;\r
     }\r
     }\r
-    \r
+\r
     public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {\r
         GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r
     public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {\r
         GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r
+        fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions);\r
     }\r
 \r
     public static XmlObject getFpdDynamicPcds() {\r
     }\r
 \r
     public static XmlObject getFpdDynamicPcds() {\r
@@ -439,16 +435,12 @@ public class GlobalData {
         GlobalData.fpdDynamicPcds = fpdDynamicPcds;\r
     }\r
 \r
         GlobalData.fpdDynamicPcds = fpdDynamicPcds;\r
     }\r
 \r
-    //////////////////////////////////////////////\r
-    //////////////////////////////////////////////\r
-    \r
     public static Set<ModuleIdentification> getModules(PackageIdentification packageId){\r
         Spd spd = spdTable.get(packageId);\r
         if (spd == null ) {\r
             Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();\r
             return dummy;\r
     public static Set<ModuleIdentification> getModules(PackageIdentification packageId){\r
         Spd spd = spdTable.get(packageId);\r
         if (spd == null ) {\r
             Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();\r
             return dummy;\r
-        }\r
-        else {\r
+        } else {\r
             return spd.getModules();\r
         }\r
     }\r
             return spd.getModules();\r
         }\r
     }\r
@@ -477,7 +469,7 @@ public class GlobalData {
         // If can't find library class declaration in every package\r
         //\r
         throw new BuildException("Can not find library class [" + name\r
         // If can't find library class declaration in every package\r
         //\r
         throw new BuildException("Can not find library class [" + name\r
-                + "] declaration in every packages. ");\r
+                + "] declaration in any SPD package!");\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
@@ -549,7 +541,6 @@ public class GlobalData {
             }\r
         }\r
         return null;\r
             }\r
         }\r
         return null;\r
-\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
@@ -574,7 +565,7 @@ public class GlobalData {
         return null;\r
 \r
     }\r
         return null;\r
 \r
     }\r
-    \r
+\r
     public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {\r
         Iterator iter = platformList.iterator();\r
         while(iter.hasNext()){\r
     public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {\r
         Iterator iter = platformList.iterator();\r
         while(iter.hasNext()){\r
@@ -583,9 +574,9 @@ public class GlobalData {
                 return platformId;\r
             }\r
         }\r
                 return platformId;\r
             }\r
         }\r
-        throw new BuildException("Can't find platform [" + name + "] in current workspace database. ");\r
+        throw new BuildException("Can't find platform [" + name + "] in the current WORKSPACE database!");\r
     }\r
     }\r
-    \r
+\r
     public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {\r
         File file = new File(workspaceDir + File.separatorChar + filename);\r
         Iterator iter = platformList.iterator();\r
     public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {\r
         File file = new File(workspaceDir + File.separatorChar + filename);\r
         Iterator iter = platformList.iterator();\r
@@ -595,9 +586,9 @@ public class GlobalData {
                 return platformId;\r
             }\r
         }\r
                 return platformId;\r
             }\r
         }\r
-        throw new BuildException("Can't find platform file [" + filename + "] in current workspace database. ");\r
+        throw new BuildException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");\r
     }\r
     }\r
-    \r
+\r
     public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r
         Iterator iter = packageList.iterator();\r
         while(iter.hasNext()){\r
     public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r
         Iterator iter = packageList.iterator();\r
         while(iter.hasNext()){\r
@@ -608,18 +599,15 @@ public class GlobalData {
                 return packageId;\r
             }\r
         }\r
                 return packageId;\r
             }\r
         }\r
-        throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r
+        throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r
     }\r
     }\r
-    \r
+\r
     public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {\r
     public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {\r
-//        System.out.println("1");\r
-//        System.out.println("##" + moduleId.getGuid());\r
         PackageIdentification packageId = getPackageForModule(moduleId);\r
         PackageIdentification packageId = getPackageForModule(moduleId);\r
-//        System.out.println("" + packageId.getGuid());\r
         moduleId.setPackage(packageId);\r
         Spd spd = spdTable.get(packageId);\r
         if (spd == null) {\r
         moduleId.setPackage(packageId);\r
         Spd spd = spdTable.get(packageId);\r
         if (spd == null) {\r
-            throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r
+            throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r
         }\r
         Set<ModuleIdentification> modules = spd.getModules();\r
         Iterator<ModuleIdentification> iter = modules.iterator();\r
         }\r
         Set<ModuleIdentification> modules = spd.getModules();\r
         Iterator<ModuleIdentification> iter = modules.iterator();\r
@@ -632,13 +620,22 @@ public class GlobalData {
                 return moduleId;\r
             }\r
         }\r
                 return moduleId;\r
             }\r
         }\r
-        throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. ");\r
+        throw new BuildException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");\r
     }\r
     }\r
-    \r
+\r
     public synchronized static Set<PackageIdentification> getPackageList(){\r
         return packageList;\r
     }\r
     public synchronized static Set<PackageIdentification> getPackageList(){\r
         return packageList;\r
     }\r
-    ///// remove!!\r
+\r
+    /**\r
+      BUGBUG: It is a walk around method. If do not clone, can't query info with\r
+      XPath correctly. \r
+      \r
+      @param object XmlObject\r
+      @param deep flag for deep clone\r
+      @return XmlObject after clone\r
+      @throws BuildException parse original XmlObject error. \r
+    **/\r
     private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r
         if ( object == null) {\r
             return null;\r
     private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r
         if ( object == null) {\r
             return null;\r
@@ -653,10 +650,10 @@ public class GlobalData {
         return result;\r
     }\r
 \r
         return result;\r
     }\r
 \r
-    ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r
-\r
+    ///\r
+    /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r
+    ///\r
     public static ToolChainInfo getToolChainInfo() {\r
     public static ToolChainInfo getToolChainInfo() {\r
-//        GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);\r
         if (toolChainInfo == null) {\r
             toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r
             if (toolChainPlatformInfo != null) {\r
         if (toolChainInfo == null) {\r
             toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r
             if (toolChainPlatformInfo != null) {\r
@@ -664,13 +661,12 @@ public class GlobalData {
             }\r
             toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r
             toolChainInfo.normalize();\r
             }\r
             toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r
             toolChainInfo.normalize();\r
-            GlobalData.log.info(toolChainInfo + "");\r
+            EdkLog.log("Init", "Current build tool chain information summary: ");\r
+            EdkLog.log("Init", toolChainInfo + "");\r
         }\r
         return toolChainInfo;\r
     }\r
 \r
         }\r
         return toolChainInfo;\r
     }\r
 \r
-\r
-\r
     public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r
         platformToolChainFamilyOption = map;\r
     }\r
     public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r
         platformToolChainFamilyOption = map;\r
     }\r
@@ -693,7 +689,8 @@ public class GlobalData {
         String[] commands = getToolChainInfo().getCommands();\r
 \r
         for (int i = 0; i < commands.length; ++i) {\r
         String[] commands = getToolChainInfo().getCommands();\r
 \r
         for (int i = 0; i < commands.length; ++i) {\r
-            if (toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()}) != null) {\r
+            String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()});\r
+            if (cmdName != null && cmdName.length() != 0) {\r
                 return true;\r
             }\r
         }\r
                 return true;\r
             }\r
         }\r
@@ -703,7 +700,7 @@ public class GlobalData {
 \r
     public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r
         ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r
 \r
     public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r
         ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r
-        ToolChainMap toolChainConfig = toolsDef.getConfig(); \r
+        ToolChainMap toolChainConfig = toolsDef.getConfig();\r
         String setting = null;\r
 \r
         if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {\r
         String setting = null;\r
 \r
         if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {\r
@@ -732,7 +729,7 @@ public class GlobalData {
             toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r
 \r
             option = moduleToolChainFamilyOption.get(fpdModuleId);\r
             toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r
 \r
             option = moduleToolChainFamilyOption.get(fpdModuleId);\r
-            if (option != null) {                \r
+            if (option != null) {\r
                 setting = option.get(toolChainFamilyKey);\r
             }\r
         }\r
                 setting = option.get(toolChainFamilyKey);\r
             }\r
         }\r
@@ -762,7 +759,7 @@ public class GlobalData {
 \r
         return setting;\r
     }\r
 \r
         return setting;\r
     }\r
-    \r
+\r
     public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r
         toolChainEnvInfo = envInfo;\r
     }\r
     public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r
         toolChainEnvInfo = envInfo;\r
     }\r
@@ -780,8 +777,8 @@ public class GlobalData {
     //\r
     // For PCD get tokenSpaceGUid\r
     //\r
     //\r
     // For PCD get tokenSpaceGUid\r
     //\r
-    public synchronized static String[] getGuidInfoFromCname(String cName){\r
-        String cNameGuid[] = null;\r
+    public synchronized static String getGuidInfoFromCname(String cName){\r
+        String cNameGuid = null;\r
         String guid = null;\r
         Set set = spdTable.keySet();\r
         Iterator iter = set.iterator();\r
         String guid = null;\r
         Set set = spdTable.keySet();\r
         Iterator iter = set.iterator();\r
@@ -794,9 +791,7 @@ public class GlobalData {
             Spd spd = (Spd) spdTable.get(iter.next());\r
             guid = spd.getGuidFromCname(cName);\r
             if (guid != null){\r
             Spd spd = (Spd) spdTable.get(iter.next());\r
             guid = spd.getGuidFromCname(cName);\r
             if (guid != null){\r
-                cNameGuid = new String[2];\r
-                cNameGuid[0] = cName;\r
-                cNameGuid[1] = guid;\r
+                cNameGuid = guid;\r
                 break;\r
             }\r
         }\r
                 break;\r
             }\r
         }\r
@@ -806,33 +801,36 @@ public class GlobalData {
     //\r
     // For PCD\r
     //\r
     //\r
     // For PCD\r
     //\r
-    public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(\r
-            String xmlObjectName) {\r
+    public synchronized static Map<FpdModuleIdentification, XmlObject>\r
+                               getFpdModuleSaXmlObject(String xmlObjectName) {\r
         Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r
         Iterator item = fpdModuleSASet.iterator();\r
         Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r
         Iterator item = fpdModuleSASet.iterator();\r
-        \r
+\r
 \r
         Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r
         Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r
         FpdModuleIdentification moduleId;\r
         while (item.hasNext()) {\r
 \r
         Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r
         Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r
         FpdModuleIdentification moduleId;\r
         while (item.hasNext()) {\r
-            \r
+\r
             moduleId = (FpdModuleIdentification) item.next();\r
             SANode = fpdModuleSA.get(moduleId);\r
             try{\r
                 if (SANode.get(xmlObjectName)!= null){\r
                     SAPcdBuildDef.put(moduleId,\r
             moduleId = (FpdModuleIdentification) item.next();\r
             SANode = fpdModuleSA.get(moduleId);\r
             try{\r
                 if (SANode.get(xmlObjectName)!= null){\r
                     SAPcdBuildDef.put(moduleId,\r
-                            (XmlObject) SANode\r
-                                    .get(xmlObjectName));\r
+                            (XmlObject) SANode.get(xmlObjectName));\r
 \r
                 }\r
 \r
                 }\r
-                            \r
-                \r
             } catch (Exception e){\r
                 EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r
             }\r
             } catch (Exception e){\r
                 EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r
             }\r
-            }\r
+        }\r
         return SAPcdBuildDef;\r
     }\r
         return SAPcdBuildDef;\r
     }\r
+\r
+    public synchronized static Map<FpdModuleIdentification,XmlObject> getFpdPcdBuildDefinitions() {\r
+        Map<FpdModuleIdentification,XmlObject> pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition");\r
+\r
+        return pcdBuildDef;\r
+    }\r
 }\r
 \r
 }\r
 \r