import java.io.BufferedWriter;\r
import java.io.File;\r
import java.io.FileWriter;\r
+import java.io.IOException;\r
import java.util.HashMap;\r
import java.util.Iterator;\r
import java.util.LinkedHashMap;\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.XmlException;\r
import org.apache.xmlbeans.XmlObject;\r
\r
import org.tianocore.common.definitions.EdkDefinitions;\r
import org.tianocore.common.exception.EdkException;\r
import org.tianocore.pcd.action.ActionMessage;\r
+import org.tianocore.build.FrameworkBuildTask;\r
import org.tianocore.build.global.GlobalData;\r
import org.tianocore.build.global.OutputManager;\r
import org.tianocore.build.global.SurfaceAreaQuery;\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
- <pre>\r
- <FPDParser platformName="Nt32" />\r
- </pre>\r
-\r
@since GenBuild 1.0\r
**/\r
public class FpdParserTask extends Task {\r
\r
- private String platformName;\r
-\r
private File fpdFile = null;\r
\r
- private PlatformIdentification platformId;\r
+ PlatformIdentification platformId;\r
\r
private String type;\r
\r
///\r
/// Mapping from modules identification to out put file name\r
///\r
- private Map<FpdModuleIdentification, String> outfiles = new LinkedHashMap<FpdModuleIdentification, String>();\r
+ Map<FpdModuleIdentification, String> outfiles = new LinkedHashMap<FpdModuleIdentification, String>();\r
\r
///\r
/// Mapping from FV name to its modules\r
///\r
- private Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
+ Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
\r
///\r
/// FpdParserTask can specify some ANT properties.\r
///\r
private Vector<Property> properties = new Vector<Property>();\r
\r
- private boolean isUnified = true;\r
+ SurfaceAreaQuery saq = null;\r
+ \r
+ boolean isUnified = true;\r
\r
/**\r
Public construct method. It is necessary for ANT task.\r
Surface area is not valid.\r
**/\r
public void execute() throws BuildException {\r
- //\r
- // If fpdFile is not specified, \r
- // then try to get FPD file by platformName\r
- //\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
//\r
isUnified = OutputManager.getInstance().prepareBuildDir(getProject());\r
\r
+ String buildDir = getProject().getProperty("BUILD_DIR");\r
//\r
// For every Target and ToolChain\r
//\r
//\r
// Prepare FV_DIR\r
//\r
- String ffsCommonDir = getProject().getProperty("BUILD_DIR") + File.separatorChar\r
- + targetList[i] + File.separatorChar\r
+ String ffsCommonDir = buildDir + File.separatorChar\r
+ + targetList[i] + "_"\r
+ toolchainList[j];\r
File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
fvDir.mkdirs();\r
//\r
// Gen build.xml\r
//\r
- PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified);\r
+ String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";\r
+ PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);\r
fileGenerator.genBuildFile();\r
\r
//\r
// Ant call ${PLATFORM}_build.xml\r
//\r
-\r
Ant ant = new Ant();\r
ant.setProject(getProject());\r
- ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml");\r
+ ant.setAntfile(platformBuildFile);\r
ant.setTarget(type);\r
ant.setInheritAll(true);\r
ant.init();\r
@throws BuildException\r
File write FV.inf files error.\r
**/\r
- private void genFvInfFiles(String ffsCommonDir) throws BuildException {\r
- String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
+ void genFvInfFiles(String ffsCommonDir) throws BuildException {\r
+ String[] validFv = saq.getFpdValidImageNames();\r
for (int i = 0; i < validFv.length; i++) {\r
//\r
// Get all global variables from FPD and set them to properties\r
//\r
- String[][] globalVariables = SurfaceAreaQuery.getFpdGlobalVariable();\r
+ String[][] globalVariables = saq.getFpdGlobalVariable();\r
for (int j = 0; j < globalVariables.length; j++) {\r
getProject().setProperty(globalVariables[j][0], globalVariables[j][1]);\r
}\r
//\r
// Options\r
//\r
- String[][] options = SurfaceAreaQuery.getFpdOptions(validFv[i]);\r
+ String[][] options = saq.getFpdOptions(validFv[i]);\r
if (options.length > 0) {\r
bw.write("[options]");\r
bw.newLine();\r
//\r
// Attributes;\r
//\r
- String[][] attributes = SurfaceAreaQuery.getFpdAttributes(validFv[i]);\r
+ String[][] attributes = saq.getFpdAttributes(validFv[i]);\r
if (attributes.length > 0) {\r
bw.write("[attributes]");\r
bw.newLine();\r
//\r
// Components\r
//\r
- String[][] components = SurfaceAreaQuery.getFpdComponents(validFv[i]);\r
+ String[][] components = saq.getFpdComponents(validFv[i]);\r
if (components.length > 0) {\r
bw.write("[components]");\r
bw.newLine();\r
bw.flush();\r
bw.close();\r
fw.close();\r
- } catch (Exception e) {\r
- throw new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + e.getMessage());\r
+ } catch (IOException ex) {\r
+ BuildException buildException = new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + ex.getMessage());\r
+ buildException.setStackTrace(ex.getStackTrace());\r
+ throw buildException;\r
}\r
}\r
}\r
@throws BuildException\r
FPD file is not valid.\r
**/\r
- public void parseFpdFile(File fpdFile) throws BuildException {\r
+ public void parseFpdFile(File fpdFile) throws BuildException, EdkException {\r
this.fpdFile = fpdFile;\r
parseFpdFile();\r
+ \r
+ //\r
+ // Call Platform_build.xml prebuild firstly in stand-alone build\r
+ // Prepare BUILD_DIR\r
+ //\r
+ isUnified = OutputManager.getInstance().prepareBuildDir(getProject());\r
+\r
+ String buildDir = getProject().getProperty("BUILD_DIR");\r
+ //\r
+ // For every Target and ToolChain\r
+ //\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 = buildDir + File.separatorChar\r
+ + targetList[i] + "_"\r
+ + toolchainList[j];\r
+ File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
+ fvDir.mkdirs();\r
+ }\r
+ }\r
+\r
+ String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";\r
+ PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);\r
+ fileGenerator.genBuildFile();\r
+ \r
+ Ant ant = new Ant();\r
+ ant.setProject(getProject());\r
+ ant.setAntfile(platformBuildFile);\r
+ ant.setTarget("prebuild");\r
+ ant.setInheritAll(true);\r
+ ant.init();\r
+ ant.execute();\r
}\r
\r
/**\r
@throws BuildException\r
FPD file is not valid.\r
**/\r
- private void parseFpdFile() throws BuildException {\r
+ void parseFpdFile() throws BuildException {\r
try {\r
XmlObject doc = XmlObject.Factory.parse(fpdFile);\r
\r
\r
Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
map.put("PlatformSurfaceArea", doc);\r
- SurfaceAreaQuery.setDoc(map);\r
+ saq = new SurfaceAreaQuery(map);\r
\r
//\r
// Initialize\r
//\r
- platformId = SurfaceAreaQuery.getFpdHeader();\r
+ platformId = saq.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
+ if( !FrameworkBuildTask.multithread) {\r
+ FrameworkBuildTask.originalProperties.put("PLATFORM", platformId.getName());\r
+ FrameworkBuildTask.originalProperties.put("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));\r
+ FrameworkBuildTask.originalProperties.put("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
+ FrameworkBuildTask.originalProperties.put("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
+ }\r
\r
//\r
// Build mode. User-defined output dir.\r
//\r
- String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();\r
- String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();\r
+ String buildMode = saq.getFpdIntermediateDirectories();\r
+ String userDefinedOutputDir = saq.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
+ GlobalData.setFpdBuildOptions(saq.getFpdBuildOptions());\r
\r
- GlobalData.setToolChainPlatformInfo(SurfaceAreaQuery.getFpdToolChainInfo());\r
+ GlobalData.setToolChainPlatformInfo(saq.getFpdToolChainInfo());\r
\r
//\r
// Parse all list modules SA\r
parseToolChainFamilyOptions();\r
parseToolChainOptions();\r
\r
- SurfaceAreaQuery.setDoc(map);\r
+ saq.push(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("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + e.getMessage());\r
+ } catch (IOException ex) {\r
+ BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());\r
+ buildException.setStackTrace(ex.getStackTrace());\r
+ throw buildException;\r
+ } catch (XmlException ex) {\r
+ BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());\r
+ buildException.setStackTrace(ex.getStackTrace());\r
+ throw buildException;\r
+ } catch (EdkException ex) {\r
+ BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());\r
+ buildException.setStackTrace(ex.getStackTrace());\r
+ throw buildException;\r
}\r
}\r
\r
-\r
-\r
/**\r
Parse all modules listed in FPD file.\r
**/\r
- private void parseModuleSAFiles() throws EdkException{\r
- Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = SurfaceAreaQuery.getFpdModules();\r
+ void parseModuleSAFiles() throws EdkException{\r
+ Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = saq.getFpdModules();\r
\r
//\r
// For every Module lists in FPD file.\r
//\r
// Judge if Module is existed?\r
// TBD\r
-\r
GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId));\r
\r
//\r
// Put fpdModuleId to the corresponding FV\r
//\r
- SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
- String fvBinding = SurfaceAreaQuery.getModuleFvBindingKeyword();\r
+ saq.push(GlobalData.getDoc(fpdModuleId));\r
+ String fvBinding = saq.getModuleFvBindingKeyword();\r
\r
fpdModuleId.setFvBinding(fvBinding);\r
updateFvs(fvBinding, fpdModuleId);\r
//\r
ModuleIdentification moduleId = fpdModuleId.getModule();\r
\r
- String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r
+ String baseName = saq.getModuleOutputFileBasename();\r
\r
if (baseName == null) {\r
baseName = moduleId.getName();\r
//\r
GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));\r
GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));\r
- SurfaceAreaQuery.pop();\r
+ saq.pop();\r
}\r
}\r
\r
- private ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
- String[][] options = SurfaceAreaQuery.getModuleBuildOptions(toolChainFamilyFlag);\r
+ ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
+ String[][] options = saq.getModuleBuildOptions(toolChainFamilyFlag);\r
if (options == null || options.length == 0) {\r
return new ToolChainMap();\r
}\r
}\r
\r
private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
- String[][] options = SurfaceAreaQuery.getPlatformBuildOptions(toolChainFamilyFlag);\r
+ String[][] options = saq.getPlatformBuildOptions(toolChainFamilyFlag);\r
if (options == null || options.length == 0) {\r
return new ToolChainMap();\r
}\r
@param fvName current FV name\r
@param moduleName current module identification\r
**/\r
- private void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) {\r
+ void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) {\r
if (fvName == null || fvName.trim().length() == 0) {\r
fvName = "NULL";\r
}\r
properties.addElement(p);\r
}\r
\r
- public void setPlatformName(String platformName) {\r
- this.platformName = platformName;\r
- }\r
-\r
public void setFpdFile(File fpdFile) {\r
this.fpdFile = fpdFile;\r
}\r
public void setType(String type) {\r
this.type = type;\r
}\r
+ \r
+ public String getAllArchForModule(ModuleIdentification moduleId) {\r
+ String archs = "";\r
+ Iterator<FpdModuleIdentification> iter = outfiles.keySet().iterator();\r
+ while (iter.hasNext()) {\r
+ FpdModuleIdentification fpdModuleId = iter.next();\r
+ \r
+ if (fpdModuleId.getModule().equals(moduleId)) {\r
+ archs += fpdModuleId.getArch() + " ";\r
+ }\r
+ }\r
+ \r
+ return archs;\r
+ }\r
}\r