]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java
Fix the IDE slave device missing bug.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / GenBuildTask.java
index f7deb19e8fc548774408d0a89255f525509544d2..c8cc4ad74890729a245d705ac896467b4ca0d5be 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.tools.ant.taskdefs.Ant;
 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
@@ -49,13 +50,19 @@ import org.tianocore.build.tools.ModuleItem;
 /**\r
   <p>\r
   <code>GenBuildTask</code> is an ANT task that can be used in ANT build\r
-  system. The main function of this task is to parse module's surface area,\r
+  system. \r
+  \r
+  <p>The main function of this task is to parse module's surface area (MSA),\r
   then generate the corresponding <em>BaseName_build.xml</em> (the real ANT\r
   build script) and call this to build the module. The whole process including:\r
-  1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances;\r
-  3. build all source files inlcude AutoGen.c; 4. generate sections;\r
+  <pre>\r
+  1. generate AutoGen.c and AutoGen.h; \r
+  2. build all dependent library instances;\r
+  3. build all source files inlcude AutoGen.c; \r
+  4. generate sections;\r
   5. generate FFS file if it is driver module while LIB file if it is Library module.\r
-  </p>\r
+  </pre>\r
+\r
 \r
   <p>\r
   The usage is (take module <em>HelloWorld</em> for example):\r
@@ -89,11 +96,8 @@ public class GenBuildTask extends Ant {
     ///\r
     File msaFile;\r
 \r
-    ///\r
-    ///\r
-    ///\r
-    private String type = "all"; // = "build";\r
-\r
+    private String type = "all"; \r
+    \r
     ///\r
     /// Module's Identification.\r
     ///\r
@@ -123,8 +127,7 @@ public class GenBuildTask extends Ant {
         GenBuildLogger logger = new GenBuildLogger(getProject());\r
         EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));\r
         EdkLog.setLogger(logger);\r
-        // remove !!\r
-        try {\r
+\r
         pushProperties();\r
         //\r
         // Enable all specified properties\r
@@ -152,8 +155,7 @@ public class GenBuildTask extends Ant {
             Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);\r
             SurfaceAreaQuery.setDoc(doc);\r
             moduleId = SurfaceAreaQuery.getMsaHeader();\r
-        }\r
-        else {\r
+        } else {\r
             Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r
             SurfaceAreaQuery.setDoc(doc);\r
             moduleId = SurfaceAreaQuery.getMsaHeader();\r
@@ -161,8 +163,7 @@ public class GenBuildTask extends Ant {
         String[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED",null);\r
         if (producedLibraryClasses.length == 0) {\r
             moduleId.setLibrary(false);\r
-        }\r
-        else {\r
+        } else {\r
             moduleId.setLibrary(true);\r
         }\r
 \r
@@ -174,8 +175,7 @@ public class GenBuildTask extends Ant {
             // Single Module build\r
             //\r
             prepareSingleModuleBuild();\r
-        }\r
-        else {\r
+        } else {\r
             //\r
             // Platform build. Restore the platform related info\r
             //\r
@@ -191,8 +191,8 @@ public class GenBuildTask extends Ant {
         }\r
 \r
         //\r
-        // If single module : intersection MSA supported ARCHs and tools def!!\r
-        // else, get arch from pass down\r
+        // If single module : get arch from pass down, otherwise intersection MSA \r
+        // supported ARCHs and tools def\r
         //\r
         Set<String> archListSupByToolChain = new LinkedHashSet<String>();\r
         String[] archs = GlobalData.getToolChainInfo().getArchs();\r
@@ -211,9 +211,8 @@ public class GenBuildTask extends Ant {
                     archSet.add(fpdArchList[i]);\r
                 }\r
             }\r
-        }\r
-        else {\r
-            archSet = archListSupByToolChain;\r
+        } else {\r
+            archSet = archListSupByToolChain; \r
         }\r
 \r
         String[] archList = archSet.toArray(new String[archSet.size()]);\r
@@ -296,20 +295,16 @@ public class GenBuildTask extends Ant {
 \r
                     if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {\r
                         applyBuild(targetList[i], toolchainList[j], fpdModuleId);\r
-                    }\r
-                    else if (type.equalsIgnoreCase("clean")) {\r
+                    } else if (type.equalsIgnoreCase("clean")) {\r
                         applyClean(fpdModuleId);\r
-                    }\r
-                    else if (type.equalsIgnoreCase("cleanall")) {\r
+                    } else if (type.equalsIgnoreCase("cleanall")) {\r
                         applyCleanall(fpdModuleId);\r
                     }\r
                 }\r
             }\r
         }\r
+        \r
         popProperties();\r
-        }catch (Exception e){\r
-            throw new BuildException(e.getMessage());\r
-        }\r
     }\r
 \r
     /**\r
@@ -331,7 +326,7 @@ public class GenBuildTask extends Ant {
         moduleId.setPackage(packageId);\r
 \r
         //\r
-        // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r
+        // Read ACTIVE_PLATFORM's FPD file \r
         //\r
         String filename = getProject().getProperty("PLATFORM_FILE");\r
 \r
@@ -342,7 +337,7 @@ public class GenBuildTask extends Ant {
         PlatformIdentification platformId = GlobalData.getPlatform(filename);\r
 \r
         //\r
-        // Read FPD file\r
+        // Read FPD file (Call FpdParserTask's method)\r
         //\r
         FpdParserTask fpdParser = new FpdParserTask();\r
         fpdParser.setProject(getProject());\r
@@ -360,6 +355,8 @@ public class GenBuildTask extends Ant {
 \r
     /**\r
       Set Module-Related information to properties.\r
+      \r
+      @param arch current build ARCH\r
     **/\r
     private void setModuleCommonProperties(String arch) {\r
         //\r
@@ -381,8 +378,7 @@ public class GenBuildTask extends Ant {
         String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r
         if (baseName == null) {\r
             getProject().setProperty("BASE_NAME", moduleId.getName());\r
-        }\r
-        else {\r
+        } else {\r
             getProject().setProperty("BASE_NAME", baseName);\r
         }\r
         getProject().setProperty("GUID", moduleId.getGuid());\r
@@ -423,8 +419,7 @@ public class GenBuildTask extends Ant {
         //\r
         if (arch.equalsIgnoreCase("EBC")) {\r
             getProject().setProperty("ENTRYPOINT", "EfiStart");\r
-        }\r
-        else {\r
+        } else {\r
             getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");\r
         }\r
 \r
@@ -438,9 +433,9 @@ public class GenBuildTask extends Ant {
             // Set cmd, like CC, DLINK\r
             //\r
             String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};\r
-            key[4] = "PATH";\r
+            key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_PATH;\r
             String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);\r
-            key[4] = "NAME";\r
+            key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME;\r
             String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);\r
             File cmdFile = new File(cmdPath + File.separatorChar + cmdName);\r
             getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));\r
