X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=inline;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2FFrameworkBuildTask.java;h=d1bf1cc90aa3107b6aa057386666413bb5aa398f;hb=d3945b9d4c002588ef0d01bd1b8d91848f7fc235;hp=88e1a20e5e93a2089219ee5fa371e702ce4e64d6;hpb=c773bec060fad36cc7b65fba89f8f8c388657424;p=mirror_edk2.git
diff --git a/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java
index 88e1a20e5e..d1bf1cc90a 100644
--- a/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java
+++ b/Tools/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java
@@ -15,7 +15,9 @@ package org.tianocore.build;
import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
@@ -23,12 +25,55 @@ import java.util.Set;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
+import org.tianocore.build.exception.AutoGenException;
+import org.tianocore.build.exception.GenBuildException;
+import org.tianocore.build.exception.PcdAutogenException;
+import org.tianocore.build.exception.PlatformPcdPreprocessBuildException;
+import org.tianocore.build.fpd.FpdParserForThread;
import org.tianocore.build.fpd.FpdParserTask;
+import org.tianocore.build.global.GenBuildLogger;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.toolchain.ConfigReader;
-import org.tianocore.build.toolchain.ToolChainConfig;
import org.tianocore.build.toolchain.ToolChainInfo;
+import org.tianocore.common.definitions.ToolDefinitions;
+import org.tianocore.common.exception.EdkException;
+import org.tianocore.common.logger.EdkLog;
+/**
+
+ FrameworkBuildTask
is an Ant task. The main function is finding
+ and processing a FPD or MSA file, then building a platform or stand-alone
+ module.
+
+
+ The task search current directory and find out all MSA and FPD files by file
+ extension. Base on ACTIVE_PLATFORM policy, decide to build a platform or a
+ stand-alone module. The ACTIVE_PLATFORM policy is:
+
+
+ 1. More than one MSA files, report error;
+ 2. Only one MSA file, but ACTIVE_PLATFORM is not specified, report error;
+ 3. Only one MSA file, and ACTIVE_PLATFORM is also specified, build this module;
+ 4. No MSA file, and ACTIVE_PLATFORM is specified, build the active platform;
+ 5. No MSA file, no ACTIVE_PLATFORM, and no FPD file, report error;
+ 6. No MSA file, no ACTIVE_PLATFORM, and only one FPD file, build the platform;
+ 7. No MSA file, no ACTIVE_PLATFORM, and more than one FPD files, list all platform
+ and let user choose one.
+
+
+
+ Framework build task also parse target file [${WORKSPACE_DIR}/Tools/Conf/target.txt].
+ And load all system environment variables to Ant properties.
+
+
+ The usage for this task is :
+
+
+ <FrameworkBuild type="cleanall" />
+
+
+ @since GenBuild 1.0
+**/
public class FrameworkBuildTask extends Task{
private Set buildFiles = new LinkedHashSet();
@@ -37,18 +82,73 @@ public class FrameworkBuildTask extends Task{
private Set msaFiles = new LinkedHashSet();
- String toolsDefFilename = "Tools" + File.separatorChar + "Conf" + File.separatorChar + "tools_def.txt";
+ //
+ // This is only for none-multi-thread build to reduce overriding message
+ //
+ public static Hashtable originalProperties = new Hashtable();
- String targetFilename = "target.txt";
+ String toolsDefFilename = ToolDefinitions.DEFAULT_TOOLS_DEF_FILE_PATH;
- String activePlatform = null;
+ String targetFilename = ToolDefinitions.TARGET_FILE_PATH;
+
+ String dbFilename = ToolDefinitions.FRAMEWORK_DATABASE_FILE_PATH;
+ String activePlatform = null;
+
+ ///
+ /// The flag to present current is multi-thread enabled
+ ///
+ public static boolean multithread = false;
+
+ ///
+ /// The concurrent thread number
+ ///
+ public static int MAX_CONCURRENT_THREAD_NUMBER = 2;
+
///
/// there are three type: all (build), clean and cleanall
///
private String type = "all";
public void execute() throws BuildException {
+ //
+ // set Logger
+ //
+ GenBuildLogger logger = new GenBuildLogger(getProject());
+ EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
+ EdkLog.setLogger(logger);
+
+ try {
+ processFrameworkBuild();
+ } catch (PcdAutogenException e) {
+ //
+ // Add more logic process here
+ //
+ throw new BuildException(e.getMessage());
+ } catch (AutoGenException e) {
+ //
+ // Add more logic process here
+ //
+ throw new BuildException(e.getMessage());
+ } catch (PlatformPcdPreprocessBuildException e) {
+ //
+ // Add more logic process here
+ //
+ throw new BuildException(e.getMessage());
+ } catch (GenBuildException e) {
+ //
+ // Add more logic process here
+ //
+ throw new BuildException(e.getMessage());
+ } catch (EdkException e) {
+ //
+ // Add more logic process here
+ //
+ throw new BuildException(e.getMessage());
+ }
+ }
+
+ private void processFrameworkBuild() throws EdkException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException {
//
// Seach build.xml -> .FPD -> .MSA file
//
@@ -67,12 +167,12 @@ public class FrameworkBuildTask extends Task{
//
buildFiles.add(files[i]);
- } else if (files[i].getName().endsWith(".fpd")) {
+ } else if (files[i].getName().endsWith(ToolDefinitions.FPD_EXTENSION)) {
//
// Second, search FPD file, if found, build it
//
fpdFiles.add(files[i]);
- } else if (files[i].getName().endsWith(".msa")) {
+ } else if (files[i].getName().endsWith(ToolDefinitions.MSA_EXTENSION)) {
//
// Third, search MSA file, if found, build it
//
@@ -80,9 +180,10 @@ public class FrameworkBuildTask extends Task{
}
}
}
- } catch (Exception e) {
- e.printStackTrace();
- throw new BuildException(e.getMessage());
+ } catch (IOException ex) {
+ BuildException buildException = new BuildException("Scanning current directory error. \n" + ex.getMessage());
+ buildException.setStackTrace(ex.getStackTrace());
+ throw buildException;
}
//
@@ -98,10 +199,9 @@ public class FrameworkBuildTask extends Task{
//
// Global Data initialization
//
- GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",
- getProject().getProperty("WORKSPACE_DIR"), toolsDefFilename);
-
-
+ File workspacePath = new File(getProject().getProperty("WORKSPACE"));
+ getProject().setProperty("WORKSPACE_DIR", workspacePath.getPath().replaceAll("(\\\\)", "/"));
+ GlobalData.initInfo(dbFilename, workspacePath.getPath(), toolsDefFilename);
//
// If find MSA file and ACTIVE_PLATFORM is set, build the module;
@@ -112,57 +212,83 @@ public class FrameworkBuildTask extends Task{
//
File buildFile = null;
if (msaFiles.size() > 1) {
- throw new BuildException("More than one MSA file under current directory. It is not allowd. ");
- }
- else if (msaFiles.size() == 1 && activePlatform == null) {
- throw new BuildException("If try to build a single module, please set ACTIVE_PLATFORM in file [Tool/Conf/target.txt]. ");
- }
- else if (msaFiles.size() == 1 && activePlatform != null) {
+ throw new BuildException("Having more than one MSA file in a directory is not allowed!");
+ } else if (msaFiles.size() == 1 && activePlatform == null) {
+ throw new BuildException("If trying to build a single module, please set ACTIVE_PLATFORM in file [" + targetFilename + "]. ");
+ } else if (msaFiles.size() == 1 && activePlatform != null) {
//
// Build the single module
//
buildFile = msaFiles.toArray(new File[1])[0];
- }
- else if (activePlatform != null) {
+ } else if (activePlatform != null) {
buildFile = new File(GlobalData.getWorkspacePath() + File.separatorChar + activePlatform);
- }
- else if (fpdFiles.size() == 1) {
+ } else if (fpdFiles.size() == 1) {
buildFile = fpdFiles.toArray(new File[1])[0];
- }
- else if (fpdFiles.size() > 1) {
+ } else if (fpdFiles.size() > 1) {
buildFile = intercommuniteWithUser();
}
//
// If there is no build files or FPD files or MSA files, stop build
//
else {
- throw new BuildException("Can't find any FPD files or MSA files in current directory. ");
+ throw new BuildException("Can't find any FPD or MSA files in the current directory. ");
}
//
// Build every FPD files (PLATFORM build)
//
- if (buildFile.getName().endsWith(".fpd")) {
- System.out.println("Start to build FPD file [" + buildFile.getPath() + "] ..>> ");
+ if (buildFile.getName().endsWith(ToolDefinitions.FPD_EXTENSION)) {
+ EdkLog.log(this, "Processing the FPD file [" + buildFile.getPath() + "] ..>> ");
+ //
+ // Iff for platform build will enable the multi-thread if set in target.txt
+ //
+ if (multithread && type.equalsIgnoreCase("all")) {
+ EdkLog.log(this, "Multi-thread build is enabled. ");
+ FpdParserForThread fpdParserForThread = new FpdParserForThread();
+ fpdParserForThread.setType(type);
+ fpdParserForThread.setProject(getProject());
+ fpdParserForThread.setFpdFile(buildFile);
+ fpdParserForThread.perform();
+ return ;
+ }
+
FpdParserTask fpdParserTask = new FpdParserTask();
fpdParserTask.setType(type);
fpdParserTask.setProject(getProject());
fpdParserTask.setFpdFile(buildFile);
- fpdParserTask.execute();
+ fpdParserTask.perform();
+
+ //
+ // If cleanall delete the Platform_build.xml
+ //
+ if (type.compareTo("cleanall") == 0) {
+ File platformBuildFile =
+ new File(getProject().getProperty("BUILD_DIR")
+ + File.separatorChar
+ + getProject().getProperty("PLATFORM")
+ + "_build.xml");
+ platformBuildFile.deleteOnExit();
+ }
}
//
// Build every MSA files (SINGLE MODULE BUILD)
//
- else if (buildFile.getName().endsWith(".msa")) {
- System.out.println("Start to build MSA file [" + buildFile.getPath() + "] ..>> ");
+ else if (buildFile.getName().endsWith(ToolDefinitions.MSA_EXTENSION)) {
+ multithread = false;
+ File tmpFile = new File(GlobalData.getWorkspacePath() + File.separatorChar + activePlatform);
+ EdkLog.log(this, "Using the FPD file [" + tmpFile.getPath() + "] for the active platform. ");
+ EdkLog.log(this, "Processing the MSA file [" + buildFile.getPath() + "] ..>> ");
GenBuildTask genBuildTask = new GenBuildTask();
genBuildTask.setSingleModuleBuild(true);
genBuildTask.setType(type);
getProject().setProperty("PLATFORM_FILE", activePlatform);
+ if( !multithread) {
+ originalProperties.put("PLATFORM_FILE", activePlatform);
+ }
genBuildTask.setProject(getProject());
genBuildTask.setMsaFile(buildFile);
- genBuildTask.execute();
+ genBuildTask.perform();
}
}
@@ -173,8 +299,7 @@ public class FrameworkBuildTask extends Task{
**/
private void backupSystemProperties() {
Map sysProperties = System.getenv();
- Set keys = sysProperties.keySet();
- Iterator iter = keys.iterator();
+ Iterator iter = sysProperties.keySet().iterator();
while (iter.hasNext()) {
String name = iter.next();
@@ -185,30 +310,33 @@ public class FrameworkBuildTask extends Task{
getProject().setProperty(name, sysProperties.get(name));
}
}
+
+ Hashtable allProperties = getProject().getProperties();
+ Iterator piter = allProperties.keySet().iterator();
+ while (piter.hasNext()) {
+ String name = (String)piter.next();
+ originalProperties.put(new String(name), new String((String)allProperties.get(name)));
+ }
}
private File intercommuniteWithUser(){
File file = null;
- if (fpdFiles.size() + msaFiles.size() > 1) {
- File[] allFiles = new File[fpdFiles.size() + msaFiles.size()];
+ if (fpdFiles.size() > 1) {
+ File[] allFiles = new File[fpdFiles.size()];
int index = 0;
Iterator iter = fpdFiles.iterator();
while (iter.hasNext()) {
allFiles[index] = iter.next();
index++;
}
- iter = msaFiles.iterator();
- while (iter.hasNext()) {
- allFiles[index] = iter.next();
- index++;
- }
- System.out.println("Find " + allFiles.length + " FPD and MSA files: ");
+
+ EdkLog.log(this, "Finding " + allFiles.length + " FPD files: ");
for (int i = 0; i < allFiles.length; i++) {
System.out.println("[" + (i + 1) + "]: " + allFiles[i].getName());
}
boolean flag = true;
- System.out.print("Please select one file to build:[1] ");
+ EdkLog.log(this, "Please select one of the following FPD files to build:[1] ");
do{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
@@ -220,7 +348,7 @@ public class FrameworkBuildTask extends Task{
}
int indexSelect = Integer.parseInt(str);
if (indexSelect <=0 || indexSelect > allFiles.length) {
- System.out.print("Please enter a number between [1.." + allFiles.length + "]:[1] ");
+ EdkLog.log(this, "Please enter a number between [1.." + allFiles.length + "]:[1] ");
continue ;
} else {
file = allFiles[indexSelect - 1];
@@ -228,17 +356,13 @@ public class FrameworkBuildTask extends Task{
continue ;
}
} catch (Exception e) {
- System.out.print("Please enter a valid number:[1] ");
+ EdkLog.log(this, "Please enter a valid number:[1] ");
flag = true;
}
} while (flag);
- }
- else if (fpdFiles.size() == 1) {
+ } else if (fpdFiles.size() == 1) {
file = fpdFiles.toArray(new File[1])[0];
}
- else if (msaFiles.size() == 1) {
- file = msaFiles.toArray(new File[1])[0];
- }
return file;
}
@@ -246,59 +370,68 @@ public class FrameworkBuildTask extends Task{
public void setType(String type) {
if (type.equalsIgnoreCase("clean") || type.equalsIgnoreCase("cleanall")) {
this.type = type.toLowerCase();
- }
- else {
+ } else {
this.type = "all";
}
}
- private void readTargetFile(){
- try {
- String[][] targetFileInfo = ConfigReader.parse(getProject().getProperty("WORKSPACE_DIR"), "Tools" + File.separatorChar + "Conf" + File.separatorChar + targetFilename);
-
- //
- // Get ToolChain Info from target.txt
- //
- ToolChainInfo envToolChainInfo = new ToolChainInfo();
- String str = getValue("TARGET", targetFileInfo);
- if (str == null || str.trim().equals("")) {
- envToolChainInfo.addTargets("*");
- }
- else {
- envToolChainInfo.addTargets(str);
- }
- str = getValue("TOOL_CHAIN_TAG", targetFileInfo);
- if (str == null || str.trim().equals("")) {
- envToolChainInfo.addTagnames("*");
- }
- else {
- envToolChainInfo.addTagnames(str);
- }
- str = getValue("TARGET_ARCH", targetFileInfo);
- if (str == null || str.trim().equals("")) {
- envToolChainInfo.addArchs("*");
- }
- else {
- envToolChainInfo.addArchs(str);
- }
- GlobalData.setToolChainEnvInfo(envToolChainInfo);
-
- str = getValue("TOOL_CHAIN_CONF", targetFileInfo);
- if (str != null) {
- toolsDefFilename = str;
+ private void readTargetFile() throws EdkException{
+ String targetFile = getProject().getProperty("WORKSPACE_DIR") + File.separatorChar + targetFilename;
+
+ String[][] targetFileInfo = ConfigReader.parse(targetFile);
+
+ //
+ // Get ToolChain Info from target.txt
+ //
+ ToolChainInfo envToolChainInfo = new ToolChainInfo();
+ String str = getValue(ToolDefinitions.TARGET_KEY_TARGET, targetFileInfo);
+ if (str == null || str.trim().equals("")) {
+ envToolChainInfo.addTargets("*");
+ } else {
+ envToolChainInfo.addTargets(str);
+ }
+ str = getValue(ToolDefinitions.TARGET_KEY_TOOLCHAIN, targetFileInfo);
+ if (str == null || str.trim().equals("")) {
+ envToolChainInfo.addTagnames("*");
+ } else {
+ envToolChainInfo.addTagnames(str);
+ }
+ str = getValue(ToolDefinitions.TARGET_KEY_ARCH, targetFileInfo);
+ if (str == null || str.trim().equals("")) {
+ envToolChainInfo.addArchs("*");
+ } else {
+ envToolChainInfo.addArchs(str);
+ }
+ GlobalData.setToolChainEnvInfo(envToolChainInfo);
+
+ str = getValue(ToolDefinitions.TARGET_KEY_TOOLS_DEF, targetFileInfo);
+ if (str != null && str.trim().length() > 0) {
+ toolsDefFilename = str;
+ }
+
+ str = getValue(ToolDefinitions.TARGET_KEY_ACTIVE_PLATFORM, targetFileInfo);
+ if (str != null && ! str.trim().equals("")) {
+ if ( ! str.endsWith(".fpd")) {
+ throw new BuildException("FPD file's extension must be \"" + ToolDefinitions.FPD_EXTENSION + "\"!");
}
-
- str = getValue("ACTIVE_PLATFORM", targetFileInfo);
- if (str != null && ! str.trim().equals("")) {
- if ( ! str.endsWith(".fpd")) {
- throw new BuildException("FPD file's file extension must be \".fpd\"");
+ activePlatform = str;
+ }
+
+ str = getValue(ToolDefinitions.TARGET_KEY_MULTIPLE_THREAD, targetFileInfo);
+ if (str != null && str.trim().equalsIgnoreCase("Enable")) {
+ multithread = true;
+ }
+
+ str = getValue(ToolDefinitions.TARGET_KEY_MAX_CONCURRENT_THREAD_NUMBER, targetFileInfo);
+ if (str != null ) {
+ try {
+ int threadNum = Integer.parseInt(str);
+ if (threadNum > 0) {
+ MAX_CONCURRENT_THREAD_NUMBER = threadNum;
}
- activePlatform = str;
+ } catch (Exception ex) {
}
}
- catch (Exception ex) {
- throw new BuildException(ex.getMessage());
- }
}
private String getValue(String key, String[][] map) {