]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java
Add thread control classes. (2)
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / fpd / FpdParserTask.java
index 80682b2e4661fb25cb281d93ea9661b6158abe76..c044856de3674d6620973090be2004c93c8cfe78 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.tools.ant.taskdefs.Ant;
 import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
+import org.tianocore.common.definitions.EdkDefinitions;\r
 import org.tianocore.common.exception.EdkException;\r
 import org.tianocore.pcd.action.ActionMessage;\r
 import org.tianocore.build.global.GlobalData;\r
@@ -54,8 +55,7 @@ import org.tianocore.build.toolchain.ToolChainMap;
   and BUILD_DIR. </p>\r
 \r
   <p>The task generates ${PLATFORM}_build.xml file which will be called by top level\r
-  build.xml. The task also generate Fv.inf files (File is for Tool GenFvImage)\r
-  and flash definition file (File is for Tool FlashMap) if necessary. </p>\r
+  build.xml. The task also generate Fv.inf files (File is for Tool GenFvImage). </p>\r
 \r
   <p>FpdParserTask task stores all FPD information to GlobalData. And parse\r
   tools definition file to set up compiler options for different Target and\r
@@ -69,9 +69,6 @@ import org.tianocore.build.toolchain.ToolChainMap;
   &lt;FPDParser platformName="Nt32" /&gt;\r
   </pre>\r
 \r
