Supporting Apriori File from build tool.
authorwuyizhong <wuyizhong@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 14 Nov 2006 07:15:01 +0000 (07:15 +0000)
committerwuyizhong <wuyizhong@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 14 Nov 2006 07:15:01 +0000 (07:15 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1949 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Conf/BuildMacro.xml
Tools/Java/Source/GenBuild/org/tianocore/build/fpd/FpdParserForThread.java
Tools/Java/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java
Tools/Java/Source/GenBuild/org/tianocore/build/fpd/PlatformBuildFileGenerator.java
Tools/Java/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java

index 262c6ac..679a577 100644 (file)
@@ -1392,4 +1392,27 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
         tofile="${DEST_DIR_OUTPUT}/${BASE_NAME}.efi"/>\r
     </sequential>\r
   </macrodef>\r
+  \r
+  <!-- \r
+    Build macro for Apriori\r
+  -->\r
+  <macrodef name="Build_Apriori">\r
+    <attribute name="FILEPATH" default="."/>\r
+    <attribute name="FILENAME"/>\r
+    <attribute name="FILEEXT" default="apr"/>\r
+    <attribute name="GUID"/>\r
+\r
+    <sequential>\r
+      <mkdir dir="${FV_DIR}/Apriori" />\r
+      <gensection inputfile="${FV_DIR}/@{FILEPATH}/@{FILENAME}.@{FILEEXT}" \r
+                  outputfile="${FV_DIR}/Apriori/@{FILENAME}.sec" \r
+                  sectiontype="EFI_SECTION_RAW"/>\r
+\r
+      <genffsfile BaseName="@{FILENAME}" ffsATTRIBCHECKSUM="TRUE" ffsFILETYPE="EFI_FV_FILETYPE_FREEFORM" \r
+                  fileGuid="@{GUID}" moduleType="BASE" outputDir="${FV_DIR}">\r
+        <sectFile fileName="${FV_DIR}/Apriori/@{FILENAME}.sec"/>\r
+      </genffsfile>\r
+      \r
+    </sequential>\r
+  </macrodef>\r
 </project>\r
index 286933f..ac930f1 100644 (file)
@@ -121,7 +121,7 @@ public class FpdParserForThread extends FpdParserTask {
         // Gen build.xml\r
         //\r
         String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";\r
-        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);\r
+        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile, aprioriType);\r
         fileGenerator.genBuildFile();\r
         \r
         //\r
index 9a4d93a..76185f0 100644 (file)
@@ -91,15 +91,24 @@ public class FpdParserTask extends Task {
     ///\r
     Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
 \r
+    ///\r
+    /// Mapping from FV apriori file to its type (PEI or DXE)\r
+    ///\r
+    Map<String, String> aprioriType = new HashMap<String, String>();\r
+    \r
     ///\r
     /// FpdParserTask can specify some ANT properties.\r
     ///\r
     private Vector<Property> properties = new Vector<Property>();\r
 \r
     SurfaceAreaQuery saq = null;\r
-    \r
-    boolean isUnified = true;\r
 \r
+    boolean isUnified = true;\r
+    \r
+    public static String PEI_APRIORI_GUID = "00000000-0000-0000-0000-000000000000";\r
+    \r
+    public static String DXE_APRIORI_GUID = "fc510ee7-ffdc-11d4-bd41-0080c73c8881";\r
+    \r
     /**\r
       Public construct method. It is necessary for ANT task.\r
     **/\r
@@ -163,7 +172,7 @@ public class FpdParserTask extends Task {
         // Gen build.xml\r
         //\r
         String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";\r
-        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);\r
+        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile, aprioriType);\r
         fileGenerator.genBuildFile();\r
 \r
         //\r
@@ -318,6 +327,33 @@ public class FpdParserTask extends Task {
                 if (files != null) {\r
                     bw.write("[files]");\r
                     bw.newLine();\r
+                    \r
+                    Set<FpdModuleIdentification> modules = null;\r
+                    \r
+                    if ( (modules = getPeiApriori(validFv[i])) != null) {\r
+                        //\r
+                        // Special GUID - validFv[i].FFS\r
+                        //\r
+                        String str = ffsCommonDir + File.separatorChar + "FV" + File.separatorChar + PEI_APRIORI_GUID + "-" + validFv[i] + ".FFS";\r
+                        bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));\r
+                        bw.newLine();\r
+                        \r
+                        File aprioriFile = new File(getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".apr");\r
+                        aprioriType.put(validFv[i], PEI_APRIORI_GUID);\r
+                        genAprioriFile(modules, aprioriFile);\r
+                    } else if((modules = getDxeApriori(validFv[i])) != null) {\r
+                        //\r
+                        // Special GUID - validFv[i].FFS\r
+                        //\r
+                        String str = ffsCommonDir + File.separatorChar + "FV" + File.separatorChar + DXE_APRIORI_GUID + "-" + validFv[i] + ".FFS";\r
+                        bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));\r
+                        bw.newLine();\r
+                        \r
+                        File aprioriFile = new File(getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".apr");\r
+                        aprioriType.put(validFv[i], DXE_APRIORI_GUID);\r
+                        genAprioriFile(modules, aprioriFile);\r
+                    }\r
+                    \r
                     for (int j = 0; j < files.length; j++) {\r
                         String str = ffsCommonDir + File.separatorChar + outfiles.get(files[j]);\r
                         bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));\r
