]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / PCDAutoGenAction.java
index 5a429e41175c00507b7fc6c6c7bbca223afafdf1..a2f1c6a1bf83bb2f5c8a26709f7f13e18c9a38b6 100644 (file)
@@ -16,24 +16,26 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.build.pcd.action;\r
 \r
-import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
+import org.tianocore.build.FrameworkBuildTask;\r
+import org.tianocore.build.autogen.CommonDefinition;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.common.logger.EdkLog;\r
+import org.tianocore.pcd.action.BuildAction;\r
 import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.pcd.entity.Token;\r
+import org.tianocore.pcd.entity.UsageIdentification;\r
 import org.tianocore.pcd.entity.UsageInstance;\r
 import org.tianocore.pcd.exception.BuildActionException;\r
-import org.tianocore.pcd.entity.UsageIdentification;\r
-import org.tianocore.pcd.action.BuildAction;\r
-import org.tianocore.pcd.action.ActionMessage;\r
 \r
-/** This class is to manage how to generate the PCD information into Autogen.c and\r
-    Autogen.h.\r
+/**\r
+    This class is to manage how to generate the PCD information into Autogen.c\r
+    and Autogen.h.\r
 **/\r
 public class PCDAutoGenAction extends BuildAction {\r
     ///\r
@@ -51,6 +53,11 @@ public class PCDAutoGenAction extends BuildAction {
     ///\r
     private boolean               isBuildUsedLibrary;\r
 \r
+    ///\r
+    /// One of PEI_PCD_DRIVER, DXE_PCD_DRIVER, NOT_PCD_DRIVER \r
+    /// \r
+    private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType;\r
+\r
     ///\r
     /// The generated string for header file.\r
     ///\r
@@ -66,6 +73,7 @@ public class PCDAutoGenAction extends BuildAction {
     ///\r
     private String[]              pcdNameArrayInMsa;\r
 \r
+    private UsageIdentification parentId = null;\r
     /**\r
       Set parameter moduleId\r
 \r
@@ -75,6 +83,14 @@ public class PCDAutoGenAction extends BuildAction {
         this.usageId = usageId;\r
     }\r
 \r
+    /**\r
+       Set paramter pcdDriverType\r
+       \r
+       @param pcdDriverType the driver type for PCD\r
+    **/\r
+    public void setPcdDriverType(CommonDefinition.PCD_DRIVER_TYPE pcdDriverType) {\r
+        this.pcdDriverType = pcdDriverType;\r
+    }\r
     /**\r
        set isBuildUsedLibrary parameter.\r
 \r
@@ -98,7 +114,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
       @return the string of header file for PCD\r
     **/\r
-    public String OutputH() {\r
+    public String getHAutoGenString() {\r
         return hAutoGenString;\r
     }\r
 \r
@@ -107,7 +123,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
       @return the string of C code file for PCD\r
     **/\r
-    public String OutputC() {\r
+    public String getCAutoGenString() {\r
         return cAutoGenString;\r
     }\r
 \r
@@ -121,11 +137,15 @@ public class PCDAutoGenAction extends BuildAction {
         @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
+        @param pcdDriverType        one of PEI_PCD_DRIVER, DXE_PCD_DRIVER,\r
+                                    NOT_PCD_DRIVER\r
     **/\r
     public PCDAutoGenAction(ModuleIdentification moduleId,\r
                             String               arch,\r
                             boolean              isBuildUsedLibrary,\r
-                            String[]             pcdNameArrayInMsa) {\r
+                            String[]             pcdNameArrayInMsa,\r
+                            CommonDefinition.PCD_DRIVER_TYPE pcdDriverType,\r
+                            ModuleIdentification parentId) {\r
         dbManager       = null;\r
         hAutoGenString  = "";\r
         cAutoGenString  = "";\r
@@ -137,12 +157,22 @@ public class PCDAutoGenAction extends BuildAction {
                                            arch,\r
                                            moduleId.getVersion(),\r
                                            moduleId.getModuleType()));\r
+        if (parentId != null) {\r
+            this.parentId = new UsageIdentification(parentId.getName(),\r
+                        parentId.getGuid(),\r
+                        parentId.getPackage().getName(),\r
+                        parentId.getPackage().getGuid(),\r
+                        arch,\r
+                        parentId.getVersion(),\r
+                        parentId.getModuleType());\r
+        }\r
         setIsBuildUsedLibrary(isBuildUsedLibrary);\r
         setPcdNameArrayInMsa(pcdNameArrayInMsa);\r
+        setPcdDriverType(pcdDriverType);\r
     }\r
 \r
     /**\r
-      check the parameter for action class.\r
+      Override function: check the parameter for action class.\r
 \r
       @throws BuildActionException Bad parameter.\r
     **/\r
@@ -160,14 +190,7 @@ public class PCDAutoGenAction extends BuildAction {
       @throws BuildActionException Failed to execute this aciton class.\r
     **/\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
+        EdkLog.log(EdkLog.EDK_DEBUG, "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r
 \r
         dbManager = GlobalData.getPCDMemoryDBManager();\r
 \r
@@ -175,8 +198,7 @@ public class PCDAutoGenAction extends BuildAction {
             return;\r
         }\r
 \r
-        ActionMessage.debug(this,\r
-                            "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens");\r
+        EdkLog.log(EdkLog.EDK_DEBUG, "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens.");\r
 \r
         generateAutogenForModule();\r
     }\r
@@ -199,53 +221,100 @@ public class PCDAutoGenAction extends BuildAction {
         boolean               found           = false;\r
 \r
         usageInstanceArray = null;\r
-        if (!isBuildUsedLibrary) {\r
-            usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(usageId);\r
-            MemoryDatabaseManager.UsageInstanceContext = usageInstanceArray;\r
-            MemoryDatabaseManager.CurrentModuleName    = moduleName;\r
-        } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r
-            usageContext = MemoryDatabaseManager.UsageInstanceContext;\r
-            //\r
-            // For building library package, although all module are library, but PCD entries of\r
-            // these library should be used to autogen.\r
-            //\r
-            if (usageContext == null) {\r
-                usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(usageId);\r
-            } else {\r
-                usageInstanceArray = new ArrayList<UsageInstance>();\r
-\r
+        \r
+        if (FrameworkBuildTask.multithread) {\r
+            if (parentId == null) {\r
+                usageInstanceArray  = dbManager.getUsageInstanceArrayById(usageId);\r
+            } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r
+                usageContext = dbManager.getUsageInstanceArrayById(parentId);\r
                 //\r
-                // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's\r
-                // <ModuleSA> in FPD file.\r
+                // For building library package, although all module are library, but PCD entries of\r
+                // these library should be used to autogen.\r
                 //\r
-                for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r
-                    found = false;\r
-                    for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r
-                        if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {\r
-                            usageInstanceArray.add(usageContext.get(index2));\r
-                            found = true;\r
-                            break;\r
+                if (usageContext == null) {\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
+                    // <ModuleSA> in FPD file.\r
+                    //\r
+                    for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r
+                        found = false;\r
+                        for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r
+                            if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {\r
+                                usageInstanceArray.add(usageContext.get(index2));\r
+                                found = true;\r
+                                break;\r
+                            }\r
                         }\r
-                    }\r
 \r
-                    if (!found) {\r
-                        //\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
-                                                                      MemoryDatabaseManager.CurrentModuleName,\r
-                                                                      moduleName,\r
-                                                                      pcdNameArrayInMsa[index],\r
-                                                                      MemoryDatabaseManager.CurrentModuleName\r
-                                                                      ));\r
+                        if (!found) {\r
+                            //\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("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
+                                                                          MemoryDatabaseManager.CurrentModuleName\r
+                                                                          ));\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        } else {\r
+            if (!isBuildUsedLibrary) {\r
+                usageInstanceArray  = dbManager.getUsageInstanceArrayById(usageId);\r
+                MemoryDatabaseManager.UsageInstanceContext = usageInstanceArray;\r
+                MemoryDatabaseManager.CurrentModuleName    = moduleName;\r
+            } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r
+                usageContext = MemoryDatabaseManager.UsageInstanceContext;\r
+                //\r
+                // For building library package, although all module are library, but PCD entries of\r
+                // these library should be used to autogen.\r
+                //\r
+                if (usageContext == null) {\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
+                    // <ModuleSA> in FPD file.\r
+                    //\r
+                    for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r
+                        found = false;\r
+                        for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r
+                            if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {\r
+                                usageInstanceArray.add(usageContext.get(index2));\r
+                                found = true;\r
+                                break;\r
+                            }\r
+                        }\r
+    \r
+                        if (!found) {\r
+                            //\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("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
+                                                                          MemoryDatabaseManager.CurrentModuleName\r
+                                                                          ));\r
+                        }\r
                     }\r
                 }\r
             }\r
         }\r
-\r
         if (usageInstanceArray == null) {\r
             return;\r
         }\r
@@ -304,43 +373,12 @@ public class PCDAutoGenAction extends BuildAction {
             cAutoGenString += usageInstance.getCAutogenStr();\r
         }\r
 \r
-        //\r
-        // Work around code, In furture following code should be modified that get\r
-        // these information from Uplevel Autogen tools.\r
-        //\r
-        if (moduleName.equalsIgnoreCase("PcdPeim")) {\r
+        if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER) {\r
             hAutoGenString += MemoryDatabaseManager.PcdPeimHString;\r
             cAutoGenString += MemoryDatabaseManager.PcdPeimCString;\r
-        } else if (moduleName.equalsIgnoreCase("PcdDxe")) {\r
+        } else if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER) {\r
             hAutoGenString += MemoryDatabaseManager.PcdDxeHString;\r
             cAutoGenString += MemoryDatabaseManager.PcdDxeCString;\r
         }\r
     }\r
-\r
-    /**\r
-      Test case function\r
-\r
-      @param argv  paramter from command line\r
-    **/\r
-    public static void main(String argv[]) {\r
-\r
-        String WorkSpace = "X:/edk2";\r
-        String logFilePath = WorkSpace  + "/EdkNt32Pkg/Nt32.fpd";\r
-\r
-        //\r
-        // At first, CollectPCDAction should be invoked to collect\r
-        // all PCD information from SPD, MSA, FPD.\r
-        //\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
-        } catch(Exception e) {\r
-            e.printStackTrace();\r
-        }\r
-    }\r
 }\r