]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java
Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / PCDAutoGenAction.java
index 40d2b32a9bd613b6bafffe7f550cdb838735c7ce..5c7b29aa17e197f84e072ce147fe9639cea76afe 100644 (file)
@@ -3,13 +3,13 @@
 \r
   This class is to manage how to generate the PCD information into Autogen.c and\r
   Autogen.h.\r
\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
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
\r
+\r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
@@ -19,24 +19,19 @@ package org.tianocore.build.pcd.action;
 import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.UUID;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
-import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.pcd.entity.Token;\r
 import org.tianocore.pcd.entity.UsageInstance;\r
 import org.tianocore.pcd.exception.BuildActionException;\r
-import org.tianocore.pcd.exception.EntityException;\r
 import org.tianocore.pcd.entity.UsageIdentification;\r
 import org.tianocore.pcd.action.BuildAction;\r
 import org.tianocore.pcd.action.ActionMessage;\r
+import org.tianocore.build.exception.PcdAutogenException;\r
 \r
 /** This class is to manage how to generate the PCD information into Autogen.c and\r
     Autogen.h.\r
@@ -46,33 +41,35 @@ public class PCDAutoGenAction extends BuildAction {
     /// The reference of DBManager in GlobalData class.\r
     ///\r
     private MemoryDatabaseManager dbManager;\r
+\r
     ///\r
     /// The identification for a UsageInstance.\r
-    /// \r
-    private UsageIdentification   usageId;\r
     ///\r
-    /// The arch of current module\r
-    /// \r
-    private String                arch;\r
+    private UsageIdentification   usageId;\r
+\r
     ///\r
     /// Whether current autogen is for building library used by current module.\r
-    /// \r
+    ///\r
     private boolean               isBuildUsedLibrary;\r
+\r
     ///\r
     /// The generated string for header file.\r
     ///\r
     private String                hAutoGenString;\r
+\r
     ///\r
     /// The generated string for C code file.\r
     ///\r
     private String                cAutoGenString;\r
+\r
     ///\r
     /// The name array of <PcdCoded> in a module.\r
-    /// \r
+    ///\r
     private String[]              pcdNameArrayInMsa;\r
+\r
     /**\r
       Set parameter moduleId\r
-  \r
+\r
       @param moduleName   the module name parameter.\r
     **/\r
     public void setUsageId(UsageIdentification usageId) {\r
@@ -81,7 +78,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
        set isBuildUsedLibrary parameter.\r
-       \r
+\r
        @param isBuildUsedLibrary\r
     **/\r
     public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary) {\r
@@ -90,7 +87,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
        set pcdNameArrayInMsa parameter.\r
-       \r
+\r
        @param pcdNameArrayInMsa\r
      */\r
     public void setPcdNameArrayInMsa(String[] pcdNameArrayInMsa) {\r
@@ -99,7 +96,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
       Get the output of generated string for header file.\r
-  \r
+\r
       @return the string of header file for PCD\r
     **/\r
     public String OutputH() {\r
@@ -108,72 +105,64 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
       Get the output of generated string for C Code file.\r
-  \r
+\r
       @return the string of C code file for PCD\r
     **/\r
     public String OutputC() {\r
         return cAutoGenString;\r
     }\r
 \r
-   \r
+\r
     /**\r
         Construct function\r
 \r
         This function mainly initialize some member variable.\r
-   \r
+\r
         @param moduleId             the identification for module\r
         @param arch                 the architecture for module\r
         @param isBuildUsedLibary    Is the current module library.\r
         @param pcdNameArrayInMsa    the pcd name array got from MSA file.\r
     **/\r
-    public PCDAutoGenAction(ModuleIdentification moduleId, \r
+    public PCDAutoGenAction(ModuleIdentification moduleId,\r
                             String               arch,\r
                             boolean              isBuildUsedLibrary,\r
                             String[]             pcdNameArrayInMsa) {\r
-        UsageIdentification usageId = new UsageIdentification(moduleId.getName(), \r
-                                                              moduleId.getGuid(), \r
-                                                              moduleId.getPackage().getName(), \r
-                                                              moduleId.getPackage().getGuid(), \r
-                                                              arch, \r
-                                                              moduleId.getVersion(), \r
-                                                              moduleId.getModuleType());\r
         dbManager       = null;\r
         hAutoGenString  = "";\r
         cAutoGenString  = "";\r
 \r
-        setUsageId(usageId);\r
+        setUsageId(new UsageIdentification(moduleId.getName(),\r
+                                           moduleId.getGuid(),\r
+                                           moduleId.getPackage().getName(),\r
+                                           moduleId.getPackage().getGuid(),\r
+                                           arch,\r
+                                           moduleId.getVersion(),\r
+                                           moduleId.getModuleType()));\r
         setIsBuildUsedLibrary(isBuildUsedLibrary);\r
         setPcdNameArrayInMsa(pcdNameArrayInMsa);\r
     }\r
 \r
     /**\r
-      check the parameter for action class.\r
-      \r
+      Override function: check the parameter for action class.\r
+\r
       @throws BuildActionException Bad parameter.\r
     **/\r
-    public void checkParameter() throws BuildActionException {\r
-        \r
+    public void checkParameter() {\r
     }\r
 \r
     /**\r
       Core execution function for this action class.\r
-     \r
+\r
       All PCD information of this module comes from memory dabase. The collection\r
       work should be done before this action execution.\r
-      Currently, we should generated all PCD information(maybe all dynamic) as array \r
-      in Pei emulated driver for simulating PCD runtime database. \r
-      \r
+      Currently, we should generated all PCD information(maybe all dynamic) as array\r
+      in Pei emulated driver for simulating PCD runtime database.\r
+\r
       @throws BuildActionException Failed to execute this aciton class.\r
     **/\r
-    public void performAction() throws BuildActionException {\r
-        ActionMessage.debug(this, \r
+    public void performAction() {\r
+        ActionMessage.debug(this,\r
                             "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r
-        //\r
-        // Check the PCD memory database manager is valid.\r
-        //\r
-        if(GlobalData.getPCDMemoryDBManager() == null) {\r
-            throw new BuildActionException("Memory database has not been initlizated!");\r
-        }\r
 \r
         dbManager = GlobalData.getPCDMemoryDBManager();\r
 \r
@@ -182,14 +171,14 @@ public class PCDAutoGenAction extends BuildAction {
         }\r
 \r
         ActionMessage.debug(this,\r
-                            "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens");\r
+                            "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens.");\r
 \r
         generateAutogenForModule();\r
     }\r
 \r
     /**\r
       Generate the autogen string for a common module.\r
-     \r
+\r
       All PCD information of this module comes from memory dabase. The collection\r
       work should be done before this action execution.\r
     **/\r
@@ -206,24 +195,24 @@ public class PCDAutoGenAction extends BuildAction {
 \r
         usageInstanceArray = null;\r
         if (!isBuildUsedLibrary) {\r
-            usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(usageId);\r
-            dbManager.UsageInstanceContext = usageInstanceArray;\r
-            dbManager.CurrentModuleName    = moduleName; \r
+            usageInstanceArray  = dbManager.getUsageInstanceArrayById(usageId);\r
+            MemoryDatabaseManager.UsageInstanceContext = usageInstanceArray;\r
+            MemoryDatabaseManager.CurrentModuleName    = moduleName;\r
         } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r
-            usageContext = dbManager.UsageInstanceContext;\r
+            usageContext = MemoryDatabaseManager.UsageInstanceContext;\r
             //\r
-            // For building library package, although all module are library, but PCD entries of \r
+            // For building library package, although all module are library, but PCD entries of\r
             // these library should be used to autogen.\r
-            // \r
+            //\r
             if (usageContext == null) {\r
-                usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(usageId);\r
+                usageInstanceArray  = dbManager.getUsageInstanceArrayById(usageId);\r
             } else {\r
                 usageInstanceArray = new ArrayList<UsageInstance>();\r
 \r
                 //\r
-                // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's \r
+                // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's\r
                 // <ModuleSA> in FPD file.\r
-                // \r
+                //\r
                 for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r
                     found = false;\r
                     for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r
@@ -238,14 +227,14 @@ public class PCDAutoGenAction extends BuildAction {
                         //\r
                         // All library's PCD should instanted in module's <ModuleSA> who\r
                         // use this library instance. If not, give errors.\r
-                        // \r
-                        throw new BuildActionException (String.format("[PCD Autogen Error] Module %s use library instance %s, the PCD %s " +\r
-                                                                      "is required by this library instance, but can not find " +\r
-                                                                      "it in the %s's <ModuleSA> in FPD file!",\r
-                                                                      dbManager.CurrentModuleName,\r
+                        //\r
+                        throw new BuildActionException (String.format("Module %s using library instance %s; the PCD %s " +\r
+                                                                      "is required by this library instance, but can not be found " +\r
+                                                                      "in the %s's <ModuleSA> in the FPD file!",\r
+                                                                      MemoryDatabaseManager.CurrentModuleName,\r
                                                                       moduleName,\r
                                                                       pcdNameArrayInMsa[index],\r
-                                                                      dbManager.CurrentModuleName\r
+                                                                      MemoryDatabaseManager.CurrentModuleName\r
                                                                       ));\r
                     }\r
                 }\r
@@ -258,18 +247,18 @@ public class PCDAutoGenAction extends BuildAction {
 \r
         //\r
         // Generate all PCD entry for a module.\r
-        // \r
+        //\r
         for(index = 0; index < usageInstanceArray.size(); index ++) {\r
             usageInstance = usageInstanceArray.get(index);\r
             //\r
             // Before generate any PCD information into autogen.h/autogen.c for a module,\r
             // generate TokenSpaceGuid array variable firstly. For every dynamicEx type\r
-            // PCD in this module the token, they are all reference to TokenSpaceGuid \r
+            // PCD in this module the token, they are all reference to TokenSpaceGuid\r
             // array.\r
-            // \r
+            //\r
             if (usageInstanceArray.get(index).modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
                 guidStringArray = usageInstance.parentToken.tokenSpaceName.split("-");\r
-                guidStringCName = "_gPcd_TokenSpaceGuid_" + \r
+                guidStringCName = "_gPcd_TokenSpaceGuid_" +\r
                                   usageInstance.parentToken.tokenSpaceName.replaceAll("-", "_");\r
                 guidString      = String.format("{ 0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",\r
                                                 guidStringArray[0],\r
@@ -283,22 +272,21 @@ public class PCDAutoGenAction extends BuildAction {
                                                 (guidStringArray[4].substring(6, 8)),\r
                                                 (guidStringArray[4].substring(8, 10)),\r
                                                 (guidStringArray[4].substring(10, 12)));\r
-                \r
+\r
                 Pattern pattern = Pattern.compile("(" + guidStringCName + ")+?");\r
                 Matcher matcher = pattern.matcher(cAutoGenString + " ");\r
                 //\r
                 // Find whether this guid array variable has been generated into autogen.c\r
                 // For different DyanmicEx pcd token who use same token space guid, the token space\r
                 // guid array should be only generated once.\r
-                // \r
+                //\r
                 if (!matcher.find()) {\r
-                    hAutoGenString += String.format("extern EFI_GUID %s;\r\n",\r
-                                                    guidStringCName);\r
+                    hAutoGenString += String.format("extern EFI_GUID %s;\r\n", guidStringCName);\r
                     if (!isBuildUsedLibrary) {\r
                         cAutoGenString += String.format("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID %s = %s;\r\n",\r
                                                         guidStringCName,\r
                                                         guidString);\r
-                    } \r
+                    }\r
                 }\r
             }\r
 \r
@@ -306,21 +294,21 @@ public class PCDAutoGenAction extends BuildAction {
             //\r
             // For every PCD entry for this module(usage instance), autogen string would\r
             // be appand.\r
-            // \r
+            //\r
             hAutoGenString += usageInstance.getHAutogenStr() + "\r\n";\r
             cAutoGenString += usageInstance.getCAutogenStr();\r
         }\r
 \r
         //\r
-        // Work around code, In furture following code should be modified that get \r
+        // Work around code, In furture following code should be modified that get\r
         // these information from Uplevel Autogen tools.\r
-        // \r
+        //\r
         if (moduleName.equalsIgnoreCase("PcdPeim")) {\r
-            hAutoGenString += dbManager.PcdPeimHString;\r
-            cAutoGenString += dbManager.PcdPeimCString;\r
+            hAutoGenString += MemoryDatabaseManager.PcdPeimHString;\r
+            cAutoGenString += MemoryDatabaseManager.PcdPeimCString;\r
         } else if (moduleName.equalsIgnoreCase("PcdDxe")) {\r
-            hAutoGenString += dbManager.PcdDxeHString;\r
-            cAutoGenString += dbManager.PcdDxeCString;\r
+            hAutoGenString += MemoryDatabaseManager.PcdDxeHString;\r
+            cAutoGenString += MemoryDatabaseManager.PcdDxeCString;\r
         }\r
     }\r
 \r
@@ -333,20 +321,17 @@ public class PCDAutoGenAction extends BuildAction {
 \r
         String WorkSpace = "X:/edk2";\r
         String logFilePath = WorkSpace  + "/EdkNt32Pkg/Nt32.fpd";\r
-        String[] nameArray = null;\r
 \r
         //\r
         // At first, CollectPCDAction should be invoked to collect\r
         // all PCD information from SPD, MSA, FPD.\r
         //\r
-        CollectPCDAction collectionAction = new CollectPCDAction();\r
+        PlatformPcdPreprocessActionForBuilding collectionAction = new PlatformPcdPreprocessActionForBuilding();\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
                             WorkSpace,null);\r
 \r
         try {\r
-            collectionAction.perform(WorkSpace, \r
-                                     logFilePath,\r
-                                     ActionMessage.MAX_MESSAGE_LEVEL);\r
+            collectionAction.perform(logFilePath, ActionMessage.MAX_MESSAGE_LEVEL);\r
         } catch(Exception e) {\r
             e.printStackTrace();\r
         }\r