@@ -375,7 +411,7 @@ public class FpdParserTask extends Task {
         }\r
 \r
         String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";\r
-        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);\r
+        PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile, aprioriType);\r
         fileGenerator.genBuildFile();\r
         \r
         Ant ant = new Ant();\r
@@ -688,6 +724,97 @@ public class FpdParserTask extends Task {
         return archs;\r
     }\r
     \r
+    private void genAprioriFile(Set<FpdModuleIdentification> modules, File file) {\r
+        try {\r
+            FileWriter fw = new FileWriter(file);\r
+            BufferedWriter bw = new BufferedWriter(fw);\r
+            \r
+            Iterator<FpdModuleIdentification> iter = modules.iterator();\r
+            while(iter.hasNext()) {\r
+                bw.write(iter.next().getModule().getGuid());\r
+                bw.newLine();\r
+            }\r
+            \r
+            bw.flush();\r
+            bw.close();\r
+            fw.close();\r
+        }  catch (IOException ex) {\r
+            BuildException buildException = new BuildException("Generation of the Apriori file [" + file.getPath() + "] failed!\n" + ex.getMessage());\r
+            buildException.setStackTrace(ex.getStackTrace());\r
+            throw buildException;\r
+        }\r
+    }\r
+    \r
+    private Set<FpdModuleIdentification> getPeiApriori(String fvName) throws EdkException {\r
+        Node node = saq.getPeiApriori(fvName);\r
+        Set<FpdModuleIdentification> result = new LinkedHashSet<FpdModuleIdentification>();\r
+        if (node == null) {\r
+            return null;\r
+        }\r
+        \r
+        NodeList childNodes = node.getChildNodes();\r
+        for (int i = 0; i < childNodes.getLength(); i++) {\r
+            Node childItem = childNodes.item(i);\r
+            if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
+                //\r
+                // Find child elements "IncludeModules"\r
+                //\r
+                if (childItem.getNodeName().compareTo("IncludeModules") == 0) {\r
+                    //\r
+                    // result will be updated\r
+                    //\r
+                    processNodes(childItem, result);\r
+                } else if (childItem.getNodeName().compareTo("FvName") == 0) {\r
+                    \r
+                } else if (childItem.getNodeName().compareTo("InfFileName") == 0) {\r
+                    \r
+                } else {\r
+                    //\r
+                    // Report Warning\r
+                    //\r
+                    EdkLog.log(this, EdkLog.EDK_WARNING, "Unrecognised element " + childItem.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='APRIORI' Identifier='0']");\r
+                }\r
+            }\r
+        }\r
+        \r
+        return result;\r
+    }\r
+\r
+    private Set<FpdModuleIdentification> getDxeApriori(String fvName) throws EdkException {\r
+        Node node = saq.getDxeApriori(fvName);\r
+        Set<FpdModuleIdentification> result = new LinkedHashSet<FpdModuleIdentification>();\r
+        if (node == null) {\r
+            return null;\r
+        }\r
+        \r
+        NodeList childNodes = node.getChildNodes();\r
+        for (int i = 0; i < childNodes.getLength(); i++) {\r
+            Node childItem = childNodes.item(i);\r
+            if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
+                //\r
+                // Find child elements "IncludeModules"\r
+                //\r
+                if (childItem.getNodeName().compareTo("IncludeModules") == 0) {\r
+                    //\r
+                    // result will be updated\r
+                    //\r
+                    processNodes(childItem, result);\r
+                } else if (childItem.getNodeName().compareTo("FvName") == 0) {\r
+                    \r
+                } else if (childItem.getNodeName().compareTo("InfFileName") == 0) {\r
+                    \r
+                } else {\r
+                    //\r
+                    // Report Warning\r
+                    //\r
+                    EdkLog.log(this, EdkLog.EDK_WARNING, "Unrecognised element " + childItem.getNodeName() + " under FPD.BuildOptions.UserExtensions[UserID='APRIORI' Identifier='1']");\r
+                }\r
+            }\r
+        }\r
+        \r
+        return result;\r
+    }\r
+    \r
     private Set<FpdModuleIdentification> getModuleSequenceForFv(String fvName) throws EdkException {\r
         Node node = saq.getFpdModuleSequence(fvName);\r
         Set<FpdModuleIdentification> result = new LinkedHashSet<FpdModuleIdentification>();\r
index d4b4622..1e5c774 100644 (file)
@@ -64,6 +64,8 @@ public class PlatformBuildFileGenerator {
     \r
     private File platformBuildFile = null;\r
     \r
+    private Map<String, String> aprioriType = null;\r
+    \r
     private Project project;\r
     \r
     private String info = "DO NOT EDIT \n" \r
@@ -72,13 +74,14 @@ public class PlatformBuildFileGenerator {
         + "Abstract:\n"\r
         + "Auto-generated ANT build file for building EFI Modules and Platforms\n";\r
 \r
-    public PlatformBuildFileGenerator(Project project, Map<FpdModuleIdentification, String> outfiles, Map<String, Set<FpdModuleIdentification>> fvs, boolean isUnified, SurfaceAreaQuery saq, String platformBuildFile){\r
+    public PlatformBuildFileGenerator(Project project, Map<FpdModuleIdentification, String> outfiles, Map<String, Set<FpdModuleIdentification>> fvs, boolean isUnified, SurfaceAreaQuery saq, String platformBuildFile, Map<String, String> aprioriType){\r
         this.project = project;\r
         this.outfiles = outfiles;\r
         this.isUnified = isUnified;\r
         this.fvs = fvs;\r
         this.saq = saq;\r
         this.platformBuildFile = new File(platformBuildFile);\r
+        this.aprioriType = aprioriType;\r
     }\r
     \r
     /**\r
@@ -193,6 +196,39 @@ public class PlatformBuildFileGenerator {
         Element ele = document.createElement("target");\r
         ele.setAttribute("name", "modules");\r
 \r
+        //\r
+        // Try to build apriori if necessary\r
+        //\r
+        //\r
+        // For every Target and ToolChain\r
+        //\r
+        String[] targetList = GlobalData.getToolChainInfo().getTargets();\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
+                //\r
+                // Prepare FV_DIR\r
+                //\r
+                String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
+                                + targetList[i] + "_" \r
+                                + toolchainList[j];\r
+                File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
+                Element fvEle = document.createElement("var");\r
+                fvEle.setAttribute("name", "FV_DIR");\r
+                fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
+                ele.appendChild(fvEle);\r
+                \r
+                Iterator<String> aprIter = aprioriType.keySet().iterator();\r
+                while (aprIter.hasNext()) {\r
+                    String fvName = aprIter.next();\r
+                    Element moduleEle = document.createElement("Build_Apriori");\r
+                    moduleEle.setAttribute("FILENAME", fvName);\r
+                    moduleEle.setAttribute("GUID", aprioriType.get(fvName));\r
+                    ele.appendChild(moduleEle);\r
+                }\r
+            }\r
+        }\r
+        \r
         //\r
         // Get all valid FV name\r
         //\r
index cf31873..9e4c445 100644 (file)
@@ -2011,6 +2011,32 @@ public class SurfaceAreaQuery {
                }\r
        }\r
     \r
+    public Node getPeiApriori(String fvName) {\r
+        String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName + "']" };\r
+        Object[] result = get("PlatformSurfaceArea", xPath);\r
+        \r
+        if (result == null || result.length == 0) {\r
+            return null;\r
+        }\r
+        \r
+        UserExtensionsDocument.UserExtensions a =  (UserExtensionsDocument.UserExtensions)result[0];\r
+        \r
+        return a.getDomNode();\r
+    }\r
+    \r
+    public Node getDxeApriori(String fvName) {\r
+        String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName + "']" };\r
+        Object[] result = get("PlatformSurfaceArea", xPath);\r
+        \r
+        if (result == null || result.length == 0) {\r
+            return null;\r
+        }\r
+        \r
+        UserExtensionsDocument.UserExtensions a =  (UserExtensionsDocument.UserExtensions)result[0];\r
+        \r
+        return a.getDomNode();\r
+    }\r
+    \r
     public Node getFpdModuleSequence(String fvName) {\r
         String[] xPath = new String[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName + "']" };\r
         Object[] result = get("PlatformSurfaceArea", xPath);\r