]> 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 89c85ed8c26d54d28b1eec37975c4bb37321e756..4a7b56fc49eb13b1aad0d046ea96862cf75330cc 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Iterator;
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
-import java.util.logging.Logger;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
@@ -57,9 +56,6 @@ import org.tianocore.build.toolchain.ToolChainMap;
   @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
@@ -91,6 +87,8 @@ public class GlobalData {
 \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
@@ -163,8 +161,12 @@ public class GlobalData {
         // CONF dir + tools definition file name\r
         //\r
         File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r
-        System.out.println("Using tool definiton file [" + toolsDefFile.getPath() + "].");\r
-        toolsDef = new ToolChainConfig(toolsDefFile);\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
@@ -175,7 +177,7 @@ public class GlobalData {
             //\r
             // validate FrameworkDatabaseFile\r
             //\r
-            if (! db.validate()) {\r
+            if (!db.validate()) {\r
                 throw new BuildException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r
             }\r
             //\r
@@ -185,7 +187,7 @@ public class GlobalData {
                 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
@@ -199,16 +201,16 @@ public class GlobalData {
                 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
-                    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
-                    if (! fpdDoc.validate()) {\r
+                    if (!fpdDoc.validate()) {\r
                         throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r
                     }\r
                     //\r
@@ -219,8 +221,8 @@ public class GlobalData {
                     //\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
@@ -259,8 +261,7 @@ public class GlobalData {
         }\r
         if (msaFile == null){\r
             throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
-        }\r
-        else {\r
+        } else {\r
             return msaFile;\r
         }\r
     }\r
@@ -285,8 +286,7 @@ public class GlobalData {
         }\r
         if (packageId == null){\r
             throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
-        }\r
-        else {\r
+        } else {\r
             return packageId;\r
         }\r
     }\r
@@ -320,16 +320,14 @@ public class GlobalData {
     }\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
+      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 and MBD files if necessary. </p>\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
+      only parse the MSA files if necessary. </p>\r
+    \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
@@ -387,7 +385,7 @@ public class GlobalData {
     }\r
 \r
     public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {\r
-        if (! msaFile.exists()) {\r
+        if (!msaFile.exists()) {\r
             throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");\r
         }\r
         try {\r
@@ -395,7 +393,7 @@ public class GlobalData {
             //\r
             // Validate File if they accord with XML Schema\r
             //\r
-            if ( ! doc.validate()){\r
+            if ( !doc.validate()){\r
                 throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r
             }\r
             //\r
@@ -416,18 +414,17 @@ public class GlobalData {
             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
-    public static Map<String, XmlObject> getFpdBuildOptions() {\r
-        Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-        map.put("BuildOptions", fpdBuildOptions);\r
-        return map;\r
+    public static Map<String, XmlObject> getFpdBuildOptionsMap() {\r
+        return fpdBuildOptionsMap;\r
     }\r
 \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
@@ -438,16 +435,12 @@ public class GlobalData {
         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
-        }\r
-        else {\r
+        } else {\r
             return spd.getModules();\r
         }\r
     }\r
@@ -548,7 +541,6 @@ public class GlobalData {
             }\r
         }\r
         return null;\r
-\r
     }\r
 \r
     /**\r
@@ -607,18 +599,15 @@ public class GlobalData {
                 return packageId;\r
             }\r
         }\r
-        throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " in the current workspace!");\r
+        throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r
     }\r
 \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
-//        System.out.println("" + packageId.getGuid());\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() + " in the 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
@@ -631,13 +620,22 @@ public class GlobalData {
                 return moduleId;\r
             }\r
         }\r
-        throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in package, " + packageId + ", in the current workspace!");\r
+        throw new BuildException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");\r
     }\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
@@ -652,10 +650,10 @@ public class GlobalData {
         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
-//        GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);\r
         if (toolChainInfo == null) {\r
             toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r
             if (toolChainPlatformInfo != null) {\r
@@ -663,13 +661,12 @@ public class GlobalData {
             }\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
-\r
     public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r
         platformToolChainFamilyOption = map;\r
     }\r