X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2FGenBuildTask.java;h=42d3313ad3e95335c7a7863040af65e5dbb81f5c;hp=5ee07fb34edc84643d82140139892dcae317f77e;hb=bf3a7173e34fa0754df81c53f24b72ce40fa5372;hpb=250258de0d6ed07201db565101d45f4d92729bce diff --git a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java index 5ee07fb34e..42d3313ad3 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java +++ b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java @@ -1,9 +1,9 @@ /** @file - This file is ANT task GenBuild. - - The file is used to parse a specified Module, and generate its build time + This file is ANT task GenBuild. + + The file is used to parse a specified Module, and generate its build time ANT script build.xml, then call the the ANT script to build the module. - + Copyright (c) 2006, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -16,8 +16,6 @@ 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.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -27,143 +25,89 @@ 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.common.definitions.ToolDefinitions; +import org.tianocore.common.exception.EdkException; +import org.tianocore.common.logger.EdkLog; 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.PropertyManager; 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; /**

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, + system. + +

The main function of this task is to parse module's surface area (MSA), 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.
+  
+ +

The usage is (take module HelloWorld for example):

- +
-   <GenBuild baseName="HelloWorld" 
-             mbdFilename="${MODULE_DIR}/HelloWorld.mbd" 
-             msaFilename="${MODULE_DIR}/HelloWorld.msa"/>
+    <GenBuild 
+       msaFile="${PACKAGE_DIR}/Application/HelloWorld/HelloWorld.msa"
+       type="cleanall" />
   
- +

This task calls AutoGen to generate AutoGen.c and - AutoGen.h. The task also parses the development environment - configuration files, such as collecting package information, setting compiler - flags and so on. + AutoGen.h. +

+ +

+ This task will also set properties for current module, such as PACKAGE, + PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR + (relative to Workspace), MODULE or BASE_NAME, GUID, VERSION, MODULE_DIR, + MODULE_RELATIVE_DIR (relative to Package), CONFIG_DIR, BIN_DIR, + DEST_DIR_DEBUG, DEST_DIR_OUTPUT, TARGET, ARCH, TOOLCHAIN, TOOLCHAIN_FAMILY, + SUBSYSTEM, ENTRYPOINT, EBC_TOOL_LIB_PATH, all compiler command related + properties (CC, CC_FLAGS, CC_DPATH, CC_SPATH, CC_FAMILY, CC_EXT).

- @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 map = new HashMap(); - - /// - /// Module's base name. - /// - private String baseName; - - /// - /// Current build Arch, such as IA32, X64, IPF and so on. - /// - private String arch; - - /// - /// Module's GUID (Globally Unique Identifier). - /// - private String guid; - - /// - /// Module's component type, such as SEC, LIBRARY, BS_DRIVER and so on. - /// - private String componentType; - - /// - /// This value is used in build time. Override module's component type. When - /// search FFS (Sections information) in common file, buildtype instead of - /// component type. - /// - private String buildType; - - /// - /// List all required includes for current build module. - /// - public Set includes = new LinkedHashSet(); - - /// - /// List all libraries for current build module. - /// - public Set libraries = new LinkedHashSet(); + File msaFile; + private String type = "all"; + /// - /// List all source files for current build module. + /// Module's Identification. /// - public Set sourceFiles = new LinkedHashSet(); + private ModuleIdentification moduleId; - /// - /// Flag to identify what surface area files are specified. Current value is - /// NO_SA, ONLY_MSA, ONLY_LIBMSA, - /// MSA_AND_MBD or LIBMSA_AND_LIBMBD. - /// - /// @see org.tianocore.build.global.GlobaData - /// - private int flag = GlobalData.NO_SA; + private Vector properties = new Vector(); - /// - /// The information at the header of build.xml. - /// - private String info = "====================================================================\n" - + "DO NOT EDIT \n" - + "File auto-generated by build utility\n" - + "\n" - + "Abstract:\n" - + "Auto-generated ANT build file for building of EFI Modules/Platforms\n" - + "====================================================================="; + private boolean isSingleModuleBuild = false; /** Public construct method. It is necessary for ANT task. @@ -172,968 +116,570 @@ public class GenBuildTask extends Task { } /** - ANT task's entry point, will be called after init(). The main steps is described - as following: -
    -
  • Judge current build mode (MODULE | PACKAGE | PLATFORM). This step will execute - only once in whole build process;
  • -
  • Initialize global information (Framework DB, SPD files and all MSA files - listed in SPD). This step will execute only once in whole build process;
  • -
  • Restore some important ANT property. If current build is single module - build, here will set many default values;
  • -
  • Get the current module's overridded surface area information from - global data;
  • -
  • Set up the output directories, including BIN_DIR, DEST_DIR_OUTPUT and - DEST_DIR_DEBUG;
  • -
  • Get module dependent library instances and include pathes;
  • -
  • Judge whether current module is built. If yes, skip it;
  • -
  • Call AutoGen and PCD to generate AutoGen.c & AutoGen.h
  • -
  • Set up the compile flags;
  • -
  • Generate BaseName_build.xml;
  • -
  • Call to BaseName_build.xml, and build the current module.
  • -
- -

Build is dependent on BuildMacro.xml which define many macro.

- + @throws BuildException From module build, exception from module surface area invalid. **/ public void execute() throws BuildException { - System.out.println("Module [" + baseName + "] start."); - OutputManager.update(getProject()); - GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db", - getProject().getProperty("WORKSPACE_DIR")); - recallFixedProperties(); - arch = getProject().getProperty("ARCH"); - arch = arch.toUpperCase(); - map = GlobalData.getDoc(baseName); - // - // Initialize SurfaceAreaQuery - // - SurfaceAreaQuery.setDoc(map); + // + // set Logger // - // Setup Output Management - // - String[] outdir = SurfaceAreaQuery.getOutputDirectory(); - OutputManager.update(getProject(), outdir[1], outdir[0]); - - updateIncludesAndLibraries(); + GenBuildLogger logger = new GenBuildLogger(getProject()); + EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL")); + EdkLog.setLogger(logger); - if (GlobalData.isModuleBuilt(baseName, arch)) { - return; - } else { - GlobalData.registerBuiltModule(baseName, arch); - } + PropertyManager.setProject(getProject()); + PropertyManager.save(); // - // Call AutoGen - // - AutoGen autogen = new AutoGen(getProject().getProperty("DEST_DIR_DEBUG"), baseName, arch); - autogen.genAutogen(); + // Enable all specified properties // - // Update parameters - // - updateParameters(); + Iterator iter = properties.iterator(); + while (iter.hasNext()) { + Property item = iter.next(); + PropertyManager.setProperty(item.getName(), item.getValue()); + } + // - // Update flags like CC_FLAGS, LIB_FLAGS etc. + // GenBuild should specify either msaFile or moduleGuid & packageGuid // - flagsSetup(); - GlobalData.addLibrary(baseName, arch, getProject().getProperty("BIN_DIR") + File.separatorChar + baseName + ".lib"); - GlobalData.addModuleLibrary(baseName, arch, libraries); + if (msaFile == null ) { + String moduleGuid = getProject().getProperty("MODULE_GUID"); + String moduleVersion = getProject().getProperty("MODULE_VERSION"); + String packageGuid = getProject().getProperty("PACKAGE_GUID"); + String packageVersion = getProject().getProperty("PACKAGE_VERSION"); + if (moduleGuid == null || packageGuid == null) { + throw new BuildException("GenBuild parameter error."); + } + PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion); + moduleId = new ModuleIdentification(moduleGuid, moduleVersion); + moduleId.setPackage(packageId); + Map doc = GlobalData.getNativeMsa(moduleId); + SurfaceAreaQuery.setDoc(doc); + moduleId = SurfaceAreaQuery.getMsaHeader(); + } else { + Map doc = GlobalData.getNativeMsa(msaFile); + SurfaceAreaQuery.setDoc(doc); + moduleId = SurfaceAreaQuery.getMsaHeader(); + } + String[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED",null); + if (producedLibraryClasses.length == 0) { + moduleId.setLibrary(false); + } else { + moduleId.setLibrary(true); + } + // - // If ComponentType is USER_DEFINED, - // then call the exist BaseName_build.xml directly. + // Judge whether it is single module build or not // - if (buildType.equalsIgnoreCase("CUSTOM_BUILD")) { - System.out.println("Call user-defined " + baseName + "_build.xml"); - Ant ant = new Ant(); - ant.setProject(getProject()); - ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + baseName + "_build.xml"); - ant.setInheritAll(true); - ant.init(); - ant.execute(); - return; + if (isSingleModuleBuild) { + // + // Single Module build + // + prepareSingleModuleBuild(); + } else { + // + // Platform build. Restore the platform related info + // + String filename = getProject().getProperty("PLATFORM_FILE"); + PlatformIdentification platformId = GlobalData.getPlatform(filename); + PropertyManager.setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/")); + PropertyManager.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 ${BASE_NAME}_build.xml file + // If single module : get arch from pass down, otherwise intersection MSA + // supported ARCHs and tools def // - System.out.println("Generate " + baseName + "_build.xml"); - genBuildFile(); - System.out.println("Call the " + baseName + "_build.xml"); - Ant ant = new Ant(); - ant.setProject(getProject()); - ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + baseName + "_build.xml"); - ant.setInheritAll(true); - ant.init(); - ant.execute(); - } + Set archListSupByToolChain = new LinkedHashSet(); + String[] archs = GlobalData.getToolChainInfo().getArchs(); - /** - 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"); - } - - /** - Get the dependent library instances and include package name from - surface area, and initialize module include pathes. - - **/ - private void updateIncludesAndLibraries() { - List rawIncludes = SurfaceAreaQuery.getIncludePackageName(arch); - if (rawIncludes != null) { - Iterator iter = rawIncludes.iterator(); - while (iter.hasNext()) { - String packageName = (String) iter.next(); - includes.add("${WORKSPACE_DIR}" + File.separatorChar + GlobalData.getPackagePath(packageName) - + File.separatorChar + "Include"); - includes.add("${WORKSPACE_DIR}" + File.separatorChar + GlobalData.getPackagePath(packageName) - + File.separatorChar + "Include" + File.separatorChar + archDir(arch)); - } + for (int i = 0; i < archs.length; i ++) { + archListSupByToolChain.add(archs[i]); } - includes.add("${DEST_DIR_DEBUG}"); - List rawLibraries = SurfaceAreaQuery.getLibraryInstance(this.arch, CommonDefinition.AlwaysConsumed); - if (rawLibraries != null) { - Iterator iter = rawLibraries.iterator(); - while (iter.hasNext()) { - libraries.add((String) iter.next()); + + Set archSet = new LinkedHashSet(); + + if ( getProject().getProperty("ARCH") != null) { + String[] fpdArchList = getProject().getProperty("ARCH").split(" "); + + for (int i = 0; i < fpdArchList.length; i++) { + if (archListSupByToolChain.contains(fpdArchList[i])) { + archSet.add(fpdArchList[i]); + } } + } else { + archSet = archListSupByToolChain; } - normalize(); - } - /** - Normalize all dependent library instance and include pathes' format. - - **/ - private void normalize() { - String[] includesArray = includes.toArray(new String[includes.size()]); - includes.clear(); - for (int i = 0; i < includesArray.length; i++) { - includes.add((new File(includesArray[i])).getPath()); - } - String[] librariesArray = libraries.toArray(new String[libraries.size()]); - libraries.clear(); - for (int i = 0; i < librariesArray.length; i++) { - libraries.add((new File(librariesArray[i])).getPath()); - } - } + String[] archList = archSet.toArray(new String[archSet.size()]); - /** - Restore some important ANT property. If current build is single module - build, here will set many default values. - -

