Introduce a new property INCLUDE_PATHS. This property can used by customized build...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / GenBuildTask.java
index 8e7ee3b941194e2a3200f3b047526aad23290785..42d3313ad3e95335c7a7863040af65e5dbb81f5c 100644 (file)
@@ -16,13 +16,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 package org.tianocore.build;\r
 \r
 import java.io.File;\r
-import java.util.Hashtable;\r
 import java.util.Iterator;\r
 import java.util.LinkedHashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
-import java.util.Stack;\r
 import java.util.Vector;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
@@ -109,8 +107,6 @@ public class GenBuildTask extends Ant {
 \r
     private Vector<Property> properties = new Vector<Property>();\r
 \r
-    private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();\r
-\r
     private boolean isSingleModuleBuild = false;\r
 \r
     /**\r
@@ -569,6 +565,11 @@ public class GenBuildTask extends Ant {
         }\r
         PropertyManager.setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r
 \r
+        //\r
+        // Get all includepath and set to INCLUDE_PATHS\r
+        //\r
+        String[] includes = prepareIncludePaths(fpdModuleId);\r
+        \r
         //\r
         // if it is CUSTOM_BUILD\r
         // then call the exist BaseName_build.xml directly.\r
@@ -587,7 +588,7 @@ public class GenBuildTask extends Ant {
         // TBD\r
         //\r
         String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword();\r
-        ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId);\r
+        ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId, includes);\r
         String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
         fileGenerator.genBuildFile(buildFilename);\r
 \r
@@ -697,4 +698,89 @@ public class GenBuildTask extends Ant {
     public void setSingleModuleBuild(boolean isSingleModuleBuild) {\r
         this.isSingleModuleBuild = isSingleModuleBuild;\r
     }\r
+    \r
+    private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) {\r
+        //\r
+        // Prepare the includes: PackageDependencies and Output debug direactory\r
+        //\r
+        Set<String> includes = new LinkedHashSet<String>();\r
+        String arch = fpdModuleId.getArch();\r
+        \r
+        //\r
+        // WORKSPACE\r
+        //\r
+        includes.add("${WORKSPACE_DIR}" + File.separatorChar);\r
+        \r
+        //\r
+        // Module iteself\r
+        //\r
+        includes.add("${MODULE_DIR}");\r
+        includes.add("${MODULE_DIR}" + File.separatorChar + archDir(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 + archDir(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 + archDir(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 + archDir(arch));\r
+\r
+        //\r
+        // Debug files output directory\r
+        //\r
+        includes.add("${DEST_DIR_DEBUG}");\r
+        \r
+        //\r
+        // set to INCLUDE_PATHS property\r
+        //\r
+        Iterator<String> iter = includes.iterator();\r
+        StringBuffer includePaths = new StringBuffer();\r
+        while (iter.hasNext()) {\r
+            includePaths.append(iter.next());\r
+            includePaths.append("; ");\r
+        }\r
+        PropertyManager.setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths.toString()).replaceAll("(\\\\)", "/"));\r
+        \r
+        return includes.toArray(new String[includes.size()]);\r
+    }\r
+    \r
+    /**\r
+     Return the name of the directory that corresponds to the architecture.\r
+     This is a translation from the XML Schema tag to a directory that\r
+     corresponds to our directory name coding convention.\r
+    \r
+     **/\r
+   private String archDir(String arch) {\r
+       return arch.replaceFirst("X64", "x64")\r
+                  .replaceFirst("IPF", "Ipf")\r
+                  .replaceFirst("IA32", "Ia32")\r
+                  .replaceFirst("ARM", "Arm")\r
+                  .replaceFirst("EBC", "Ebc");\r
+   }    \r
 }\r