X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2FModuleBuildFileGenerator.java;h=c02bc1fce8873a467934e77e4e8b567bbfc320d4;hb=0923e8b3b22a10416d9c8e0a192f0e88758a1b90;hp=08f49478aea6c1084a632223c83b7260a3df4d1d;hpb=a33f3dd1783f7d8d824ef858b18573f9f0ccdd78;p=mirror_edk2.git diff --git a/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java b/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java index 08f49478ae..c02bc1fce8 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java +++ b/Tools/Source/GenBuild/org/tianocore/build/ModuleBuildFileGenerator.java @@ -13,28 +13,33 @@ package org.tianocore.build; import java.io.File; import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.Map; -import java.util.Set; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.tianocore.build.exception.GenBuildException; import org.tianocore.build.fpd.FpdParserTask; -import org.tianocore.build.global.GlobalData; import org.tianocore.build.global.SurfaceAreaQuery; import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.PackageIdentification; +import org.tianocore.common.exception.EdkException; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -46,16 +51,16 @@ public class ModuleBuildFileGenerator { /// Pass: TARGET, TOOLCHAIN, ARCH /// PACKAGE, PACKAGE_GUID, PACKAGE_VERSION /// - String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PLATFORM_FILE", "PACKAGE_GUID", "PACKAGE_VERSION"}; + String[] inheritProperties = {"ARCH", "MODULE_GUID", "MODULE_VERSION", "PACKAGE_GUID", "PACKAGE_VERSION"}; /// /// The information at the header of build.xml. /// private String info = "DO NOT EDIT \n" - + "File auto-generated by build utility\n" + + "This file is auto-generated by the build utility\n" + "\n" + "Abstract:\n" - + "Auto-generated ANT build file for building of EFI Modules/Platforms\n"; + + "Auto-generated ANT build file for build EFI Modules and Platforms\n"; private FpdModuleIdentification fpdModuleId; @@ -63,10 +68,16 @@ public class ModuleBuildFileGenerator { private String ffsKeyword; - public ModuleBuildFileGenerator(Project project, String ffsKeyword, FpdModuleIdentification fpdModuleId) { + private String[] includes; + + private SurfaceAreaQuery saq = null; + + public ModuleBuildFileGenerator(Project project, String ffsKeyword, FpdModuleIdentification fpdModuleId, String[] includes, SurfaceAreaQuery saq) { this.project = project; this.fpdModuleId = fpdModuleId; this.ffsKeyword = ffsKeyword; + this.includes = includes; + this.saq = saq; } /** @@ -84,7 +95,7 @@ public class ModuleBuildFileGenerator { @throws BuildException Error throws during BaseName_build.xml generating. **/ - public void genBuildFile(String buildFilename) throws BuildException { + public void genBuildFile(String buildFilename) throws GenBuildException, EdkException { FfsProcess fp = new FfsProcess(); DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance(); try { @@ -137,7 +148,9 @@ public class ModuleBuildFileGenerator { // // Parse all sourfiles but files specified in sections // - applyLibraryInstance(document, ele); + if (!FrameworkBuildTask.multithread) { + applyLibraryInstance(document, ele); + } root.appendChild(ele); // @@ -211,7 +224,8 @@ public class ModuleBuildFileGenerator { // generate all directory path // (new File(file.getParent())).mkdirs(); - Result result = new StreamResult(file); + FileOutputStream outputStream = new FileOutputStream(file); + Result result = new StreamResult(new OutputStreamWriter(outputStream)); // // Write the DOM document to the file @@ -220,8 +234,22 @@ public class ModuleBuildFileGenerator { xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); xformer.setOutputProperty(OutputKeys.INDENT, "yes"); xformer.transform(source, result); - } catch (Exception ex) { - throw new BuildException("Module [" + fpdModuleId.getModule().getName() + "] generating build file failed.\n" + ex.getMessage()); + } catch (ParserConfigurationException ex) { + GenBuildException e = new GenBuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage()); + e.setStackTrace(ex.getStackTrace()); + throw e; + } catch (FileNotFoundException ex) { + GenBuildException e = new GenBuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage()); + e.setStackTrace(ex.getStackTrace()); + throw e; + } catch (TransformerConfigurationException ex) { + GenBuildException e = new GenBuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage()); + e.setStackTrace(ex.getStackTrace()); + throw e; + } catch (TransformerException ex) { + GenBuildException e = new GenBuildException("Generating the module [" + fpdModuleId.getModule().getName() + "] build.xml file failed!.\n" + ex.getMessage()); + e.setStackTrace(ex.getStackTrace()); + throw e; } } @@ -232,41 +260,6 @@ public class ModuleBuildFileGenerator { @param root Root element for current **/ private void applyCleanElement(Document document, Node root) { - ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch()); - for (int i = 0; i < libinstances.length; i++) { - // - // Put package file path to module identification - // - PackageIdentification packageId = libinstances[i].getPackage(); - - // - // Generate ANT script to clean - // - Element ele = document.createElement("GenBuild"); - ele.setAttribute("type", "clean"); - - // - // Prepare pass down information - // - Map passDownMap = new LinkedHashMap(); - for (int j = 0; j < inheritProperties.length; j ++){ - passDownMap.put(inheritProperties[j], "${" + inheritProperties[j] + "}"); - } - passDownMap.put("MODULE_GUID", libinstances[i].getGuid()); - passDownMap.put("MODULE_VERSION", libinstances[i].getVersion()); - - passDownMap.put("PACKAGE_GUID", packageId.getGuid()); - passDownMap.put("PACKAGE_VERSION", packageId.getVersion()); - - for (int j = 0; j < inheritProperties.length; j ++){ - Element property = document.createElement("property"); - property.setAttribute("name", inheritProperties[j]); - property.setAttribute("value", passDownMap.get(inheritProperties[j])); - ele.appendChild(property); - } - - root.appendChild(ele); - } // // // @@ -289,42 +282,6 @@ public class ModuleBuildFileGenerator { @param root Root element for current **/ private void applyDeepcleanElement(Document document, Node root) { - ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch()); - for (int i = 0; i < libinstances.length; i++) { - // - // Put package file path to module identification - // - PackageIdentification packageId = libinstances[i].getPackage(); - - // - // Generate ANT script to clean - // - Element ele = document.createElement("GenBuild"); - ele.setAttribute("type", "cleanall"); - - // - // Prepare pass down information - // - Map passDownMap = new LinkedHashMap(); - for (int j = 0; j < inheritProperties.length; j ++){ - passDownMap.put(inheritProperties[j], "${" + inheritProperties[j] + "}"); - } - - passDownMap.put("MODULE_GUID", libinstances[i].getGuid()); - passDownMap.put("MODULE_VERSION", libinstances[i].getVersion()); - - passDownMap.put("PACKAGE_GUID", packageId.getGuid()); - passDownMap.put("PACKAGE_VERSION", packageId.getVersion()); - - for (int j = 0; j < inheritProperties.length; j ++){ - Element property = document.createElement("property"); - property.setAttribute("name", inheritProperties[j]); - property.setAttribute("value", passDownMap.get(inheritProperties[j])); - ele.appendChild(property); - } - - root.appendChild(ele); - } // // // @@ -359,9 +316,8 @@ public class ModuleBuildFileGenerator { @param document current BaseName_build.xml XML document @param root Root element for current **/ - private void applyLibraryInstance(Document document, Node root) { - ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch()); -// String propertyLibs = ""; + private void applyLibraryInstance(Document document, Node root) throws EdkException { + ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch()); for (int i = 0; i < libinstances.length; i++) { // // Put package file path to module identification @@ -373,7 +329,6 @@ public class ModuleBuildFileGenerator { // Element ele = document.createElement("GenBuild"); ele.setAttribute("type", "build"); -// ele.setAttribute("inheritAll", "false"); // // Prepare pass down information @@ -397,23 +352,7 @@ public class ModuleBuildFileGenerator { } root.appendChild(ele); -// propertyLibs += " " + project.getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib"; } -// project.setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/")); - } - - /** - Return the name of the directory that corresponds to the architecture. - This is a translation from the XML Schema tag to a directory that - corresponds to our directory name coding convention. - - **/ - private String archDir(String arch) { - return arch.replaceFirst("X64", "x64") - .replaceFirst("IPF", "Ipf") - .replaceFirst("IA32", "Ia32") - .replaceFirst("ARM", "Arm") - .replaceFirst("EBC", "Ebc"); } /** @@ -423,69 +362,19 @@ public class ModuleBuildFileGenerator { @param root Root element for current **/ private void applyCompileElement(Document document, Node root) { - // - // Prepare the includes: PackageDependencies and Output debug direactory - // - Set includes = new LinkedHashSet(); - String arch = project.getProperty("ARCH"); - - // - // WORKSPACE - // - includes.add("${WORKSPACE_DIR}"); - - // - // Module iteself - // - includes.add("${MODULE_DIR}"); - includes.add("${MODULE_DIR}" + File.separatorChar + archDir(arch)); - - // - // Packages in PackageDenpendencies - // - PackageIdentification[] packageDependencies = SurfaceAreaQuery.getDependencePkg(fpdModuleId.getArch()); - for (int i = 0; i < packageDependencies.length; i++) { - GlobalData.refreshPackageIdentification(packageDependencies[i]); - File packageFile = packageDependencies[i].getSpdFile(); - includes.add(packageFile.getParent() + File.separatorChar + "Include"); - includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch)); - } - - // - // All Dependency Library Instance's PackageDependencies - // - ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch()); - for (int i = 0; i < libinstances.length; i++) { - SurfaceAreaQuery.push(GlobalData.getDoc(libinstances[i], fpdModuleId.getArch())); - PackageIdentification[] libraryPackageDependencies = SurfaceAreaQuery.getDependencePkg(fpdModuleId.getArch()); - for (int j = 0; j < libraryPackageDependencies.length; j++) { - GlobalData.refreshPackageIdentification(libraryPackageDependencies[j]); - File packageFile = libraryPackageDependencies[j].getSpdFile(); - includes.add(packageFile.getParent() + File.separatorChar + "Include"); - includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch)); - } - SurfaceAreaQuery.pop(); - } - - - // - // The package which the module belongs to - // TBD - includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include"); - includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + archDir(arch)); - - // - // Debug files output directory - // - includes.add("${DEST_DIR_DEBUG}"); - // // sourceFiles[][0] is FileType, [][1] is File name relative to Module_Dir // - String[][] sourceFiles = SurfaceAreaQuery.getSourceFiles(fpdModuleId.getArch()); + String[][] sourceFiles = saq.getSourceFiles(fpdModuleId.getArch()); FileProcess fileProcess = new FileProcess(); fileProcess.init(project, includes, document); + + // + // Initialize some properties by user + // + Element initEle = document.createElement("Build_Init"); + root.appendChild(initEle); String moduleDir = project.getProperty("MODULE_DIR"); // @@ -512,11 +401,10 @@ public class ModuleBuildFileGenerator { Element ele = document.createElement("Build_Unicode_Database"); ele.setAttribute("FILEPATH", "."); ele.setAttribute("FILENAME", "${BASE_NAME}"); - String[] includePaths = includes.toArray(new String[includes.size()]); Element includesEle = document.createElement("EXTRA.INC"); - for (int i = 0; i < includePaths.length; i++) { + for (int i = 0; i < includes.length; i++) { Element includeEle = document.createElement("includepath"); - includeEle.setAttribute("path", includePaths[i]); + includeEle.setAttribute("path", includes[i]); includesEle.appendChild(includeEle); } ele.appendChild(includesEle);