]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/GenBuild/org/tianocore/build/GenBuildTask.java
Fixed an issue which a library module could be built even it's not in the active...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / GenBuildTask.java
index 79eeb2757fcc4b5962df7e7e7e1debc4701a1398..468b5f9ecc494a7a365cff4e93184cd32e8917e5 100644 (file)
@@ -26,14 +26,11 @@ import java.util.Vector;
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.tools.ant.BuildListener;\r
+import org.apache.tools.ant.Location;\r
 import org.apache.tools.ant.Project;\r
 import org.apache.tools.ant.taskdefs.Ant;\r
 import org.apache.tools.ant.taskdefs.Property;\r
 import org.apache.xmlbeans.XmlObject;\r
-\r
-import org.tianocore.common.definitions.ToolDefinitions;\r
-import org.tianocore.common.exception.EdkException;\r
-import org.tianocore.common.logger.EdkLog;\r
 import org.tianocore.build.autogen.AutoGen;\r
 import org.tianocore.build.exception.AutoGenException;\r
 import org.tianocore.build.exception.GenBuildException;\r
@@ -48,6 +45,9 @@ import org.tianocore.build.id.ModuleIdentification;
 import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.build.tools.ModuleItem;\r
+import org.tianocore.common.definitions.ToolDefinitions;\r
+import org.tianocore.common.exception.EdkException;\r
+import org.tianocore.common.logger.EdkLog;\r
 \r
 /**\r
   <p>\r
@@ -151,6 +151,10 @@ public class GenBuildTask extends Ant {
             BuildException buildException = new BuildException(e.getMessage());\r
             buildException.setStackTrace(e.getStackTrace());\r
             throw buildException;\r
+        } catch (Exception e) {\r
+            BuildException buildException = new BuildException(e.getMessage());\r
+            buildException.setStackTrace(e.getStackTrace());\r
+            throw buildException;\r
         }\r
     }\r
 \r
@@ -197,12 +201,13 @@ public class GenBuildTask extends Ant {
             moduleId.setMsaFile(msaFile);\r
         }\r
         \r
-        String[] producedLibraryClasses = saq.getLibraryClasses("ALWAYS_PRODUCED",null);\r
+        String[] producedLibraryClasses = saq.getLibraryClasses("ALWAYS_PRODUCED", null, null);\r
         if (producedLibraryClasses.length == 0) {\r
             moduleId.setLibrary(false);\r
         } else {\r
             moduleId.setLibrary(true);\r
         }\r
+        moduleId.setBinary(saq.getBinaryModule());\r
 \r
         //\r
         // Judge whether it is single module build or not\r
@@ -226,9 +231,9 @@ public class GenBuildTask extends Ant {
         }\r
 \r
         Set<String> archSet = new LinkedHashSet<String>();\r
-\r
-        if ( getProject().getProperty("ARCH") != null) {\r
-            String[] fpdArchList = getProject().getProperty("ARCH").split(" ");\r
+        String archString = getProject().getProperty("ARCH");\r
+        if (archString != null && archString.length() > 0) {\r
+            String[] fpdArchList = archString.split(" ");\r
 \r
             for (int i = 0; i < fpdArchList.length; i++) {\r
                 if (archListSupByToolChain.contains(fpdArchList[i])) {\r
@@ -247,17 +252,21 @@ public class GenBuildTask extends Ant {
         List moduleSupportedArchs = saq.getModuleSupportedArchs();\r
         if (moduleSupportedArchs != null) {\r
             for (int k = 0; k < archList.length; k++) {\r
-                if ( ! moduleSupportedArchs.contains(archList[k])) {\r
-                    throw new BuildException("Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures.");\r
+                if (!moduleSupportedArchs.contains(archList[k])) {\r
+                    EdkLog.log(this, EdkLog.EDK_WARNING, "Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures.");\r
+                    archList[k] = "";\r
                 }\r
             }\r
         }\r
 \r
         if (archList.length == 0) {\r
-            EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: " + moduleId + " was not found in current platform FPD file!\n");\r
+            EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: " + "[" + archString + "] is not supported for " + moduleId + " in this build!\n");\r
         }\r
 \r
         for (int k = 0; k < archList.length; k++) {\r
+            if (archList[k] == "") {\r
+                continue;\r
+            }\r
 \r
             getProject().setProperty("ARCH", archList[k]);\r
 \r
@@ -266,8 +275,13 @@ public class GenBuildTask extends Ant {
             //\r
             // Whether the module is built before\r
             //\r
-            if (moduleId.isLibrary() == false && GlobalData.hasFpdModuleSA(fpdModuleId) == false) {\r
-                EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");\r
+            if ((moduleId.isLibrary() == false || isSingleModuleBuild) && GlobalData.hasFpdModuleSA(fpdModuleId) == false) {\r
+                if (isSingleModuleBuild) {\r
+                    EdkLog.log(this, EdkLog.EDK_ERROR, "Error: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");\r
+                    throw new BuildException("No platform containing this module!");\r
+                } else {\r
+                    EdkLog.log(this, EdkLog.EDK_WARNING, "Warning: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");\r
+                }\r
                 continue;\r
             } else if (GlobalData.isModuleBuilt(fpdModuleId)) {\r
                 break;\r
@@ -323,10 +337,8 @@ public class GenBuildTask extends Ant {
 \r
                     if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {\r
                         applyBuild(targetList[i], toolchainList[j], fpdModuleId);\r
-                    } else if (type.equalsIgnoreCase("clean")) {\r
-                        applyClean(fpdModuleId);\r
-                    } else if (type.equalsIgnoreCase("cleanall")) {\r
-                        applyCleanall(fpdModuleId);\r
+                    } else {\r
+                        applyNonBuildTarget(fpdModuleId);\r
                     }\r
                 }\r
             }\r
@@ -429,7 +441,7 @@ public class GenBuildTask extends Ant {
         String msaFileName = msaFile.getName();\r
         getProject().setProperty("MODULE_DIR", msaFile.getParent().replaceAll("(\\\\)", "/"));\r
         getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/") \r
-            + File.separatorChar + msaFileName.substring(0, msaFileName.length() - 3));\r
+            + File.separatorChar + msaFileName.substring(0, msaFileName.lastIndexOf('.')));\r
 \r
         //\r
         // SUBSYSTEM\r
@@ -645,10 +657,11 @@ public class GenBuildTask extends Ant {
         // if it is CUSTOM_BUILD\r
         // then call the exist BaseName_build.xml directly.\r
         //\r
-        if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
-            EdkLog.log(this, "Call user-defined " + moduleId.getName() + "_build.xml");\r
+        String buildFilename = "";\r
+        if ((buildFilename = GetCustomizedBuildFile(fpdModuleId.getArch())) != "") {\r
+            EdkLog.log(this, "Call user-defined " + buildFilename);\r
             \r
-            String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+            String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + buildFilename;\r
             antCall(antFilename, null);\r
             \r
             return ;\r
@@ -660,7 +673,7 @@ public class GenBuildTask extends Ant {
         //\r
         String ffsKeyword = saq.getModuleFfsKeyword();\r
         ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId, includes, saq);\r
-        String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+        buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
         fileGenerator.genBuildFile(buildFilename);\r
 \r
         //\r
@@ -670,6 +683,24 @@ public class GenBuildTask extends Ant {
         antCall(antFilename, null);\r
     }\r
 \r
+    private void applyNonBuildTarget(FpdModuleIdentification fpdModuleId){\r
+        //\r
+        // if it is CUSTOM_BUILD\r
+        // then call the exist BaseName_build.xml directly.\r
+        //\r
+        if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
+            EdkLog.log(this, "Calling user-defined " + moduleId.getName() + "_build.xml");\r
+            \r
+            String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+            antCall(antFilename, this.type);\r
+            \r
+            return ;\r
+        }\r
+\r
+        String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+        antCall(antFilename, this.type);\r
+    }\r
+\r
     private void applyClean(FpdModuleIdentification fpdModuleId){\r
         //\r
         // if it is CUSTOM_BUILD\r
@@ -811,4 +842,15 @@ public class GenBuildTask extends Ant {
    public void setExternalProperties(Vector<Property> v) {\r
        this.properties = v;\r
    }\r
+\r
+   private String GetCustomizedBuildFile(String arch) {\r
+       String[][] files = saq.getSourceFiles(arch);\r
+       for (int i = 0; i < files.length; ++i) {\r
+           if (files[i][1].endsWith("build.xml")) {\r
+               return files[i][1];\r
+           }\r
+       }\r
+\r
+       return "";\r
+   }\r
 }\r