]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / GlobalData.java
index 99cccc364cc3211317f79f2894155cffa89a2d40..1e7568757af2ef77e978d26a8e0c2a0193134334 100644 (file)
@@ -16,34 +16,34 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\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
+import java.util.logging.Logger;\r
+\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.DbPathAndFilename;\r
 import org.tianocore.FrameworkDatabaseDocument;\r
 import org.tianocore.ModuleSurfaceAreaDocument;\r
 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
-import org.tianocore.build.exception.EdkException;\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.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.pcd.entity.MemoryDatabaseManager;\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
+import org.tianocore.exception.EdkException;\r
+import org.tianocore.logger.EdkLog;\r
 \r
 /**\r
   GlobalData provide initializing, instoring, querying and update global data.\r
@@ -107,7 +107,7 @@ public class GlobalData {
     ///\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
@@ -130,10 +130,6 @@ 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 final MemoryDatabasseManager 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
@@ -144,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 BuildException {\r
         //\r
         // ensure this method will be revoked only once\r
         //\r
@@ -152,8 +148,8 @@ public class GlobalData {
             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
@@ -165,9 +161,8 @@ public class GlobalData {
         // If ToolChain has been set up before, do nothing.\r
         // CONF dir + tools definition file name\r
         //\r
-        String confDir = GlobalData.workspaceDir + File.separatorChar + "Tools" + File.separatorChar + "Conf";\r
-        File toolsDefFile = new File(confDir + File.separatorChar + toolsDefFilename);\r
-        System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. ");\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
         \r
         //\r
@@ -180,7 +175,7 @@ public class GlobalData {
             // validate FrameworkDatabaseFile\r
             //\r
             if (! db.validate()) {\r
-                throw new BuildException("Framework Database file [" + dbFile.getPath() + "] is invalid.");\r
+                throw new BuildException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r
             }\r
             //\r
             // Get package list\r
@@ -213,7 +208,7 @@ public class GlobalData {
                     // 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
+                        throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r
                     }\r
                     //\r
                     // We can change Map to XmlObject\r
@@ -230,8 +225,7 @@ public class GlobalData {
                 }\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
@@ -263,7 +257,7 @@ public class GlobalData {
             }\r
         }\r
         if (msaFile == null){\r
-            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");\r
+            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
         }\r
         else {\r
             return msaFile;\r
@@ -289,7 +283,7 @@ public class GlobalData {
             }\r
         }\r
         if (packageId == null){\r
-            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");\r
+            throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
         }\r
         else {\r
             return packageId;\r
@@ -319,7 +313,11 @@ public class GlobalData {
         }\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
       Query overrided module surface area information. If current is Package\r
       or Platform build, also include the information from FPD file. \r
@@ -341,7 +339,7 @@ public class GlobalData {
         //\r
         // First part: get the MSA files info\r
         //\r
-        doc = getNativeMsa(moduleId);\r
+        doc.putAll(getNativeMsa(moduleId));\r
         \r
         //\r
         // Second part: put build options\r
@@ -389,7 +387,7 @@ public class GlobalData {
     \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
+            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
@@ -397,7 +395,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() + "] is invalid.");\r
+                throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r
             }\r
             //\r
             // parse MSA file\r
@@ -413,6 +411,7 @@ public class GlobalData {
             msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r
             msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r
             msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r
+            msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r
             return msaMap;\r
         }\r
         catch (Exception ex){\r
@@ -476,7 +475,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
-                + "] declaration in every packages. ");\r
+                + "] declaration in any SPD package!");\r
     }\r
 \r
     /**\r
@@ -507,15 +506,16 @@ public class GlobalData {
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
-    public static String[] getGuid(PackageIdentification[] packages, String name)\r
+    public static String[] getGuid(List<PackageIdentification> packages, String name)\r
             throws BuildException {\r
         if (packages == null) {\r
             // throw Exception or not????\r
             return new String[0];\r
         }\r
         String[] result = null;\r
-        for (int i = 0; i < packages.length; i++) {\r
-            Spd spd = spdTable.get(packages[i]);\r
+        Iterator item = packages.iterator();\r
+        while (item.hasNext()){\r
+            Spd spd = spdTable.get(item.next());\r
             //\r
             // If find one package defined the GUID\r
             //\r
@@ -523,20 +523,22 @@ public class GlobalData {
                 return result;\r
             }\r
         }\r
+\r
         return null;\r
     }\r
 \r
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
-    public static String[] getPpiGuid(PackageIdentification[] packages,\r
+    public static String[] getPpiGuid(List<PackageIdentification> packages,\r
             String name) throws BuildException {\r
         if (packages == null) {\r
             return new String[0];\r
         }\r
         String[] result = null;\r
-        for (int i = 0; i < packages.length; i++) {\r
-            Spd spd = spdTable.get(packages[i]);\r
+        Iterator item = packages.iterator();\r
+        while (item.hasNext()){\r
+            Spd spd = spdTable.get(item.next());\r
             //\r
             // If find one package defined the Ppi GUID\r
             //\r
@@ -551,18 +553,19 @@ public class GlobalData {
     /**\r
      * return two values: {cName, GuidValue}\r
      */\r