-  <p>The task will initialize all information through parsing Framework Database,\r
-  SPD, Tool chain configuration files. </p>\r
-\r
   @since GenBuild 1.0\r
 **/\r
 public class FpdParserTask extends Task {\r
@@ -80,30 +77,28 @@ public class FpdParserTask extends Task {
 \r
     private File fpdFile = null;\r
 \r
-    private PlatformIdentification platformId;\r
+    PlatformIdentification platformId;\r
 \r
-    ///\r
-    ///\r
-    ///\r
     private String type;\r
 \r
     ///\r
     /// Mapping from modules identification to out put file name\r
     ///\r
-    private Map<FpdModuleIdentification, String> outfiles = new LinkedHashMap<FpdModuleIdentification, String>();\r
+    Map<FpdModuleIdentification, String> outfiles = new LinkedHashMap<FpdModuleIdentification, String>();\r
 \r
     ///\r
     /// Mapping from FV name to its modules\r
     ///\r
-    private Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
+    Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
 \r
     ///\r
     /// FpdParserTask can specify some ANT properties.\r
     ///\r
     private Vector<Property> properties = new Vector<Property>();\r
 \r
-    private boolean isUnified = true;\r
-\r
+    SurfaceAreaQuery saq = null;\r
+    \r
+    boolean isUnified = true;\r
 \r
     /**\r
       Public construct method. It is necessary for ANT task.\r
@@ -127,7 +122,10 @@ public class FpdParserTask extends Task {
      Surface area is not valid.\r
     **/\r
     public void execute() throws BuildException {\r
-        // Remove !!\r
+        //\r
+        // If fpdFile is not specified, \r
+        // then try to get FPD file by platformName\r
+        //\r
         if ( fpdFile == null) {\r
             if (platformName == null) {\r
                 throw new BuildException("FpdParserTask parameter error. Please specify either the platform name or FPD file!");\r
@@ -150,14 +148,14 @@ public class FpdParserTask extends Task {
         // For every Target and ToolChain\r
         //\r
         String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
-        for (int i = 0; i < targetList.length; i++){\r
+        for (int i = 0; i < targetList.length; i++) {\r
             String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
-            for(int j = 0; j < toolchainList.length; j++){\r
+            for(int j = 0; j < toolchainList.length; j++) {\r
                 //\r
                 // Prepare FV_DIR\r
                 //\r
                 String ffsCommonDir = getProject().getProperty("BUILD_DIR") + File.separatorChar\r
-                                + targetList[i] + File.separatorChar\r
+                                + targetList[i] + "_"\r
                                 + toolchainList[j];\r
                 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
                 fvDir.mkdirs();\r
@@ -173,7 +171,7 @@ public class FpdParserTask extends Task {
         //\r
         // Gen build.xml\r
         //\r
-        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, isUnified);\r
+        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq);\r
         fileGenerator.genBuildFile();\r
 \r
         //\r
@@ -187,8 +185,6 @@ public class FpdParserTask extends Task {
         ant.setInheritAll(true);\r
         ant.init();\r
         ant.execute();\r
-\r
-//        GlobalData.log.info("Fpd build end. ");\r
     }\r
 \r
     /**\r
@@ -199,13 +195,13 @@ public class FpdParserTask extends Task {
       @throws BuildException\r
                   File write FV.inf files error.\r
     **/\r
-    private void genFvInfFiles(String ffsCommonDir) throws BuildException {\r
-        String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
+    void genFvInfFiles(String ffsCommonDir) throws BuildException {\r
+        String[] validFv = saq.getFpdValidImageNames();\r
         for (int i = 0; i < validFv.length; i++) {\r
             //\r
             // Get all global variables from FPD and set them to properties\r
             //\r
-            String[][] globalVariables = SurfaceAreaQuery.getFpdGlobalVariable();\r
+            String[][] globalVariables = saq.getFpdGlobalVariable();\r
             for (int j = 0; j < globalVariables.length; j++) {\r
                 getProject().setProperty(globalVariables[j][0], globalVariables[j][1]);\r
             }\r
@@ -222,7 +218,7 @@ public class FpdParserTask extends Task {
                 //\r
                 // Options\r
                 //\r
-                String[][] options = SurfaceAreaQuery.getFpdOptions(validFv[i]);\r
+                String[][] options = saq.getFpdOptions(validFv[i]);\r
                 if (options.length > 0) {\r
                     bw.write("[options]");\r
                     bw.newLine();\r
@@ -243,7 +239,7 @@ public class FpdParserTask extends Task {
                 //\r
                 // Attributes;\r
                 //\r
-                String[][] attributes = SurfaceAreaQuery.getFpdAttributes(validFv[i]);\r
+                String[][] attributes = saq.getFpdAttributes(validFv[i]);\r
                 if (attributes.length > 0) {\r
                     bw.write("[attributes]");\r
                     bw.newLine();\r
@@ -264,7 +260,7 @@ public class FpdParserTask extends Task {
                 //\r
                 // Components\r
                 //\r
-                String[][] components = SurfaceAreaQuery.getFpdComponents(validFv[i]);\r
+                String[][] components = saq.getFpdComponents(validFv[i]);\r
                 if (components.length > 0) {\r
                     bw.write("[components]");\r
                     bw.newLine();\r
@@ -322,7 +318,7 @@ public class FpdParserTask extends Task {
       @throws BuildException\r
                   FPD file is not valid.\r
      **/\r
-    private void parseFpdFile() throws BuildException {\r
+    void parseFpdFile() throws BuildException {\r
         try {\r
             XmlObject doc = XmlObject.Factory.parse(fpdFile);\r
 \r
@@ -332,12 +328,12 @@ public class FpdParserTask extends Task {
 \r
             Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
             map.put("PlatformSurfaceArea", doc);\r
-            SurfaceAreaQuery.setDoc(map);\r
+            saq = new SurfaceAreaQuery(map);\r
 \r
             //\r
             // Initialize\r
             //\r
-            platformId = SurfaceAreaQuery.getFpdHeader();\r
+            platformId = saq.getFpdHeader();\r
             platformId.setFpdFile(fpdFile);\r
             getProject().setProperty("PLATFORM", platformId.getName());\r
             getProject().setProperty("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));\r
@@ -347,17 +343,17 @@ public class FpdParserTask extends Task {
             //\r
             // Build mode. User-defined output dir.\r
             //\r
-            String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();\r
-            String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();\r
+            String buildMode = saq.getFpdIntermediateDirectories();\r
+            String userDefinedOutputDir = saq.getFpdOutputDirectory();\r
 \r
             OutputManager.getInstance().setup(userDefinedOutputDir, buildMode);\r
 \r
             //\r
             // TBD. Deal PCD and BuildOption related Info\r
             //\r
-            GlobalData.setFpdBuildOptions(SurfaceAreaQuery.getFpdBuildOptions());\r
+            GlobalData.setFpdBuildOptions(saq.getFpdBuildOptions());\r
 \r
-            GlobalData.setToolChainPlatformInfo(SurfaceAreaQuery.getFpdToolChainInfo());\r
+            GlobalData.setToolChainPlatformInfo(saq.getFpdToolChainInfo());\r
 \r
             //\r
             // Parse all list modules SA\r
@@ -370,7 +366,7 @@ public class FpdParserTask extends Task {
             parseToolChainFamilyOptions();\r
             parseToolChainOptions();\r
 \r
-            SurfaceAreaQuery.setDoc(map);\r
+            saq.push(map);\r
 \r
             //\r
             // Pcd Collection. Call CollectPCDAction to collect pcd info.\r
@@ -382,13 +378,11 @@ public class FpdParserTask extends Task {
         }\r
     }\r
 \r
-\r
-\r
     /**\r
       Parse all modules listed in FPD file.\r
     **/\r
-    private void parseModuleSAFiles() throws EdkException{\r
-        Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = SurfaceAreaQuery.getFpdModules();\r
+    void parseModuleSAFiles() throws EdkException{\r
+        Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = saq.getFpdModules();\r
 \r
         //\r
         // For every Module lists in FPD file.\r
@@ -401,15 +395,13 @@ public class FpdParserTask extends Task {
             //\r
             // Judge if Module is existed?\r
             // TBD\r
-\r
             GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId));\r
 \r
             //\r
             // Put fpdModuleId to the corresponding FV\r
             //\r
-            SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
-            String fvBinding = SurfaceAreaQuery.getModuleFvBindingKeyword();\r
-            SurfaceAreaQuery.pop();\r
+            saq.push(GlobalData.getDoc(fpdModuleId));\r
+            String fvBinding = saq.getModuleFvBindingKeyword();\r
 \r
             fpdModuleId.setFvBinding(fvBinding);\r
             updateFvs(fvBinding, fpdModuleId);\r
@@ -418,9 +410,9 @@ public class FpdParserTask extends Task {
             // Prepare for out put file name\r
             //\r
             ModuleIdentification moduleId = fpdModuleId.getModule();\r
-            SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
-            String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r
-            SurfaceAreaQuery.pop();\r
+\r
+            String baseName = saq.getModuleOutputFileBasename();\r
+            \r
             if (baseName == null) {\r
                 baseName = moduleId.getName();\r
             }\r
@@ -431,25 +423,24 @@ public class FpdParserTask extends Task {
             //\r
             // parse module build options, if any\r
             //\r
-            SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
             GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));\r
             GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));\r
-            SurfaceAreaQuery.pop();\r
+            saq.pop();\r
         }\r
     }\r
 \r
-    private ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
-        String[][] options = SurfaceAreaQuery.getModuleBuildOptions(toolChainFamilyFlag);\r
+    ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
+        String[][] options = saq.getModuleBuildOptions(toolChainFamilyFlag);\r
         if (options == null || options.length == 0) {\r
-            return null;\r
+            return new ToolChainMap();\r
         }\r
         return parseOptions(options);\r
     }\r
 \r
     private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
-        String[][] options = SurfaceAreaQuery.getPlatformBuildOptions(toolChainFamilyFlag);\r
+        String[][] options = saq.getPlatformBuildOptions(toolChainFamilyFlag);\r
         if (options == null || options.length == 0) {\r
-            return null;\r
+            return new ToolChainMap();\r
         }\r
         return parseOptions(options);\r
     }\r
@@ -484,7 +475,7 @@ public class FpdParserTask extends Task {
       @param fvName current FV name\r
       @param moduleName current module identification\r
     **/\r
-    private void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) {\r
+    void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) {\r
         if (fvName == null || fvName.trim().length() == 0) {\r
             fvName = "NULL";\r
         }\r
@@ -496,8 +487,7 @@ public class FpdParserTask extends Task {
             if (fvs.containsKey(fvNameArray[i])) {\r
                 Set<FpdModuleIdentification> set = fvs.get(fvNameArray[i]);\r
                 set.add(fpdModuleId);\r
-            }\r
-            else {\r
+            } else {\r
                 Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r
                 set.add(fpdModuleId);\r
                 fvs.put(fvNameArray[i], set);\r
@@ -535,13 +525,7 @@ public class FpdParserTask extends Task {
             throw new BuildException("Module type is not specified.");\r
         }\r
 \r
-        String[][] suffix = { { "BASE", ".FFS"},\r
-                              { "SEC", ".SEC" }, { "PEI_CORE", ".PEI" },\r
-                              { "PEIM", ".PEI" }, { "DXE_CORE", ".DXE" },\r
-                              { "DXE_DRIVER", ".DXE" }, { "DXE_RUNTIME_DRIVER", ".DXE" },\r
-                              { "DXE_SAL_DRIVER", ".DXE" }, { "DXE_SMM_DRIVER", ".DXE" },\r
-                              { "TOOL", ".FFS" }, { "UEFI_DRIVER", ".DXE" },\r
-                              { "UEFI_APPLICATION", ".APP" }, { "USER_DEFINED", ".FFS" } };\r
+        String[][] suffix = EdkDefinitions.ModuleTypeExtensions;\r
 \r
         for (int i = 0; i < suffix.length; i++) {\r
             if (suffix[i][0].equalsIgnoreCase(moduleType)) {\r
@@ -573,6 +557,18 @@ public class FpdParserTask extends Task {
     public void setType(String type) {\r
         this.type = type;\r
     }\r
-\r
-\r
+    \r
+    public String getAllArchForModule(ModuleIdentification moduleId) {\r
+        String archs = "";\r
+        Iterator<FpdModuleIdentification> iter = outfiles.keySet().iterator();\r
+        while (iter.hasNext()) {\r
+            FpdModuleIdentification fpdModuleId = iter.next();\r
+            \r
+            if (fpdModuleId.getModule().equals(moduleId)) {\r
+                archs += fpdModuleId.getArch() + " ";\r
+            }\r
+        }\r
+        \r
+        return archs;\r
+    }\r
 }\r