Fully support active platform policy.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@763 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
wuyizhong 2006-07-05 06:22:06 +00:00
parent c64af698a3
commit de4bb9f6ed
9 changed files with 224 additions and 73 deletions

View File

@ -1,3 +1,11 @@
ACTIVE_PLATFORM = MdePkg.fpd
ACTIVE_TARGET = DEBUG
ACTIVE_ARCH = IA32
# Relative to WORKSPACE
TOOLS_DEFINITION_FILE = Tools/Conf/tools_def.txt
# Relative to WORKSPACE
# ACTIVE_PLATFORM = MdePkg/MdePkg.fpd
# Separate multiple targets with space, not not use comma
TARGET =
TARGET_ARCH =
TAGNAME =

View File

@ -1,3 +1,16 @@
/** @file FrameworkBuildTask.java
The file is ANT task to find MSA or FPD file and build them.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.build;
import java.io.BufferedReader;
@ -12,6 +25,8 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.tianocore.build.fpd.FpdParserTask;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.toolchain.ConfigReader;
import org.tianocore.build.toolchain.ToolChainConfig;
import org.tianocore.build.toolchain.ToolChainInfo;
public class FrameworkBuildTask extends Task{
@ -22,6 +37,12 @@ public class FrameworkBuildTask extends Task{
private Set<File> msaFiles = new LinkedHashSet<File>();
String toolsDefFilename = "Tools" + File.separatorChar + "Conf" + File.separatorChar + "tools_def.txt";
String targetFilename = "target.txt";
String activePlatform = null;
///
/// there are three type: all (build), clean and cleanall
///
@ -64,45 +85,65 @@ public class FrameworkBuildTask extends Task{
throw new BuildException(e.getMessage());
}
//
// If there is no build files or FPD files or MSA files, stop build
//
if (fpdFiles.size() == 0 && msaFiles.size() == 0) {
throw new BuildException("Can't find any build.xml file or FPD files or MSA files in current directory. ");
}
File buildFile = intercommuniteWithUser();
System.out.println("Start to build file [" + buildFile.getPath() + "] ..>> ");
//
// Deal with all environment variable (Add them to properties)
//
backupSystemProperties();
//
// Get ToolChain Info from environment
// Read target.txt file
//
ToolChainInfo envToolChainInfo = new ToolChainInfo();
envToolChainInfo.addTargets(getProject().getProperty("TARGET"));
envToolChainInfo.addTagnames(getProject().getProperty("TAGNAME"));
envToolChainInfo.addArchs(getProject().getProperty("ARCH"));
GlobalData.setToolChainEnvInfo(envToolChainInfo);
readTargetFile();
//
// Global Data initialization
//
String toolsDefFilename = "tools_def.txt";
if (getProject().getProperty("TOOLS_DEF") != null) {
toolsDefFilename = getProject().getProperty("TOOLS_DEF");
}
GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db",
getProject().getProperty("WORKSPACE_DIR"), toolsDefFilename);
//
// If find MSA file and ACTIVE_PLATFORM is set, build the module;
// else fail build.
// If without MSA file, and ACTIVE_PLATFORM is set, build the ACTIVE_PLATFORM.
// If ACTIVE_PLATFORM is not set, and only find one FPD file, build the platform;
// If find more than one FPD files, let user select one.
//
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) {
//
// Build the single module
//
buildFile = msaFiles.toArray(new File[1])[0];
}
else if (activePlatform != null) {
buildFile = new File(GlobalData.getWorkspacePath() + File.separatorChar + activePlatform);
}
else if (fpdFiles.size() == 1) {
buildFile = fpdFiles.toArray(new File[1])[0];
}
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. ");
}
//
// Build every FPD files (PLATFORM build)
//
if (buildFile.getName().endsWith(".fpd")) {
System.out.println("Start to build FPD file [" + buildFile.getPath() + "] ..>> ");
FpdParserTask fpdParserTask = new FpdParserTask();
fpdParserTask.setType(type);
fpdParserTask.setProject(getProject());
@ -114,8 +155,11 @@ public class FrameworkBuildTask extends Task{
// Build every MSA files (SINGLE MODULE BUILD)
//
else if (buildFile.getName().endsWith(".msa")) {
System.out.println("Start to build MSA file [" + buildFile.getPath() + "] ..>> ");
GenBuildTask genBuildTask = new GenBuildTask();
genBuildTask.setSingleModuleBuild(true);
genBuildTask.setType(type);
getProject().setProperty("PLATFORM_FILE", activePlatform);
genBuildTask.setProject(getProject());
genBuildTask.setMsaFile(buildFile);
genBuildTask.execute();
@ -207,4 +251,62 @@ public class FrameworkBuildTask extends Task{
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("TAGNAME", 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("TOOLS_DEFINITION_FILE", targetFileInfo);
if (str != null) {
toolsDefFilename = str;
}
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;
}
}
catch (Exception ex) {
throw new BuildException(ex.getMessage());
}
}
private String getValue(String key, String[][] map) {
for (int i = 0; i < map[0].length; i++){
if (key.equalsIgnoreCase(map[0][i])) {
return map[1][i];
}
}
return null;
}
}

View File

@ -100,11 +100,10 @@ public class GenBuildTask extends Ant {
private ModuleIdentification moduleId;
private Vector<Property> properties = new Vector<Property>();
private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();
private static Hashtable backupProperties;
private boolean isSingleModuleBuild = false;
/**
Public construct method. It is necessary for ANT task.
@ -170,7 +169,7 @@ public class GenBuildTask extends Ant {
//
// Judge whether it is single module build or not
//
if (getProject().getProperty("PLATFORM") == null) {
if (isSingleModuleBuild) {
//
// Single Module build
//
@ -180,8 +179,8 @@ public class GenBuildTask extends Ant {
//
// Platform build. Restore the platform related info
//
String platformName = getProject().getProperty("PLATFORM");
PlatformIdentification platformId = GlobalData.getPlatform(platformName);
String filename = getProject().getProperty("PLATFORM_FILE");
PlatformIdentification platformId = GlobalData.getPlatform(filename);
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
@ -309,13 +308,13 @@ public class GenBuildTask extends Ant {
//
// Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)
//
String activePlatformName = getProject().getProperty("ACTIVE_PLATFORM");
String filename = getProject().getProperty("PLATFORM_FILE");
if (activePlatformName == null){
if (filename == null){
throw new BuildException("Plese set ACTIVE_PLATFORM if you want to build a single module. ");
}
PlatformIdentification platformId = GlobalData.getPlatform(activePlatformName);
PlatformIdentification platformId = GlobalData.getPlatform(filename);
//
// Read FPD file
@ -328,7 +327,7 @@ public class GenBuildTask extends Ant {
// Prepare for Platform related common properties
// PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
//
getProject().setProperty("PLATFORM", activePlatformName);
getProject().setProperty("PLATFORM", platformId.getName());
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
}
@ -766,4 +765,8 @@ public class GenBuildTask extends Ant {
getProject().setProperty(item, (String)backupProperties.get(item));
}
}
public void setSingleModuleBuild(boolean isSingleModuleBuild) {
this.isSingleModuleBuild = isSingleModuleBuild;
}
}

View File

@ -46,7 +46,7 @@ public class ModuleBuildFileGenerator {
/// Pass: TARGET, TOOLCHAIN, ARCH
/// PACKAGE, PACKAGE_GUID, PACKAGE_VERSION
///
String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PLATFORM", "PACKAGE_GUID", "PACKAGE_VERSION"};
String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PLATFORM_FILE", "PACKAGE_GUID", "PACKAGE_VERSION"};
///
/// The information at the header of <em>build.xml</em>.

View File

@ -8,9 +8,7 @@ import org.apache.tools.ant.Task;
import org.apache.xmlbeans.XmlObject;
import org.tianocore.build.fpd.FpdParserTask;
import org.tianocore.build.global.GlobalData;
import org.tianocore.build.global.OutputManager;
import org.tianocore.build.global.SurfaceAreaQuery;
import org.tianocore.build.id.FpdModuleIdentification;
import org.tianocore.build.id.ModuleIdentification;
import org.tianocore.build.id.PackageIdentification;
import org.tianocore.build.id.PlatformIdentification;
@ -31,6 +29,7 @@ public class OutputDirSetup extends Task {
///
private String componentType;
private boolean isSingleModuleBuild = false;
// private ToolChainFactory toolChainFactory;
/**
@ -64,7 +63,7 @@ public class OutputDirSetup extends Task {
//
// Judge whether it is single module build or not
//
if (getProject().getProperty("PLATFORM") == null) {
if (isSingleModuleBuild) {
//
// Single Module build
//
@ -74,8 +73,8 @@ public class OutputDirSetup extends Task {
//
// Platform build
//
String platformName = getProject().getProperty("PLATFORM");
PlatformIdentification platformId = GlobalData.getPlatform(platformName);
String filename = getProject().getProperty("PLATFORM_FILE");
PlatformIdentification platformId = GlobalData.getPlatform(filename);
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
@ -160,9 +159,9 @@ public class OutputDirSetup extends Task {
//
// Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)
//
String activePlatformName = getProject().getProperty("env.ACTIVE_PLATFORM");
PlatformIdentification platformId = GlobalData.getPlatform(activePlatformName);
String filename = getProject().getProperty("PLATFORM_FILE");
PlatformIdentification platformId = GlobalData.getPlatform(filename);
//
// Read FPD file
@ -174,7 +173,7 @@ public class OutputDirSetup extends Task {
// Prepare for Platform related common properties
// PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR
//
getProject().setProperty("PLATFORM", activePlatformName);
getProject().setProperty("PLATFORM", platformId.getName());
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
}

View File

@ -139,7 +139,7 @@ public class FpdParserTask extends Task {
if (platformName == null) {
throw new BuildException("FpdParserTask parameter error. Please specify platform name or FPD file. ");
}
platformId = GlobalData.getPlatform(platformName);
platformId = GlobalData.getPlatformByName(platformName);
fpdFile = platformId.getFpdFile();
}
@ -147,20 +147,6 @@ public class FpdParserTask extends Task {
// Parse FPD file
//
parseFpdFile();
getProject().setProperty("PLATFORM", platformId.getName());
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
//
// Pcd Collection. Call CollectPCDAction to collect pcd info.
//
try {
CollectPCDAction ca = new CollectPCDAction();
ca.perform(GlobalData.getWorkspacePath(),platformId.getFpdFile().getPath(),ActionMessage.NULL_MESSAGE_LEVEL);
} catch (Exception e){
throw new BuildException(e.getMessage());
}
//
// Prepare BUILD_DIR
@ -359,12 +345,16 @@ public class FpdParserTask extends Task {
Map<String, XmlObject> map = new HashMap<String, XmlObject>();
map.put("PlatformSurfaceArea", doc);
SurfaceAreaQuery.setDoc(map);
SurfaceAreaQuery.getFpdUserExtension();
//
// Initialize
//
platformId = SurfaceAreaQuery.getFpdHeader();
platformId.setFpdFile(fpdFile);
getProject().setProperty("PLATFORM", platformId.getName());
getProject().setProperty("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
//
// Build mode. User-defined output dir.
@ -393,6 +383,16 @@ public class FpdParserTask extends Task {
parseToolChainOptions();
SurfaceAreaQuery.setDoc(map);
//
// Pcd Collection. Call CollectPCDAction to collect pcd info.
//
try {
CollectPCDAction ca = new CollectPCDAction();
ca.perform(GlobalData.getWorkspacePath(),platformId.getFpdFile().getPath(),ActionMessage.NULL_MESSAGE_LEVEL);
} catch (Exception e){
throw new BuildException(e.getMessage());
}
} catch (Exception e) {
e.printStackTrace();
throw new BuildException("Load FPD file [" + fpdFile.getPath() + "] error. \n" + e.getMessage());

View File

@ -166,8 +166,7 @@ public class GlobalData {
// If ToolChain has been set up before, do nothing.
// CONF dir + tools definition file name
//
String confDir = GlobalData.workspaceDir + File.separatorChar + "Tools" + File.separatorChar + "Conf";
File toolsDefFile = new File(confDir + File.separatorChar + toolsDefFilename);
File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);
System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. ");
toolsDef = new ToolChainConfig(toolsDefFile);
@ -576,21 +575,27 @@ public class GlobalData {
}
/////////////////////////// Update!! Update!! Update!!
// public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {
// return pcdDbManager;
// }
///////////////////////////
public synchronized static PlatformIdentification getPlatform(String name) throws BuildException {
public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {
Iterator iter = platformList.iterator();
while(iter.hasNext()){
PlatformIdentification platformId = (PlatformIdentification)iter.next();
if (platformId.getName().equalsIgnoreCase(name)) {
// GlobalData.log.info("Platform: " + platformId + platformId.getFpdFile());
return platformId;
}
}
throw new BuildException("Can't find platform [" + name + "] in current workspace. ");
throw new BuildException("Can't find platform [" + name + "] in current workspace database. ");
}
public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {
File file = new File(workspaceDir + File.separatorChar + filename);
Iterator iter = platformList.iterator();
while(iter.hasNext()){
PlatformIdentification platformId = (PlatformIdentification)iter.next();
if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {
return platformId;
}
}
throw new BuildException("Can't find platform file [" + filename + "] in current workspace database. ");
}
public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {

View File

@ -26,7 +26,37 @@ import java.util.regex.Pattern;
import org.apache.xmlbeans.XmlNormalizedString;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlString;
import org.tianocore.*;
import org.tianocore.BuildOptionsDocument;
import org.tianocore.CNameType;
import org.tianocore.DataIdDocument;
import org.tianocore.ExternsDocument;
import org.tianocore.FileNameConvention;
import org.tianocore.FvAttributeDocument;
import org.tianocore.FvImagesDocument;
import org.tianocore.FvOptionDocument;
import org.tianocore.GuidDeclarationsDocument;
import org.tianocore.GuidsDocument;
import org.tianocore.LibrariesDocument;
import org.tianocore.LibraryClassDeclarationsDocument;
import org.tianocore.LibraryClassDocument;
import org.tianocore.ModuleDefinitionsDocument;
import org.tianocore.ModuleSADocument;
import org.tianocore.ModuleSaBuildOptionsDocument;
import org.tianocore.ModuleTypeDef;
import org.tianocore.MsaFilesDocument;
import org.tianocore.MsaHeaderDocument;
import org.tianocore.OptionDocument;
import org.tianocore.PPIsDocument;
import org.tianocore.PackageDependenciesDocument;
import org.tianocore.PackageHeadersDocument;
import org.tianocore.PcdCodedDocument;
import org.tianocore.PlatformDefinitionsDocument;
import org.tianocore.PlatformHeaderDocument;
import org.tianocore.PpiDeclarationsDocument;
import org.tianocore.ProtocolDeclarationsDocument;
import org.tianocore.Sentence;
import org.tianocore.SpdHeaderDocument;
import org.tianocore.SupportedArchitectures;
import org.tianocore.FilenameDocument.Filename;
import org.tianocore.MsaHeaderDocument.MsaHeader;
import org.tianocore.ProtocolsDocument.Protocols.Protocol;
@ -1344,7 +1374,7 @@ public class SurfaceAreaQuery {
}
public static XmlObject getFpdUserExtension() {
String[] xPath = new String[] { "" };
String[] xPath = new String[] { "/UserExtensions" };
Object[] queryResult = get("PlatformSurfaceArea", xPath);
if (queryResult == null) {

View File

@ -37,6 +37,10 @@ public class PlatformIdentification extends Identification{
return fpdFile;
}
public String getRelativeFpdFile (){
return fpdFile.getPath().substring(GlobalData.getWorkspacePath().length());
}
public String getPlatformRelativeDir(){
return fpdFile.getParent().substring(GlobalData.getWorkspacePath().length());
}