X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Ffpd%2FFpdParserTask.java;h=3d2c36ad2135d463a2e3eed67bb6fc3ed9f52b0e;hb=2a9060e2949f6d21da847ba84a894cefff78d949;hp=f0b1f021b3512a2c5af305036fdd4b45946748e9;hpb=80eb97ffc03f4af85f77325a64afbdfb52b8c4f9;p=mirror_edk2.git diff --git a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java index f0b1f021b3..3d2c36ad21 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java @@ -18,6 +18,7 @@ package org.tianocore.build.fpd; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -30,11 +31,13 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.Ant; import org.apache.tools.ant.taskdefs.Property; +import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.tianocore.common.definitions.EdkDefinitions; import org.tianocore.common.exception.EdkException; import org.tianocore.pcd.action.ActionMessage; +import org.tianocore.build.FrameworkBuildTask; import org.tianocore.build.global.GlobalData; import org.tianocore.build.global.OutputManager; import org.tianocore.build.global.SurfaceAreaQuery; @@ -63,40 +66,34 @@ import org.tianocore.build.toolchain.ToolChainMap;

The method parseFpdFile is also prepared for single module build.

-

The usage is (take NT32 Platform for example):

- -
-  <FPDParser platformName="Nt32" />
-  
- @since GenBuild 1.0 **/ public class FpdParserTask extends Task { - private String platformName; - private File fpdFile = null; - private PlatformIdentification platformId; + PlatformIdentification platformId; private String type; /// /// Mapping from modules identification to out put file name /// - private Map outfiles = new LinkedHashMap(); + Map outfiles = new LinkedHashMap(); /// /// Mapping from FV name to its modules /// - private Map> fvs = new HashMap>(); + Map> fvs = new HashMap>(); /// /// FpdParserTask can specify some ANT properties. /// private Vector properties = new Vector(); - private boolean isUnified = true; + SurfaceAreaQuery saq = null; + + boolean isUnified = true; /** Public construct method. It is necessary for ANT task. @@ -120,18 +117,6 @@ public class FpdParserTask extends Task { Surface area is not valid. **/ public void execute() throws BuildException { - // - // If fpdFile is not specified, - // then try to get FPD file by platformName - // - if ( fpdFile == null) { - if (platformName == null) { - throw new BuildException("FpdParserTask parameter error. Please specify either the platform name or FPD file!"); - } - platformId = GlobalData.getPlatformByName(platformName); - fpdFile = platformId.getFpdFile(); - } - // // Parse FPD file // @@ -142,6 +127,7 @@ public class FpdParserTask extends Task { // isUnified = OutputManager.getInstance().prepareBuildDir(getProject()); + String buildDir = getProject().getProperty("BUILD_DIR"); // // For every Target and ToolChain // @@ -152,8 +138,8 @@ public class FpdParserTask extends Task { // // Prepare FV_DIR // - String ffsCommonDir = getProject().getProperty("BUILD_DIR") + File.separatorChar - + targetList[i] + File.separatorChar + String ffsCommonDir = buildDir + File.separatorChar + + targetList[i] + "_" + toolchainList[j]; File fvDir = new File(ffsCommonDir + File.separatorChar + "FV"); fvDir.mkdirs(); @@ -169,16 +155,16 @@ public class FpdParserTask extends Task { // // Gen build.xml // - PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified); + String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml"; + PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile); fileGenerator.genBuildFile(); // // Ant call ${PLATFORM}_build.xml // - Ant ant = new Ant(); ant.setProject(getProject()); - ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml"); + ant.setAntfile(platformBuildFile); ant.setTarget(type); ant.setInheritAll(true); ant.init(); @@ -193,13 +179,13 @@ public class FpdParserTask extends Task { @throws BuildException File write FV.inf files error. **/ - private void genFvInfFiles(String ffsCommonDir) throws BuildException { - String[] validFv = SurfaceAreaQuery.getFpdValidImageNames(); + void genFvInfFiles(String ffsCommonDir) throws BuildException { + String[] validFv = saq.getFpdValidImageNames(); for (int i = 0; i < validFv.length; i++) { // // Get all global variables from FPD and set them to properties // - String[][] globalVariables = SurfaceAreaQuery.getFpdGlobalVariable(); + String[][] globalVariables = saq.getFpdGlobalVariable(); for (int j = 0; j < globalVariables.length; j++) { getProject().setProperty(globalVariables[j][0], globalVariables[j][1]); } @@ -216,7 +202,7 @@ public class FpdParserTask extends Task { // // Options // - String[][] options = SurfaceAreaQuery.getFpdOptions(validFv[i]); + String[][] options = saq.getFpdOptions(validFv[i]); if (options.length > 0) { bw.write("[options]"); bw.newLine(); @@ -237,7 +223,7 @@ public class FpdParserTask extends Task { // // Attributes; // - String[][] attributes = SurfaceAreaQuery.getFpdAttributes(validFv[i]); + String[][] attributes = saq.getFpdAttributes(validFv[i]); if (attributes.length > 0) { bw.write("[attributes]"); bw.newLine(); @@ -258,7 +244,7 @@ public class FpdParserTask extends Task { // // Components // - String[][] components = SurfaceAreaQuery.getFpdComponents(validFv[i]); + String[][] components = saq.getFpdComponents(validFv[i]); if (components.length > 0) { bw.write("[components]"); bw.newLine(); @@ -293,8 +279,10 @@ public class FpdParserTask extends Task { bw.flush(); bw.close(); fw.close(); - } catch (Exception e) { - throw new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + e.getMessage()); + } catch (IOException ex) { + BuildException buildException = new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + ex.getMessage()); + buildException.setStackTrace(ex.getStackTrace()); + throw buildException; } } } @@ -305,9 +293,46 @@ public class FpdParserTask extends Task { @throws BuildException FPD file is not valid. **/ - public void parseFpdFile(File fpdFile) throws BuildException { + public void parseFpdFile(File fpdFile) throws BuildException, EdkException { this.fpdFile = fpdFile; parseFpdFile(); + + // + // Call Platform_build.xml prebuild firstly in stand-alone build + // Prepare BUILD_DIR + // + isUnified = OutputManager.getInstance().prepareBuildDir(getProject()); + + String buildDir = getProject().getProperty("BUILD_DIR"); + // + // For every Target and ToolChain + // + String[] targetList = GlobalData.getToolChainInfo().getTargets(); + for (int i = 0; i < targetList.length; i++) { + String[] toolchainList = GlobalData.getToolChainInfo().getTagnames(); + for(int j = 0; j < toolchainList.length; j++) { + // + // Prepare FV_DIR + // + String ffsCommonDir = buildDir + File.separatorChar + + targetList[i] + "_" + + toolchainList[j]; + File fvDir = new File(ffsCommonDir + File.separatorChar + "FV"); + fvDir.mkdirs(); + } + } + + String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml"; + PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile); + fileGenerator.genBuildFile(); + + Ant ant = new Ant(); + ant.setProject(getProject()); + ant.setAntfile(platformBuildFile); + ant.setTarget("prebuild"); + ant.setInheritAll(true); + ant.init(); + ant.execute(); } /** @@ -316,7 +341,7 @@ public class FpdParserTask extends Task { @throws BuildException FPD file is not valid. **/ - private void parseFpdFile() throws BuildException { + void parseFpdFile() throws BuildException { try { XmlObject doc = XmlObject.Factory.parse(fpdFile); @@ -326,32 +351,39 @@ public class FpdParserTask extends Task { Map map = new HashMap(); map.put("PlatformSurfaceArea", doc); - SurfaceAreaQuery.setDoc(map); + saq = new SurfaceAreaQuery(map); // // Initialize // - platformId = SurfaceAreaQuery.getFpdHeader(); + platformId = saq.getFpdHeader(); platformId.setFpdFile(fpdFile); getProject().setProperty("PLATFORM", platformId.getName()); getProject().setProperty("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/")); getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/")); getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/")); + + if( !FrameworkBuildTask.multithread) { + FrameworkBuildTask.originalProperties.put("PLATFORM", platformId.getName()); + FrameworkBuildTask.originalProperties.put("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/")); + FrameworkBuildTask.originalProperties.put("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/")); + FrameworkBuildTask.originalProperties.put("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/")); + } // // Build mode. User-defined output dir. // - String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories(); - String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory(); + String buildMode = saq.getFpdIntermediateDirectories(); + String userDefinedOutputDir = saq.getFpdOutputDirectory(); OutputManager.getInstance().setup(userDefinedOutputDir, buildMode); // // TBD. Deal PCD and BuildOption related Info // - GlobalData.setFpdBuildOptions(SurfaceAreaQuery.getFpdBuildOptions()); + GlobalData.setFpdBuildOptions(saq.getFpdBuildOptions()); - GlobalData.setToolChainPlatformInfo(SurfaceAreaQuery.getFpdToolChainInfo()); + GlobalData.setToolChainPlatformInfo(saq.getFpdToolChainInfo()); // // Parse all list modules SA @@ -364,25 +396,33 @@ public class FpdParserTask extends Task { parseToolChainFamilyOptions(); parseToolChainOptions(); - SurfaceAreaQuery.setDoc(map); + saq.push(map); // // Pcd Collection. Call CollectPCDAction to collect pcd info. // PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding(); ca.perform(platformId.getFpdFile().getPath(), ActionMessage.NULL_MESSAGE_LEVEL); - } catch (Exception e) { - throw new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + e.getMessage()); + } catch (IOException ex) { + BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage()); + buildException.setStackTrace(ex.getStackTrace()); + throw buildException; + } catch (XmlException ex) { + BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage()); + buildException.setStackTrace(ex.getStackTrace()); + throw buildException; + } catch (EdkException ex) { + BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage()); + buildException.setStackTrace(ex.getStackTrace()); + throw buildException; } } - - /** Parse all modules listed in FPD file. **/ - private void parseModuleSAFiles() throws EdkException{ - Map> moduleSAs = SurfaceAreaQuery.getFpdModules(); + void parseModuleSAFiles() throws EdkException{ + Map> moduleSAs = saq.getFpdModules(); // // For every Module lists in FPD file. @@ -395,14 +435,13 @@ public class FpdParserTask extends Task { // // Judge if Module is existed? // TBD - GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId)); // // Put fpdModuleId to the corresponding FV // - SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId)); - String fvBinding = SurfaceAreaQuery.getModuleFvBindingKeyword(); + saq.push(GlobalData.getDoc(fpdModuleId)); + String fvBinding = saq.getModuleFvBindingKeyword(); fpdModuleId.setFvBinding(fvBinding); updateFvs(fvBinding, fpdModuleId); @@ -412,7 +451,7 @@ public class FpdParserTask extends Task { // ModuleIdentification moduleId = fpdModuleId.getModule(); - String baseName = SurfaceAreaQuery.getModuleOutputFileBasename(); + String baseName = saq.getModuleOutputFileBasename(); if (baseName == null) { baseName = moduleId.getName(); @@ -426,12 +465,12 @@ public class FpdParserTask extends Task { // GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false)); GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true)); - SurfaceAreaQuery.pop(); + saq.pop(); } } - private ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException { - String[][] options = SurfaceAreaQuery.getModuleBuildOptions(toolChainFamilyFlag); + ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException { + String[][] options = saq.getModuleBuildOptions(toolChainFamilyFlag); if (options == null || options.length == 0) { return new ToolChainMap(); } @@ -439,7 +478,7 @@ public class FpdParserTask extends Task { } private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException { - String[][] options = SurfaceAreaQuery.getPlatformBuildOptions(toolChainFamilyFlag); + String[][] options = saq.getPlatformBuildOptions(toolChainFamilyFlag); if (options == null || options.length == 0) { return new ToolChainMap(); } @@ -476,7 +515,7 @@ public class FpdParserTask extends Task { @param fvName current FV name @param moduleName current module identification **/ - private void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) { + void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) { if (fvName == null || fvName.trim().length() == 0) { fvName = "NULL"; } @@ -547,10 +586,6 @@ public class FpdParserTask extends Task { properties.addElement(p); } - public void setPlatformName(String platformName) { - this.platformName = platformName; - } - public void setFpdFile(File fpdFile) { this.fpdFile = fpdFile; } @@ -558,4 +593,18 @@ public class FpdParserTask extends Task { public void setType(String type) { this.type = type; } + + public String getAllArchForModule(ModuleIdentification moduleId) { + String archs = ""; + Iterator iter = outfiles.keySet().iterator(); + while (iter.hasNext()) { + FpdModuleIdentification fpdModuleId = iter.next(); + + if (fpdModuleId.getModule().equals(moduleId)) { + archs += fpdModuleId.getArch() + " "; + } + } + + return archs; + } }