]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java
Add class header to FrameworkBuildTask. Remove some unused code from top level build...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / FrameworkBuildTask.java
index b9afc57bad39774a4ea23e976f0068eb7d69c6fe..fe7a8ce70da7475efe752f7ae7e843e41b46fb83 100644 (file)
@@ -1,3 +1,16 @@
+/** @file FrameworkBuildTask.java\r
+  \r
+  The file is ANT task to find MSA or FPD file and build them. \r
\r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution.  The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ **/\r
 package org.tianocore.build;\r
 \r
 import java.io.BufferedReader;\r
@@ -12,8 +25,45 @@ import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;\r
 import org.tianocore.build.fpd.FpdParserTask;\r
 import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.toolchain.ConfigReader;\r
 import org.tianocore.build.toolchain.ToolChainInfo;\r
+import org.tianocore.common.definitions.ToolDefinitions;\r
 \r
+/**\r
+  <p>\r
+  <code>FrameworkBuildTask</code> is an Ant task. The main function is finding\r
+  and processing a FPD or MSA file, then building a platform or stand-alone \r
+  module. \r
+  \r
+  <p>\r
+  The task search current directory and find out all MSA and FPD files by file\r
+  extension. Base on ACTIVE_PLATFORM policy, decide to build a platform or a\r
+  stand-alone module. The ACTIVE_PLATFORM policy is: \r
+  \r
+  <pre>\r
+  1. More than one MSA files, report error; \r
+  2. Only one MSA file, but ACTIVE_PLATFORM is not specified, report error;\r
+  3. Only one MSA file, and ACTIVE_PLATFORM is also specified, build this module;\r
+  4. No MSA file, and ACTIVE_PLATFORM is specified, build the active platform;\r
+  5. No MSA file, no ACTIVE_PLATFORM, and no FPD file, report error;\r
+  6. No MSA file, no ACTIVE_PLATFORM, and only one FPD file, build the platform;\r
+  7. No MSA file, no ACTIVE_PLATFORM, and more than one FPD files, list all platform\r
+  and let user choose one. \r
+  </pre>\r
+  \r
+  <p>\r
+  Framework build task also parse target file [${WORKSPACE_DIR}/Tools/Conf/target.txt].\r
+  And load all system environment variables to Ant properties.  \r
+  \r
+  <p>\r
+  The usage for this task is : \r
+  \r
+  <pre>\r
+  &lt;FrameworkBuild type="cleanall" /&gt;\r
+  </pre>\r
+  \r
+  @since GenBuild 1.0\r
+**/\r
 public class FrameworkBuildTask extends Task{\r
 \r
     private Set<File> buildFiles = new LinkedHashSet<File>();\r
@@ -22,6 +72,14 @@ public class FrameworkBuildTask extends Task{
     \r
     private Set<File> msaFiles = new LinkedHashSet<File>();\r
     \r
+    String toolsDefFilename = ToolDefinitions.DEFAULT_TOOLS_DEF_FILE_PATH;\r
+    \r
+    String targetFilename = ToolDefinitions.TARGET_FILE_PATH;\r
+    \r
+    String dbFilename = ToolDefinitions.FRAMEWORK_DATABASE_FILE_PATH;\r
+    \r
+    String activePlatform = null;\r
+    \r
     ///\r
     /// there are three type: all (build), clean and cleanall\r
     ///\r
@@ -46,12 +104,12 @@ public class FrameworkBuildTask extends Task{
                         //\r
                         buildFiles.add(files[i]);\r
 \r
-                    } else if (files[i].getName().endsWith(".fpd")) {\r
+                    } else if (files[i].getName().endsWith(ToolDefinitions.FPD_EXTENSION)) {\r
                         //\r
                         // Second, search FPD file, if found, build it\r
                         //\r
                         fpdFiles.add(files[i]);\r
-                    } else if (files[i].getName().endsWith(".msa")) {\r
+                    } else if (files[i].getName().endsWith(ToolDefinitions.MSA_EXTENSION)) {\r
                         //\r
                         // Third, search MSA file, if found, build it\r
                         //\r
@@ -60,49 +118,62 @@ public class FrameworkBuildTask extends Task{
                 }\r
             }\r
         } catch (Exception e) {\r
-            e.printStackTrace();\r
             throw new BuildException(e.getMessage());\r
         }\r
         \r
-        //\r
-        // If there is no build files or FPD files or MSA files, stop build\r
-        //\r
-        if (fpdFiles.size() == 0 && msaFiles.size() == 0) {\r
-            throw new BuildException("Can't find any build.xml file or FPD files or MSA files in current directory. ");\r
-        }\r
-        \r
-        File buildFile = intercommuniteWithUser();\r
-        System.out.println("Start to build file [" + buildFile.getPath() + "] ..>> ");\r
-        \r
         //\r
         // Deal with all environment variable (Add them to properties)\r
         //\r
         backupSystemProperties();\r
         \r
         //\r
-        // Get ToolChain Info from environment\r
+        // Read target.txt file\r
         //\r
-        ToolChainInfo envToolChainInfo = new ToolChainInfo(); \r
-        envToolChainInfo.addTargets(getProject().getProperty("TARGET")); \r
-        envToolChainInfo.addTagnames(getProject().getProperty("TAGNAME")); \r
-        envToolChainInfo.addArchs(getProject().getProperty("ARCH")); \r
-        GlobalData.setToolChainEnvInfo(envToolChainInfo);\r
-        \r
+        readTargetFile();\r
+\r
         //\r
         // Global Data initialization\r
         //\r
-        String toolsDefFilename = "tools_def.txt";\r
-        if (getProject().getProperty("TOOLS_DEF") != null) {\r
-            toolsDefFilename = getProject().getProperty("TOOLS_DEF");\r
-        }\r
-        \r
-        GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",\r
-                            getProject().getProperty("WORKSPACE_DIR"), toolsDefFilename);\r
+        File workspacePath = new File(getProject().getProperty("WORKSPACE"));\r
+        getProject().setProperty("WORKSPACE_DIR", workspacePath.getPath().replaceAll("(\\\\)", "/"));\r
+        GlobalData.initInfo(dbFilename, workspacePath.getPath(), toolsDefFilename);\r
         \r
