Backup original properties to avoid property overriding message. This change is for multi-thread build preparations. (3)

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1438 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
wuyizhong 2006-09-04 07:13:01 +00:00
parent 1e8e8a82dd
commit aca6c736f6
5 changed files with 103 additions and 75 deletions

View File

@ -16,6 +16,7 @@ package org.tianocore.build;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
@ -26,7 +27,6 @@ import org.apache.tools.ant.Task;
import org.tianocore.build.fpd.FpdParserForThread;
import org.tianocore.build.fpd.FpdParserTask;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.global.PropertyManager;
import org.tianocore.build.toolchain.ConfigReader;
import org.tianocore.build.toolchain.ToolChainInfo;
import org.tianocore.common.definitions.ToolDefinitions;
@ -74,6 +74,11 @@ public class FrameworkBuildTask extends Task{
private Set<File> msaFiles = new LinkedHashSet<File>();
//
// This is only for none-multi-thread build to reduce overriding message
//
public static Hashtable<String, String> originalProperties = new Hashtable<String, String>();
String toolsDefFilename = ToolDefinitions.DEFAULT_TOOLS_DEF_FILE_PATH;
String targetFilename = ToolDefinitions.TARGET_FILE_PATH;
@ -81,17 +86,17 @@ public class FrameworkBuildTask extends Task{
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 = 1;
///
/// there are three type: all (build), clean and cleanall
///
@ -147,7 +152,7 @@ public class FrameworkBuildTask extends Task{
// Global Data initialization
//
File workspacePath = new File(getProject().getProperty("WORKSPACE"));
PropertyManager.setProperty(getProject(), "WORKSPACE_DIR", workspacePath.getPath().replaceAll("(\\\\)", "/"));
getProject().setProperty("WORKSPACE_DIR", workspacePath.getPath().replaceAll("(\\\\)", "/"));
GlobalData.initInfo(dbFilename, workspacePath.getPath(), toolsDefFilename);
//
@ -228,7 +233,10 @@ public class FrameworkBuildTask extends Task{
GenBuildTask genBuildTask = new GenBuildTask();
genBuildTask.setSingleModuleBuild(true);
genBuildTask.setType(type);
PropertyManager.setProperty(getProject(), "PLATFORM_FILE", activePlatform);
getProject().setProperty("PLATFORM_FILE", activePlatform);
if( !multithread) {
originalProperties.put("PLATFORM_FILE", activePlatform);
}
genBuildTask.setProject(getProject());
genBuildTask.setMsaFile(buildFile);
genBuildTask.execute();
@ -242,8 +250,7 @@ public class FrameworkBuildTask extends Task{
**/
private void backupSystemProperties() {
Map<String, String> sysProperties = System.getenv();
Set<String> keys = sysProperties.keySet();
Iterator<String> iter = keys.iterator();
Iterator<String> iter = sysProperties.keySet().iterator();
while (iter.hasNext()) {
String name = iter.next();
@ -251,9 +258,17 @@ public class FrameworkBuildTask extends Task{
// If system environment variable is not in ANT properties, add it
//
if (getProject().getProperty(name) == null) {
PropertyManager.setProperty(getProject(), name, sysProperties.get(name));
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(){

View File

@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
package org.tianocore.build;
import java.io.File;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@ -26,6 +27,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Ant;
import org.apache.tools.ant.taskdefs.Property;
import org.apache.xmlbeans.XmlObject;
@ -38,7 +41,6 @@ import org.tianocore.build.fpd.FpdParserTask;
import org.tianocore.build.global.GenBuildLogger;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.global.OutputManager;
import org.tianocore.build.global.PropertyManager;
import org.tianocore.build.global.SurfaceAreaQuery;
import org.tianocore.build.id.FpdModuleIdentification;
import org.tianocore.build.id.ModuleIdentification;
@ -125,22 +127,24 @@ public class GenBuildTask extends Ant {
From module build, exception from module surface area invalid.
**/
public void execute() throws BuildException {
//
if (!FrameworkBuildTask.multithread) {
cleanupProperties();
}
//
// set Logger
//
GenBuildLogger logger = new GenBuildLogger(getProject());
EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
EdkLog.setLogger(logger);
PropertyManager.setProject(getProject());
PropertyManager.save();
//
// Enable all specified properties
//
Iterator<Property> iter = properties.iterator();
while (iter.hasNext()) {
Property item = iter.next();
PropertyManager.setProperty(item.getName(), item.getValue());
getProject().setProperty(item.getName(), item.getValue());
}
//
@ -181,14 +185,6 @@ public class GenBuildTask extends Ant {
//
prepareSingleModuleBuild();
} else {
//
// Platform build. Restore the platform related info
//
String filename = getProject().getProperty("PLATFORM_FILE");
PlatformIdentification platformId = GlobalData.getPlatform(filename);
PropertyManager.setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
PropertyManager.setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
String packageGuid = getProject().getProperty("PACKAGE_GUID");
String packageVersion = getProject().getProperty("PACKAGE_VERSION");
PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
@ -236,7 +232,7 @@ public class GenBuildTask extends Ant {
for (int k = 0; k < archList.length; k++) {
PropertyManager.setProperty("ARCH", archList[k]);
getProject().setProperty("ARCH", archList[k]);
FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
@ -261,7 +257,7 @@ public class GenBuildTask extends Ant {
// Prepare for target related common properties
// TARGET
//
PropertyManager.setProperty("TARGET", targetList[i]);
getProject().setProperty("TARGET", targetList[i]);
String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
for(int j = 0; j < toolchainList.length; j ++){
//
@ -277,7 +273,7 @@ public class GenBuildTask extends Ant {
// Prepare for toolchain related common properties
// TOOLCHAIN
//
PropertyManager.setProperty("TOOLCHAIN", toolchainList[j]);
getProject().setProperty("TOOLCHAIN", toolchainList[j]);
System.out.println("Build " + moduleId + " start >>>");
System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);
@ -308,8 +304,6 @@ public class GenBuildTask extends Ant {
}
}
}
PropertyManager.restore();
}
/**
@ -347,17 +341,30 @@ public class GenBuildTask extends Ant {
FpdParserTask fpdParser = new FpdParserTask();
fpdParser.setProject(getProject());
fpdParser.parseFpdFile(platformId.getFpdFile());
PropertyManager.setProperty("ARCH", fpdParser.getAllArchForModule(moduleId));
//
// Prepare for Platform related common properties
// PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
//
PropertyManager.setProperty("PLATFORM", platformId.getName());
PropertyManager.setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
PropertyManager.setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
getProject().setProperty("ARCH", fpdParser.getAllArchForModule(moduleId));
}
private void cleanupProperties() {
Project newProject = new Project();
Hashtable<String, String> passdownProperties = FrameworkBuildTask.originalProperties;
Iterator<String> iter = passdownProperties.keySet().iterator();
while (iter.hasNext()) {
String item = iter.next();
newProject.setProperty(item, passdownProperties.get(item));
}
newProject.setInputHandler(getProject().getInputHandler());
Iterator listenerIter = getProject().getBuildListeners().iterator();
while (listenerIter.hasNext()) {
newProject.addBuildListener((BuildListener) listenerIter.next());
}
getProject().initSubProject(newProject);
setProject(newProject);
}
/**
Set Module-Related information to properties.
@ -370,29 +377,29 @@ public class GenBuildTask extends Ant {
// PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
//
PackageIdentification packageId = moduleId.getPackage();
PropertyManager.setProperty("PACKAGE", packageId.getName());
PropertyManager.setProperty("PACKAGE_GUID", packageId.getGuid());
PropertyManager.setProperty("PACKAGE_VERSION", packageId.getVersion());
PropertyManager.setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));
PropertyManager.setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
getProject().setProperty("PACKAGE", packageId.getName());
getProject().setProperty("PACKAGE_GUID", packageId.getGuid());
getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());
getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));
getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));
//
// MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
// MODULE_DIR, MODULE_RELATIVE_DIR
//
PropertyManager.setProperty("MODULE", moduleId.getName());
getProject().setProperty("MODULE", moduleId.getName());
String baseName = saq.getModuleOutputFileBasename();
if (baseName == null) {
PropertyManager.setProperty("BASE_NAME", moduleId.getName());
getProject().setProperty("BASE_NAME", moduleId.getName());
} else {
PropertyManager.setProperty("BASE_NAME", baseName);
getProject().setProperty("BASE_NAME", baseName);
}
PropertyManager.setProperty("GUID", moduleId.getGuid());
PropertyManager.setProperty("FILE_GUID", moduleId.getGuid());
PropertyManager.setProperty("VERSION", moduleId.getVersion());
PropertyManager.setProperty("MODULE_TYPE", moduleId.getModuleType());
PropertyManager.setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
PropertyManager.setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));
getProject().setProperty("GUID", moduleId.getGuid());
getProject().setProperty("FILE_GUID", moduleId.getGuid());
getProject().setProperty("VERSION", moduleId.getVersion());
getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());
getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));
getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));
//
// SUBSYSTEM
@ -418,18 +425,18 @@ public class GenBuildTask extends Ant {
break ;
}
}
PropertyManager.setProperty("SUBSYSTEM", subsystem);
getProject().setProperty("SUBSYSTEM", subsystem);
//
// ENTRYPOINT
//
if (arch.equalsIgnoreCase("EBC")) {
PropertyManager.setProperty("ENTRYPOINT", "EfiStart");
getProject().setProperty("ENTRYPOINT", "EfiStart");
} else {
PropertyManager.setProperty("ENTRYPOINT", "_ModuleEntryPoint");
getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");
}
PropertyManager.setProperty("OBJECTS", "");
getProject().setProperty("OBJECTS", "");
}
private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {
@ -444,7 +451,7 @@ public class GenBuildTask extends Ant {
key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME;
String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);
File cmdFile = new File(cmdPath + File.separatorChar + cmdName);
PropertyManager.setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));
getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));
//
// set CC_FLAGS
@ -454,7 +461,7 @@ public class GenBuildTask extends Ant {
Set<String> addset = new LinkedHashSet<String>();
Set<String> subset = new LinkedHashSet<String>();
putFlagsToSet(addset, cmdFlags);
PropertyManager.setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));
getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));
//
// Set CC_EXT
@ -462,9 +469,9 @@ public class GenBuildTask extends Ant {
key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_EXT;
String extName = GlobalData.getCommandSetting(key, fpdModuleId);
if ( extName != null && ! extName.equalsIgnoreCase("")) {
PropertyManager.setProperty(cmd[m] + "_EXT", extName);
getProject().setProperty(cmd[m] + "_EXT", extName);
} else {
PropertyManager.setProperty(cmd[m] + "_EXT", "");
getProject().setProperty(cmd[m] + "_EXT", "");
}
//
@ -473,7 +480,7 @@ public class GenBuildTask extends Ant {
key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY;
String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);
if (toolChainFamily != null) {
PropertyManager.setProperty(cmd[m] + "_FAMILY", toolChainFamily);
getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);
}
//
@ -482,9 +489,9 @@ public class GenBuildTask extends Ant {
key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_SPATH;
String spath = GlobalData.getCommandSetting(key, fpdModuleId);
if (spath != null) {
PropertyManager.setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));
getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));
} else {
PropertyManager.setProperty(cmd[m] + "_SPATH", "");
getProject().setProperty(cmd[m] + "_SPATH", "");
}
//
@ -493,9 +500,9 @@ public class GenBuildTask extends Ant {
key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_DPATH;
String dpath = GlobalData.getCommandSetting(key, fpdModuleId);
if (dpath != null) {
PropertyManager.setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));
getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));
} else {
PropertyManager.setProperty(cmd[m] + "_DPATH", "");
getProject().setProperty(cmd[m] + "_DPATH", "");
}
}
}
@ -566,7 +573,7 @@ public class GenBuildTask extends Ant {
for (int i = 0; i < libinstances.length; i++) {
propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";
}
PropertyManager.setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));
getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));
//
// Get all includepath and set to INCLUDE_PATHS
@ -768,7 +775,7 @@ public class GenBuildTask extends Ant {
includePaths.append(iter.next());
includePaths.append("; ");
}
PropertyManager.setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths.toString()).replaceAll("(\\\\)", "/"));
getProject().setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths.toString()).replaceAll("(\\\\)", "/"));
return includes.toArray(new String[includes.size()]);
}

View File

@ -31,7 +31,6 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.tianocore.build.fpd.FpdParserTask;
import org.tianocore.build.global.SurfaceAreaQuery;
import org.tianocore.build.global.PropertyManager;
import org.tianocore.build.id.FpdModuleIdentification;
import org.tianocore.build.id.ModuleIdentification;
import org.tianocore.build.id.PackageIdentification;
@ -46,7 +45,7 @@ public class ModuleBuildFileGenerator {
/// Pass: TARGET, TOOLCHAIN, ARCH
/// PACKAGE, PACKAGE_GUID, PACKAGE_VERSION
///
String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PLATFORM_FILE", "PACKAGE_GUID", "PACKAGE_VERSION"};
String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PACKAGE_GUID", "PACKAGE_VERSION"};
///
/// The information at the header of <em>build.xml</em>.
@ -418,7 +417,7 @@ public class ModuleBuildFileGenerator {
for (int i = 0; i < sourceFiles.length; i++) {
str += " " + sourceFiles[i][1];
}
PropertyManager.setProperty(project, "SOURCE_FILES", str.replaceAll("(\\\\)", "/"));
project.setProperty("SOURCE_FILES", str.replaceAll("(\\\\)", "/"));
}
/**

View File

@ -35,6 +35,7 @@ import org.apache.xmlbeans.XmlObject;
import org.tianocore.common.definitions.EdkDefinitions;
import org.tianocore.common.exception.EdkException;
import org.tianocore.pcd.action.ActionMessage;
import org.tianocore.build.FrameworkBuildTask;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.global.OutputManager;
import org.tianocore.build.global.SurfaceAreaQuery;
@ -339,6 +340,13 @@ public class FpdParserTask extends Task {
getProject().setProperty("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
if( !FrameworkBuildTask.multithread) {
FrameworkBuildTask.originalProperties.put("PLATFORM", platformId.getName());
FrameworkBuildTask.originalProperties.put("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));
FrameworkBuildTask.originalProperties.put("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
FrameworkBuildTask.originalProperties.put("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
}
//
// Build mode. User-defined output dir.

View File

@ -16,7 +16,6 @@ package org.tianocore.build.global;
import org.apache.tools.ant.Project;
import java.io.File;
import org.tianocore.build.global.PropertyManager;
/**
OutputManager class is used to setup output directories (BIN_DIR, DEST_DIR_OUTPUT,
@ -144,11 +143,11 @@ public class OutputManager {
//
// Set properties
//
PropertyManager.setProperty(project, "BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));
PropertyManager.setProperty(project, "FV_DIR", fvDir.replaceAll("(\\\\)", "/"));
PropertyManager.setProperty(project, "BIN_DIR", binDir.replaceAll("(\\\\)", "/"));
PropertyManager.setProperty(project, "DEST_DIR_DEBUG", (destDir + File.separatorChar + "DEBUG").replaceAll("(\\\\)", "/"));
PropertyManager.setProperty(project, "DEST_DIR_OUTPUT", (destDir + File.separatorChar + "OUTPUT").replaceAll("(\\\\)", "/"));
project.setProperty("BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));
project.setProperty("FV_DIR", fvDir.replaceAll("(\\\\)", "/"));
project.setProperty("BIN_DIR", binDir.replaceAll("(\\\\)", "/"));
project.setProperty("DEST_DIR_DEBUG", (destDir + File.separatorChar + "DEBUG").replaceAll("(\\\\)", "/"));
project.setProperty("DEST_DIR_OUTPUT", (destDir + File.separatorChar + "OUTPUT").replaceAll("(\\\\)", "/"));
//
// Create all directory if necessary
@ -187,7 +186,7 @@ public class OutputManager {
//
// Set to property
//
PropertyManager.setProperty(project, "BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));
project.setProperty("BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));
//
// Create all directory if necessary