X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2FGenBuildTask.java;h=1c97da282527634e1b486c76334ae9b9f555d0c2;hp=2d91991b8a9b92fe07eac3d8d33c5eff4ff5896b;hb=68542af1ea969b7bf685befc9117e517257d840c;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4 diff --git a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java index 2d91991b8a..1c97da2825 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java @@ -16,54 +16,45 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. package org.tianocore.build; import java.io.File; -import java.util.HashMap; -import java.util.HashSet; +import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Stack; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -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.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.Ant; +import org.apache.tools.ant.taskdefs.Property; import org.apache.xmlbeans.XmlObject; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.tianocore.build.autogen.AutoGen; -import org.tianocore.build.autogen.CommonDefinition; import org.tianocore.build.fpd.FpdParserTask; +import org.tianocore.build.global.GenBuildLogger; import org.tianocore.build.global.GlobalData; import org.tianocore.build.global.OutputManager; import org.tianocore.build.global.SurfaceAreaQuery; -import org.tianocore.build.toolchain.ToolChainFactory; -import org.tianocore.FilenameDocument; -import org.tianocore.MsaHeaderDocument; -import org.tianocore.MsaLibHeaderDocument; +import org.tianocore.build.id.FpdModuleIdentification; +import org.tianocore.build.id.ModuleIdentification; +import org.tianocore.build.id.PackageIdentification; +import org.tianocore.build.id.PlatformIdentification; +import org.tianocore.build.tools.ModuleItem; +import org.tianocore.exception.EdkException; +import org.tianocore.logger.EdkLog; /**
GenBuildTask
is an ANT task that can be used in ANT build
system. The main function of this task is to parse module's surface area,
then generate the corresponding BaseName_build.xml (the real ANT
- build script) and call this to build the module.
+ build script) and call this to build the module. The whole process including:
+ 1. generate AutoGen.c and AutoGen.h; 2. build all dependent library instances;
+ 3. build all source files inlcude AutoGen.c; 4. generate sections;
+ 5. generate FFS file if it is driver module while LIB file if it is Library module.
@@ -71,11 +62,16 @@ import org.tianocore.MsaLibHeaderDocument;
- <GenBuild baseName="HelloWorld" - mbdFilename="${MODULE_DIR}/HelloWorld.mbd" - msaFilename="${MODULE_DIR}/HelloWorld.msa"/> + <GenBuild + msaFilename="HelloWorld.msa"/> + processTo="ALL"/>+
processTo
provides a way to customize the whole build process.
+ processTo can be one value of ALL, AUTOGEN, FILES, LIBRARYINSTANCES, SECTIONS, NONE.
+ Default is ALL, means whole
+
This task calls Build is dependent on BuildMacro.xml which define many macro. If current build is single module build, then the default Note that for package build, package name is stored in In Single Module Build mode, platform-related information is not ready.
+ The method read the system environment variable Take command The final flags is composed of STD, GLOBAL and PROJ. If CC_FLAGS or
- IA32_CC_FLAGS is specified, STD, GLOBAL and PROJ will not affect. AutoGen
to generate AutoGen.c and
AutoGen.h. The task also parses the development environment
@@ -86,85 +82,29 @@ import org.tianocore.MsaLibHeaderDocument;
@since GenBuild 1.0
**/
-public class GenBuildTask extends Task {
-
+public class GenBuildTask extends Ant {
+
///
/// Module surface area file.
///
- File msaFilename;
-
- ///
- /// Module build description file.
- ///
- File mbdFilename;
-
- ///
- /// Module surface area information after overrided.
- ///
- public Map
-
-
- ARCH
- is IA32
. Also set up the properties PACKAGE
,
- PACKAGE_DIR
, TARGET
and MODULE_DIR
PLATFORM
- and package directory is stored in PLATFORM_DIR
.
-
-
- @throws BuildException
- Error throws during BaseName_build.xml generating.
- **/
- private void genBuildFile() throws BuildException {
- FfsProcess fp = new FfsProcess();
- DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
- try {
- DocumentBuilder dombuilder = domfac.newDocumentBuilder();
- Document document = dombuilder.newDocument();
- Comment rootComment = document.createComment(info);
- //
- // create root element and its attributes
- //
- Element root = document.createElement("project");
- //
- // root.setAttribute("name", base_name);
- //
- root.setAttribute("default", "main");
- root.setAttribute("basedir", ".");
- //
- // element for External ANT tasks
- //
- root.appendChild(document.createComment("Apply external ANT tasks"));
- Element ele = document.createElement("taskdef");
- ele.setAttribute("resource", "frameworktasks.tasks");
- root.appendChild(ele);
- ele = document.createElement("taskdef");
- ele.setAttribute("resource", "cpptasks.tasks");
- root.appendChild(ele);
- ele = document.createElement("typedef");
- ele.setAttribute("resource", "cpptasks.types");
- root.appendChild(ele);
- ele = document.createElement("taskdef");
- ele.setAttribute("resource", "net/sf/antcontrib/antlib.xml");
- root.appendChild(ele);
- //
- // elements for Properties
- //
- root.appendChild(document.createComment("All Properties"));
- ele = document.createElement("property");
- ele.setAttribute("name", "BASE_NAME");
- ele.setAttribute("value", baseName);
- root.appendChild(ele);
- //
- // Generate the default target,
- // which depends on init, sections and output target
- //
- root.appendChild(document.createComment("Default target"));
- ele = document.createElement("target");
- ele.setAttribute("name", "main");
- ele.setAttribute("depends", "libraries, sourcefiles, sections, output");
- root.appendChild(ele);
- //
- // compile all source files
- //
- root.appendChild(document.createComment("Compile all dependency Library instances."));
- ele = document.createElement("target");
- ele.setAttribute("name", "libraries");
- //
- // Parse all sourfiles but files specified in sections
- //
- applyLibraryInstance(document, ele);
- root.appendChild(ele);
- //
- // compile all source files
- //
- root.appendChild(document.createComment("sourcefiles target"));
- ele = document.createElement("target");
- ele.setAttribute("name", "sourcefiles");
- //
- // Parse all sourfiles but files specified in sections
- //
- applyCompileElement(document, ele);
- root.appendChild(ele);
- //
- // generate the init target
- // main purpose is create all nessary pathes
- // generate the sections target
- //
- root.appendChild(document.createComment("sections target"));
- ele = document.createElement("target");
- ele.setAttribute("name", "sections");
- applySectionsElement(document, ele, fp);
- root.appendChild(ele);
- //
- // generate the output target
- //
- root.appendChild(document.createComment("output target"));
- ele = document.createElement("target");
- ele.setAttribute("name", "output");
- applyOutputElement(document, ele, fp);
- root.appendChild(ele);
- //
- // generate the clean target
- //
- root.appendChild(document.createComment("clean target"));
- ele = document.createElement("target");
- ele.setAttribute("name", "clean");
- applyCleanElement(document, ele);
- root.appendChild(ele);
- //
- // generate the Clean All target
- //
- root.appendChild(document.createComment("Clean All target"));
- ele = document.createElement("target");
- ele.setAttribute("name", "cleanall");
- applyDeepcleanElement(document, ele);
- root.appendChild(ele);
- //
- // add the root element to the document
- //
- document.appendChild(rootComment);
- document.appendChild(root);
- //
- // Prepare the DOM document for writing
- //
- Source source = new DOMSource(document);
- //
- // Prepare the output file
- //
- File file = new File(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + baseName
- + "_build.xml");
- //
- // generate all directory path
- //
- (new File(file.getParent())).mkdirs();
- Result result = new StreamResult(file);
+ else {
//
- // Write the DOM document to the file
+ // Platform build. Restore the platform related info
//
- Transformer xformer = TransformerFactory.newInstance().newTransformer();
- 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 [" + baseName + "] generating build file failed.\n" + ex.getMessage());
+ String filename = getProject().getProperty("PLATFORM_FILE");
+ PlatformIdentification platformId = GlobalData.getPlatform(filename);
+ getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));
+ getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));
+
+ String packageGuid = getProject().getProperty("PACKAGE_GUID");
+ String packageVersion = getProject().getProperty("PACKAGE_VERSION");
+ PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
+ moduleId.setPackage(packageId);
}
- }
-
- /**
- Generate the clean elements for BaseName_build.xml.
-
- @param document current BaseName_build.xml XML document
- @param root Root element for current
- **/
- private void applyCleanElement(Document document, Node root) {
- String[] libinstances = libraries.toArray(new String[libraries.size()]);
- for (int i = 0; i < libinstances.length; i++) {
- File file = new File(GlobalData.getModulePath(libinstances[i]) + File.separatorChar + "build.xml");
-
- Element ifEle = document.createElement("if");
- Element availableEle = document.createElement("available");
- availableEle.setAttribute("file", file.getPath());
- ifEle.appendChild(availableEle);
- Element elseEle = document.createElement("then");
-
- Element ele = document.createElement("ant");
- ele.setAttribute("antfile", file.getPath());
- ele.setAttribute("inheritAll", "false");
- ele.setAttribute("target", libinstances[i] + "_clean");
- //
- // Workspace_DIR
- //
- Element property = document.createElement("property");
- property.setAttribute("name", "WORKSPACE_DIR");
- property.setAttribute("value", "${WORKSPACE_DIR}");
- ele.appendChild(property);
- //
- // Package Dir
- //
- property = document.createElement("property");
- property.setAttribute("name", "PACKAGE_DIR");
- property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar
- + GlobalData.getPackagePathForModule(libinstances[i]));
- ele.appendChild(property);
- //
- // ARCH
- //
- property = document.createElement("property");
- property.setAttribute("name", "ARCH");
- property.setAttribute("value", "${ARCH}");
- ele.appendChild(property);
- //
- // TARGET
- //
- property = document.createElement("property");
- property.setAttribute("name", "TARGET");
- property.setAttribute("value", "${TARGET}");
- ele.appendChild(property);
- //
- // PACKAGE
- //
- property = document.createElement("property");
- property.setAttribute("name", "PACKAGE");
- property.setAttribute("value", GlobalData.getPackageNameForModule(libinstances[i]));
- ele.appendChild(property);
-
- elseEle.appendChild(ele);
- ifEle.appendChild(elseEle);
- root.appendChild(ifEle);
+
+ //
+ // If single module : intersection MSA supported ARCHs and tools def!!
+ // else, get arch from pass down
+ //
+ String[] archList = GlobalData.getToolChainInfo().getArchs();
+
+ //
+ // Judge if arch is all supported by current module. If not, throw Exception.
+ //
+ List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs();
+ if (moduleSupportedArchs != null) {
+ for (int k = 0; k < archList.length; k++) {
+ if ( ! moduleSupportedArchs.contains(archList[k])) {
+ throw new BuildException("ARCH [" + archList[k] + "] is not supported by " + moduleId + ". " + moduleId + " only supports [" + moduleSupportedArchs + "].");
+ }
+ }
}
- }
-
- /**
- Generate the cleanall elements for BaseName_build.xml.
-
- @param document current BaseName_build.xml XML document
- @param root Root element for current
- **/
- private void applyDeepcleanElement(Document document, Node root) {
- String[] libinstances = libraries.toArray(new String[libraries.size()]);
- for (int i = 0; i < libinstances.length; i++) {
- File file = new File(GlobalData.getModulePath(libinstances[i]) + File.separatorChar + "build.xml");
-
- Element ifEle = document.createElement("if");
- Element availableEle = document.createElement("available");
- availableEle.setAttribute("file", file.getPath());
- ifEle.appendChild(availableEle);
- Element elseEle = document.createElement("then");
-
- Element ele = document.createElement("ant");
- ele.setAttribute("antfile", file.getPath());
- ele.setAttribute("inheritAll", "false");
- ele.setAttribute("target", libinstances[i] + "_cleanall");
- //
- // Workspace_DIR
- //
- Element property = document.createElement("property");
- property.setAttribute("name", "WORKSPACE_DIR");
- property.setAttribute("value", "${WORKSPACE_DIR}");
- ele.appendChild(property);
- //
- // Package Dir
- //
- property = document.createElement("property");
- property.setAttribute("name", "PACKAGE_DIR");
- property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar
- + GlobalData.getPackagePathForModule(libinstances[i]));
- ele.appendChild(property);
- //
- // ARCH
- //
- property = document.createElement("property");
- property.setAttribute("name", "ARCH");
- property.setAttribute("value", "${ARCH}");
- ele.appendChild(property);
- //
- // TARGET
+
+ for (int k = 0; k < archList.length; k++) {
+ getProject().setProperty("ARCH", archList[k]);
+
+ FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]);
+
//
- property = document.createElement("property");
- property.setAttribute("name", "TARGET");
- property.setAttribute("value", "${TARGET}");
- ele.appendChild(property);
+ // Whether the module is built before
//
- // PACKAGE
+ if (GlobalData.isModuleBuilt(fpdModuleId)) {
+ return ;
+ }
+ else {
+ GlobalData.registerBuiltModule(fpdModuleId);
+ }
+
//
- property = document.createElement("property");
- property.setAttribute("name", "PACKAGE");
- property.setAttribute("value", GlobalData.getPackageNameForModule(libinstances[i]));
- ele.appendChild(property);
-
- elseEle.appendChild(ele);
- ifEle.appendChild(elseEle);
- root.appendChild(ifEle);
+ // For Every TOOLCHAIN, TARGET
+ //
+ String[] targetList = GlobalData.getToolChainInfo().getTargets();
+ for (int i = 0; i < targetList.length; i ++){
+ //
+ // Prepare for target related common properties
+ // TARGET
+ //
+ getProject().setProperty("TARGET", targetList[i]);
+ String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();
+ for(int j = 0; j < toolchainList.length; j ++){
+ //
+ // check if any tool is defined for current target + toolchain + arch
+ // don't do anything if no tools found
+ //
+ if (GlobalData.isCommandSet(targetList[i], toolchainList[j], archList[k]) == false) {
+ System.out.println("Warning: No build issued. No tools found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n");
+ continue;
+ }
+
+ //
+ // Prepare for toolchain related common properties
+ // TOOLCHAIN
+ //
+ getProject().setProperty("TOOLCHAIN", toolchainList[j]);
+
+ System.out.println("Build " + moduleId + " start >>>");
+ System.out.println("Target: " + targetList[i] + " Tagname: " + toolchainList[j] + " Arch: " + archList[k]);
+ SurfaceAreaQuery.setDoc(GlobalData.getDoc(fpdModuleId));
+
+ //
+ // Prepare for all other common properties
+ // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR
+ // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE
+ // MODULE_DIR, MODULE_RELATIVE_DIR
+ // SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH
+ // LIBS, OBJECTS, SDB_FILES
+ //
+ setModuleCommonProperties(archList[k]);
+
+ //
+ // OutputManage prepare for
+ // BIN_DIR, DEST_DIR_DEBUG, DEST_DIR_OUTPUT, BUILD_DIR, FV_DIR
+ //
+ OutputManager.getInstance().update(getProject());
+
+ if (type.equalsIgnoreCase("all") || type.equalsIgnoreCase("build")) {
+ applyBuild(targetList[i], toolchainList[j], fpdModuleId);
+ }
+ else if (type.equalsIgnoreCase("clean")) {
+ applyClean(fpdModuleId);
+ }
+ else if (type.equalsIgnoreCase("cleanall")) {
+ applyCleanall(fpdModuleId);
+ }
+ }
+ }
}
- }
-
- /**
- Generate the dependent library instances elements for BaseName_build.xml.
-
- @param document current BaseName_build.xml XML document
- @param root Root element for current
- **/
- private void applyLibraryInstance(Document document, Node root) {
- String[] libinstances = libraries.toArray(new String[libraries.size()]);
- for (int i = 0; i < libinstances.length; i++) {
- Element ele = document.createElement("ant");
- File file = new File(GlobalData.getModulePath(libinstances[i]) + File.separatorChar + "build.xml");
- ele.setAttribute("antfile", file.getPath());
- ele.setAttribute("inheritAll", "false");
- ele.setAttribute("target", libinstances[i]);
- //
- // Workspace_DIR
- //
- Element property = document.createElement("property");
- property.setAttribute("name", "WORKSPACE_DIR");
- property.setAttribute("value", "${WORKSPACE_DIR}");
- ele.appendChild(property);
- //
- // Package Dir
- //
- property = document.createElement("property");
- property.setAttribute("name", "PACKAGE_DIR");
- property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar
- + GlobalData.getPackagePathForModule(libinstances[i]));
- ele.appendChild(property);
- //
- // ARCH
- //
- property = document.createElement("property");
- property.setAttribute("name", "ARCH");
- property.setAttribute("value", "${ARCH}");
- ele.appendChild(property);
- //
- // TARGET
- //
- property = document.createElement("property");
- property.setAttribute("name", "TARGET");
- property.setAttribute("value", "${TARGET}");
- ele.appendChild(property);
- //
- // PACKAGE
- //
- property = document.createElement("property");
- property.setAttribute("name", "PACKAGE");
- property.setAttribute("value", GlobalData.getPackageNameForModule(libinstances[i]));
- ele.appendChild(property);
- root.appendChild(ele);
+ popProperties();
+ }catch (Exception e){
+ throw new BuildException(e.getMessage());
}
- Element expand = document.createElement("Expand");
- root.appendChild(expand);
}
-
+
/**
- Generate the build source files elements for BaseName_build.xml.
+ This method is used to prepare Platform-related information.
- @param document current BaseName_build.xml XML document
- @param root Root element for current
+ ACTIVE_PLATFORM
+ and search in the Framework Database. Note that platform name in the Framework
+ Database must be unique. null
.
-
- @param node Filename node of MSA/MBD or specified in each Section
- @return File type
- **/
- private String getFiletype(Node node) {
- String str = null;
- try {
- FilenameDocument file = (FilenameDocument) XmlObject.Factory.parse(node);
- str = file.getFilename().getFileType();
- } catch (Exception e) {
- str = null;
- }
- return str;
- }
-
- /**
- Return all source files but AutoGen.c.
-
- @return source files Node array
- **/
- public Node[] getSourceFiles() {
- XmlObject[] files = SurfaceAreaQuery.getSourceFiles(arch);
- if (files == null) {
- return new Node[0];
+ getProject().setProperty("SUBSYSTEM", subsystem);
+
+ //
+ // ENTRYPOINT
+ //
+ if (arch.equalsIgnoreCase("EBC")) {
+ getProject().setProperty("ENTRYPOINT", "EfiStart");
}
- VectorCC
and arch IA32
for example,
- Those flags are from ToolChainFactory
:
-
- Those flags can user-define:
-
-
-
- ToolChainFactory
executes only once
- during whole build process.
- **/
- private void flagsSetup() {
- Project project = getProject();
- //
- // If ToolChain has been set up before, do nothing.
- //
- ToolChainFactory toolChainFactory = new ToolChainFactory(project);
- toolChainFactory.setupToolChain();
-
- String[] cmd = ToolChainFactory.commandType;
- Set