+        //\r
+        // If find MSA file and ACTIVE_PLATFORM is set, build the module; \r
+        // else fail build. \r
+        // If without MSA file, and ACTIVE_PLATFORM is set, build the ACTIVE_PLATFORM. \r
+        // If ACTIVE_PLATFORM is not set, and only find one FPD file, build the platform; \r
+        // If find more than one FPD files, let user select one. \r
+        //\r
+        File buildFile = null;\r
+        if (msaFiles.size() > 1) {\r
+            throw new BuildException("Having more than one MSA file in a directory is not allowed!");\r
+        } else if (msaFiles.size() == 1 && activePlatform == null) {\r
+            throw new BuildException("If trying to build a single module, please set ACTIVE_PLATFORM in file [" + targetFilename + "]. ");\r
+        } else if (msaFiles.size() == 1 && activePlatform != null) {\r
+            //\r
+            // Build the single module\r
+            //\r
+            buildFile = msaFiles.toArray(new File[1])[0];\r
+        } else if (activePlatform != null) {\r
+            buildFile = new File(GlobalData.getWorkspacePath() + File.separatorChar + activePlatform);\r
+        } else if (fpdFiles.size() == 1) {\r
+            buildFile = fpdFiles.toArray(new File[1])[0];\r
+        } else if (fpdFiles.size() > 1) {\r
+            buildFile = intercommuniteWithUser();\r
+        }\r
+        //\r
+        // If there is no build files or FPD files or MSA files, stop build\r
+        //\r
+        else {\r
+            throw new BuildException("Can't find any FPD or MSA files in the current directory. ");\r
+        }\r
+\r
         //\r
         // Build every FPD files (PLATFORM build)\r
         //\r
