X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Ffpd%2FPlatformBuildFileGenerator.java;h=d4b4622c6098b8279f4e7be393b109a4b56672db;hb=02c768ee72f71bf3fef9c88068081b6112f68614;hp=e6a1002da3b711bbd0384b719b07a8e9e07bc680;hpb=391dbbb1c00daefe78e7e44499d048943ca866ae;p=mirror_edk2.git diff --git a/Tools/Source/GenBuild/org/tianocore/build/fpd/PlatformBuildFileGenerator.java b/Tools/Source/GenBuild/org/tianocore/build/fpd/PlatformBuildFileGenerator.java index e6a1002da3..d4b4622c60 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/fpd/PlatformBuildFileGenerator.java +++ b/Tools/Source/GenBuild/org/tianocore/build/fpd/PlatformBuildFileGenerator.java @@ -12,6 +12,7 @@ package org.tianocore.build.fpd; import java.io.File; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -39,17 +40,30 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +/** + class PlatformBuildFileGenerator is used to generate ${PLATFORM}_build.xml file. + + @since GenBuild 1.0 +**/ public class PlatformBuildFileGenerator { - private String platformName; - /// /// Mapping from modules identification to out put file name /// private Map outfiles; + + /// + /// Mapping from FV name to its modules + /// + private Map> fvs = new HashMap>(); + private boolean isUnified = true; + private SurfaceAreaQuery saq = null; + + private File platformBuildFile = null; + private Project project; private String info = "DO NOT EDIT \n" @@ -58,11 +72,13 @@ public class PlatformBuildFileGenerator { + "Abstract:\n" + "Auto-generated ANT build file for building EFI Modules and Platforms\n"; - public PlatformBuildFileGenerator(Project project, Map outfiles, boolean isUnified){ + public PlatformBuildFileGenerator(Project project, Map outfiles, Map> fvs, boolean isUnified, SurfaceAreaQuery saq, String platformBuildFile){ this.project = project; this.outfiles = outfiles; this.isUnified = isUnified; - this.platformName = project.getProperty("PLATFORM"); + this.fvs = fvs; + this.saq = saq; + this.platformBuildFile = new File(platformBuildFile); } /** @@ -148,14 +164,10 @@ public class PlatformBuildFileGenerator { // Source source = new DOMSource(document); // - // Prepare the output file - // - File file = new File(project.getProperty("PLATFORM_DIR") + File.separatorChar + platformName + "_build.xml"); - // // generate all directory path // - (new File(file.getParent())).mkdirs(); - Result result = new StreamResult(file); + (new File(platformBuildFile.getParent())).mkdirs(); + Result result = new StreamResult(platformBuildFile); // // Write the DOM document to the file // @@ -164,72 +176,123 @@ public class PlatformBuildFileGenerator { xformer.setOutputProperty(OutputKeys.INDENT, "yes"); xformer.transform(source, result); } catch (Exception ex) { - throw new BuildException("Generation of the " + platformName + "_build.xml failed!\n" + ex.getMessage()); + throw new BuildException("Generating platform build file [" + platformBuildFile.getPath() + "_build.xml] failed. \n" + ex.getMessage()); } } + /** + 1. Get All valid Fv Image Names in sequence + 2. For each FV, get modules by sequences + 3. Get other modules + + @param document XML document + @param root Node + **/ private void applyModules(Document document, Node root) { root.appendChild(document.createComment("Modules target")); Element ele = document.createElement("target"); ele.setAttribute("name", "modules"); - Set set = outfiles.keySet(); - Iterator iter = set.iterator(); - while (iter.hasNext()) { - FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next(); - ModuleIdentification moduleId = fpdModuleId.getModule(); - Element moduleEle = document.createElement("GenBuild"); - moduleEle.setAttribute("type", "build"); - // - // Inherit Properties. - //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"} - // - - // - // ARCH - // - Element property = document.createElement("property"); - property.setAttribute("name", "ARCH"); - property.setAttribute("value", fpdModuleId.getArch()); - moduleEle.appendChild(property); - - // - // MODULE_GUID - // - property = document.createElement("property"); - property.setAttribute("name", "MODULE_GUID"); - property.setAttribute("value", moduleId.getGuid()); - moduleEle.appendChild(property); - - // - // MODULE_VERSION - // - property = document.createElement("property"); - property.setAttribute("name", "MODULE_VERSION"); - property.setAttribute("value", moduleId.getVersion()); - moduleEle.appendChild(property); - - // - // PACKAGE_GUID - // - property = document.createElement("property"); - property.setAttribute("name", "PACKAGE_GUID"); - property.setAttribute("value", moduleId.getPackage().getGuid()); - moduleEle.appendChild(property); - - // - // PACKAGE_VERSION - // - property = document.createElement("property"); - property.setAttribute("name", "PACKAGE_VERSION"); - property.setAttribute("value", moduleId.getPackage().getVersion()); - moduleEle.appendChild(property); - - ele.appendChild(moduleEle); + // + // Get all valid FV name + // + String[] validFv = saq.getFpdValidImageNames(); + + // + // For each valid FV, get all modules in sequence + // + for (int i = 0; i < validFv.length; i++) { + if (fvs.containsKey(validFv[i])) { + Set set = fvs.get(validFv[i]); + Iterator iter = set.iterator(); + while (iter.hasNext()) { + FpdModuleIdentification fpdModuleId = iter.next(); + applySingleModule(document, ele, fpdModuleId); + } + } } + + // + // Get all other modules + // + Iterator fvsNameIter = fvs.keySet().iterator(); + + while (fvsNameIter.hasNext()) { + String fvName = fvsNameIter.next(); + if (!isContain(validFv, fvName)) { + Set set = fvs.get(fvName); + Iterator iter = set.iterator(); + while (iter.hasNext()) { + FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next(); + applySingleModule(document, ele, fpdModuleId); + } + } + } + root.appendChild(ele); } + private void applySingleModule(Document document, Node root, FpdModuleIdentification fpdModuleId) { + ModuleIdentification moduleId = fpdModuleId.getModule(); + Element moduleEle = document.createElement("GenBuild"); + moduleEle.setAttribute("type", "build"); + // + // Inherit Properties. + //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"} + // + + // + // ARCH + // + Element property = document.createElement("property"); + property.setAttribute("name", "ARCH"); + property.setAttribute("value", fpdModuleId.getArch()); + moduleEle.appendChild(property); + + // + // MODULE_GUID + // + property = document.createElement("property"); + property.setAttribute("name", "MODULE_GUID"); + property.setAttribute("value", moduleId.getGuid()); + moduleEle.appendChild(property); + + // + // MODULE_VERSION + // + property = document.createElement("property"); + property.setAttribute("name", "MODULE_VERSION"); + property.setAttribute("value", moduleId.getVersion()); + moduleEle.appendChild(property); + + // + // PACKAGE_GUID + // + property = document.createElement("property"); + property.setAttribute("name", "PACKAGE_GUID"); + property.setAttribute("value", moduleId.getPackage().getGuid()); + moduleEle.appendChild(property); + + // + // PACKAGE_VERSION + // + property = document.createElement("property"); + property.setAttribute("name", "PACKAGE_VERSION"); + property.setAttribute("value", moduleId.getPackage().getVersion()); + moduleEle.appendChild(property); + + root.appendChild(moduleEle); + } + + private boolean isContain(String[] list, String item) { + for (int i = 0; i < list.length; i++) { + if (list[i].equalsIgnoreCase(item)) { + return true; + } + } + return false; + } + private void applyFvs(Document document, Node root) { // // FVS Target @@ -246,9 +309,9 @@ public class PlatformBuildFileGenerator { String[] toolchainList = GlobalData.getToolChainInfo().getTagnames(); for(int j = 0; j < toolchainList.length; j++){ String fvOutputDir = project.getProperty("BUILD_DIR") + File.separatorChar - + targetList[i] + File.separatorChar + + targetList[i] + "_" + toolchainList[j] + File.separatorChar + "FV"; - String[] validFv = SurfaceAreaQuery.getFpdValidImageNames(); + String[] validFv = saq.getFpdValidImageNames(); for (int k = 0; k < validFv.length; k++) { String inputFile = fvOutputDir + "" + File.separatorChar + validFv[k].toUpperCase() + ".inf"; Element fvEle = document.createElement("genfvimage"); @@ -358,9 +421,12 @@ public class PlatformBuildFileGenerator { if (isUnified) { String[] targetList = GlobalData.getToolChainInfo().getTargets(); for (int i = 0; i < targetList.length; ++i) { - Element cleanAllEle = document.createElement("delete"); - cleanAllEle.setAttribute("dir", project.getProperty("BUILD_DIR") + File.separatorChar + targetList[i]); - ele.appendChild(cleanAllEle); + String[] toolchainList = GlobalData.getToolChainInfo().getTagnames(); + for(int j = 0; j < toolchainList.length; j++) { + Element cleanAllEle = document.createElement("delete"); + cleanAllEle.setAttribute("dir", project.getProperty("BUILD_DIR") + File.separatorChar + targetList[i] + "_" + toolchainList[j]); + ele.appendChild(cleanAllEle); + } } } else { Set set = outfiles.keySet(); @@ -440,7 +506,7 @@ public class PlatformBuildFileGenerator { Element ele = document.createElement("target"); ele.setAttribute("name", "prebuild"); - Node node = SurfaceAreaQuery.getFpdUserExtensionPreBuild(); + Node node = saq.getFpdUserExtensionPreBuild(); if (node != null) { // // For every Target and ToolChain @@ -453,7 +519,7 @@ public class PlatformBuildFileGenerator { // Prepare FV_DIR // String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar - + targetList[i] + File.separatorChar + + targetList[i] + "_" + toolchainList[j]; File fvDir = new File(ffsCommonDir + File.separatorChar + "FV"); Element fvEle = document.createElement("var"); @@ -461,6 +527,11 @@ public class PlatformBuildFileGenerator { fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/")); ele.appendChild(fvEle); + Element targetDirEle = document.createElement("var"); + targetDirEle.setAttribute("name", "TARGET_DIR"); + targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/")); + ele.appendChild(targetDirEle); + NodeList childNodes = node.getChildNodes(); for (int k = 0; k < childNodes.getLength(); k++) { Node childItem = childNodes.item(k); @@ -468,7 +539,6 @@ public class PlatformBuildFileGenerator { ele.appendChild(recursiveNode(childItem, document)); } } - } } } @@ -484,7 +554,7 @@ public class PlatformBuildFileGenerator { Element ele = document.createElement("target"); ele.setAttribute("name", "postbuild"); - Node node = SurfaceAreaQuery.getFpdUserExtensionPostBuild(); + Node node = saq.getFpdUserExtensionPostBuild(); if (node != null) { // // For every Target and ToolChain @@ -497,7 +567,7 @@ public class PlatformBuildFileGenerator { // Prepare FV_DIR // String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar - + targetList[i] + File.separatorChar + + targetList[i] + "_" + toolchainList[j]; File fvDir = new File(ffsCommonDir + File.separatorChar + "FV"); Element fvEle = document.createElement("var"); @@ -505,6 +575,11 @@ public class PlatformBuildFileGenerator { fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/")); ele.appendChild(fvEle); + Element targetDirEle = document.createElement("var"); + targetDirEle.setAttribute("name", "TARGET_DIR"); + targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/")); + ele.appendChild(targetDirEle); + NodeList childNodes = node.getChildNodes(); for (int k = 0; k < childNodes.getLength(); k++) { Node childItem = childNodes.item(k); @@ -534,7 +609,7 @@ public class PlatformBuildFileGenerator { root.appendChild(recursiveNode(childItem, document)); } else if (childItem.getNodeType() == Node.TEXT_NODE){ - if ( ! childItem.getNodeValue().trim().equalsIgnoreCase("")) { + if (!childItem.getNodeValue().trim().equalsIgnoreCase("")) { root.setTextContent(childItem.getNodeValue()); } }