]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
Added synchronized to getCommandSetting to solve multi-thread build issue
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / GlobalData.java
index 3a5d1dd9a086ec730719744142484309a3fb2a1b..e5e4d5e67164ba3434c5cbe73224de6e196fd4f4 100644 (file)
@@ -17,15 +17,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 package org.tianocore.build.global;\r
 \r
 import java.io.File;\r
+import java.io.IOException;\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
-import org.apache.tools.ant.BuildException;\r
+import org.apache.xmlbeans.XmlException;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
 import org.tianocore.common.exception.EdkException;\r
@@ -57,9 +57,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 +88,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
@@ -141,7 +140,7 @@ public class GlobalData {
       @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 EdkException {\r
         //\r
         // ensure this method will be revoked only once\r
         //\r
@@ -163,12 +162,8 @@ 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
-        try {\r
-            toolsDef = new ToolChainConfig(toolsDefFile);\r
-        } catch (Exception e) {\r
-            throw new BuildException(e.getMessage());\r
-        }\r
+        EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Using tool definition file [" + toolsDefFile.getPath() + "].");\r
+        toolsDef = new ToolChainConfig(toolsDefFile);\r
 \r
         //\r
         // Parse Framework Database\r
@@ -180,7 +175,7 @@ public class GlobalData {
             // validate FrameworkDatabaseFile\r
             //\r
             if (!db.validate()) {\r
-                throw new BuildException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r
+                throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r
             }\r
             //\r
             // Get package list\r
@@ -189,9 +184,18 @@ 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
+                    //\r
+                    // Report warning if existing two packages with same GUID and Version\r
+                    //\r
+                    if (spdTable.containsKey(spd.getPackageId())) {\r
+                        //\r
+                        // BUGBUG\r
+                        //\r
+                        EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two packages with same GUID and Version. They are ... " + spd.getPackageId().getSpdFile().getPath());\r
+                    }\r
                     spdTable.put(spd.getPackageId(), spd);\r
                 }\r
             }\r
@@ -203,34 +207,46 @@ 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
-                        throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r
+                        throw new EdkException("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() + "] format is invalid!");\r
+                        throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r
                     }\r
                     //\r
                     // We can change Map to XmlObject\r
                     //\r
-                    //\r
-                    // TBD check SPD or FPD is existed in FS\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
+                    //\r
+                    // Report warning if existing two platfrom with same GUID and Version\r
+                    //\r
+                    if (platformList.contains(platformId)) {\r
+                        //\r
+                        // BUGBUG\r
+                        //\r
+                        EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile.getPath());\r
+                    }\r
                     platformList.add(platformId);\r
                 }\r
             }\r
-        } catch (Exception e) {\r
-            throw new BuildException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + e.getMessage());\r
+        } catch(IOException ex) {\r
+            EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());\r
+            edkException.setStackTrace(ex.getStackTrace());\r
+            throw edkException;\r
+        } catch(XmlException ex) {\r
+            EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());\r
+            edkException.setStackTrace(ex.getStackTrace());\r
+            throw edkException;\r
         }\r
     }\r
 \r