-    public static String[] getProtocolGuid(PackageIdentification[] packages,\r
+    public static String[] getProtocolGuid(List<PackageIdentification> packages,\r
             String name) throws BuildException {\r
         if (packages == null) {\r
             return new String[0];\r
         }\r
         String[] result = null;\r
-        for (int i = 0; i < packages.length; i++) {\r
-            Spd spd = spdTable.get(packages[i]);\r
+        Iterator item = packages.iterator();\r
+        while (item.hasNext()){\r
+            Spd spd = spdTable.get(item.next());\r
             //\r
             // If find one package defined the protocol GUID\r
             //\r
-            if ((result = spd.getProtocol(name)) != null) {\r
+            if ((result = spd.getProtocol(name))!= null){\r
                 return result;\r
             }\r
         }\r
@@ -570,21 +573,27 @@ public class GlobalData {
 \r
     }\r
     \r
-    /////////////////////////// Update!! Update!! Update!!\r
-//    public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
-//        return pcdDbManager;\r
-//    }\r
-    ///////////////////////////\r
-    public synchronized static PlatformIdentification getPlatform(String name) throws BuildException {\r
+    public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {\r
         Iterator iter = platformList.iterator();\r
         while(iter.hasNext()){\r
             PlatformIdentification platformId = (PlatformIdentification)iter.next();\r
             if (platformId.getName().equalsIgnoreCase(name)) {\r
-//                GlobalData.log.info("Platform: " + platformId + platformId.getFpdFile());\r
                 return platformId;\r
             }\r
         }\r
-        throw new BuildException("Can't find platform [" + name + "] in current workspace. ");\r
+        throw new BuildException("Can't find platform [" + name + "] in the current WORKSPACE database!");\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
+        while(iter.hasNext()){\r
+            PlatformIdentification platformId = (PlatformIdentification)iter.next();\r
+            if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {\r
+                return platformId;\r
+            }\r
+        }\r
+        throw new BuildException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");\r
     }\r
     \r
     public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r
@@ -597,7 +606,7 @@ public class GlobalData {
                 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.getGuid() + " in the current workspace!");\r
     }\r
     \r
     public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {\r
@@ -608,7 +617,7 @@ public class GlobalData {
         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.getGuid() + " in the current workspace!");\r
         }\r
         Set<ModuleIdentification> modules = spd.getModules();\r
         Iterator<ModuleIdentification> iter = modules.iterator();\r
@@ -621,7 +630,7 @@ public class GlobalData {
                 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.getGuid() + " in package, " + packageId + ", in the current workspace!");\r
     }\r
     \r
     public synchronized static Set<PackageIdentification> getPackageList(){\r
@@ -678,6 +687,19 @@ public class GlobalData {
         moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r
     }\r
 \r
+    public static boolean isCommandSet(String target, String toolchain, String arch) {\r
+        String[] commands = getToolChainInfo().getCommands();\r
+\r
+        for (int i = 0; i < commands.length; ++i) {\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
+\r
+        return false;\r
+    }\r
+\r
     public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r
         ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r
         ToolChainMap toolChainConfig = toolsDef.getConfig(); \r
@@ -750,52 +772,67 @@ public class GlobalData {
     //\r
     // for PCD\r
     //\r
-//    public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
-//        return pcdDbManager;\r
-//    }\r
+    public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
+        return pcdDbManager;\r
+    }\r
 \r
     //\r
-    // For PCD\r
+    // For PCD get tokenSpaceGUid\r
     //\r
-    /**\r
-     * \r
-     * @param guidName\r
-     * @return\r
-     */\r
-//    public synchronized static String[] getGuidInfoGuid(String guidName) {\r
-//        String[] cNameGuid = null;\r
-//        Set set = spdTable.keySet();\r
-//        Iterator iter = set.iterator();\r
-//\r
-//        while (iter.hasNext()) {\r
-//            Spd spd = (Spd) spdTable.get(iter.next());\r
-//            cNameGuid = spd.getGuidNameArray(guidName);\r
-//            if (cNameGuid != null) {\r
-//                break;\r
-//            }\r
-//        }\r
-//        return cNameGuid;\r
-//    }\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
+\r
+        if (iter == null) {\r
+            return null;\r
+        }\r
+\r
+        while (iter.hasNext()){\r
+            Spd spd = (Spd) spdTable.get(iter.next());\r
+            guid = spd.getGuidFromCname(cName);\r
+            if (guid != null){\r
+                cNameGuid = guid;\r
+                break;\r
+            }\r
+        }\r
+        return cNameGuid;\r
+    }\r
 \r
     //\r
     // For PCD\r
     //\r
-//    public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(\r
-//            String xmlObjectName) {\r
-//        Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r
-//        Iterator item = fpdModuleSASet.iterator();\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
-//            moduleId = (FpdModuleIdentification) item.next();\r
-//            SANode = fpdModuleSA.get(item.next());\r
-//            SAPcdBuildDef.put(moduleId,\r
-//                    (PcdBuildDefinitionDocument.PcdBuildDefinition) SANode\r
-//                            .get(xmlObjectName));\r
-//        }\r
-//        return SAPcdBuildDef;\r
-//    }\r
+    public synchronized static Map<FpdModuleIdentification, XmlObject> \r
+                               getFpdModuleSaXmlObject(String xmlObjectName) {\r
+        Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r
+        Iterator item = fpdModuleSASet.iterator();\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
+            moduleId = (FpdModuleIdentification) item.next();\r
+            SANode = fpdModuleSA.get(moduleId);\r
+            try{\r
+                if (SANode.get(xmlObjectName)!= null){\r
+                    SAPcdBuildDef.put(moduleId,\r
+                            (XmlObject) SANode.get(xmlObjectName));\r
+\r
+                }\r
+            } catch (Exception e){\r
+                EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r
+            }\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