]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java
Introduce a new property INCLUDE_PATHS. This property can used by customized build...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / ModuleBuildFileGenerator.java
index b4f34f762a4344f6465c0d8fd4b6612365098bb6..34b3771a993c6a7306ea24251167c727a2ca8a25 100644 (file)
@@ -13,9 +13,9 @@ package org.tianocore.build;
 \r
 import java.io.File;\r
 import java.util.LinkedHashMap;\r
-import java.util.LinkedHashSet;\r
 import java.util.Map;\r
-import java.util.Set;\r
+import java.io.FileOutputStream;\r
+import java.io.OutputStreamWriter;\r
 \r
 import javax.xml.parsers.DocumentBuilder;\r
 import javax.xml.parsers.DocumentBuilderFactory;\r
@@ -30,8 +30,8 @@ import javax.xml.transform.stream.StreamResult;
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.Project;\r
 import org.tianocore.build.fpd.FpdParserTask;\r
-import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.global.PropertyManager;\r
 import org.tianocore.build.id.FpdModuleIdentification;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PackageIdentification;\r
@@ -52,10 +52,10 @@ public class ModuleBuildFileGenerator {
     /// The information at the header of <em>build.xml</em>.\r
     ///\r
     private String info = "DO NOT EDIT \n"\r
-                        + "File auto-generated by build utility\n"\r
+                        + "This file is auto-generated by the build utility\n"\r
                         + "\n"\r
                         + "Abstract:\n"\r
-                        + "Auto-generated ANT build file for building of EFI Modules/Platforms\n";\r
+                        + "Auto-generated ANT build file for build EFI Modules and Platforms\n";\r
 \r
     private FpdModuleIdentification fpdModuleId;\r
     \r
@@ -63,10 +63,13 @@ public class ModuleBuildFileGenerator {
     \r
     private String ffsKeyword;\r
     \r
-    public ModuleBuildFileGenerator(Project project, String ffsKeyword, FpdModuleIdentification fpdModuleId) {\r
+    private String[] includes;\r
+    \r
+    public ModuleBuildFileGenerator(Project project, String ffsKeyword, FpdModuleIdentification fpdModuleId, String[] includes) {\r
         this.project = project;\r
         this.fpdModuleId = fpdModuleId;\r
         this.ffsKeyword = ffsKeyword;\r
+        this.includes = includes;\r
     }\r
     \r
     /**\r
@@ -211,7 +214,8 @@ public class ModuleBuildFileGenerator {
             // generate all directory path\r
             //\r
             (new File(file.getParent())).mkdirs();\r
-            Result result = new StreamResult(file);\r
+            FileOutputStream outputStream = new FileOutputStream(file);\r
+            Result result = new StreamResult(new OutputStreamWriter(outputStream));\r
             \r
             //\r
             // Write the DOM document to the file\r
@@ -221,7 +225,7 @@ public class ModuleBuildFileGenerator {
             xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
             xformer.transform(source, result);\r
         } catch (Exception ex) {\r
-            throw new BuildException("Module [" + fpdModuleId.getModule().getName() + "] generating build file failed.\n" + ex.getMessage());\r
+            throw new BuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage());\r
         }\r
     }\r
 \r
@@ -232,41 +236,6 @@ public class ModuleBuildFileGenerator {
       @param root Root element for current\r
     **/\r
     private void applyCleanElement(Document document, Node root) {\r
-        ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
-        for (int i = 0; i < libinstances.length; i++) {\r
-            //\r
-            // Put package file path to module identification\r
-            //\r
-            PackageIdentification packageId = libinstances[i].getPackage();\r
-            \r
-            //\r
-            // Generate ANT script to clean\r
-            //\r
-            Element ele = document.createElement("GenBuild");\r
-            ele.setAttribute("type", "clean");\r
-            \r
-            //\r
-            // Prepare pass down information\r
-            //\r
-            Map<String, String> passDownMap = new LinkedHashMap<String, String>();\r
-            for (int j = 0; j < inheritProperties.length; j ++){\r
-                passDownMap.put(inheritProperties[j], "${" + inheritProperties[j] + "}");\r
-            }\r
-            passDownMap.put("MODULE_GUID", libinstances[i].getGuid());\r
-            passDownMap.put("MODULE_VERSION", libinstances[i].getVersion());\r
-            \r
-            passDownMap.put("PACKAGE_GUID", packageId.getGuid());\r
-            passDownMap.put("PACKAGE_VERSION", packageId.getVersion());\r
-            \r
-            for (int j = 0; j < inheritProperties.length; j ++){\r
-                Element property = document.createElement("property");\r
-                property.setAttribute("name", inheritProperties[j]);\r
-                property.setAttribute("value", passDownMap.get(inheritProperties[j]));\r
-                ele.appendChild(property);\r
-            }\r
-\r
-            root.appendChild(ele);\r
-        }\r
         //\r
         // <delete includeemptydirs="true">\r
         //   <fileset dir="${DEST_DIR_OUTPUT}" includes="" excludes="" />\r
@@ -289,42 +258,6 @@ public class ModuleBuildFileGenerator {
       @param root Root element for current\r
     **/\r
     private void applyDeepcleanElement(Document document, Node root) {\r
-        ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
-        for (int i = 0; i < libinstances.length; i++) {\r
-            //\r
-            // Put package file path to module identification\r
-            //\r
-            PackageIdentification packageId = libinstances[i].getPackage();\r
-            \r
-            //\r
-            // Generate ANT script to clean\r
-            //\r
-            Element ele = document.createElement("GenBuild");\r
-            ele.setAttribute("type", "cleanall");\r
-            \r
-            //\r
-            // Prepare pass down information\r
-            //\r
-            Map<String, String> passDownMap = new LinkedHashMap<String, String>();\r
-            for (int j = 0; j < inheritProperties.length; j ++){\r
-                passDownMap.put(inheritProperties[j], "${" + inheritProperties[j] + "}");\r
-            }\r
-            \r
-            passDownMap.put("MODULE_GUID", libinstances[i].getGuid());\r
-            passDownMap.put("MODULE_VERSION", libinstances[i].getVersion());\r
-            \r
-            passDownMap.put("PACKAGE_GUID", packageId.getGuid());\r
-            passDownMap.put("PACKAGE_VERSION", packageId.getVersion());\r
-            \r
-            for (int j = 0; j < inheritProperties.length; j ++){\r
-                Element property = document.createElement("property");\r
-                property.setAttribute("name", inheritProperties[j]);\r
-                property.setAttribute("value", passDownMap.get(inheritProperties[j]));\r
-                ele.appendChild(property);\r
-            }\r
-\r
-            root.appendChild(ele);\r
-        }\r
         //\r
         // <delete includeemptydirs="true">\r
         //   <fileset dir="${DEST_DIR_OUTPUT}" includes="" excludes="" />\r
@@ -361,7 +294,6 @@ public class ModuleBuildFileGenerator {
     **/\r
     private void applyLibraryInstance(Document document, Node root) {\r
         ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
-//        String propertyLibs = "";\r
         for (int i = 0; i < libinstances.length; i++) {\r
             //\r
             // Put package file path to module identification\r
@@ -373,7 +305,6 @@ public class ModuleBuildFileGenerator {
             //\r
             Element ele = document.createElement("GenBuild");\r
             ele.setAttribute("type", "build");\r
-//            ele.setAttribute("inheritAll", "false");\r
             \r
             //\r
             // Prepare pass down information\r
@@ -397,11 +328,9 @@ public class ModuleBuildFileGenerator {
             }\r
             \r
             root.appendChild(ele);\r
-//            propertyLibs += " " + project.getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";\r
         }\r
-//        project.setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r
     }\r
-    \r
+\r
     /**\r
       Generate the build source files elements for BaseName_build.xml. \r
       \r
@@ -409,61 +338,6 @@ public class ModuleBuildFileGenerator {
       @param root Root element for current\r
     **/\r
     private void applyCompileElement(Document document, Node root) {\r
-        //\r
-        // Prepare the includes: PackageDependencies and Output debug direactory\r
-        //\r
-        Set<String> includes = new LinkedHashSet<String>();\r
-        \r
-        //\r
-        // WORKSPACE\r
-        //\r
-        includes.add("${WORKSPACE_DIR}");\r
-        \r
-        //\r
-        // Module iteself\r
-        //\r
-        includes.add("${MODULE_DIR}");\r
-        includes.add("${MODULE_DIR}" + File.separatorChar + "${ARCH}");\r
-        \r
-        //\r
-        // Packages in PackageDenpendencies\r
-        //\r
-        PackageIdentification[] packageDependencies = SurfaceAreaQuery.getDependencePkg(fpdModuleId.getArch());\r
-        for (int i = 0; i < packageDependencies.length; i++) {\r
-            GlobalData.refreshPackageIdentification(packageDependencies[i]);\r
-            File packageFile = packageDependencies[i].getSpdFile();\r
-            includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
-            includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
-        }\r
-\r
-        //\r
-        // All Dependency Library Instance's PackageDependencies\r
-        //\r
-        ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
-        for (int i = 0; i < libinstances.length; i++) {\r
-            SurfaceAreaQuery.push(GlobalData.getDoc(libinstances[i], fpdModuleId.getArch()));\r
-            PackageIdentification[] libraryPackageDependencies = SurfaceAreaQuery.getDependencePkg(fpdModuleId.getArch());\r
-            for (int j = 0; j < libraryPackageDependencies.length; j++) {\r
-                GlobalData.refreshPackageIdentification(libraryPackageDependencies[j]);\r
-                File packageFile = libraryPackageDependencies[j].getSpdFile();\r
-                includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
-                includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
-            }\r
-            SurfaceAreaQuery.pop();\r
-        }\r
-        \r
-        \r
-        //\r
-        // The package which the module belongs to\r
-        // TBD\r
-        includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include");\r
-        includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
-\r
-        //\r
-        // Debug files output directory\r
-        //\r
-        includes.add("${DEST_DIR_DEBUG}");\r
-        \r
         //\r
         // sourceFiles[][0] is FileType, [][1] is File name relative to Module_Dir\r
         //\r
@@ -471,6 +345,12 @@ public class ModuleBuildFileGenerator {
 \r
         FileProcess fileProcess = new FileProcess();\r
         fileProcess.init(project, includes, document);\r
+        \r
+        //\r
+        // Initialize some properties by user\r
+        //\r
+        Element initEle = document.createElement("Build_Init");\r
+        root.appendChild(initEle);\r
 \r
         String moduleDir = project.getProperty("MODULE_DIR");\r
         //\r
@@ -497,11 +377,10 @@ public class ModuleBuildFileGenerator {
             Element ele = document.createElement("Build_Unicode_Database");\r
             ele.setAttribute("FILEPATH", ".");\r
             ele.setAttribute("FILENAME", "${BASE_NAME}");\r
-            String[] includePaths = includes.toArray(new String[includes.size()]);\r
             Element includesEle = document.createElement("EXTRA.INC");\r
-            for (int i = 0; i < includePaths.length; i++) {\r
+            for (int i = 0; i < includes.length; i++) {\r
                 Element includeEle = document.createElement("includepath");\r
-                includeEle.setAttribute("path", includePaths[i]);\r
+                includeEle.setAttribute("path", includes[i]);\r
                 includesEle.appendChild(includeEle);\r
             }\r
             ele.appendChild(includesEle);\r
@@ -534,7 +413,7 @@ public class ModuleBuildFileGenerator {
         for (int i = 0; i < sourceFiles.length; i++) {\r
             str += " " + sourceFiles[i][1];\r
         }\r
-        project.setProperty("SOURCE_FILES", str.replaceAll("(\\\\)", "/"));\r
+        PropertyManager.setProperty(project, "SOURCE_FILES", str.replaceAll("(\\\\)", "/"));\r
     }\r
 \r
     /**\r