-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 =
+
+/** @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
private ModuleIdentification moduleId;\r
\r
private Vector<Property> properties = new Vector<Property>();\r
- \r
+\r
private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();\r
\r
- \r
- private static Hashtable backupProperties;\r
+ private boolean isSingleModuleBuild = false;\r
\r
/**\r
Public construct method. It is necessary for ANT task.\r
//\r
// Judge whether it is single module build or not\r
//\r
- if (getProject().getProperty("PLATFORM") == null) {\r
+ if (isSingleModuleBuild) {\r
//\r
// Single Module build\r
//\r
//\r
// Platform build. Restore the platform related info\r
//\r
- String platformName = getProject().getProperty("PLATFORM");\r
- PlatformIdentification platformId = GlobalData.getPlatform(platformName);\r
+ String filename = getProject().getProperty("PLATFORM_FILE");\r
+ PlatformIdentification platformId = GlobalData.getPlatform(filename);\r
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
\r
//\r
// Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r
//\r
- String activePlatformName = getProject().getProperty("ACTIVE_PLATFORM");\r
+ String filename = getProject().getProperty("PLATFORM_FILE");\r
\r
- if (activePlatformName == null){\r
+ if (filename == null){\r
throw new BuildException("Plese set ACTIVE_PLATFORM if you want to build a single module. ");\r
}\r
\r
- PlatformIdentification platformId = GlobalData.getPlatform(activePlatformName);\r
+ PlatformIdentification platformId = GlobalData.getPlatform(filename);\r
\r
//\r
// Read FPD file\r
// Prepare for Platform related common properties\r
// PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r
//\r
- getProject().setProperty("PLATFORM", activePlatformName);\r
+ getProject().setProperty("PLATFORM", platformId.getName());\r
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
}\r
getProject().setProperty(item, (String)backupProperties.get(item));\r
}\r
}\r
+\r
+ public void setSingleModuleBuild(boolean isSingleModuleBuild) {\r
+ this.isSingleModuleBuild = isSingleModuleBuild;\r
+ }\r
}\r
/// Pass: TARGET, TOOLCHAIN, ARCH\r
/// PACKAGE, PACKAGE_GUID, PACKAGE_VERSION\r
///\r
- String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PLATFORM", "PACKAGE_GUID", "PACKAGE_VERSION"};\r
+ String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PLATFORM_FILE", "PACKAGE_GUID", "PACKAGE_VERSION"};\r
\r
///\r
/// The information at the header of <em>build.xml</em>.\r
import org.apache.xmlbeans.XmlObject;\r
import org.tianocore.build.fpd.FpdParserTask;\r
import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.global.OutputManager;\r
import org.tianocore.build.global.SurfaceAreaQuery;\r
-import org.tianocore.build.id.FpdModuleIdentification;\r
import org.tianocore.build.id.ModuleIdentification;\r
import org.tianocore.build.id.PackageIdentification;\r
import org.tianocore.build.id.PlatformIdentification;\r
///\r
private String componentType;\r
\r
+ private boolean isSingleModuleBuild = false;\r
// private ToolChainFactory toolChainFactory;\r
\r
/**\r
//\r
// Judge whether it is single module build or not\r
//\r
- if (getProject().getProperty("PLATFORM") == null) {\r
+ if (isSingleModuleBuild) {\r
//\r
// Single Module build\r
//\r
//\r
// Platform build\r
//\r
- String platformName = getProject().getProperty("PLATFORM");\r
- PlatformIdentification platformId = GlobalData.getPlatform(platformName);\r
+ String filename = getProject().getProperty("PLATFORM_FILE");\r
+ PlatformIdentification platformId = GlobalData.getPlatform(filename);\r
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
\r
//\r
// Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r
//\r
- String activePlatformName = getProject().getProperty("env.ACTIVE_PLATFORM");\r
- \r
- PlatformIdentification platformId = GlobalData.getPlatform(activePlatformName);\r
+ String filename = getProject().getProperty("PLATFORM_FILE");\r
+\r
+ PlatformIdentification platformId = GlobalData.getPlatform(filename);\r
\r
//\r
// Read FPD file\r
// Prepare for Platform related common properties\r
// PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r
//\r
- getProject().setProperty("PLATFORM", activePlatformName);\r
+ getProject().setProperty("PLATFORM", platformId.getName());\r
getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
}\r
if (platformName == null) {\r
throw new BuildException("FpdParserTask parameter error. Please specify platform name or FPD file. ");\r
}\r
- platformId = GlobalData.getPlatform(platformName);\r
+ platformId = GlobalData.getPlatformByName(platformName);\r
fpdFile = platformId.getFpdFile();\r
}\r
\r
// Parse FPD file\r
//\r
parseFpdFile();\r
-\r
- getProject().setProperty("PLATFORM", platformId.getName());\r
- getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
- getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
-\r
- //\r
- // Pcd Collection. Call CollectPCDAction to collect pcd info.\r
- //\r
- try {\r
- CollectPCDAction ca = new CollectPCDAction();\r
- ca.perform(GlobalData.getWorkspacePath(),platformId.getFpdFile().getPath(),ActionMessage.NULL_MESSAGE_LEVEL);\r
- } catch (Exception e){\r
- throw new BuildException(e.getMessage());\r
- }\r
\r
//\r
// Prepare BUILD_DIR\r
Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
map.put("PlatformSurfaceArea", doc);\r
SurfaceAreaQuery.setDoc(map);\r
- \r
+ SurfaceAreaQuery.getFpdUserExtension();\r
//\r
// Initialize\r
//\r
platformId = SurfaceAreaQuery.getFpdHeader();\r
platformId.setFpdFile(fpdFile);\r
+ getProject().setProperty("PLATFORM", platformId.getName());\r
+ getProject().setProperty("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));\r
+ getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+ getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
\r
//\r
// Build mode. User-defined output dir. \r
parseToolChainOptions();\r
\r
SurfaceAreaQuery.setDoc(map);\r
+ \r
+ //\r
+ // Pcd Collection. Call CollectPCDAction to collect pcd info.\r
+ //\r
+ try {\r
+ CollectPCDAction ca = new CollectPCDAction();\r
+ ca.perform(GlobalData.getWorkspacePath(),platformId.getFpdFile().getPath(),ActionMessage.NULL_MESSAGE_LEVEL);\r
+ } catch (Exception e){\r
+ throw new BuildException(e.getMessage());\r
+ }\r
} catch (Exception e) {\r
e.printStackTrace();\r
throw new BuildException("Load FPD file [" + fpdFile.getPath() + "] error. \n" + e.getMessage());\r
// If ToolChain has been set up before, do nothing.\r
// CONF dir + tools definition file name\r
//\r
- String confDir = GlobalData.workspaceDir + File.separatorChar + "Tools" + File.separatorChar + "Conf";\r
- File toolsDefFile = new File(confDir + File.separatorChar + toolsDefFilename);\r
+ File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r
System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. ");\r
toolsDef = new ToolChainConfig(toolsDefFile);\r
\r
\r
}\r
\r
- /////////////////////////// Update!! Update!! Update!!\r
-// public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
-// return pcdDbManager;\r
-// }\r
- ///////////////////////////\r
- public synchronized static PlatformIdentification getPlatform(String name) throws BuildException {\r
+ public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {\r
Iterator iter = platformList.iterator();\r
while(iter.hasNext()){\r
PlatformIdentification platformId = (PlatformIdentification)iter.next();\r
if (platformId.getName().equalsIgnoreCase(name)) {\r
-// GlobalData.log.info("Platform: " + platformId + platformId.getFpdFile());\r
return platformId;\r
}\r
}\r
- throw new BuildException("Can't find platform [" + name + "] in current workspace. ");\r
+ throw new BuildException("Can't find platform [" + name + "] in current workspace database. ");\r
+ }\r
+ \r
+ public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {\r
+ File file = new File(workspaceDir + File.separatorChar + filename);\r
+ Iterator iter = platformList.iterator();\r
+ while(iter.hasNext()){\r
+ PlatformIdentification platformId = (PlatformIdentification)iter.next();\r
+ if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {\r
+ return platformId;\r
+ }\r
+ }\r
+ throw new BuildException("Can't find platform file [" + filename + "] in current workspace database. ");\r
}\r
\r
public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r
import org.apache.xmlbeans.XmlNormalizedString;\r
import org.apache.xmlbeans.XmlObject;\r
import org.apache.xmlbeans.XmlString;\r
-import org.tianocore.*;\r
+import org.tianocore.BuildOptionsDocument;\r
+import org.tianocore.CNameType;\r
+import org.tianocore.DataIdDocument;\r
+import org.tianocore.ExternsDocument;\r
+import org.tianocore.FileNameConvention;\r
+import org.tianocore.FvAttributeDocument;\r
+import org.tianocore.FvImagesDocument;\r
+import org.tianocore.FvOptionDocument;\r
+import org.tianocore.GuidDeclarationsDocument;\r
+import org.tianocore.GuidsDocument;\r
+import org.tianocore.LibrariesDocument;\r
+import org.tianocore.LibraryClassDeclarationsDocument;\r
+import org.tianocore.LibraryClassDocument;\r
+import org.tianocore.ModuleDefinitionsDocument;\r
+import org.tianocore.ModuleSADocument;\r
+import org.tianocore.ModuleSaBuildOptionsDocument;\r
+import org.tianocore.ModuleTypeDef;\r
+import org.tianocore.MsaFilesDocument;\r
+import org.tianocore.MsaHeaderDocument;\r
+import org.tianocore.OptionDocument;\r
+import org.tianocore.PPIsDocument;\r
+import org.tianocore.PackageDependenciesDocument;\r
+import org.tianocore.PackageHeadersDocument;\r
+import org.tianocore.PcdCodedDocument;\r
+import org.tianocore.PlatformDefinitionsDocument;\r
+import org.tianocore.PlatformHeaderDocument;\r
+import org.tianocore.PpiDeclarationsDocument;\r
+import org.tianocore.ProtocolDeclarationsDocument;\r
+import org.tianocore.Sentence;\r
+import org.tianocore.SpdHeaderDocument;\r
+import org.tianocore.SupportedArchitectures;\r
import org.tianocore.FilenameDocument.Filename;\r
import org.tianocore.MsaHeaderDocument.MsaHeader;\r
import org.tianocore.ProtocolsDocument.Protocols.Protocol;\r
}\r
\r
public static XmlObject getFpdUserExtension() {\r
- String[] xPath = new String[] { "" };\r
+ String[] xPath = new String[] { "/UserExtensions" };\r
\r
Object[] queryResult = get("PlatformSurfaceArea", xPath);\r
if (queryResult == null) {\r
return fpdFile;\r
}\r
\r
+ public String getRelativeFpdFile (){\r
+ return fpdFile.getPath().substring(GlobalData.getWorkspacePath().length());\r
+ }\r
+ \r
public String getPlatformRelativeDir(){\r
return fpdFile.getParent().substring(GlobalData.getWorkspacePath().length());\r
}\r