@@ -448,7 +443,7 @@ public class GenBuildTask extends Ant {
             //\r
             // set CC_FLAGS\r
             //\r
-            key[4] = "FLAGS";\r
+            key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS;\r
             String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);\r
             Set<String> addset = new LinkedHashSet<String>();\r
             Set<String> subset = new LinkedHashSet<String>();\r
@@ -458,19 +453,18 @@ public class GenBuildTask extends Ant {
             //\r
             // Set CC_EXT\r
             //\r
-            key[4] = "EXT";\r
+            key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_EXT;\r
             String extName = GlobalData.getCommandSetting(key, fpdModuleId);\r
             if ( extName != null && ! extName.equalsIgnoreCase("")) {\r
                 getProject().setProperty(cmd[m] + "_EXT", extName);\r
-            }\r
-            else {\r
+            } else {\r
                 getProject().setProperty(cmd[m] + "_EXT", "");\r
             }\r
 \r
             //\r
             // set CC_FAMILY\r
             //\r
-            key[4] = "FAMILY";\r
+            key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY;\r
             String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);\r
             if (toolChainFamily != null) {\r
                 getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);\r
@@ -479,24 +473,22 @@ public class GenBuildTask extends Ant {
             //\r
             // set CC_SPATH\r
             //\r
-            key[4] = "SPATH";\r
+            key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_SPATH;\r
             String spath = GlobalData.getCommandSetting(key, fpdModuleId);\r
             if (spath != null) {\r
                 getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));\r
-            }\r
-            else {\r
+            } else {\r
                 getProject().setProperty(cmd[m] + "_SPATH", "");\r
             }\r
 \r
             //\r
             // set CC_DPATH\r
             //\r