-        if (buildFile.getName().endsWith(".fpd")) {\r
+        if (buildFile.getName().endsWith(ToolDefinitions.FPD_EXTENSION)) {\r
+            System.out.println("Processing the FPD file [" + buildFile.getPath() + "] ..>> ");\r
             FpdParserTask fpdParserTask = new FpdParserTask();\r
             fpdParserTask.setType(type);\r
             fpdParserTask.setProject(getProject());\r
@@ -113,9 +184,14 @@ public class FrameworkBuildTask extends Task{
         //\r
         // Build every MSA files (SINGLE MODULE BUILD)\r
         //\r
-        else if (buildFile.getName().endsWith(".msa")) {\r
+        else if (buildFile.getName().endsWith(ToolDefinitions.MSA_EXTENSION)) {\r
+            File tmpFile = new File(GlobalData.getWorkspacePath() + File.separatorChar + activePlatform);\r
+            System.out.println("Using the FPD file [" + tmpFile.getPath() + "] for the active platform. ");\r
+            System.out.println("Processing the MSA file [" + buildFile.getPath() + "] ..>> ");\r
             GenBuildTask genBuildTask = new GenBuildTask();\r
+            genBuildTask.setSingleModuleBuild(true);\r
             genBuildTask.setType(type);\r
+            getProject().setProperty("PLATFORM_FILE", activePlatform);\r
             genBuildTask.setProject(getProject());\r
             genBuildTask.setMsaFile(buildFile);\r
             genBuildTask.execute();\r
@@ -145,26 +221,22 @@ public class FrameworkBuildTask extends Task{
 \r
     private File intercommuniteWithUser(){\r
         File file = null;\r
-        if (fpdFiles.size() + msaFiles.size() > 1) {\r
-            File[] allFiles = new File[fpdFiles.size() + msaFiles.size()];\r
+        if (fpdFiles.size() > 1) {\r
+            File[] allFiles = new File[fpdFiles.size()];\r
             int index = 0;\r
             Iterator<File> iter = fpdFiles.iterator();\r
             while (iter.hasNext()) {\r
                 allFiles[index] = iter.next();\r
                 index++;\r
             }\r
-            iter = msaFiles.iterator();\r
-            while (iter.hasNext()) {\r
-                allFiles[index] = iter.next();\r
-                index++;\r
-            }\r
-            System.out.println("Find " + allFiles.length + " FPD and MSA files: ");\r
+\r
+            System.out.println("Finding " + allFiles.length + " FPD files: ");\r
             for (int i = 0; i < allFiles.length; i++) {\r
                 System.out.println("[" + (i + 1) + "]: " + allFiles[i].getName());\r
             }\r
             \r
             boolean flag = true;\r
-            System.out.print("Please select one file to build:[1] ");\r
+            System.out.print("Please select one of the following FPD files to build:[1] ");\r
             do{\r
                 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r
                 try {\r
@@ -188,13 +260,9 @@ public class FrameworkBuildTask extends Task{
                     flag = true;\r
                 }\r
             } while (flag);\r
-        }\r
-        else if (fpdFiles.size() == 1) {\r
+        } else if (fpdFiles.size() == 1) {\r
             file = fpdFiles.toArray(new File[1])[0];\r
         }\r
-        else if (msaFiles.size() == 1) {\r
-            file = msaFiles.toArray(new File[1])[0];\r
-        }\r
         return file;\r
     }\r
     \r
@@ -202,9 +270,65 @@ public class FrameworkBuildTask extends Task{
     public void setType(String type) {\r
         if (type.equalsIgnoreCase("clean") || type.equalsIgnoreCase("cleanall")) {\r
             this.type = type.toLowerCase();\r
-        }\r
-        else {\r
+        } else {\r
             this.type = "all";\r
         }\r
     }\r
+    \r
+    private void readTargetFile(){\r
+        try {\r
+            String targetFile = getProject().getProperty("WORKSPACE_DIR") + File.separatorChar + targetFilename;\r
+            \r
+            String[][] targetFileInfo = ConfigReader.parse(targetFile);\r
+            \r
+            //\r
+            // Get ToolChain Info from target.txt\r
+            //\r
+            ToolChainInfo envToolChainInfo = new ToolChainInfo(); \r
+            String str = getValue(ToolDefinitions.TARGET_KEY_TARGET, targetFileInfo);\r
+            if (str == null || str.trim().equals("")) {\r
+                envToolChainInfo.addTargets("*");\r
+            } else {\r
+                envToolChainInfo.addTargets(str);\r
+            }\r
+            str = getValue(ToolDefinitions.TARGET_KEY_TOOLCHAIN, targetFileInfo);\r
+            if (str == null || str.trim().equals("")) {\r
+                envToolChainInfo.addTagnames("*");\r
+            } else {\r
+                envToolChainInfo.addTagnames(str);\r
+            }\r
+            str = getValue(ToolDefinitions.TARGET_KEY_ARCH, targetFileInfo);\r
+            if (str == null || str.trim().equals("")) {\r
+                envToolChainInfo.addArchs("*");\r
+            } else {\r
+                envToolChainInfo.addArchs(str);\r
+            }\r
+            GlobalData.setToolChainEnvInfo(envToolChainInfo);\r
+            \r
+            str = getValue(ToolDefinitions.TARGET_KEY_TOOLS_DEF, targetFileInfo);\r
+            if (str != null && str.trim().length() > 0) {\r
+                toolsDefFilename = str;\r
+            }\r
+            \r
+            str = getValue(ToolDefinitions.TARGET_KEY_ACTIVE_PLATFORM, targetFileInfo);\r
+            if (str != null && ! str.trim().equals("")) {\r
+                if ( ! str.endsWith(".fpd")) {\r
+                    throw new BuildException("FPD file's extension must be \"" + ToolDefinitions.FPD_EXTENSION + "\"!");\r
+                }\r
+                activePlatform = str;\r
+            }\r
+        }\r
+        catch (Exception ex) {\r
+            throw new BuildException(ex.getMessage());\r
+        }\r
+    }\r
+    \r
+    private String getValue(String key, String[][] map) {\r
+        for (int i = 0; i < map[0].length; i++){\r
+            if (key.equalsIgnoreCase(map[0][i])) {\r
+                return map[1][i];\r
+            }\r
+        }\r
+        return null;\r
+    }\r
 }\r