If current build is single module build, then the default ARCH - is IA32. Also set up the properties PACKAGE, - PACKAGE_DIR, TARGET and MODULE_DIR

- -

Note that for package build, package name is stored in PLATFORM - and package directory is stored in PLATFORM_DIR.

- - @see org.tianocore.build.global.OutputManager - **/ - private void recallFixedProperties() { // - // If build is for module build + // Judge if arch is all supported by current module. If not, throw Exception. // - if (getProject().getProperty("PACKAGE_DIR") == null) { - ToolChainFactory toolChainFactory = new ToolChainFactory(getProject()); - toolChainFactory.setupToolChain(); - // - // PACKAGE PACKAGE_DIR ARCH (Default) COMMON_FILE BUILD_MACRO - // - if (getProject().getProperty("ARCH") == null) { - getProject().setProperty("ARCH", "IA32"); + List moduleSupportedArchs = SurfaceAreaQuery.getModuleSupportedArchs(); + if (moduleSupportedArchs != null) { + for (int k = 0; k < archList.length; k++) { + if ( ! moduleSupportedArchs.contains(archList[k])) { + throw new BuildException("Specified architecture [" + archList[k] + "] is not supported by " + moduleId + ". The module " + moduleId + " only supports [" + moduleSupportedArchs + "] architectures."); + } } - String packageName = GlobalData.getPackageNameForModule(baseName); - getProject().setProperty("PACKAGE", packageName); - - String packageDir = GlobalData.getPackagePath(packageName); - getProject().setProperty("PACKAGE_DIR", - getProject().getProperty("WORKSPACE_DIR") + File.separatorChar + packageDir); - - getProject().setProperty("TARGET", toolChainFactory.getCurrentTarget()); - - getProject().setProperty("MODULE_DIR", - getProject().replaceProperties(getProject().getProperty("MODULE_DIR"))); } - if (OutputManager.PLATFORM != null) { - getProject().setProperty("PLATFORM", OutputManager.PLATFORM); - } - if (OutputManager.PLATFORM_DIR != null) { - getProject().setProperty("PLATFORM_DIR", OutputManager.PLATFORM_DIR); - } - } - /** - The whole BaseName_build.xml is composed of seven part. -
    -
  • ANT properties;
  • -
  • Dependent module (dependent library instances in most case);
  • -
  • Source files;
  • -
  • Sections if module is not library;
  • -
  • Output (different for library module and driver module);
  • -
  • Clean;
  • -
  • Clean all.
  • -
- - @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); - // - // Write the DOM document to the file - // - 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()); - } - } + for (int k = 0; k < archList.length; k++) { - /** - 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); - } - } + PropertyManager.setProperty("ARCH", archList[k]); - /** - 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 - // - 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); - } - } + FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, archList[k]); - /** - 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); + // Whether the module is built before // - // 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 + if (moduleId.isLibrary() == false && GlobalData.hasFpdModuleSA(fpdModuleId) == false) { + System.out.println("\nWARNING: " + moduleId + " for " + archList[k] + " was not found in current platform FPD file!\n"); + continue; + } else if (GlobalData.isModuleBuilt(fpdModuleId)) { + break; + } else { + GlobalData.registerBuiltModule(fpdModuleId); + } + // - property = document.createElement("property"); - property.setAttribute("name", "PACKAGE"); - property.setAttribute("value", GlobalData.getPackageNameForModule(libinstances[i])); - ele.appendChild(property); - root.appendChild(ele); + // For Every TOOLCHAIN, TARGET + // + String[] targetList = GlobalData.getToolChainInfo().getTargets(); + for (int i = 0; i < targetList.length; i ++){ + // + // Prepare for target related common properties + // TARGET + // + PropertyManager.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 were found for [target=" + targetList[i] + " toolchain=" + toolchainList[j] + " arch=" + archList[k] + "]\n"); + continue; + } + + // + // Prepare for toolchain related common properties + // TOOLCHAIN + // + PropertyManager.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 + // + 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); + } + } + } } - Element expand = document.createElement("Expand"); - root.appendChild(expand); + + PropertyManager.restore(); } - + /** - Generate the build source files elements for BaseName_build.xml. - - @param document current BaseName_build.xml XML document - @param root Root element for current + This method is used to prepare Platform-related information. + +