-            key[4] = "DPATH";\r
+            key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_DPATH;\r
             String dpath = GlobalData.getCommandSetting(key, fpdModuleId);\r
             if (dpath != null) {\r
                 getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));\r
-            }\r
-            else {\r
+            } else {\r
                 getProject().setProperty(cmd[m] + "_DPATH", "");\r
             }\r
         }\r
@@ -543,7 +535,7 @@ public class GenBuildTask extends Ant {
         this.type = type;\r
     }\r
 \r
-    private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException{\r
+    private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws BuildException{\r
         //\r
         // AutoGen\r
         //\r
@@ -555,8 +547,13 @@ public class GenBuildTask extends Ant {
         //\r
         // Get compiler flags\r
         //\r
-        getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r
-\r
+        try {\r
+            getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r
+        }\r
+        catch (EdkException ee) {\r
+            throw new BuildException(ee.getMessage());\r
+        }\r
+        \r
         //\r
         // Prepare LIBS\r
         //\r
@@ -573,12 +570,10 @@ public class GenBuildTask extends Ant {
         //\r
         if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
             GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r
-            Ant ant = new Ant();\r
-            ant.setProject(getProject());\r
-            ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
-            ant.setInheritAll(true);\r
-            ant.init();\r
-            ant.execute();\r
+            \r
+            String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+            antCall(antFilename, null);\r
+            \r
             return ;\r
         }\r
 \r
@@ -594,12 +589,8 @@ public class GenBuildTask extends Ant {
         //\r
         // Ant call ${BASE_NAME}_build.xml\r
         //\r
-        Ant ant = new Ant();\r
-        ant.setProject(getProject());\r
-        ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
-        ant.setInheritAll(true);\r
-        ant.init();\r
-        ant.execute();\r
+        String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+        antCall(antFilename, null);\r
     }\r
 \r
     private void applyClean(FpdModuleIdentification fpdModuleId){\r
@@ -609,27 +600,15 @@ public class GenBuildTask extends Ant {
         //\r
         if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
             GlobalData.log.info("Calling user-defined " + moduleId.getName() + "_build.xml");\r
-            Ant ant = new Ant();\r
-            ant.setProject(getProject());\r
-            ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
-            ant.setTarget("clean");\r
-            ant.setInheritAll(true);\r
-            ant.init();\r
-            ant.execute();\r
+            \r
+            String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+            antCall(antFilename, "clean");\r
+            \r
             return ;\r
         }\r
 \r
-        Ant ant = new Ant();\r
-        ant.setProject(getProject());\r
-        ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
-        ant.setTarget("clean");\r
-        ant.setInheritAll(true);\r
-        ant.init();\r
-        ant.execute();\r
-\r
-        //\r
-        // Delete current module's DEST_DIR_OUTPUT\r
-        // TBD\r
+        String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+        antCall(antFilename, "clean");\r
     }\r
 \r
     private void applyCleanall(FpdModuleIdentification fpdModuleId){\r
@@ -639,32 +618,30 @@ public class GenBuildTask extends Ant {
         //\r
         if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
             GlobalData.log.info("Calling user-defined " + moduleId.getName() + "_build.xml");\r
-            Ant ant = new Ant();\r
-            ant.setProject(getProject());\r
-            ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
-            ant.setTarget("cleanall");\r
-            ant.setInheritAll(true);\r
-            ant.init();\r
-            ant.execute();\r
+\r
+            String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+            antCall(antFilename, "cleanall");\r
+            \r
             return ;\r
         }\r
+        \r
+        String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+        antCall(antFilename, "cleanall");\r
+    }\r
 \r
+    private void antCall(String antFilename, String target) {\r
         Ant ant = new Ant();\r
         ant.setProject(getProject());\r
-        ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
-        ant.setTarget("cleanall");\r
+        ant.setAntfile(antFilename);\r
+        if (target != null) {\r
+            ant.setTarget(target);\r
+        }\r
         ant.setInheritAll(true);\r
         ant.init();\r
         ant.execute();\r
-\r
-        //\r
-        // Delete current module's DEST_DIR_OUTPUT\r
-        // TBD\r
     }\r
 \r
 \r
-\r
-\r
     /**\r
       Separate the string and instore in set.\r
 \r