]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/FfsProcess.java
Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / FfsProcess.java
index 6660382e6431c0e17cccdbcf64b9d6042df298f1..15f975901b73c2c5d9630e8f5582432bef633e57 100644 (file)
@@ -14,13 +14,9 @@ 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
@@ -32,9 +28,7 @@ import org.tianocore.build.global.SurfaceAreaQuery;
 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
@@ -163,45 +157,16 @@ public class FfsProcess {
         }\r
         \r
         //\r
-        // if module specify sections itself, it's okay\r
-        // otherwise find sections from WORKSPACE default setting with\r
-        // ComponentType\r
+        // If FfsFormatKey is not null, report exception and fail build\r
+        // Otherwise report warning message\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
-            }\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
+        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 the FfsFormatKey [" + buildType + "] attribute in the FPD file!");            \r
         }\r
+\r
         if (ffs == null) {\r
             return false;\r
         } else {\r
@@ -277,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
@@ -380,20 +345,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