In Single Module Build mode, platform-related information is not ready. + The method read the system environment variable ACTIVE_PLATFORM + and search in the Framework Database. Note that platform name in the Framework + Database must be unique.

+ **/ - private void applyCompileElement(Document document, Node root) { - FileProcess fileProcess = new FileProcess(); - fileProcess.init(getProject(), includes, sourceFiles, document); - Node[] files = this.getSourceFiles(); + private void prepareSingleModuleBuild(){ // - // Parse all unicode files + // Find out the package which the module belongs to + // TBD: Enhance it!!!! // - for (int i = 0; i < files.length; i++) { - String filetype = getFiletype(files[i]); - if (filetype != null) { - fileProcess.parseFile(getFilename(files[i]), filetype, root, true); - } else { - fileProcess.parseFile(getFilename(files[i]), root, true); - } - } - if (fileProcess.isUnicodeExist()) { - Element ele = document.createElement("Build_Unicode_Database"); - ele.setAttribute("FILEPATH", "."); - ele.setAttribute("FILENAME", "${BASE_NAME}"); - root.appendChild(ele); - } + PackageIdentification packageId = GlobalData.getPackageForModule(moduleId); + + moduleId.setPackage(packageId); // - // Parse AutoGen.c & AutoGen.h + // Read ACTIVE_PLATFORM's FPD file // - if (!baseName.equalsIgnoreCase("Shell")) { - fileProcess.parseFile(getProject().getProperty("DEST_DIR_DEBUG") + File.separatorChar + "AutoGen.c", root, - false); + String filename = getProject().getProperty("PLATFORM_FILE"); + + if (filename == null){ + throw new BuildException("Please set ACTIVE_PLATFORM in the file: Tools/Conf/target.txt if you want to build a single module!"); } + + PlatformIdentification platformId = GlobalData.getPlatform(filename); + // - // Parse all source files + // Read FPD file (Call FpdParserTask's method) // - for (int i = 0; i < files.length; i++) { - String filetype = getFiletype(files[i]); - if (filetype != null) { - fileProcess.parseFile(getFilename(files[i]), filetype, root, false); - } else { - fileProcess.parseFile(getFilename(files[i]), root, false); - } - } + FpdParserTask fpdParser = new FpdParserTask(); + fpdParser.setProject(getProject()); + fpdParser.parseFpdFile(platformId.getFpdFile()); + // - // root.appendChild(parallelEle); + // Prepare for Platform related common properties + // PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR // - Iterator iter = sourceFiles.iterator(); - String str = ""; - while (iter.hasNext()) { - str += " " + (String) iter.next(); - } - getProject().setProperty("SOURCE_FILES", str); + PropertyManager.setProperty("PLATFORM", platformId.getName()); + PropertyManager.setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/")); + PropertyManager.setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/")); } - /** - Generate the section elements for BaseName_build.xml. Library module will - skip this process. - - @param document current BaseName_build.xml XML document - @param root Root element for current - **/ - private void applySectionsElement(Document document, Node root, FfsProcess fp) { - if (fp.initSections(buildType, getProject())) { - String targetFilename = guid + "-" + baseName + FpdParserTask.getSuffix(componentType); - String[] list = fp.getGenSectionElements(document, baseName, guid, targetFilename); - - for (int i = 0; i < list.length; i++) { - Element ele = document.createElement(list[i]); - ele.setAttribute("FILEPATH", "."); - ele.setAttribute("FILENAME", "${BASE_NAME}"); - root.appendChild(ele); - } - } - } /** - Generate the output elements for BaseName_build.xml. If module is library, - call the LIB command, else call the GenFfs command. + Set Module-Related information to properties. - @param document current BaseName_build.xml XML document - @param root Root element for current + @param arch current build ARCH **/ - private void applyOutputElement(Document document, Node root, FfsProcess fp) { - if (flag == GlobalData.ONLY_LIBMSA || flag == GlobalData.LIBMSA_AND_LIBMBD) { - // - // call Lib command - // - Element cc = document.createElement("Build_Library"); - cc.setAttribute("FILENAME", baseName); - root.appendChild(cc); - } + private void setModuleCommonProperties(String arch) { // - // if it is a module but library + // Prepare for all other common properties + // PACKAGE, PACKAGE_GUID, PACKAGE_VERSION, PACKAGE_DIR, PACKAGE_RELATIVE_DIR // - else { - if (fp.getFfsNode() != null) { - root.appendChild(fp.getFfsNode()); - } - } - } + PackageIdentification packageId = moduleId.getPackage(); + PropertyManager.setProperty("PACKAGE", packageId.getName()); + PropertyManager.setProperty("PACKAGE_GUID", packageId.getGuid()); + PropertyManager.setProperty("PACKAGE_VERSION", packageId.getVersion()); + PropertyManager.setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/")); + PropertyManager.setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/")); - /** - Get file name from node. If some wrong, return string with zero length. - - @param node Filename node of MSA/MBD or specified in each Section - @return File name - **/ - private String getFilename(Node node) { - String path = null; - String filename = "${MODULE_DIR}" + File.separatorChar; - String str = ""; - try { - FilenameDocument file = (FilenameDocument) XmlObject.Factory.parse(node); - str = file.getFilename().getStringValue().trim(); - path = file.getFilename().getPath(); - } catch (Exception e) { - str = ""; - } - if (path != null) { - filename += path + File.separatorChar + str; + // + // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE + // MODULE_DIR, MODULE_RELATIVE_DIR + // + PropertyManager.setProperty("MODULE", moduleId.getName()); + String baseName = SurfaceAreaQuery.getModuleOutputFileBasename(); + if (baseName == null) { + PropertyManager.setProperty("BASE_NAME", moduleId.getName()); } else { - filename += str; - } - return getProject().replaceProperties(filename); - } - - /** - Get file type from node. If some wrong or not specified, return - 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; + PropertyManager.setProperty("BASE_NAME", baseName); + } + PropertyManager.setProperty("GUID", moduleId.getGuid()); + PropertyManager.setProperty("FILE_GUID", moduleId.getGuid()); + PropertyManager.setProperty("VERSION", moduleId.getVersion()); + PropertyManager.setProperty("MODULE_TYPE", moduleId.getModuleType()); + PropertyManager.setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/")); + PropertyManager.setProperty("MODULE_RELATIVE_DIR", moduleId.getModuleRelativePath().replaceAll("(\\\\)", "/")); + + // + // SUBSYSTEM + // + String[][] subsystemMap = { { "BASE", "EFI_BOOT_SERVICE_DRIVER"}, + { "SEC", "EFI_BOOT_SERVICE_DRIVER" }, + { "PEI_CORE", "EFI_BOOT_SERVICE_DRIVER" }, + { "PEIM", "EFI_BOOT_SERVICE_DRIVER" }, + { "DXE_CORE", "EFI_BOOT_SERVICE_DRIVER" }, + { "DXE_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, + { "DXE_RUNTIME_DRIVER", "EFI_RUNTIME_DRIVER" }, + { "DXE_SAL_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, + { "DXE_SMM_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, + { "TOOL", "EFI_BOOT_SERVICE_DRIVER" }, + { "UEFI_DRIVER", "EFI_BOOT_SERVICE_DRIVER" }, + { "UEFI_APPLICATION", "EFI_APPLICATION" }, + { "USER_DEFINED", "EFI_BOOT_SERVICE_DRIVER"} }; + + String subsystem = "EFI_BOOT_SERVICE_DRIVER"; + for (int i = 0; i < subsystemMap.length; i++) { + if (moduleId.getModuleType().equalsIgnoreCase(subsystemMap[i][0])) { + subsystem = subsystemMap[i][1]; + break ; + } } - return str; - } + PropertyManager.setProperty("SUBSYSTEM", subsystem); - /** - 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]; - } - Vector vector = new Vector(); - for (int i = 0; i < files.length; i++) { - vector.addElement(files[i].getDomNode()); - } // - // To be consider sourcefiles from Sections + // ENTRYPOINT // - return vector.toArray(new Node[vector.size()]); - } - - /** - Get current module's base name. - - @return base name - **/ - public String getBaseName() { - return baseName; - } - - /** - Set MBD surface area file. For ANT use. - - @param mbdFilename Surface Area file - **/ - public void setMbdFilename(File mbdFilename) { - this.mbdFilename = mbdFilename; - } + if (arch.equalsIgnoreCase("EBC")) { + PropertyManager.setProperty("ENTRYPOINT", "EfiStart"); + } else { + PropertyManager.setProperty("ENTRYPOINT", "_ModuleEntryPoint"); + } - /** - Set MSA surface area file. For ANT use. - - @param msaFilename Surface Area file - **/ - public void setMsaFilename(File msaFilename) { - this.msaFilename = msaFilename; + PropertyManager.setProperty("OBJECTS", ""); } - /** - Compile flags setup. - -

Take command CC and arch IA32 for example, - Those flags are from ToolChainFactory:

-
    -
  • IA32_CC
  • -
  • IA32_CC_STD_FLAGS
  • -
  • IA32_CC_GLOBAL_FLAGS
  • -
  • IA32_CC_GLOBAL_ADD_FLAGS
  • -
  • IA32_CC_GLOBAL_SUB_FLAGS
  • -
- Those flags can user-define: -
    -
  • IA32_CC_PROJ_FLAGS
  • -
  • IA32_CC_PROJ_ADD_FLAGS
  • -
  • IA32_CC_PROJ_SUB_FLAGS
  • -
  • CC_PROJ_FLAGS
  • -
  • CC_PROJ_ADD_FLAGS
  • -
  • CC_PROJ_SUB_FLAGS
  • -
  • CC_FLAGS
  • -
  • IA32_CC_FLAGS
  • -
- -

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.

- - Note that the 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 addSet = new HashSet(40); - Set subSet = new HashSet(40); - for (int i = 0; i < cmd.length; i++) { - String str = ToolChainFactory.getValue(arch + "_" + cmd[i]); + private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException { + String[] cmd = GlobalData.getToolChainInfo().getCommands(); + for ( int m = 0; m < cmd.length; m++) { // - // Command line path+command name + // Set cmd, like CC, DLINK // - if (str != null) { - project.setProperty(cmd[i], str); - } - // - // ARCH_CMD_STD_FLAGS - // - str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_STD_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); - project.setProperty(cmd[i] + "_STD_FLAGS", str); - } - // - // ARCH_CMD_GLOBAL_FLAGS - // - str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_GLOBAL_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); - } - // - // ARCH_CMD_GLOBAL_ADD_FLAGS - // - str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_GLOBAL_ADD_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); - } - // - // ARCH_CMD_GLOBAL_SUB_FLAGS - // - str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_GLOBAL_SUB_FLAGS"); - if (str != null) { - putFlagsToSet(subSet, str); - } - // - // ARCH_CMD_PROJ_FLAGS - // - str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); - } - // - // ARCH_CMD_PROG_FLAGS - // - str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_ADD_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); - } - // - // ARCH_CMD_PROG_FLAGS - // - str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_SUB_FLAGS"); - if (str != null) { - putFlagsToSet(subSet, str); - } + String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null}; + key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_PATH; + String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId); + key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME; + String cmdName = GlobalData.getCommandSetting(key, fpdModuleId); + File cmdFile = new File(cmdPath + File.separatorChar + cmdName); + PropertyManager.setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/")); + // - // CMD_PROJ_FLAGS + // set CC_FLAGS // - str = project.getProperty(cmd[i] + "_PROJ_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); - } + key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS; + String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId); + Set addset = new LinkedHashSet(); + Set subset = new LinkedHashSet(); + putFlagsToSet(addset, cmdFlags); + PropertyManager.setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset))); + // - // CMD_PROG_FLAGS + // Set CC_EXT // - str = project.getProperty(cmd[i] + "_PROJ_ADD_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); + key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_EXT; + String extName = GlobalData.getCommandSetting(key, fpdModuleId); + if ( extName != null && ! extName.equalsIgnoreCase("")) { + PropertyManager.setProperty(cmd[m] + "_EXT", extName); + } else { + PropertyManager.setProperty(cmd[m] + "_EXT", ""); } + // - // CMD_PROG_FLAGS + // set CC_FAMILY // - str = project.getProperty(cmd[i] + "_PROJ_SUB_FLAGS"); - if (str != null) { - putFlagsToSet(subSet, str); + key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY; + String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId); + if (toolChainFamily != null) { + PropertyManager.setProperty(cmd[m] + "_FAMILY", toolChainFamily); } + // - // If IA32_CC_FLAGS or IA32_LIB_FLAGS .. has defined in BuildOptions + // set CC_SPATH // - if ((str = project.getProperty(arch + "_" + cmd[i] + "_FLAGS")) != null) { - project.setProperty(cmd[i] + "_FLAGS", getRawFlags(addSet, subSet)); - addSet.clear(); - subSet.clear(); - putFlagsToSet(addSet, project.replaceProperties(str)); - project.setProperty(cmd[i] + "_FLAGS", project.replaceProperties(getFlags(addSet, subSet))); - addSet.clear(); - subSet.clear(); + key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_SPATH; + String spath = GlobalData.getCommandSetting(key, fpdModuleId); + if (spath != null) { + PropertyManager.setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/")); + } else { + PropertyManager.setProperty(cmd[m] + "_SPATH", ""); } + // - // If CC_FLAGS or LIB_FLAGS .. has defined in BuildOptions + // set CC_DPATH // - else if ((str = project.getProperty(cmd[i] + "_FLAGS")) != null) { - project.setProperty(cmd[i] + "_FLAGS", getRawFlags(addSet, subSet)); - addSet.clear(); - subSet.clear(); - putFlagsToSet(addSet, project.replaceProperties(str)); - project.setProperty(cmd[i] + "_FLAGS", project.replaceProperties(getFlags(addSet, subSet))); - addSet.clear(); - subSet.clear(); + key[4] = ToolDefinitions.TOOLS_DEF_ATTRIBUTE_DPATH; + String dpath = GlobalData.getCommandSetting(key, fpdModuleId); + if (dpath != null) { + PropertyManager.setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/")); } else { - project.setProperty(cmd[i] + "_FLAGS", getFlags(addSet, subSet)); - addSet.clear(); - subSet.clear(); + PropertyManager.setProperty(cmd[m] + "_DPATH", ""); } } - project.setProperty("C_FLAGS", project.getProperty("CC_FLAGS")); + } + + public void setMsaFile(File msaFile) { + this.msaFile = msaFile; } /** - Initialize some properties will be used in current module build, including - user-defined option from Option of BuildOptions in - surface area. + Method is for ANT to initialize MSA file. + + @param msaFilename MSA file name **/ - private void updateParameters() { - getProject().setProperty("OBJECTS", ""); - getProject().setProperty("SDB_FILES", ""); - getProject().setProperty("BASE_NAME", baseName); - if (map.get("MsaHeader") != null) { - guid = SurfaceAreaQuery.getModuleGuid();//header.getGuid().getStringValue(); - componentType = SurfaceAreaQuery.getComponentType();//header.getComponentType().toString(); - if (!componentType.equalsIgnoreCase("LIBRARY")) { - flag = GlobalData.MSA_AND_MBD; - } else { - flag = GlobalData.LIBMSA_AND_LIBMBD; - } - } - - else if (map.get("MsaLibHeader") != null) { - flag = GlobalData.LIBMSA_AND_LIBMBD; - MsaLibHeaderDocument.MsaLibHeader header = ((MsaLibHeaderDocument) map.get("MsaLibHeader")) - .getMsaLibHeader(); - guid = header.getGuid().getStringValue(); - componentType = header.getComponentType().toString(); + public void setMsaFile(String msaFilename) { + String moduleDir = getProject().getProperty("MODULE_DIR"); + + // + // If is Single Module Build, then use the Base Dir defined in build.xml + // + if (moduleDir == null) { + moduleDir = getProject().getBaseDir().getPath(); + } + msaFile = new File(moduleDir + File.separatorChar + msaFilename); + } + + public void addConfiguredModuleItem(ModuleItem moduleItem) { + PackageIdentification packageId = new PackageIdentification(moduleItem.getPackageGuid(), moduleItem.getPackageVersion()); + ModuleIdentification moduleId = new ModuleIdentification(moduleItem.getModuleGuid(), moduleItem.getModuleVersion()); + moduleId.setPackage(packageId); + this.moduleId = moduleId; + } + + /** + Add a property. + + @param p property + **/ + public void addProperty(Property p) { + properties.addElement(p); + } + + public void setType(String type) { + this.type = type; + } + + private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws BuildException{ + // + // AutoGen + // + + AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch()); + autogen.genAutogen(); + + + // + // Get compiler flags + // + try { + getCompilerFlags(buildTarget, buildTagname, fpdModuleId); + } + catch (EdkException ee) { + throw new BuildException(ee.getMessage()); } - if (componentType != null) { - getProject().setProperty("COMPONENT_TYPE", componentType); + // + // Prepare LIBS + // + ModuleIdentification[] libinstances = SurfaceAreaQuery.getLibraryInstance(fpdModuleId.getArch()); + String propertyLibs = ""; + for (int i = 0; i < libinstances.length; i++) { + propertyLibs += " " + getProject().getProperty("BIN_DIR") + File.separatorChar + libinstances[i].getName() + ".lib"; } + PropertyManager.setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/")); - if (guid != null) { - getProject().setProperty("FILE_GUID", guid); + // + // Get all includepath and set to INCLUDE_PATHS + // + String[] includes = prepareIncludePaths(fpdModuleId); + + // + // if it is CUSTOM_BUILD + // then call the exist BaseName_build.xml directly. + // + if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) { + System.out.println("Call user-defined " + moduleId.getName() + "_build.xml"); + + String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml"; + antCall(antFilename, null); + + return ; } + // - // Get all options and set to properties + // Generate ${BASE_NAME}_build.xml + // TBD // - String[][] options = SurfaceAreaQuery.getOptions(arch); - for (int i = 0; i < options.length; i++) { - if (options[i][0] != null && options[i][1] != null) { - getProject().setProperty(options[i][0], getProject().replaceProperties(options[i][1])); - } + String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword(); + ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId, includes); + String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml"; + fileGenerator.genBuildFile(buildFilename); + + // + // Ant call ${BASE_NAME}_build.xml + // + String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml"; + antCall(antFilename, null); + } + + private void applyClean(FpdModuleIdentification fpdModuleId){ + // + // if it is CUSTOM_BUILD + // then call the exist BaseName_build.xml directly. + // + if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) { + System.out.println("Calling user-defined " + moduleId.getName() + "_build.xml"); + + String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml"; + antCall(antFilename, "clean"); + + return ; } - buildType = getProject().getProperty("BUILD_TYPE"); - if (buildType == null) { - buildType = componentType; + String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml"; + antCall(antFilename, "clean"); + } + + private void applyCleanall(FpdModuleIdentification fpdModuleId){ + // + // if it is CUSTOM_BUILD + // then call the exist BaseName_build.xml directly. + // + if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) { + System.out.println("Calling user-defined " + moduleId.getName() + "_build.xml"); + + String antFilename = getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml"; + antCall(antFilename, "cleanall"); + + return ; } + + String antFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml"; + antCall(antFilename, "cleanall"); + } + private void antCall(String antFilename, String target) { + Ant ant = new Ant(); + ant.setProject(getProject()); + ant.setAntfile(antFilename); + if (target != null) { + ant.setTarget(target); + } + ant.setInheritAll(true); + ant.init(); + ant.execute(); } + /** Separate the string and instore in set. - -

String is separated by Java Regulation Expression + +

String is separated by Java Regulation Expression "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+".

- +

For example:

- +
         "/nologo", "/W3", "/WX"
         "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
       
- + @param set store the separated string @param str string to separate **/ private void putFlagsToSet(Set set, String str) { + if (str == null || str.length() == 0) { + return; + } + Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); Matcher matcher = myPattern.matcher(str + " "); while (matcher.find()) { String item = str.substring(matcher.start(1), matcher.end(1)); - if (!set.contains(item)) { - set.add(item); - } + set.add(item); } } - + /** - Generate the final flags string will be used by compile command. - + Generate the final flags string will be used by compile command. + @param add the add flags set @param sub the sub flags set @return final flags after add set substract sub set @@ -1143,45 +689,98 @@ public class GenBuildTask extends Task { add.removeAll(sub); Iterator iter = add.iterator(); while (iter.hasNext()) { - String str = getProject().replaceProperties((String) iter.next()); + String str = (String) iter.next(); result += str.substring(1, str.length() - 1) + " "; } return result; } - /** - Generate the flags string with original format. The format is defined by - Java Regulation Expression "[^\\\\]?(\".*?[^\\\\]\")[ \t,]+".

- -

For example:

- -
-        "/nologo", "/W3", "/WX"
-        "/C", "/DSTRING_DEFINES_FILE=\"BdsStrDefs.h\""
-      
- - @param add the add flags set - @param sub the sub flags set - @return flags with original format - **/ - private String getRawFlags(Set add, Set sub) { - String result = ""; - add.removeAll(sub); - Iterator iter = add.iterator(); + public void setSingleModuleBuild(boolean isSingleModuleBuild) { + this.isSingleModuleBuild = isSingleModuleBuild; + } + + private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) { + // + // Prepare the includes: PackageDependencies and Output debug direactory + // + Set includes = new LinkedHashSet(); + String arch = fpdModuleId.getArch(); + + // + // WORKSPACE + // + includes.add("${WORKSPACE_DIR}" + File.separatorChar); + + // + // 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}"); + + // + // set to INCLUDE_PATHS property + // + Iterator iter = includes.iterator(); + StringBuffer includePaths = new StringBuffer(); while (iter.hasNext()) { - String str = getProject().replaceProperties((String) iter.next()); - result += "\"" + str.substring(1, str.length() - 1) + "\", "; + includePaths.append(iter.next()); + includePaths.append("; "); } - return result; + PropertyManager.setProperty("INCLUDE_PATHS", getProject().replaceProperties(includePaths.toString()).replaceAll("(\\\\)", "/")); + + return includes.toArray(new String[includes.size()]); } - + /** - Set base name. For ANT use. - - @param baseName Base name - **/ - public void setBaseName(String baseName) { - this.baseName = baseName; - } - + 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"); + } }