]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/FfsProcess.java
Change GenBuildLogger format.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / FfsProcess.java
index 9371c7e6d5de8c9493d8b97aaa3dc270e0df4ba6..702c28fee765b2dbcf4bd7a94214ef2802a8d4a5 100644 (file)
@@ -14,33 +14,26 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 package org.tianocore.build;\r
 \r
 import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.InputStream;\r
 import java.util.Vector;\r
 \r
 import javax.xml.namespace.QName;\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Project;\r
 import org.apache.xmlbeans.XmlCursor;\r
-import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.BuildOptionsDocument;\r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.common.definitions.EdkDefinitions;\r
+import org.tianocore.common.logger.EdkLog;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
-import org.w3c.dom.NamedNodeMap;\r
-import org.w3c.dom.Node;\r
-import org.w3c.dom.NodeList;\r
 \r
 /** \r
   <p><code>FfsProcess</code> is a class to find the corresponding FFS layout. </p>\r
   \r
-  <p>Property <code>COMMON_FILE</code> specified which file to search. The element\r
-  in <code>COMMON_FILE</code> is like following: </p>\r
+  <p>The FFS Layout is like following: </p>\r
   \r
   <pre>\r
     &lt;Ffs type="APPLICATION"&gt;\r
@@ -60,11 +53,6 @@ import org.w3c.dom.NodeList;
 **/\r
 public class FfsProcess {\r
 \r
-    ///\r
-    /// Xml Document Node for corresponding FFS layout\r
-    ///\r
-    private Node ffs;\r
-    \r
     private BuildOptionsDocument.BuildOptions.Ffs ffsXmlObject;\r
 \r
     ///\r
@@ -95,19 +83,7 @@ public class FfsProcess {
     ///\r
     /// mapping from section type to section output file extension\r
     ///\r
-    public static final String[][] sectionExt = { { "EFI_SECTION_FREEFORM_SUBTYPE_GUID", ".sec" },\r
-                                                 { "EFI_SECTION_VERSION", ".ver" },\r
-                                                 { "EFI_SECTION_USER_INTERFACE", ".ui" },\r
-                                                 { "EFI_SECTION_DXE_DEPEX", ".dpx" },\r
-                                                 { "EFI_SECTION_PEI_DEPEX", ".dpx" }, \r
-                                                 { "EFI_SECTION_PE32", ".pe32" },\r
-                                                 { "EFI_SECTION_PIC", ".pic" }, \r
-                                                 { "EFI_SECTION_TE", ".tes" },\r
-                                                 { "EFI_SECTION_RAW", ".sec" }, \r
-                                                 { "EFI_SECTION_COMPRESSION", ".sec" },\r
-                                                 { "EFI_SECTION_GUID_DEFINED", ".sec" },\r
-                                                 { "EFI_SECTION_COMPATIBILITY16", ".sec" },\r
-                                                 { "EFI_SECTION_FIRMWARE_VOLUME_IMAGE", ".sec" } };\r
+    public static final String[][] sectionExt = EdkDefinitions.SectionTypeExtensions;\r
 \r
     /**\r
       search in the type, if componentType is listed in type, return true; \r
@@ -128,33 +104,20 @@ public class FfsProcess {
     }\r
 \r
     /**\r
-      Find the corresponding FFS layout in <code>COMMON_FILE</code> if it\r
-      does not specify in module's surface area. \r
+      Find the corresponding FFS layout in <code>FPD</code>. \r
       \r
       @param buildType Current module's component type\r
       @param project Ant project\r
       @return whether find the corresponding FFS layout\r
       @throws BuildException\r
-              If specified COMMON_FILE XML file is not valide.\r
+              If can't find FFS Layout in FPD.\r
     **/\r
     public boolean initSections(String buildType, Project project, FpdModuleIdentification fpdModuleId) throws BuildException {\r
         //\r
-        // Firstly, try to find in ModuleSA\r
-        //\r
-//        BuildOptionsDocument.BuildOptions.Ffs[] ffsArray = SurfaceAreaQuery.getModuleFfs();\r
-//        for (int i = 0; i < ffsArray.length; i++) {\r
-//            if (isMatch(ffsArray[i].getFfsKey(), buildType)) {\r
-//                ffsXmlObject = ffsArray[i];\r
-//                return true;\r
-//            }\r
-//        }\r
-        \r
+        // Try to find Ffs layout from FPD file\r
         //\r
-        // secondly, try to sections defined in PLATFORM level\r
-        //\r
-        SurfaceAreaQuery.push(GlobalData.getFpdBuildOptions());\r
-        BuildOptionsDocument.BuildOptions.Ffs[] ffsArray = SurfaceAreaQuery.getFpdFfs();\r
-        SurfaceAreaQuery.pop();\r
+        SurfaceAreaQuery saq = new SurfaceAreaQuery(GlobalData.getFpdBuildOptionsMap());\r
+        BuildOptionsDocument.BuildOptions.Ffs[] ffsArray = saq.getFpdFfs();\r
         for (int i = 0; i < ffsArray.length; i++) {\r
             if (isMatch(ffsArray[i].getFfsKey(), buildType)) {\r
                 ffsXmlObject = ffsArray[i];\r
@@ -167,17 +130,12 @@ public class FfsProcess {
         // Otherwise report warning message\r
         //\r
         if (buildType == null) {\r
-            System.out.println("Warning: this module doesn't specify a FfsFormatKey. ");\r
-            }\r
-        else {\r
-            throw new BuildException("Can't find FfsFormatKey [" + buildType + "] in FPD file. ");            \r
-        }\r
-\r
-        if (ffs == null) {\r
-            return false;\r
+            EdkLog.log(EdkLog.EDK_WARNING, "Warning: this module doesn't specify a FfsFormatKey. ");\r
         } else {\r
-            return true;\r
+            throw new BuildException("Can't find the FfsFormatKey [" + buildType + "] attribute in the FPD file!");            \r
         }\r
+\r
+        return false;\r
     }\r
     \r
     /**\r
@@ -191,43 +149,36 @@ public class FfsProcess {
     **/\r
     public String[] getGenSectionElements(Document document, String basename, String guid, String targetFilename) {\r
         this.basename = basename;\r
-        if (ffs == null && ffsXmlObject == null) {\r
+        if (ffsXmlObject == null) {\r
             return new String[0];\r
         }\r
         Vector<String> sectionList = new Vector<String>();\r
         XmlCursor cursor = null;\r
         try {\r
-            if (ffsXmlObject == null) {\r
-                cursor = XmlObject.Factory.parse(ffs).newCursor();\r
-            }\r
-            else {\r
-                cursor = ffsXmlObject.newCursor();\r
-            }\r
+            cursor = ffsXmlObject.newCursor();\r
         } catch (Exception e) {\r
             return null;\r
         }\r
         int mode = MODE_NONE;\r
-        Element root = document.createElement("genffsfile");\r
-        root.setAttribute("outputDir", "${BIN_DIR}");\r
-        root.setAttribute("moduleType", "${MODULE_TYPE}");\r
-        root.setAttribute("BaseName", basename);\r
-        root.setAttribute("fileGuid", guid);\r
-        if (ffsXmlObject == null) {\r
-            cursor.toFirstChild();\r
-        }\r
+        Element genffsfileEle = document.createElement("genffsfile");\r
+        genffsfileEle.setAttribute("outputDir", "${BIN_DIR}");\r
+        genffsfileEle.setAttribute("moduleType", "${MODULE_TYPE}");\r
+        genffsfileEle.setAttribute("BaseName", basename);\r
+        genffsfileEle.setAttribute("fileGuid", guid);\r
+\r
         if (cursor.toFirstChild()) {\r
             do {\r
                 if (cursor.getName().getLocalPart().equalsIgnoreCase("Attribute")) {\r
                     String name = cursor.getAttributeText(new QName("Name"));\r
                     String value = cursor.getAttributeText(new QName("Value"));\r
-                    root.setAttribute(changeAttributeName(name), value);\r
+                    genffsfileEle.setAttribute(changeAttributeName(name), value);\r
                 } else if (cursor.getName().getLocalPart().equalsIgnoreCase("Section")) {\r
                     cursor.push();\r
-                    dealSection(mode, document, root, cursor, sectionList);\r
+                    dealSection(mode, document, genffsfileEle, cursor, sectionList);\r
                     cursor.pop();\r
                 } else if (cursor.getName().getLocalPart().equalsIgnoreCase("Sections")) {\r
                     cursor.push();\r
-                    dealSections(mode, document, root, cursor, sectionList);\r
+                    dealSections(mode, document, genffsfileEle, cursor, sectionList);\r
                     cursor.pop();\r
                 }\r
             } while (cursor.toNextSibling());\r
@@ -252,7 +203,7 @@ public class FfsProcess {
         targetEle.appendChild(fileEle);\r
         outofdateEle.appendChild(targetEle);\r
         Element sequentialEle = document.createElement("sequential");\r
-        sequentialEle.appendChild(root);\r
+        sequentialEle.appendChild(genffsfileEle);\r
         outofdateEle.appendChild(sequentialEle);\r
         ffsNode = outofdateEle;\r
         return result;\r
@@ -351,20 +302,55 @@ public class FfsProcess {
     **/\r
     private void dealSection(int mode, Document doc, Element root, XmlCursor cursor, Vector<String> list) {\r
         String type = cursor.getAttributeText(new QName("SectionType"));\r
-        list.addElement(type);\r
+        \r
+        //\r
+        // Judge if file is specified? Yes, just use the file, else call Build Macro\r
+        // If fileName is null, means without FileNames specify in FPD file\r
+        //\r
+        String fileName = null;\r
+        cursor.push();\r
+        if (cursor.toFirstChild()) {\r
+            do {\r
+                if (cursor.getName().getLocalPart().equalsIgnoreCase("Filenames")) {\r
+                    cursor.push();\r
+                    if (cursor.toFirstChild()) {\r
+                        do {\r
+                            if (cursor.getName().getLocalPart().equalsIgnoreCase("Filename")) {\r
+                                fileName = cursor.getTextValue();\r
+                            }\r
+                        } while (cursor.toNextSibling());\r
+                    }\r
+                    cursor.pop();\r
+                }\r
+            } while (cursor.toNextSibling());\r
+        }\r
+\r
+        cursor.pop();\r
+        \r
+        if (fileName == null) {\r
+            list.addElement(type);\r
+        }\r
         if (mode == MODE_GUID_DEFINED) {\r
             //\r
             // <input file="${DEST_DIR_OUTPUT}\Bds.pe32"/>\r
             //\r
             Element ele = doc.createElement("input");\r
-            ele.setAttribute("file", "${DEST_DIR_OUTPUT}" + File.separatorChar + basename + getSectionExt(type));\r
+            if (fileName == null) {\r
+                ele.setAttribute("file", "${DEST_DIR_OUTPUT}" + File.separatorChar + basename + getSectionExt(type));\r
+            } else {\r
+                ele.setAttribute("file", "${PLATFORM_DIR}" + File.separatorChar + fileName);\r
+            }\r
             root.appendChild(ele);\r
         } else {\r
             //\r
             // <sectFile fileName= "..."/>\r
             //\r
             Element ele = doc.createElement("sectFile");\r
-            ele.setAttribute("fileName", "${DEST_DIR_OUTPUT}" + File.separatorChar + basename + getSectionExt(type));\r
+            if (fileName == null) {\r
+                ele.setAttribute("fileName", "${DEST_DIR_OUTPUT}" + File.separatorChar + basename + getSectionExt(type));\r
+            } else {\r
+                ele.setAttribute("fileName", "${PLATFORM_DIR}" + File.separatorChar + fileName);\r
+            }\r
             root.appendChild(ele);\r
         }\r
     }\r