]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/FfsProcess.java
Remove additional / or \ in relative path.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / FfsProcess.java
index 267a50e4e36bd9c1c2490ecafe8d115790f0d116..2d8ed0b0239d53d62bcd3899309a354ecb551ec6 100644 (file)
@@ -14,23 +14,21 @@ 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.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
@@ -60,6 +58,8 @@ public class FfsProcess {
     /// Xml Document Node for corresponding FFS layout\r
     ///\r
     private Node ffs;\r
+    \r
+    private BuildOptionsDocument.BuildOptions.Ffs ffsXmlObject;\r
 \r
     ///\r
     /// ANT script to call GenFfs\r
@@ -131,51 +131,42 @@ public class FfsProcess {
       @throws BuildException\r
               If specified COMMON_FILE XML file is not valide.\r
     **/\r
-    public boolean initSections(String buildType, Project project) throws BuildException {\r
+    public boolean initSections(String buildType, Project project, FpdModuleIdentification fpdModuleId) throws BuildException {\r
         //\r
-        // first try to sections defined in PLATFORM level\r
+        // Firstly, try to find in ModuleSA\r
         //\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
         //\r
-        // if module specify sections itself, it's okay\r
-        // otherwise find sections from WORKSPACE default setting with\r
-        // ComponentType\r
+        // secondly, try to sections defined in PLATFORM level\r
         //\r
-        if (ffs == null) {\r
-            File file = new File(project.getProperty("COMMON_FILE"));\r
-            //\r
-            // if common file is not existed, just return\r
-            //\r
-            if (!file.exists()) {\r
-                return false;\r
+        SurfaceAreaQuery.push(GlobalData.getFpdBuildOptions());\r
+        BuildOptionsDocument.BuildOptions.Ffs[] ffsArray = SurfaceAreaQuery.getFpdFfs();\r
+        SurfaceAreaQuery.pop();\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
-            DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
-            try {\r
-                DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
-                InputStream is = new FileInputStream(file);\r
-                Document doc = dombuilder.parse(is);\r
-                Element root = doc.getDocumentElement();\r
-                NodeList items = root.getChildNodes();\r
-                for (int i = 0; i < items.getLength(); i++) {\r
-                    Node node = items.item(i);\r
-                    if (node.getNodeType() == Node.ELEMENT_NODE) {\r
-                        String nodeName = node.getNodeName();\r
-                        if (nodeName.equalsIgnoreCase("Ffs")) {\r
-                            NamedNodeMap attr = node.getAttributes();\r
-                            Node type = attr.getNamedItem("type");\r
-                            if (type != null) {\r
-                                if (isMatch(type.getTextContent(), buildType)) {\r
-                                    ffs = node;\r
-                                    return true;\r
-                                }\r
-                            }\r
-                        }\r
-                    }\r
-                }\r
-            } catch (Exception e) {\r
-                throw new BuildException("Parse COMMON_FILE [" + file.getPath() + "] error!\n" + e.getMessage());\r
+        }\r
+        \r
+        //\r
+        // If FfsFormatKey is not null, report exception and fail build\r
+        // 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
         } else {\r
@@ -194,22 +185,30 @@ public class FfsProcess {
     **/\r
     public String[] getGenSectionElements(Document document, String basename, String guid, String targetFilename) {\r
         this.basename = basename;\r
-        if (ffs == null) {\r
+        if (ffs == null && ffsXmlObject == null) {\r
             return new String[0];\r
         }\r
         Vector<String> sectionList = new Vector<String>();\r
         XmlCursor cursor = null;\r
         try {\r
-            cursor = XmlObject.Factory.parse(ffs).newCursor();\r
+            if (ffsXmlObject == null) {\r
+                cursor = XmlObject.Factory.parse(ffs).newCursor();\r
+            }\r
+            else {\r
+                cursor = ffsXmlObject.newCursor();\r
+            }\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
-        cursor.toFirstChild();\r
+        if (ffsXmlObject == null) {\r
+            cursor.toFirstChild();\r
+        }\r
         if (cursor.toFirstChild()) {\r
             do {\r
                 if (cursor.getName().getLocalPart().equalsIgnoreCase("Attribute")) {\r
@@ -243,7 +242,7 @@ public class FfsProcess {
         outofdateEle.appendChild(sourceEle);\r
         Element targetEle = document.createElement("targetfiles");\r
         Element fileEle = document.createElement("file");\r
-        fileEle.setAttribute("name", "${BIN_DIR}\\" + targetFilename);\r
+        fileEle.setAttribute("name", "${BIN_DIR}" + File.separatorChar + targetFilename);\r
         targetEle.appendChild(fileEle);\r
         outofdateEle.appendChild(targetEle);\r
         Element sequentialEle = document.createElement("sequential");\r
@@ -365,7 +364,7 @@ public class FfsProcess {
     }\r
 \r
     /**\r
-       Get the corresponding section file suffix.\r
+      Get the corresponding section file suffix.\r
        \r
       @param type Section type\r
       @return Corresponding section file extension\r