+/** @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
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.ToolChainConfig;\r
import org.tianocore.build.toolchain.ToolChainInfo;\r
\r
public class FrameworkBuildTask extends Task{\r
\r
private Set<File> msaFiles = new LinkedHashSet<File>();\r
\r
+ String toolsDefFilename = "Tools" + File.separatorChar + "Conf" + File.separatorChar + "tools_def.txt";\r
+ \r
+ String targetFilename = "target.txt";\r
+ \r
+ String activePlatform = null;\r
+ \r
///\r
/// there are three type: all (build), clean and cleanall\r
///\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
\r
+\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("More than one MSA file under current directory. It is not allowd. ");\r
+ }\r
+ else if (msaFiles.size() == 1 && activePlatform == null) {\r
+ throw new BuildException("If try to build a single module, please set ACTIVE_PLATFORM in file [Tool/Conf/target.txt]. ");\r
+ }\r
+ else if (msaFiles.size() == 1 && activePlatform != null) {\r
+ //\r
+ // Build the single module\r
+ //\r
+ buildFile = msaFiles.toArray(new File[1])[0];\r
+ }\r
+ else if (activePlatform != null) {\r
+ buildFile = new File(GlobalData.getWorkspacePath() + File.separatorChar + activePlatform);\r
+ }\r
+ else if (fpdFiles.size() == 1) {\r
+ buildFile = fpdFiles.toArray(new File[1])[0];\r
+ }\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 files or MSA files in current directory. ");\r
+ }\r
+\r
//\r
// Build every FPD files (PLATFORM build)\r
//\r
if (buildFile.getName().endsWith(".fpd")) {\r
+ System.out.println("Start to build FPD file [" + buildFile.getPath() + "] ..>> ");\r
FpdParserTask fpdParserTask = new FpdParserTask();\r
fpdParserTask.setType(type);\r
fpdParserTask.setProject(getProject());\r
// Build every MSA files (SINGLE MODULE BUILD)\r
//\r
else if (buildFile.getName().endsWith(".msa")) {\r
+ System.out.println("Start to build 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
this.type = "all";\r
}\r
}\r
+ \r
+ private void readTargetFile(){\r
+ try {\r
+ String[][] targetFileInfo = ConfigReader.parse(getProject().getProperty("WORKSPACE_DIR"), "Tools" + File.separatorChar + "Conf" + File.separatorChar + targetFilename);\r
+ \r
+ //\r
+ // Get ToolChain Info from target.txt\r
+ //\r
+ ToolChainInfo envToolChainInfo = new ToolChainInfo(); \r
+ String str = getValue("TARGET", targetFileInfo);\r
+ if (str == null || str.trim().equals("")) {\r
+ envToolChainInfo.addTargets("*");\r
+ }\r
+ else {\r
+ envToolChainInfo.addTargets(str);\r
+ }\r
+ str = getValue("TAGNAME", targetFileInfo);\r
+ if (str == null || str.trim().equals("")) {\r
+ envToolChainInfo.addTagnames("*");\r
+ }\r
+ else {\r
+ envToolChainInfo.addTagnames(str);\r
+ }\r
+ str = getValue("TARGET_ARCH", targetFileInfo);\r
+ if (str == null || str.trim().equals("")) {\r
+ envToolChainInfo.addArchs("*");\r
+ }\r
+ else {\r
+ envToolChainInfo.addArchs(str);\r
+ }\r
+ GlobalData.setToolChainEnvInfo(envToolChainInfo);\r
+ \r
+ str = getValue("TOOLS_DEFINITION_FILE", targetFileInfo);\r
+ if (str != null) {\r
+ toolsDefFilename = str;\r
+ }\r
+ \r
+ str = getValue("ACTIVE_PLATFORM", targetFileInfo);\r
+ if (str != null && ! str.trim().equals("")) {\r
+ if ( ! str.endsWith(".fpd")) {\r
+ throw new BuildException("FPD file's file extension must be \".fpd\"");\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