/** @file\r
- This file is ANT task GenBuild. \r
- \r
- The file is used to parse a specified Module, and generate its build time \r
+ This file is ANT task GenBuild.\r
+\r
+ The file is used to parse a specified Module, and generate its build time\r
ANT script build.xml, then call the the ANT script to build the module.\r
- \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
package org.tianocore.build;\r
\r
import java.io.File;\r
-import java.util.Hashtable;\r
import java.util.Iterator;\r
import java.util.LinkedHashSet;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Set;\r
-import java.util.Stack;\r
import java.util.Vector;\r
import java.util.regex.Matcher;\r
import java.util.regex.Pattern;\r
import org.apache.tools.ant.taskdefs.Property;\r
import org.apache.xmlbeans.XmlObject;\r
\r
+import org.tianocore.common.definitions.ToolDefinitions;\r
+import org.tianocore.common.exception.EdkException;\r
+import org.tianocore.common.logger.EdkLog;\r
import org.tianocore.build.autogen.AutoGen;\r
import org.tianocore.build.fpd.FpdParserTask;\r
import org.tianocore.build.global.GenBuildLogger;\r
import org.tianocore.build.global.GlobalData;\r
import org.tianocore.build.global.OutputManager;\r
+import org.tianocore.build.global.PropertyManager;\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
import org.tianocore.build.tools.ModuleItem;\r
-import org.tianocore.exception.EdkException;\r
-import org.tianocore.logger.EdkLog;\r
\r
/**\r
<p>\r
<code>GenBuildTask</code> is an ANT task that can be used in ANT build\r
- system. The main function of this task is to parse module's surface area,\r
+ system. \r
+ \r
+ <p>The main function of this task is to parse module's surface area (MSA),\r
then generate the corresponding <em>BaseName_build.xml</em> (the real ANT\r
build script) and call this to build the module. The whole process including:\r
- 1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances; \r
- 3. build all source files inlcude AutoGen.c; 4. generate sections;\r
- 5. generate FFS file if it is driver module while LIB file if it is Library module. \r
- </p>\r
\r
+ <pre>\r
+ 1. generate AutoGen.c and AutoGen.h; \r
+ 2. build all dependent library instances;\r
+ 3. build all source files inlcude AutoGen.c; \r
+ 4. generate sections;\r
+ 5. generate FFS file if it is driver module while LIB file if it is Library module.\r
+ </pre>\r
+\r
+\r
<p>\r
The usage is (take module <em>HelloWorld</em> for example):\r
</p>\r
- \r
+\r
<pre>\r
- <GenBuild \r
- msaFilename="HelloWorld.msa"/> \r
- processTo="ALL"/>\r
+ <GenBuild \r
+ msaFile="${PACKAGE_DIR}/Application/HelloWorld/HelloWorld.msa"\r
+ type="cleanall" />\r
</pre>\r
- \r
- <p><code>processTo</code> provides a way to customize the whole build process. \r
- processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE. \r
- Default is ALL, means whole \r
- </p>\r
- \r
+\r
<p>\r
This task calls <code>AutoGen</code> to generate <em>AutoGen.c</em> and\r
- <em>AutoGen.h</em>. The task also parses the development environment\r
- configuration files, such as collecting package information, setting compiler\r
- flags and so on.\r
+ <em>AutoGen.h</em>. \r
+ </p>\r
+\r
+ <p>\r
+ This task will also set properties for current module, such as PACKAGE, \r
+ PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR \r
+ (relative to Workspace), MODULE or BASE_NAME, GUID, VERSION, MODULE_DIR, \r
+ MODULE_RELATIVE_DIR (relative to Package), CONFIG_DIR, BIN_DIR, \r
+ DEST_DIR_DEBUG, DEST_DIR_OUTPUT, TARGET, ARCH, TOOLCHAIN, TOOLCHAIN_FAMILY, \r
+ SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH, all compiler command related \r
+ properties (CC, CC_FLAGS, CC_DPATH, CC_SPATH, CC_FAMILY, CC_EXT). \r
</p>\r
- \r
\r
@since GenBuild 1.0\r
**/\r
public class GenBuildTask extends Ant {\r
- \r
+\r
///\r
/// Module surface area file.\r
///\r
File msaFile;\r
\r
- ///\r
- /// \r
- ///\r
- private String type = "all"; // = "build";\r
+ private String type = "all"; \r
\r
///\r
/// Module's Identification.\r
\r
private Vector<Property> properties = new Vector<Property>();\r
\r
- private static Stack<Hashtable> backupPropertiesStack = new Stack<Hashtable>();\r
- \r
private boolean isSingleModuleBuild = false;\r
- \r
+\r
/**\r
Public construct method. It is necessary for ANT task.\r
**/\r
}\r
\r
/**\r
- \r
+\r
@throws BuildException\r
From module build, exception from module surface area invalid.\r
**/\r
GenBuildLogger logger = new GenBuildLogger(getProject());\r
EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));\r
EdkLog.setLogger(logger);\r
- // remove !!\r
- try {\r
- pushProperties();\r
+\r
+ PropertyManager.setProject(getProject());\r
+ PropertyManager.save();\r
//\r
// Enable all specified properties\r
//\r
Iterator<Property> iter = properties.iterator();\r
while (iter.hasNext()) {\r
Property item = iter.next();\r
- getProject().setProperty(item.getName(), item.getValue());\r
+ PropertyManager.setProperty(item.getName(), item.getValue());\r
}\r
- \r
+\r
//\r
// GenBuild should specify either msaFile or moduleGuid & packageGuid\r
//\r
String packageGuid = getProject().getProperty("PACKAGE_GUID");\r
String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r
if (moduleGuid == null || packageGuid == null) {\r
- throw new BuildException("GenBuild parameters error. ");\r
+ throw new BuildException("GenBuild parameter error.");\r
}\r
PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r
moduleId = new ModuleIdentification(moduleGuid, moduleVersion);\r
Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);\r
SurfaceAreaQuery.setDoc(doc);\r
moduleId = SurfaceAreaQuery.getMsaHeader();\r
- }\r
- else {\r
+ } else {\r
Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);\r
SurfaceAreaQuery.setDoc(doc);\r
moduleId = SurfaceAreaQuery.getMsaHeader();\r
String[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED",null);\r
if (producedLibraryClasses.length == 0) {\r
moduleId.setLibrary(false);\r
- }\r
- else {\r
+ } else {\r
moduleId.setLibrary(true);\r
}\r
- \r
+\r
//\r
// Judge whether it is single module build or not\r
//\r
// Single Module build\r
//\r
prepareSingleModuleBuild();\r
- }\r
- else {\r
+ } else {\r
//\r
// Platform build. Restore the platform related info\r
//\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
+ PropertyManager.setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+ PropertyManager.setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
+\r
String packageGuid = getProject().getProperty("PACKAGE_GUID");\r
String packageVersion = getProject().getProperty("PACKAGE_VERSION");\r
PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);\r
moduleId.setPackage(packageId);\r
}\r
- \r
+\r
//\r
- // If single module : intersection MSA supported ARCHs and tools def!!\r
- // else, get arch from pass down\r
+ // If single module : get arch from pass down, otherwise intersection MSA \r
+ // supported ARCHs and tools def\r
//\r
- String[] archList = new String[0];\r
- if ( getProject().getProperty("ARCH") != null ) {\r
- archList = getProject().getProperty("ARCH").split(" ");\r
+ Set<String> archListSupByToolChain = new LinkedHashSet<String>();\r
+ String[] archs = GlobalData.getToolChainInfo().getArchs();\r
+\r
+ for (int i = 0; i < archs.length; i ++) {\r
+ archListSupByToolChain.add(archs[i]);\r
}\r
- else {\r
- archList = GlobalData.getToolChainInfo().getArchs();\r
+\r
+ Set<String> archSet = new LinkedHashSet<String>();\r
+\r
+ if ( getProject().getProperty("ARCH") != null) {\r
+ String[] fpdArchList = getProject().getProperty("ARCH").split(" ");\r
+\r
+ for (int i = 0; i < fpdArchList.length; i++) {\r
+ if (archListSupByToolChain.contains(fpdArchList[i])) {\r
+ archSet.add(fpdArchList[i]);\r
+ }\r
+ }\r
+ } else {\r
+ archSet = archListSupByToolChain; \r
}\r
- \r
- \r
+\r
+ String[] archList = archSet.toArray(new String[archSet.size()]);\r
+\r
//\r
// Judge if arch is all supported by current module. If not, throw Exception.\r
//\r
if (moduleSupportedArchs != null) {\r
for (int k = 0; k < archList.length; k++) {\r
if ( ! moduleSupportedArchs.contains(archList[k])) {\r
- throw new BuildException("ARCH [" + archList[k] + "] is not supported by " + moduleId + ". " + moduleId + " only supports [" + moduleSupportedArchs + "].");\r
+ throw new BuildException("Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures.");\r
}\r
}\r
}\r
- \r
+\r
for (int k = 0; k < archList.length; k++) {\r
- getProject().setProperty("ARCH", archList[k]);\r
- \r
+\r
+ PropertyManager.setProperty("ARCH", archList[k]);\r
+\r
FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);\r
- \r
+\r
//\r
// Whether the module is built before\r
//\r
- if (GlobalData.isModuleBuilt(fpdModuleId)) {\r
- return ;\r
- }\r
- else {\r
+ if (moduleId.isLibrary() == false && GlobalData.hasFpdModuleSA(fpdModuleId) == false) {\r
+ System.out.println("\nWARNING: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n");\r
+ continue;\r
+ } else if (GlobalData.isModuleBuilt(fpdModuleId)) {\r
+ break;\r
+ } else {\r
GlobalData.registerBuiltModule(fpdModuleId);\r
}\r
- \r
+\r
//\r
// For Every TOOLCHAIN, TARGET\r
//\r
// Prepare for target related common properties\r
// TARGET\r
//\r
- getProject().setProperty("TARGET", targetList[i]);\r
+ PropertyManager.setProperty("TARGET", targetList[i]);\r
String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
for(int j = 0; j < toolchainList.length; j ++){\r
//\r
// check if any tool is defined for current target + toolchain + arch\r
// don't do anything if no tools found\r
- // \r
+ //\r
if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {\r
- System.out.println("!!!Warning: No build issued. No tools found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");\r
+ System.out.println("Warning: No build issued. No tools were found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");\r
continue;\r
}\r
\r
// Prepare for toolchain related common properties\r
// TOOLCHAIN\r
//\r
- getProject().setProperty("TOOLCHAIN", toolchainList[j]);\r
+ PropertyManager.setProperty("TOOLCHAIN", toolchainList[j]);\r
\r
System.out.println("Build " + moduleId + " start >>>");\r
System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);\r
SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));\r
- \r
+\r
//\r
// Prepare for all other common properties\r
// PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r
// MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r
// MODULE_DIR, MODULE_RELATIVE_DIR\r
// SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH\r
- // LIBS, OBJECTS, SDB_FILES\r
//\r
setModuleCommonProperties(archList[k]);\r
- \r
+\r
//\r
- // OutputManage prepare for \r
+ // OutputManage prepare for\r
// BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR\r
//\r
OutputManager.getInstance().update(getProject());\r
- \r
+\r
if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {\r
applyBuild(targetList[i], toolchainList[j], fpdModuleId);\r
- }\r
- else if (type.equalsIgnoreCase("clean")) {\r
+ } else if (type.equalsIgnoreCase("clean")) {\r
applyClean(fpdModuleId);\r
- }\r
- else if (type.equalsIgnoreCase("cleanall")) {\r
+ } else if (type.equalsIgnoreCase("cleanall")) {\r
applyCleanall(fpdModuleId);\r
}\r
}\r
}\r
}\r
- popProperties();\r
- }catch (Exception e){\r
- e.printStackTrace();\r
- throw new BuildException(e.getMessage());\r
- }\r
+ \r
+ PropertyManager.restore();\r
}\r
\r
/**\r
- This method is used to prepare Platform-related information. \r
- \r
+ This method is used to prepare Platform-related information.\r
+\r
<p>In Single Module Build mode, platform-related information is not ready.\r
- The method read the system environment variable <code>ACTIVE_PLATFORM</code> \r
+ The method read the system environment variable <code>ACTIVE_PLATFORM</code>\r
and search in the Framework Database. Note that platform name in the Framework\r
Database must be unique. </p>\r
- \r
+\r
**/\r
private void prepareSingleModuleBuild(){\r
//\r
// TBD: Enhance it!!!!\r
//\r
PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);\r
- \r
+\r
moduleId.setPackage(packageId);\r
- \r
+\r
//\r
- // Read ACTIVE_PLATFORM's FPD file (Call FpdParserTask's method)\r
+ // Read ACTIVE_PLATFORM's FPD file \r
//\r
String filename = getProject().getProperty("PLATFORM_FILE");\r
- \r
+\r
if (filename == null){\r
- throw new BuildException("Plese set ACTIVE_PLATFORM if you want to build a single module. ");\r
+ throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!");\r
}\r
- \r
+\r
PlatformIdentification platformId = GlobalData.getPlatform(filename);\r
- \r
+\r
//\r
- // Read FPD file\r
+ // Read FPD file (Call FpdParserTask's method)\r
//\r
FpdParserTask fpdParser = new FpdParserTask();\r
fpdParser.setProject(getProject());\r
fpdParser.parseFpdFile(platformId.getFpdFile());\r
- \r
+\r
//\r
// Prepare for Platform related common properties\r
// PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\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
+ PropertyManager.setProperty("PLATFORM", platformId.getName());\r
+ PropertyManager.setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+ PropertyManager.setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
}\r
\r
\r
/**\r
Set Module-Related information to properties.\r
+ \r
+ @param arch current build ARCH\r
**/\r
private void setModuleCommonProperties(String arch) {\r
//\r
// PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR\r
//\r
PackageIdentification packageId = moduleId.getPackage();\r
- getProject().setProperty("PACKAGE", packageId.getName());\r
- getProject().setProperty("PACKAGE_GUID", packageId.getGuid());\r
- getProject().setProperty("PACKAGE_VERSION", packageId.getVersion());\r
- getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r
- getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r
- \r
+ PropertyManager.setProperty("PACKAGE", packageId.getName());\r
+ PropertyManager.setProperty("PACKAGE_GUID", packageId.getGuid());\r
+ PropertyManager.setProperty("PACKAGE_VERSION", packageId.getVersion());\r
+ PropertyManager.setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/"));\r
+ PropertyManager.setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/"));\r
+\r
//\r
// MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE\r
// MODULE_DIR, MODULE_RELATIVE_DIR\r
//\r
- getProject().setProperty("MODULE", moduleId.getName());\r
+ PropertyManager.setProperty("MODULE", moduleId.getName());\r
String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r
if (baseName == null) {\r
- getProject().setProperty("BASE_NAME", moduleId.getName());\r
- }\r
- else {\r
- getProject().setProperty("BASE_NAME", baseName);\r
- }\r
- getProject().setProperty("GUID", moduleId.getGuid());\r
- getProject().setProperty("FILE_GUID", moduleId.getGuid());\r
- getProject().setProperty("VERSION", moduleId.getVersion());\r
- getProject().setProperty("MODULE_TYPE", moduleId.getModuleType());\r
- getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));\r
- getProject().setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));\r
- \r
+ PropertyManager.setProperty("BASE_NAME", moduleId.getName());\r
+ } else {\r
+ PropertyManager.setProperty("BASE_NAME", baseName);\r
+ }\r
+ PropertyManager.setProperty("GUID", moduleId.getGuid());\r
+ PropertyManager.setProperty("FILE_GUID", moduleId.getGuid());\r
+ PropertyManager.setProperty("VERSION", moduleId.getVersion());\r
+ PropertyManager.setProperty("MODULE_TYPE", moduleId.getModuleType());\r
+ PropertyManager.setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/"));\r
+ PropertyManager.setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/"));\r
+\r
//\r
// SUBSYSTEM\r
//\r
String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"},\r
- { "SEC", "EFI_BOOT_SERVICE_DRIVER" }, \r
- { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" }, \r
- { "PEIM", "EFI_BOOT_SERVICE_DRIVER" }, \r
+ { "SEC", "EFI_BOOT_SERVICE_DRIVER" },\r
+ { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r
+ { "PEIM", "EFI_BOOT_SERVICE_DRIVER" },\r
{ "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" },\r
- { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r
- { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" }, \r
- { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r
- { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, \r
- { "TOOL", "EFI_BOOT_SERVICE_DRIVER" }, \r
+ { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
+ { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" },\r
+ { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
+ { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
+ { "TOOL", "EFI_BOOT_SERVICE_DRIVER" },\r
{ "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" },\r
- { "UEFI_APPLICATION", "EFI_APPLICATION" }, \r
- { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} }; \r
- \r
+ { "UEFI_APPLICATION", "EFI_APPLICATION" },\r
+ { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} };\r
+\r
String subsystem = "EFI_BOOT_SERVICE_DRIVER";\r
for (int i = 0; i < subsystemMap.length; i++) {\r
if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) {\r
break ;\r
}\r
}\r
- getProject().setProperty("SUBSYSTEM", subsystem);\r
- \r
+ PropertyManager.setProperty("SUBSYSTEM", subsystem);\r
+\r
//\r
// ENTRYPOINT\r
//\r
if (arch.equalsIgnoreCase("EBC")) {\r
- getProject().setProperty("ENTRYPOINT", "EfiStart");\r
+ PropertyManager.setProperty("ENTRYPOINT", "EfiStart");\r
+ } else {\r
+ PropertyManager.setProperty("ENTRYPOINT", "_ModuleEntryPoint");\r
}\r
- else {\r
- getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint");\r
- }\r
- \r
- //\r
- // LIBS, OBJECTS, SDB_FILES\r
- //\r
- getProject().setProperty("OBJECTS", "");\r
- getProject().setProperty("SDB_FILES", "");\r
- getProject().setProperty("LIBS", "");\r
+\r
+ PropertyManager.setProperty("OBJECTS", "");\r
}\r
\r
private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException {\r
// Set cmd, like CC, DLINK\r
//\r
String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null};\r
- key[4] = "PATH";\r
+ key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_PATH;\r
String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId);\r
- key[4] = "NAME";\r
+ key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME;\r
String cmdName = GlobalData.getCommandSetting(key, fpdModuleId);\r
File cmdFile = new File(cmdPath + File.separatorChar + cmdName);\r
-// GlobalData.log.info("PATH: " + cmdFile.getPath());\r
- getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));\r
- \r
+ PropertyManager.setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/"));\r
+\r
//\r
// set CC_FLAGS\r
//\r
- key[4] = "FLAGS";\r
+ key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS;\r
String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId);\r
-// GlobalData.log.info("Flags: " + cmdFlags);\r
Set<String> addset = new LinkedHashSet<String>();\r
Set<String> subset = new LinkedHashSet<String>();\r
putFlagsToSet(addset, cmdFlags);\r
- getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));\r
- \r
+ PropertyManager.setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset)));\r
+\r
//\r
// Set CC_EXT\r
//\r
- key[4] = "EXT";\r
+ key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_EXT;\r
String extName = GlobalData.getCommandSetting(key, fpdModuleId);\r
-// GlobalData.log.info("Ext: " + extName);\r
if ( extName != null && ! extName.equalsIgnoreCase("")) {\r
- getProject().setProperty(cmd[m] + "_EXT", extName);\r
- }\r
- else {\r
- getProject().setProperty(cmd[m] + "_EXT", "");\r
+ PropertyManager.setProperty(cmd[m] + "_EXT", extName);\r
+ } else {\r
+ PropertyManager.setProperty(cmd[m] + "_EXT", "");\r
}\r
- \r
+\r
//\r
// set CC_FAMILY\r
//\r
- key[4] = "FAMILY";\r
+ key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY;\r
String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId);\r
-// GlobalData.log.info("FAMILY: " + toolChainFamily);\r
if (toolChainFamily != null) {\r
- getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily);\r
+ PropertyManager.setProperty(cmd[m] + "_FAMILY", toolChainFamily);\r
}\r
- \r
+\r
//\r
// set CC_SPATH\r
//\r
- key[4] = "SPATH";\r
+ key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_SPATH;\r
String spath = GlobalData.getCommandSetting(key, fpdModuleId);\r
-// GlobalData.log.info("SPATH: " + spath);\r
if (spath != null) {\r
- getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));\r
+ PropertyManager.setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/"));\r
+ } else {\r
+ PropertyManager.setProperty(cmd[m] + "_SPATH", "");\r
}\r
- else {\r
- getProject().setProperty(cmd[m] + "_SPATH", "");\r
- }\r
- \r
+\r
//\r
// set CC_DPATH\r
//\r
- key[4] = "DPATH";\r
+ key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_DPATH;\r
String dpath = GlobalData.getCommandSetting(key, fpdModuleId);\r
-// GlobalData.log.info("DPATH: " + dpath);\r
if (dpath != null) {\r
- getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));\r
- }\r
- else {\r
- getProject().setProperty(cmd[m] + "_DPATH", "");\r
+ PropertyManager.setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/"));\r
+ } else {\r
+ PropertyManager.setProperty(cmd[m] + "_DPATH", "");\r
}\r
}\r
}\r
- \r
+\r
public void setMsaFile(File msaFile) {\r
this.msaFile = msaFile;\r
}\r
\r
/**\r
- Method is for ANT to initialize MSA file. \r
- \r
+ Method is for ANT to initialize MSA file.\r
+\r
@param msaFilename MSA file name\r
**/\r
public void setMsaFile(String msaFilename) {\r
String moduleDir = getProject().getProperty("MODULE_DIR");\r
- \r
+\r
//\r
// If is Single Module Build, then use the Base Dir defined in build.xml\r
//\r
}\r
msaFile = new File(moduleDir + File.separatorChar + msaFilename);\r
}\r
- \r
+\r
public void addConfiguredModuleItem(ModuleItem moduleItem) {\r
PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion());\r
ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion());\r
moduleId.setPackage(packageId);\r
this.moduleId = moduleId;\r
}\r
- \r
+\r
/**\r
- Add a property. \r
- \r
+ Add a property.\r
+\r
@param p property\r
**/\r
public void addProperty(Property p) {\r
public void setType(String type) {\r
this.type = type;\r
}\r
- \r
- private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException{\r
+\r
+ private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws BuildException{\r
//\r
// AutoGen\r
//\r
- \r
- AutoGen autogen = new AutoGen(getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());\r
+\r
+ AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch());\r
autogen.genAutogen();\r
- \r
- \r
+\r
+\r
//\r
// Get compiler flags\r
//\r
- getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r
+ try {\r
+ getCompilerFlags(buildTarget, buildTagname, fpdModuleId);\r
+ }\r
+ catch (EdkException ee) {\r
+ throw new BuildException(ee.getMessage());\r
+ }\r
\r
//\r
// Prepare LIBS\r
for (int i = 0; i < libinstances.length; i++) {\r
propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib";\r
}\r
- getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r
+ PropertyManager.setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r
+\r
+ //\r
+ // Get all includepath and set to INCLUDE_PATHS\r
+ //\r
+ String[] includes = prepareIncludePaths(fpdModuleId);\r
\r
//\r
// if it is CUSTOM_BUILD\r
// then call the exist BaseName_build.xml directly.\r
//\r
if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
- GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r
- Ant ant = new Ant();\r
- ant.setProject(getProject());\r
- ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
- ant.setInheritAll(true);\r
- ant.init();\r
- ant.execute();\r
+ System.out.println("Call user-defined " + moduleId.getName() + "_build.xml");\r
+ \r
+ String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+ antCall(antFilename, null);\r
+ \r
return ;\r
}\r
- \r
+\r
//\r
// Generate ${BASE_NAME}_build.xml\r
// TBD\r
//\r
String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword();\r
- ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId);\r
+ ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId, includes);\r
String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
fileGenerator.genBuildFile(buildFilename);\r
- \r
+\r
//\r
// Ant call ${BASE_NAME}_build.xml\r
//\r
- Ant ant = new Ant();\r
- ant.setProject(getProject());\r
- ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
- ant.setInheritAll(true);\r
- ant.init();\r
- ant.execute();\r
+ String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+ antCall(antFilename, null);\r
}\r
- \r
+\r
private void applyClean(FpdModuleIdentification fpdModuleId){\r
//\r
// if it is CUSTOM_BUILD\r
// then call the exist BaseName_build.xml directly.\r
//\r
if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
- GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r
- Ant ant = new Ant();\r
- ant.setProject(getProject());\r
- ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
- ant.setTarget("clean");\r
- ant.setInheritAll(true);\r
- ant.init();\r
- ant.execute();\r
+ System.out.println("Calling user-defined " + moduleId.getName() + "_build.xml");\r
+ \r
+ String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+ antCall(antFilename, "clean");\r
+ \r
return ;\r
}\r
- \r
- Ant ant = new Ant();\r
- ant.setProject(getProject());\r
- ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
- ant.setTarget("clean");\r
- ant.setInheritAll(true);\r
- ant.init();\r
- ant.execute();\r
- \r
- //\r
- // Delete current module's DEST_DIR_OUTPUT\r
- // TBD\r
+\r
+ String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+ antCall(antFilename, "clean");\r
}\r
- \r
+\r
private void applyCleanall(FpdModuleIdentification fpdModuleId){\r
//\r
// if it is CUSTOM_BUILD\r
// then call the exist BaseName_build.xml directly.\r
//\r
if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) {\r
- GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml");\r
- Ant ant = new Ant();\r
- ant.setProject(getProject());\r
- ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml");\r
- ant.setTarget("cleanall");\r
- ant.setInheritAll(true);\r
- ant.init();\r
- ant.execute();\r
+ System.out.println("Calling user-defined " + moduleId.getName() + "_build.xml");\r
+\r
+ String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+ antCall(antFilename, "cleanall");\r
+ \r
return ;\r
}\r
\r
+ String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml";\r
+ antCall(antFilename, "cleanall");\r
+ }\r
+\r
+ private void antCall(String antFilename, String target) {\r
Ant ant = new Ant();\r
ant.setProject(getProject());\r
- ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml");\r
- ant.setTarget("cleanall");\r
+ ant.setAntfile(antFilename);\r
+ if (target != null) {\r
+ ant.setTarget(target);\r
+ }\r
ant.setInheritAll(true);\r
ant.init();\r
ant.execute();\r
- \r
- //\r
- // Delete current module's DEST_DIR_OUTPUT\r
- // TBD\r
}\r
\r
\r
-\r
-\r
/**\r
Separate the string and instore in set.\r
- \r
- <p> String is separated by Java Regulation Expression \r
+\r
+ <p> String is separated by Java Regulation Expression\r
"[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>\r
- \r
+\r
<p>For example: </p>\r
- \r
+\r
<pre>\r
"/nologo", "/W3", "/WX"\r
"/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""\r
</pre>\r
- \r
+\r
@param set store the separated string\r
@param str string to separate\r
**/\r
set.add(item);\r
}\r
}\r
- \r
+\r
/**\r
- Generate the final flags string will be used by compile command. \r
- \r
+ Generate the final flags string will be used by compile command.\r
+\r
@param add the add flags set\r
@param sub the sub flags set\r
@return final flags after add set substract sub set\r
return result;\r
}\r
\r
- /**\r
- Generate the flags string with original format. The format is defined by \r
- Java Regulation Expression "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+". </p>\r
- \r
- <p>For example: </p>\r
- \r
- <pre>\r
- "/nologo", "/W3", "/WX"\r
- "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""\r
- </pre>\r
- \r
- @param add the add flags set\r
- @param sub the sub flags set\r
- @return flags with original format\r
- **/\r
- private String getRawFlags(Set<String> add, Set<String> sub) {\r
- String result = null;\r
- add.removeAll(sub);\r
- Iterator iter = add.iterator();\r
- while (iter.hasNext()) {\r
- String str = (String) iter.next();\r
- result += "\"" + str.substring(1, str.length() - 1) + "\", ";\r
- }\r
- return result;\r
+ public void setSingleModuleBuild(boolean isSingleModuleBuild) {\r
+ this.isSingleModuleBuild = isSingleModuleBuild;\r
}\r
-\r
- private String parseOptionString(String optionString, Set<String> addSet, Set<String> subSet) {\r
- boolean overrideOption = false;\r
- Pattern pattern = Pattern.compile("ADD\\.\\[(.+)\\]");\r
- Matcher matcher = pattern.matcher(optionString);\r
-\r
- while (matcher.find()) {\r
- overrideOption = true;\r
- String addOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();\r
- putFlagsToSet(addSet, addOption);\r
- \r
+ \r
+ private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) {\r
+ //\r
+ // Prepare the includes: PackageDependencies and Output debug direactory\r
+ //\r
+ Set<String> includes = new LinkedHashSet<String>();\r
+ String arch = fpdModuleId.getArch();\r
+ \r
+ //\r
+ // WORKSPACE\r
+ //\r
+ includes.add("${WORKSPACE_DIR}" + File.separatorChar);\r
+ \r
+ //\r
+ // Module iteself\r
+ //\r
+ includes.add("${MODULE_DIR}");\r
+ includes.add("${MODULE_DIR}" + File.separatorChar + archDir(arch));\r
+ \r
+ //\r
+ // Packages in PackageDenpendencies\r
+ //\r
+ PackageIdentification[] packageDependencies = SurfaceAreaQuery.getDependencePkg(fpdModuleId.getArch());\r
+ for (int i = 0; i < packageDependencies.length; i++) {\r
+ GlobalData.refreshPackageIdentification(packageDependencies[i]);\r
+ File packageFile = packageDependencies[i].getSpdFile();\r
+ includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
+ includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
}\r
\r
- pattern = Pattern.compile("SUB\\.\\[(.+)\\]");\r
- matcher = pattern.matcher(optionString);\r
-\r
- while (matcher.find()) {\r
- overrideOption = true;\r
- String subOption = optionString.substring(matcher.start(1), matcher.end(1)).trim();\r
- putFlagsToSet(subSet, subOption);\r
+ //\r
+ // All Dependency Library Instance's PackageDependencies\r
+ //\r
+ ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch());\r
+ for (int i = 0; i < libinstances.length; i++) {\r
+ SurfaceAreaQuery.push(GlobalData.getDoc(libinstances[i], fpdModuleId.getArch()));\r
+ PackageIdentification[] libraryPackageDependencies = SurfaceAreaQuery.getDependencePkg(fpdModuleId.getArch());\r
+ for (int j = 0; j < libraryPackageDependencies.length; j++) {\r
+ GlobalData.refreshPackageIdentification(libraryPackageDependencies[j]);\r
+ File packageFile = libraryPackageDependencies[j].getSpdFile();\r
+ includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
+ includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
+ }\r
+ SurfaceAreaQuery.pop();\r
}\r
+ \r
+ \r
+ //\r
+ // The package which the module belongs to\r
+ // TBD\r
+ includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include");\r
+ includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
\r
- if (overrideOption == true) {\r
- return null;\r
+ //\r
+ // Debug files output directory\r
+ //\r
+ includes.add("${DEST_DIR_DEBUG}");\r
+ \r
+ //\r
+ // set to INCLUDE_PATHS property\r
+ //\r
+ Iterator<String> iter = includes.iterator();\r
+ StringBuffer includePaths = new StringBuffer();\r
+ while (iter.hasNext()) {\r
+ includePaths.append(iter.next());\r
+ includePaths.append("; ");\r
}\r
-\r
- return optionString;\r
+ PropertyManager.setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths.toString()).replaceAll("(\\\\)", "/"));\r
+ \r
+ return includes.toArray(new String[includes.size()]);\r
}\r
\r
- private void pushProperties() {\r
- backupPropertiesStack.push(getProject().getProperties());\r
- }\r
+ /**\r
+ Return the name of the directory that corresponds to the architecture.\r
+ This is a translation from the XML Schema tag to a directory that\r
+ corresponds to our directory name coding convention.\r
\r
- private void popProperties() {\r
- Hashtable backupProperties = backupPropertiesStack.pop();\r
- Set keys = backupProperties.keySet();\r
- Iterator iter = keys.iterator();\r
- while (iter.hasNext()) {\r
- String item = (String)iter.next();\r
- getProject().setProperty(item, (String)backupProperties.get(item));\r
- }\r
- }\r
-\r
- public void setSingleModuleBuild(boolean isSingleModuleBuild) {\r
- this.isSingleModuleBuild = isSingleModuleBuild;\r
- }\r
+ **/\r
+ private String archDir(String arch) {\r
+ return arch.replaceFirst("X64", "x64")\r
+ .replaceFirst("IPF", "Ipf")\r
+ .replaceFirst("IA32", "Ia32")\r
+ .replaceFirst("ARM", "Arm")\r
+ .replaceFirst("EBC", "Ebc");\r
+ } \r
}\r