/** @file\r
- This file is ANT task FpdParserTask. \r
- \r
- FpdParserTask is used to parse FPD (Framework Platform Description) and generate\r
- build.out.xml. It is for Package or Platform build use. \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
+ This file is ANT task FpdParserTask.\r
+\r
+ FpdParserTask is used to parse FPD (Framework Platform Description) and generate\r
+ build.out.xml. It is for Package or Platform build use.\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.fpd;\r
\r
import java.io.BufferedWriter;\r
import java.util.Set;\r
import java.util.Vector;\r
\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.transform.OutputKeys;\r
-import javax.xml.transform.Result;\r
-import javax.xml.transform.Source;\r
-import javax.xml.transform.Transformer;\r
-import javax.xml.transform.TransformerFactory;\r
-import javax.xml.transform.dom.DOMSource;\r
-import javax.xml.transform.stream.StreamResult;\r
-\r
import org.apache.tools.ant.BuildException;\r
import org.apache.tools.ant.Task;\r
+import org.apache.tools.ant.taskdefs.Ant;\r
import org.apache.tools.ant.taskdefs.Property;\r
import org.apache.xmlbeans.XmlObject;\r
-import org.w3c.dom.Comment;\r
-import org.w3c.dom.Document;\r
-import org.w3c.dom.Element;\r
\r
+import org.tianocore.common.exception.EdkException;\r
+import org.tianocore.pcd.action.ActionMessage;\r
import org.tianocore.build.global.GlobalData;\r
import org.tianocore.build.global.OutputManager;\r
-import org.tianocore.build.global.OverrideProcess;\r
import org.tianocore.build.global.SurfaceAreaQuery;\r
-import org.tianocore.build.pcd.action.CollectPCDAction;\r
-import org.tianocore.build.pcd.action.ActionMessage;\r
-import org.tianocore.BuildOptionsDocument;\r
-import org.tianocore.FrameworkPlatformDescriptionDocument;\r
-import org.tianocore.ModuleSADocument;\r
-\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PlatformIdentification;\r
+import org.tianocore.build.pcd.action.PlatformPcdPreprocessActionForBuilding;\r
+import org.tianocore.build.toolchain.ToolChainAttribute;\r
+import org.tianocore.build.toolchain.ToolChainElement;\r
+import org.tianocore.build.toolchain.ToolChainMap;\r
\r
/**\r
- <code>FpdParserTask</code> is an ANT task. The main function is parsing FPD\r
- XML file and generating its ANT build script for Platform or Package. \r
- \r
+ <code>FpdParserTask</code> is an ANT task. The main function is parsing Framework\r
+ Platform Descritpion (FPD) XML file and generating its ANT build script for\r
+ corresponding platform.\r
+\r
+ <p>The task sets global properties PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r
+ and BUILD_DIR. </p>\r
+\r
+ <p>The task generates ${PLATFORM}_build.xml file which will be called by top level\r
+ build.xml. The task also generate Fv.inf files (File is for Tool GenFvImage)\r
+ and flash definition file (File is for Tool FlashMap) if necessary. </p>\r
+\r
+ <p>FpdParserTask task stores all FPD information to GlobalData. And parse\r
+ tools definition file to set up compiler options for different Target and\r
+ different ToolChainTag. </p>\r
+\r
+ <p>The method parseFpdFile is also prepared for single module build. </p>\r
+\r
<p>The usage is (take NT32 Platform for example):</p>\r
- \r
+\r
<pre>\r
- <FPDParser fpdfilename="Build\Nt32.fpd" />\r
+ <FPDParser platformName="Nt32" />\r
</pre>\r
- \r
- <p>The task will initialize all information through parsing Framework Database, \r
+\r
+ <p>The task will initialize all information through parsing Framework Database,\r
SPD, Tool chain configuration files. </p>\r
- \r
+\r
@since GenBuild 1.0\r
**/\r
public class FpdParserTask extends Task {\r
\r
- ///\r
- /// FV dir: ${PLATFORM_DIR}/Build/FV\r
- ///\r
- public static final String FV_OUTPUT_DIR = "${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "FV";\r
+ private String platformName;\r
\r
- private File fpdFilename;\r
+ private File fpdFile = null;\r
\r
- private File guiddatabase;\r
+ private PlatformIdentification platformId;\r
\r
///\r
- /// Keep platform buildoption information\r
///\r
- public static XmlObject platformBuildOptions = null;\r
+ ///\r
+ private String type;\r
\r
///\r
/// Mapping from modules identification to out put file name\r
///\r
/// Mapping from FV name to its modules\r
///\r
- private Map<String, Set<FpdModuleIdentification> > fvs = new HashMap<String, Set<FpdModuleIdentification> >();\r
-\r
- ///\r
- /// Mapping from sequence number to its modules\r
- ///\r
- private Map<String, Set<FpdModuleIdentification> > sequences = new HashMap<String, Set<FpdModuleIdentification> >();\r
+ private Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
\r
///\r
- /// FpdParserTask can specify some ANT properties. \r
+ /// FpdParserTask can specify some ANT properties.\r
///\r
private Vector<Property> properties = new Vector<Property>();\r
\r
- private String info = "====================================================================\n"\r
- + "DO NOT EDIT \n"\r
- + "File auto-generated by build utility\n"\r
- + "\n"\r
- + "Abstract:\n"\r
- + "Auto-generated ANT build file for building of EFI Modules/Platforms\n"\r
- + "=====================================================================";\r
+ private boolean isUnified = true;\r
+\r
\r
/**\r
Public construct method. It is necessary for ANT task.\r
**/\r
- public FpdParserTask () {\r
+ public FpdParserTask() {\r
}\r
\r
/**\r
- ANT task's entry method. The main steps is described as following: \r
- \r
- <ul>\r
- <li>Initialize global information (Framework DB, SPD files and all MSA files \r
- listed in SPD). This step will execute only once in whole build process;</li>\r
- <li>Parse specified FPD file; </li>\r
- <li>Generate FV.inf files; </li>\r
- <li>Generate build.out.xml file for Flatform or Package build; </li>\r
- <li>Collect PCD information. </li>\r
- </ul>\r
- \r
- @throws BuildException\r
- Surface area is not valid. \r
+ ANT task's entry method. The main steps is described as following:\r
+\r
+ <ul>\r
+ <li>Initialize global information (Framework DB, SPD files and all MSA files\r
+ listed in SPD). This step will execute only once in whole build process;</li>\r
+ <li>Parse specified FPD file; </li>\r
+ <li>Generate FV.inf files; </li>\r
+ <li>Generate PlatformName_build.xml file for Flatform build; </li>\r
+ <li>Collect PCD information. </li>\r
+ </ul>\r
+\r
+ @throws BuildException\r
+ Surface area is not valid.\r
**/\r
public void execute() throws BuildException {\r
- OutputManager.update(getProject());\r
- //\r
- // Parse DB and SPDs files. Initialize Global Data\r
- //\r
- GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db", getProject()\r
- .getProperty("WORKSPACE_DIR"));\r
+ // Remove !!\r
+ if ( fpdFile == null) {\r
+ if (platformName == null) {\r
+ throw new BuildException("FpdParserTask parameter error. Please specify either the platform name or FPD file!");\r
+ }\r
+ platformId = GlobalData.getPlatformByName(platformName);\r
+ fpdFile = platformId.getFpdFile();\r
+ }\r
+\r
//\r
// Parse FPD file\r
//\r
parseFpdFile();\r
+\r
+ //\r
+ // Prepare BUILD_DIR\r
+ //\r
+ isUnified = OutputManager.getInstance().prepareBuildDir(getProject());\r
+\r
//\r
- // Gen Fv.inf files\r
+ // For every Target and ToolChain\r
//\r
- genFvInfFiles();\r
+ String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
+ for (int i = 0; i < targetList.length; i++){\r
+ String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
+ for(int j = 0; j < toolchainList.length; j++){\r
+ //\r
+ // Prepare FV_DIR\r
+ //\r
+ String ffsCommonDir = getProject().getProperty("BUILD_DIR") + File.separatorChar\r
+ + targetList[i] + File.separatorChar\r
+ + toolchainList[j];\r
+ File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
+ fvDir.mkdirs();\r
+ getProject().setProperty("FV_DIR", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
+\r
+ //\r
+ // Gen Fv.inf files\r
+ //\r
+ genFvInfFiles(ffsCommonDir);\r
+ }\r
+ }\r
+\r
//\r
// Gen build.xml\r
//\r
- genBuildFile();\r
+ PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, isUnified);\r
+ fileGenerator.genBuildFile();\r
+\r
+ //\r
+ // Ant call ${PLATFORM}_build.xml\r
//\r
- // Collect PCD information \r
- // \r
- collectPCDInformation (); \r
+\r
+ Ant ant = new Ant();\r
+ ant.setProject(getProject());\r
+ ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml");\r
+ ant.setTarget(type);\r
+ ant.setInheritAll(true);\r
+ ant.init();\r
+ ant.execute();\r
+\r
+// GlobalData.log.info("Fpd build end. ");\r
}\r
- \r
+\r
/**\r
- Generate Fv.inf files. The Fv.inf file is composed with four \r
- parts: Options, Attributes, Components and Files. The Fv.inf files \r
- will be under ${PLATFOMR_DIR}\Build\Fv.\r
- \r
+ Generate Fv.inf files. The Fv.inf file is composed with four\r
+ parts: Options, Attributes, Components and Files. The Fv.inf files\r
+ will be under FV_DIR.\r
+\r
@throws BuildException\r
- File write FV.inf files error. \r
+ File write FV.inf files error.\r
**/\r
- private void genFvInfFiles() throws BuildException{\r
+ private void genFvInfFiles(String ffsCommonDir) throws BuildException {\r
String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
for (int i = 0; i < validFv.length; i++) {\r
- getProject().setProperty("FV_FILENAME", validFv[i].toUpperCase());\r
//\r
// Get all global variables from FPD and set them to properties\r
//\r
- String[][] globalVariables = SurfaceAreaQuery\r
- .getFpdGlobalVariable();\r
+ String[][] globalVariables = SurfaceAreaQuery.getFpdGlobalVariable();\r
for (int j = 0; j < globalVariables.length; j++) {\r
- getProject().setProperty(globalVariables[j][0],\r
- globalVariables[j][1]);\r
+ getProject().setProperty(globalVariables[j][0], globalVariables[j][1]);\r
}\r
\r
- File fvFile = new File(getProject().replaceProperties(\r
- FV_OUTPUT_DIR + File.separatorChar + validFv[i].toUpperCase()\r
- + ".inf"));\r
+ getProject().setProperty("FV_FILENAME", validFv[i]);\r
+\r
+ File fvFile = new File(getProject().replaceProperties( getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".inf"));\r
fvFile.getParentFile().mkdirs();\r
\r
try {\r
FileWriter fw = new FileWriter(fvFile);\r
BufferedWriter bw = new BufferedWriter(fw);\r
+\r
//\r
// Options\r
//\r
}\r
bw.newLine();\r
}\r
+\r
//\r
// Attributes;\r
//\r
- String[][] attributes = SurfaceAreaQuery\r
- .getFpdAttributes(validFv[i]);\r
+ String[][] attributes = SurfaceAreaQuery.getFpdAttributes(validFv[i]);\r
if (attributes.length > 0) {\r
bw.write("[attributes]");\r
bw.newLine();\r
}\r
str.append("= ");\r
str.append(attributes[j][1]);\r
- bw\r
- .write(getProject().replaceProperties(\r
- str.toString()));\r
+ bw.write(getProject().replaceProperties(str.toString()));\r
bw.newLine();\r
}\r
bw.newLine();\r
}\r
+\r
//\r
// Components\r
//\r
- String[][] components = SurfaceAreaQuery\r
- .getFpdComponents(validFv[i]);\r
+ String[][] components = SurfaceAreaQuery.getFpdComponents(validFv[i]);\r
if (components.length > 0) {\r
bw.write("[components]");\r
bw.newLine();\r
}\r
str.append("= ");\r
str.append(components[j][1]);\r
- bw\r
- .write(getProject().replaceProperties(\r
- str.toString()));\r
+ bw.write(getProject().replaceProperties(str.toString()));\r
bw.newLine();\r
}\r
bw.newLine();\r
}\r
+\r
//\r
// Files\r
//\r
- Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i].toUpperCase());\r
+ Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i]);\r
if (filesSet != null) {\r
- FpdModuleIdentification[] files = filesSet.toArray(new FpdModuleIdentification[filesSet\r
- .size()]);\r
+ FpdModuleIdentification[] files = filesSet.toArray(new FpdModuleIdentification[filesSet.size()]);\r
bw.write("[files]");\r
bw.newLine();\r
for (int j = 0; j < files.length; j++) {\r
- String str = outfiles.get(files[j]);\r
- bw.write(getProject().replaceProperties(\r
- "EFI_FILE_NAME = " + str));\r
+ String str = ffsCommonDir + File.separatorChar + outfiles.get(files[j]);\r
+ bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));\r
bw.newLine();\r
}\r
}\r
bw.close();\r
fw.close();\r
} catch (Exception e) {\r
- throw new BuildException("Generate Fv.inf file failed. \n" + e.getMessage());\r
+ throw new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + e.getMessage());\r
}\r
}\r
}\r
-\r
/**\r
- Parse FPD file. \r
- \r
+ This method is used for Single Module Build.\r
+\r
+\r
@throws BuildException\r
- FPD file is not valid. \r
+ FPD file is not valid.\r
**/\r
+ public void parseFpdFile(File fpdFile) throws BuildException {\r
+ this.fpdFile = fpdFile;\r
+ parseFpdFile();\r
+ }\r
+\r
+ /**\r
+ Parse FPD file.\r
+\r
+ @throws BuildException\r
+ FPD file is not valid.\r
+ **/\r
private void parseFpdFile() throws BuildException {\r
try {\r
- FrameworkPlatformDescriptionDocument doc = (FrameworkPlatformDescriptionDocument) XmlObject.Factory\r
- .parse(fpdFilename);\r
- if ( ! doc.validate() ){\r
- throw new BuildException("FPD file is invalid.");\r
+ XmlObject doc = XmlObject.Factory.parse(fpdFile);\r
+\r
+ if (!doc.validate()) {\r
+ throw new BuildException("Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r
}\r
- platformBuildOptions = doc.getFrameworkPlatformDescription()\r
- .getBuildOptions();\r
- HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
- map.put("FrameworkPlatformDescription", doc);\r
+\r
+ Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
+ map.put("PlatformSurfaceArea", doc);\r
SurfaceAreaQuery.setDoc(map);\r
+\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
+ //\r
+ String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();\r
+ String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();\r
+\r
+ OutputManager.getInstance().setup(userDefinedOutputDir, buildMode);\r
+\r
+ //\r
+ // TBD. Deal PCD and BuildOption related Info\r
+ //\r
+ GlobalData.setFpdBuildOptions(SurfaceAreaQuery.getFpdBuildOptions());\r
+\r
+ GlobalData.setToolChainPlatformInfo(SurfaceAreaQuery.getFpdToolChainInfo());\r
+\r
//\r
// Parse all list modules SA\r
//\r
parseModuleSAFiles();\r
+\r
+ //\r
+ // TBD. Deal PCD and BuildOption related Info\r
+ //\r
+ parseToolChainFamilyOptions();\r
+ parseToolChainOptions();\r
+\r
SurfaceAreaQuery.setDoc(map);\r
+\r
+ //\r
+ // Pcd Collection. Call CollectPCDAction to collect pcd info.\r
+ //\r
+ PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();\r
+ ca.perform(platformId.getFpdFile().getPath(), ActionMessage.NULL_MESSAGE_LEVEL);\r
} catch (Exception e) {\r
- throw new BuildException("Load FPD file [" + fpdFilename.getPath()\r
- + "] error. \n" + e.getMessage());\r
+ throw new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + e.getMessage());\r
}\r
}\r
\r
+\r
+\r
/**\r
- Parse all modules listed in FPD file. \r
+ Parse all modules listed in FPD file.\r
**/\r
- private void parseModuleSAFiles() {\r
- ModuleSADocument.ModuleSA[] moduleSAs = SurfaceAreaQuery\r
- .getFpdModules();\r
+ private void parseModuleSAFiles() throws EdkException{\r
+ Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = SurfaceAreaQuery.getFpdModules();\r
+\r
//\r
// For every Module lists in FPD file.\r
//\r
- for (int i = 0; i < moduleSAs.length; i++) {\r
- String defaultFv = "NULL";\r
- String defaultArch = "IA32";\r
- String baseName = moduleSAs[i].getModuleName();\r
- if (baseName == null) {\r
- System.out.println("Warning: Module Name is not specified.");\r
- continue;\r
- }\r
- String fvBinding = moduleSAs[i].getFvBinding();\r
+ Set<FpdModuleIdentification> keys = moduleSAs.keySet();\r
+ Iterator iter = keys.iterator();\r
+ while (iter.hasNext()) {\r
+ FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
+\r
//\r
- // If the module do not specify any FvBinding, use the default value.\r
- // Else update the default FvBinding value to this value.\r
+ // Judge if Module is existed?\r
+ // TBD\r
+\r
+ GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId));\r
+\r
//\r
- if (fvBinding == null) {\r
- fvBinding = defaultFv;\r
- }\r
- else {\r
- defaultFv = fvBinding;\r
- }\r
- String arch;\r
+ // Put fpdModuleId to the corresponding FV\r
//\r
- // If the module do not specify any Arch, use the default value.\r
- // Else update the default Arch value to this value.\r
+ SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
+ String fvBinding = SurfaceAreaQuery.getModuleFvBindingKeyword();\r
+ SurfaceAreaQuery.pop();\r
+\r
+ fpdModuleId.setFvBinding(fvBinding);\r
+ updateFvs(fvBinding, fpdModuleId);\r
+\r
//\r
- if (moduleSAs[i].getArch() == null ){\r
- arch = defaultArch;\r
- }\r
- else {\r
- arch = moduleSAs[i].getArch().toString();\r
- defaultArch = arch;\r
+ // Prepare for out put file name\r
+ //\r
+ ModuleIdentification moduleId = fpdModuleId.getModule();\r
+ SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
+ String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r
+ SurfaceAreaQuery.pop();\r
+ if (baseName == null) {\r
+ baseName = moduleId.getName();\r
}\r
- Map<String, XmlObject> msaMap = GlobalData.getNativeMsa(baseName);\r
- Map<String, XmlObject> mbdMap = GlobalData.getNativeMbd(baseName);\r
- Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
+ outfiles.put(fpdModuleId, fpdModuleId.getArch() + File.separatorChar\r
+ + moduleId.getGuid() + "-" + baseName\r
+ + getSuffix(moduleId.getModuleType()));\r
+\r
//\r
- // Whether the Module SA has parsed before or not\r
+ // parse module build options, if any\r
//\r
- if (!GlobalData.isModuleParsed(baseName)) {\r
- OverrideProcess op = new OverrideProcess();\r
- //\r
- // using overriding rules\r
- // Here we can also put platform Build override\r
- //\r
- map = op.override(mbdMap, msaMap);\r
- Map<String, XmlObject> overrideMap = op.override(\r
- getPlatformOverrideInfo(moduleSAs[i]),\r
- OverrideProcess.deal(map));\r
- GlobalData.registerModule(baseName, overrideMap);\r
- } else {\r
- map = GlobalData.getDoc(baseName);\r
- }\r
- SurfaceAreaQuery.setDoc(map);\r
- String guid = SurfaceAreaQuery.getModuleGuid();\r
- String componentType = SurfaceAreaQuery.getComponentType();\r
- FpdModuleIdentification moduleId = new FpdModuleIdentification(baseName, guid, arch);\r
- updateFvs(fvBinding, moduleId);\r
- outfiles.put(moduleId, "${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar \r
- + "${TARGET}" + File.separatorChar + arch\r
- + File.separatorChar + guid + "-" + baseName\r
- + getSuffix(componentType));\r
+ SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
+ GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));\r
+ GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));\r
+ SurfaceAreaQuery.pop();\r
}\r
}\r
\r
- /**\r
- Add the current module to corresponding FV. \r
- \r
- @param fvName current FV name\r
- @param moduleName current module identification\r
- **/\r
- private void updateFvs(String fvName, FpdModuleIdentification moduleName) {\r
- String upcaseFvName = fvName.toUpperCase();\r
- if (fvs.containsKey(upcaseFvName)) {\r
- Set<FpdModuleIdentification> set = fvs.get(upcaseFvName);\r
- set.add(moduleName);\r
- } else {\r
- Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r
- set.add(moduleName);\r
- fvs.put(upcaseFvName, set);\r
+ private ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
+ String[][] options = SurfaceAreaQuery.getModuleBuildOptions(toolChainFamilyFlag);\r
+ if (options == null || options.length == 0) {\r
+ return null;\r
}\r
+ return parseOptions(options);\r
}\r
\r
- /**\r
- Get the suffix based on component type. Current relationship are listed: \r
- \r
- <pre>\r
- <b>ComponentType</b> <b>Suffix</b>\r
- APPLICATION .APP\r
- SEC .SEC\r
- PEI_CORE .PEI\r
- PE32_PEIM .PEI\r
- RELOCATABLE_PEIM .PEI\r
- PIC_PEIM .PEI\r
- COMBINED_PEIM_DRIVER .PEI\r
- TE_PEIM .PEI\r
- LOGO .FFS\r
- others .DXE\r
- </pre>\r
- \r
- @param componentType component type\r
- @return\r
- @throws BuildException\r
- If component type is null\r
- **/\r
- public static String getSuffix(String componentType) throws BuildException{\r
- if (componentType == null) {\r
- throw new BuildException("Component type is not specified.");\r
- }\r
- String str = ".DXE";\r
- if (componentType.equalsIgnoreCase("APPLICATION")) {\r
- str = ".APP";\r
- } else if (componentType.equalsIgnoreCase("SEC")) {\r
- str = ".SEC";\r
- } else if (componentType.equalsIgnoreCase("PEI_CORE")) {\r
- str = ".PEI";\r
- } else if (componentType.equalsIgnoreCase("PE32_PEIM")) {\r
- str = ".PEI";\r
- } else if (componentType.equalsIgnoreCase("RELOCATABLE_PEIM")) {\r
- str = ".PEI";\r
- } else if (componentType.equalsIgnoreCase("PIC_PEIM")) {\r
- str = ".PEI";\r
- } else if (componentType.equalsIgnoreCase("COMBINED_PEIM_DRIVER")) {\r
- str = ".PEI";\r
- } else if (componentType.equalsIgnoreCase("TE_PEIM")) {\r
- str = ".PEI";\r
- } else if (componentType.equalsIgnoreCase("LOGO")) {\r
- str = ".FFS";\r
+ private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
+ String[][] options = SurfaceAreaQuery.getPlatformBuildOptions(toolChainFamilyFlag);\r
+ if (options == null || options.length == 0) {\r
+ return null;\r
}\r
- return str;\r
+ return parseOptions(options);\r
}\r
\r
- /**\r
- Parse module surface are info described in FPD file and put them into map. \r
- \r
- @param sa module surface area info descibed in FPD file\r
- @return map list with top level elements\r
- **/\r
- private Map<String, XmlObject> getPlatformOverrideInfo(\r
- ModuleSADocument.ModuleSA sa) {\r
- Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
- map.put("SourceFiles", sa.getSourceFiles());\r
- map.put("Includes", sa.getIncludes());\r
- map.put("Libraries", sa.getLibraries());\r
- map.put("Protocols", sa.getProtocols());\r
- map.put("Events", sa.getEvents());\r
- map.put("Hobs", sa.getHobs());\r
- map.put("PPIs", sa.getPPIs());\r
- map.put("Variables", sa.getVariables());\r
- map.put("BootModes", sa.getBootModes());\r
- map.put("SystemTables", sa.getSystemTables());\r
- map.put("DataHubs", sa.getDataHubs());\r
- map.put("Formsets", sa.getFormsets());\r
- map.put("Guids", sa.getGuids());\r
- map.put("Externs", sa.getExterns());\r
- map.put("BuildOptions", platformBuildOptions);\r
+ private ToolChainMap parseOptions(String[][] options) throws EdkException {\r
+ ToolChainMap map = new ToolChainMap();\r
+ int flagIndex = ToolChainElement.ATTRIBUTE.value;\r
+\r
+ for (int i = 0; i < options.length; ++i) {\r
+ String flagString = options[i][flagIndex];\r
+ if (flagString == null) {\r
+ flagString = "";\r
+ }\r
+ options[i][flagIndex] = ToolChainAttribute.FLAGS + "";\r
+ map.put(options[i], flagString.trim());\r
+ }\r
+\r
return map;\r
}\r
\r
+ private void parseToolChainFamilyOptions() throws EdkException {\r
+ GlobalData.setPlatformToolChainFamilyOption(parsePlatformBuildOptions(true));\r
+ }\r
+\r
+ private void parseToolChainOptions() throws EdkException {\r
+ GlobalData.setPlatformToolChainOption(parsePlatformBuildOptions(false));\r
+ }\r
+\r
/**\r
- Generate build.out.xml file.\r
- \r
- @throws BuildException\r
- build.out.xml XML document create error\r
+ Add the current module to corresponding FV.\r
+\r
+ @param fvName current FV name\r
+ @param moduleName current module identification\r
**/\r
- private void genBuildFile() throws BuildException {\r
- DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
- try {\r
- DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
- Document document = dombuilder.newDocument();\r
- Comment rootComment = document.createComment(info);\r
- //\r
- // create root element and its attributes\r
- //\r
- Element root = document.createElement("project");\r
- root.setAttribute("name", getProject().getProperty("PLATFORM"));\r
- root.setAttribute("default", "main");\r
- root.setAttribute("basedir", ".");\r
- //\r
- // element for External ANT tasks\r
- //\r
- root.appendChild(document.createComment("Apply external ANT tasks"));\r
- Element ele = document.createElement("taskdef");\r
- ele.setAttribute("resource", "GenBuild.tasks");\r
- root.appendChild(ele);\r
-\r
- ele = document.createElement("taskdef");\r
- ele.setAttribute("resource", "frameworktasks.tasks");\r
- root.appendChild(ele);\r
-\r
- ele = document.createElement("property");\r
- ele.setAttribute("environment", "env");\r
- root.appendChild(ele);\r
- //\r
- // Default Target\r
- //\r
- root.appendChild(document.createComment("Default target"));\r
- ele = document.createElement("target");\r
- ele.setAttribute("name", "main");\r
- ele.setAttribute("depends", "modules, fvs");\r
- root.appendChild(ele);\r
- //\r
- // Modules Target\r
- //\r
- root.appendChild(document.createComment("Modules target"));\r
- ele = document.createElement("target");\r
- ele.setAttribute("name", "modules");\r
-\r
- Set set = outfiles.keySet();\r
- Iterator iter = set.iterator();\r
- while (iter.hasNext()) {\r
- FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
- String baseName = moduleId.getBaseName();\r
- Element moduleEle = document.createElement("ant");\r
- moduleEle.setAttribute("antfile", GlobalData\r
- .getModulePath(baseName)\r
- + File.separatorChar + "build.xml");\r
- moduleEle.setAttribute("target", baseName);\r
- //\r
- // ARCH\r
- //\r
- Element property = document.createElement("property");\r
- property.setAttribute("name", "ARCH");\r
- property.setAttribute("value", moduleId.getArch());\r
- moduleEle.appendChild(property);\r
- //\r
- // PACKAGE_DIR\r
- //\r
- property = document.createElement("property");\r
- property.setAttribute("name", "PACKAGE_DIR");\r
- property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
- + GlobalData.getPackagePathForModule(baseName));\r
- moduleEle.appendChild(property);\r
- //\r
- // PACKAGE\r
- //\r
- property = document.createElement("property");\r
- property.setAttribute("name", "PACKAGE");\r
- property.setAttribute("value", GlobalData\r
- .getPackageNameForModule(baseName));\r
- moduleEle.appendChild(property);\r
- ele.appendChild(moduleEle);\r
- }\r
- root.appendChild(ele);\r
- //\r
- // FVS Target\r
- //\r
- root.appendChild(document.createComment("FVs target"));\r
- ele = document.createElement("target");\r
- ele.setAttribute("name", "fvs");\r
-\r
- String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
- for (int i = 0; i < validFv.length; i++) {\r
- String inputFile = FV_OUTPUT_DIR + "" + File.separatorChar\r
- + validFv[i].toUpperCase() + ".inf";\r
- Element fvEle = document.createElement("genfvimage");\r
- fvEle.setAttribute("infFile", inputFile);\r
- ele.appendChild(fvEle);\r
- Element moveEle = document.createElement("move");\r
- moveEle.setAttribute("file", validFv[i].toUpperCase() + ".fv");\r
- moveEle.setAttribute("todir", FV_OUTPUT_DIR);\r
- ele.appendChild(moveEle);\r
- }\r
- root.appendChild(ele);\r
- \r
- boolean isUnified = false;\r
- BuildOptionsDocument.BuildOptions buildOptions = (BuildOptionsDocument.BuildOptions)platformBuildOptions;\r
- if (buildOptions.getOutputDirectory() != null){\r
- if (buildOptions.getOutputDirectory().getIntermediateDirectories() != null){\r
- if (buildOptions.getOutputDirectory().getIntermediateDirectories().toString().equalsIgnoreCase("UNIFIED")){\r
- isUnified = true;\r
- }\r
- }\r
- }\r
- //\r
- // Clean Target\r
- //\r
- root.appendChild(document.createComment("Clean target"));\r
- ele = document.createElement("target");\r
- ele.setAttribute("name", "clean");\r
- \r
- if (isUnified) {\r
- Element cleanEle = document.createElement("delete");\r
- cleanEle.setAttribute("includeemptydirs", "true");\r
- Element filesetEle = document.createElement("fileset");\r
- filesetEle.setAttribute("dir", getProject().getProperty("PLATFORM_DIR") + File.separatorChar + "Build" + File.separatorChar + "${TARGET}");\r
- filesetEle.setAttribute("includes", "**/OUTPUT/**");\r
- cleanEle.appendChild(filesetEle);\r
- ele.appendChild(cleanEle);\r
- }\r
- else {\r
- set = outfiles.keySet();\r
- iter = set.iterator();\r
- while (iter.hasNext()) {\r
- FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
- String baseName = moduleId.getBaseName();\r
- \r
- Element ifEle = document.createElement("if");\r
- Element availableEle = document.createElement("available");\r
- availableEle.setAttribute("file", GlobalData\r
- .getModulePath(baseName)\r
- + File.separatorChar + "build.xml");\r
- ifEle.appendChild(availableEle);\r
- Element elseEle = document.createElement("then");\r
- \r
- Element moduleEle = document.createElement("ant");\r
- moduleEle.setAttribute("antfile", GlobalData\r
- .getModulePath(baseName)\r
- + File.separatorChar + "build.xml");\r
- moduleEle.setAttribute("target", baseName + "_clean");\r
- //\r
- // ARCH\r
- //\r
- Element property = document.createElement("property");\r
- property.setAttribute("name", "ARCH");\r
- property.setAttribute("value", moduleId.getArch());\r
- moduleEle.appendChild(property);\r
- //\r
- // PACKAGE_DIR\r
- //\r
- property = document.createElement("property");\r
- property.setAttribute("name", "PACKAGE_DIR");\r
- property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
- + GlobalData.getPackagePathForModule(baseName));\r
- moduleEle.appendChild(property);\r
- //\r
- // PACKAGE\r
- //\r
- property = document.createElement("property");\r
- property.setAttribute("name", "PACKAGE");\r
- property.setAttribute("value", GlobalData\r
- .getPackageNameForModule(baseName));\r
- moduleEle.appendChild(property);\r
- elseEle.appendChild(moduleEle);\r
- ifEle.appendChild(elseEle);\r
- ele.appendChild(ifEle);\r
- }\r
- }\r
- root.appendChild(ele);\r
+ private void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) {\r
+ if (fvName == null || fvName.trim().length() == 0) {\r
+ fvName = "NULL";\r
+ }\r
+ String[] fvNameArray = fvName.split("[, \t]+");\r
+ for (int i = 0; i < fvNameArray.length; i++) {\r
//\r
- // Deep Clean Target\r
+ // Put module to corresponding fvName\r
//\r
- root.appendChild(document.createComment("Clean All target"));\r
- ele = document.createElement("target");\r
- ele.setAttribute("name", "cleanall");\r
-\r
- if (isUnified) {\r
- Element cleanAllEle = document.createElement("delete");\r
- cleanAllEle.setAttribute("dir", getProject().getProperty("PLATFORM_DIR") + File.separatorChar + "Build" + File.separatorChar + "${TARGET}");\r
- ele.appendChild(cleanAllEle);\r
+ if (fvs.containsKey(fvNameArray[i])) {\r
+ Set<FpdModuleIdentification> set = fvs.get(fvNameArray[i]);\r
+ set.add(fpdModuleId);\r
}\r
else {\r
- set = outfiles.keySet();\r
- iter = set.iterator();\r
- while (iter.hasNext()) {\r
- FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
- String baseName = moduleId.getBaseName();\r
- \r
- Element ifEle = document.createElement("if");\r
- Element availableEle = document.createElement("available");\r
- availableEle.setAttribute("file", GlobalData\r
- .getModulePath(baseName)\r
- + File.separatorChar + "build.xml");\r
- ifEle.appendChild(availableEle);\r
- Element elseEle = document.createElement("then");\r
- \r
- Element moduleEle = document.createElement("ant");\r
- moduleEle.setAttribute("antfile", GlobalData\r
- .getModulePath(baseName)\r
- + File.separatorChar + "build.xml");\r
- moduleEle.setAttribute("target", baseName + "_cleanall");\r
- //\r
- // ARCH\r
- //\r
- Element property = document.createElement("property");\r
- property.setAttribute("name", "ARCH");\r
- property.setAttribute("value", moduleId.getArch());\r
- moduleEle.appendChild(property);\r
- //\r
- // PACKAGE_DIR\r
- //\r
- property = document.createElement("property");\r
- property.setAttribute("name", "PACKAGE_DIR");\r
- property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
- + GlobalData.getPackagePathForModule(baseName));\r
- moduleEle.appendChild(property);\r
- //\r
- // PACKAGE\r
- //\r
- property = document.createElement("property");\r
- property.setAttribute("name", "PACKAGE");\r
- property.setAttribute("value", GlobalData\r
- .getPackageNameForModule(baseName));\r
- moduleEle.appendChild(property);\r
- elseEle.appendChild(moduleEle);\r
- ifEle.appendChild(elseEle);\r
- ele.appendChild(ifEle);\r
- }\r
+ Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r
+ set.add(fpdModuleId);\r
+ fvs.put(fvNameArray[i], set);\r
}\r
- root.appendChild(ele);\r
- \r
- document.appendChild(rootComment);\r
- document.appendChild(root);\r
- //\r
- // Prepare the DOM document for writing\r
- //\r
- Source source = new DOMSource(document);\r
- //\r
- // Prepare the output file\r
- //\r
- File file = new File(getProject().getProperty("PLATFORM_DIR")\r
- + File.separatorChar + "build.out.xml");\r
- //\r
- // generate all directory path\r
- //\r
- (new File(file.getParent())).mkdirs();\r
- Result result = new StreamResult(file);\r
- //\r
- // Write the DOM document to the file\r
- //\r
- Transformer xformer = TransformerFactory.newInstance()\r
- .newTransformer();\r
- xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
- xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
- xformer.transform(source, result);\r
- } catch (Exception ex) {\r
- throw new BuildException("Generate build.out.xml failed. \n" + ex.getMessage());\r
}\r
}\r
\r
/**\r
- Add a property. \r
- \r
- @param p property\r
+ Get the suffix based on module type. Current relationship are listed:\r
+\r
+ <pre>\r
+ <b>ModuleType</b> <b>Suffix</b>\r
+ BASE .FFS\r
+ SEC .SEC\r
+ PEI_CORE .PEI\r
+ PEIM .PEI\r
+ DXE_CORE .DXE\r
+ DXE_DRIVER .DXE\r
+ DXE_RUNTIME_DRIVER .DXE\r
+ DXE_SAL_DRIVER .DXE\r
+ DXE_SMM_DRIVER .DXE\r
+ TOOL .FFS\r
+ UEFI_DRIVER .DXE\r
+ UEFI_APPLICATION .APP\r
+ USER_DEFINED .FFS\r
+ </pre>\r
+\r
+ @param moduleType module type\r
+ @return\r
+ @throws BuildException\r
+ If module type is null\r
**/\r
+ public static String getSuffix(String moduleType) throws BuildException {\r
+ if (moduleType == null) {\r
+ throw new BuildException("Module type is not specified.");\r
+ }\r
+\r
+ String[][] suffix = { { "BASE", ".FFS"},\r
+ { "SEC", ".SEC" }, { "PEI_CORE", ".PEI" },\r
+ { "PEIM", ".PEI" }, { "DXE_CORE", ".DXE" },\r
+ { "DXE_DRIVER", ".DXE" }, { "DXE_RUNTIME_DRIVER", ".DXE" },\r
+ { "DXE_SAL_DRIVER", ".DXE" }, { "DXE_SMM_DRIVER", ".DXE" },\r
+ { "TOOL", ".FFS" }, { "UEFI_DRIVER", ".DXE" },\r
+ { "UEFI_APPLICATION", ".APP" }, { "USER_DEFINED", ".FFS" } };\r
+\r
+ for (int i = 0; i < suffix.length; i++) {\r
+ if (suffix[i][0].equalsIgnoreCase(moduleType)) {\r
+ return suffix[i][1];\r
+ }\r
+ }\r
+ //\r
+ // Default is '.FFS'\r
+ //\r
+ return ".FFS";\r
+ }\r
+ /**\r
+ Add a property.\r
+\r
+ @param p property\r
+ **/\r
public void addProperty(Property p) {\r
properties.addElement(p);\r
}\r
\r
- /**\r
- Get FPD file name.\r
- \r
- @return FPD file name.\r
- **/\r
- public File getFpdFilename() {\r
- return fpdFilename;\r
+ public void setPlatformName(String platformName) {\r
+ this.platformName = platformName;\r
}\r
\r
- /**\r
- Set FPD file name.\r
- \r
- @param fpdFilename FPD file name\r
- **/\r
- public void setFpdFilename(File fpdFilename) {\r
- this.fpdFilename = fpdFilename;\r
+ public void setFpdFile(File fpdFile) {\r
+ this.fpdFile = fpdFile;\r
}\r
\r
- public File getGuiddatabase() {\r
- return guiddatabase;\r
+ public void setType(String type) {\r
+ this.type = type;\r
}\r
\r
- public void setGuiddatabase(File guiddatabase) {\r
- this.guiddatabase = guiddatabase;\r
- }\r
\r
- public void collectPCDInformation() {\r
- String exceptionString = null;\r
- CollectPCDAction collectAction = new CollectPCDAction ();\r
- //\r
- // Collect all PCD information from FPD to MSA, and get help information from SPD.\r
- // These all information will be stored into memory database for future usage such \r
- // as autogen.\r
- //\r
- try {\r
- collectAction.perform (getProject().getProperty("WORKSPACE_DIR"),\r
- fpdFilename.getPath(),\r
- ActionMessage.MAX_MESSAGE_LEVEL\r
- );\r
- } catch (Exception exp) {\r
- exceptionString = exp.getMessage();\r
- if (exceptionString == null) {\r
- exceptionString = "[Internal Error]Pcd tools catch a internel errors, Please report this bug into TianoCore or send email to Wang, scott or Lu, ken!";\r
- }\r
- throw new BuildException (String.format("Fail to do PCD preprocess from FPD file: %s", exceptionString));\r
- }\r
- }\r
}\r