@@ -247,7 +263,7 @@ public class GlobalData {
     /**\r
       Get the MSA file name with absolute path\r
      */\r
-    public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {\r
+    public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException {\r
         File msaFile = null;\r
         //\r
         // TBD. Do only when package is null.\r
@@ -262,13 +278,13 @@ public class GlobalData {
             }\r
         }\r
         if (msaFile == null){\r
-            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
+            throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
         } else {\r
             return msaFile;\r
         }\r
     }\r
 \r
-    public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) {\r
+    public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException {\r
         //\r
         // If package already defined in module\r
         //\r
@@ -282,12 +298,16 @@ public class GlobalData {
             packageId = (PackageIdentification)iter.next();\r
             moduleId.setPackage(packageId);\r
             Spd spd = spdTable.get(packageId);\r
-            if (spd.getModuleFile(moduleId) != null ) {\r
-                break ;\r
+            File tempMsaFile = null;\r
+            if ((tempMsaFile = spd.getModuleFile(moduleId)) != null ) {\r
+                if (tempMsaFile.getParent().equalsIgnoreCase(moduleId.getMsaFile().getParent())) {\r
+                    break ;\r
+                }\r
+                tempMsaFile = null;\r
             }\r
         }\r
         if (packageId == null){\r
-            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
+            throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
         } else {\r
             return packageId;\r
         }\r
@@ -305,7 +325,7 @@ public class GlobalData {
     }\r
 \r
 \r
-    public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) {\r
+    public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) throws EdkException{\r
         Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r
         Set keySet = doc.keySet();\r
         Iterator iter = keySet.iterator();\r
@@ -331,7 +351,7 @@ public class GlobalData {
       @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
+    public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{\r
         if (parsedModules.containsKey(fpdModuleId)) {\r
             return parsedModules.get(fpdModuleId);\r
         }\r
@@ -361,10 +381,11 @@ public class GlobalData {
         return doc;\r
     }\r
 \r
-    public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws BuildException {\r
+    public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws EdkException{\r
         FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r
         return getDoc(fpdModuleId);\r
     }\r
+    \r
     /**\r
       Query the native MSA information with module base name.\r
 \r
@@ -376,7 +397,7 @@ public class GlobalData {
       @throws BuildException\r
               MSA file is not valid\r
     **/\r
-    public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws BuildException {\r
+    public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws EdkException {\r
         if (nativeMsa.containsKey(moduleId)) {\r
             return nativeMsa.get(moduleId);\r
         }\r
@@ -386,9 +407,9 @@ public class GlobalData {
         return msaMap;\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 EdkException {\r
         if (!msaFile.exists()) {\r
-            throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");\r
+            throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");\r
         }\r
         try {\r
             ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r
@@ -396,7 +417,7 @@ public class GlobalData {
             // Validate File if they accord with XML Schema\r
             //\r
             if ( !doc.validate()){\r
-                throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r
+                throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r
             }\r
             //\r
             // parse MSA file\r
@@ -414,20 +435,24 @@ public class GlobalData {
             msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r
             msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r
             return msaMap;\r
-        }\r
-        catch (Exception ex){\r
-            throw new BuildException(ex.getMessage());\r
+        } catch(IOException ex) {\r
+            EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());\r
+            edkException.setStackTrace(ex.getStackTrace());\r
+            throw edkException;\r
+        } catch(XmlException ex) {\r
+            EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());\r
+            edkException.setStackTrace(ex.getStackTrace());\r
+            throw edkException;\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
+    public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException {\r
         GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r
+        fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions);\r
     }\r
 \r
     public static XmlObject getFpdDynamicPcds() {\r
@@ -452,8 +477,7 @@ public class GlobalData {
      * The header file path is relative to workspace dir\r
      */\r
     public static String[] getLibraryClassHeaderFiles(\r
-            PackageIdentification[] packages, String name)\r
-            throws BuildException {\r
+            PackageIdentification[] packages, String name) throws EdkException{\r
         if (packages == null) {\r
             // throw Exception or not????\r
             return new String[0];\r
@@ -471,7 +495,7 @@ public class GlobalData {
         //\r
         // If can't find library class declaration in every package\r
         //\r
-        throw new BuildException("Can not find library class [" + name\r
+        throw new EdkException("Can not find library class [" + name\r
                 + "] declaration in any SPD package!");\r
     }\r
 \r
@@ -479,7 +503,7 @@ public class GlobalData {
      * The header file path is relative to workspace dir\r
      */\r
     public static String getPackageHeaderFiles(PackageIdentification packages,\r
-            String moduleType) throws BuildException {\r
+            String moduleType) {\r
         if (packages == null) {\r
             return new String("");\r
         }\r
@@ -503,8 +527,7 @@ public class GlobalData {
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
-    public static String[] getGuid(List<PackageIdentification> packages, String name)\r
-            throws BuildException {\r
+    public static String[] getGuid(List<PackageIdentification> packages, String name) {\r
         if (packages == null) {\r
             // throw Exception or not????\r
             return new String[0];\r
@@ -528,7 +551,7 @@ public class GlobalData {
      * return two values: {cName, GuidValue}\r
      */\r
     public static String[] getPpiGuid(List<PackageIdentification> packages,\r
-            String name) throws BuildException {\r
+            String name) {\r
         if (packages == null) {\r
             return new String[0];\r
         }\r
@@ -544,14 +567,13 @@ public class GlobalData {
             }\r
         }\r
         return null;\r
-\r
     }\r
 \r
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
     public static String[] getProtocolGuid(List<PackageIdentification> packages,\r
-            String name) throws BuildException {\r
+            String name) {\r
         if (packages == null) {\r
             return new String[0];\r
         }\r
@@ -570,7 +592,7 @@ public class GlobalData {
 \r
     }\r
 \r
-    public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {\r
+    public synchronized static PlatformIdentification getPlatformByName(String name) throws EdkException {\r
         Iterator iter = platformList.iterator();\r
         while(iter.hasNext()){\r
             PlatformIdentification platformId = (PlatformIdentification)iter.next();\r
@@ -578,10 +600,10 @@ public class GlobalData {
                 return platformId;\r
             }\r
         }\r
-        throw new BuildException("Can't find platform [" + name + "] in the current WORKSPACE database!");\r
+        throw new EdkException("Can't find platform [" + name + "] in the current WORKSPACE database!");\r
     }\r
 \r
-    public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {\r
+    public synchronized static PlatformIdentification getPlatform(String filename) throws EdkException {\r
         File file = new File(workspaceDir + File.separatorChar + filename);\r
         Iterator iter = platformList.iterator();\r
         while(iter.hasNext()){\r
@@ -590,10 +612,10 @@ public class GlobalData {
                 return platformId;\r
             }\r
         }\r
-        throw new BuildException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");\r
+        throw new EdkException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");\r
     }\r
 \r
-    public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r
+    public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws EdkException {\r
         Iterator iter = packageList.iterator();\r
         while(iter.hasNext()){\r
             PackageIdentification packageItem = (PackageIdentification)iter.next();\r
@@ -603,15 +625,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 EdkException("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
+    public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws EdkException {\r
         PackageIdentification packageId = getPackageForModule(moduleId);\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 EdkException("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
@@ -624,7 +646,7 @@ 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 EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");\r
     }\r
 \r
     public synchronized static Set<PackageIdentification> getPackageList(){\r
@@ -640,7 +662,7 @@ public class GlobalData {
       @return XmlObject after clone\r
       @throws BuildException parse original XmlObject error. \r
     **/\r
-    private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r
+    private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws EdkException {\r
         if ( object == null) {\r
             return null;\r
         }\r
@@ -648,16 +670,18 @@ public class GlobalData {
         try {\r
             result = XmlObject.Factory.parse(object.getDomNode()\r
                             .cloneNode(deep));\r
-        } catch (Exception ex) {\r
-            throw new BuildException(ex.getMessage());\r
+        } catch (XmlException ex) {\r
+            EdkException edkException = new EdkException(ex.getMessage());\r
+            edkException.setStackTrace(ex.getStackTrace());\r
+            throw edkException;\r
         }\r
         return result;\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
+    ///\r
+    /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r
+    ///\r
+    public synchronized static ToolChainInfo getToolChainInfo() {\r
         if (toolChainInfo == null) {\r
             toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r
             if (toolChainPlatformInfo != null) {\r
@@ -665,13 +689,12 @@ public class GlobalData {
             }\r
             toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r
             toolChainInfo.normalize();\r
-            GlobalData.log.info(toolChainInfo + "");\r
+            EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Current build tool chain information summary: ");\r
+            EdkLog.log("Init", EdkLog.EDK_ALWAYS, toolChainInfo + "");\r
         }\r
         return toolChainInfo;\r
     }\r
 \r
-\r
-\r
     public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r
         platformToolChainFamilyOption = map;\r
     }\r
@@ -703,7 +726,7 @@ public class GlobalData {
         return false;\r
     }\r
 \r
-    public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r
+    public synchronized static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r
         ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r
         ToolChainMap toolChainConfig = toolsDef.getConfig();\r
         String setting = null;\r