X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2FGenBuildTask.java;h=bac506abfa3f0161ff999a6c096b326474b77f2a;hp=2d91991b8a9b92fe07eac3d8d33c5eff4ff5896b;hb=196ad8d77c4a256e6a9b432541d688d2f40f4614;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4 diff --git a/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java b/Tools/Source/GenBuild/org/tianocore/build/GenBuildTask.java index 2d91991b8a..bac506abfa 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 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 map = new HashMap(); - - /// - /// Module's base name. - /// - private String baseName; + File msaFile; /// - /// 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(); - - /// - /// List all source files for current build module. - /// - public Set sourceFiles = new LinkedHashSet(); - - /// - /// 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 String type = "all"; // = "build"; + /// - /// The information at the header of build.xml. + /// Module's Identification. /// - 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 ModuleIdentification moduleId; + private Vector properties = new Vector(); + + private static Stack backupPropertiesStack = new Stack(); + + private boolean isSingleModuleBuild = false; + /** Public construct method. It is necessary for ANT task. **/ @@ -172,920 +112,546 @@ public class GenBuildTask extends Task { } /** - ANT task's entry point, will be called after init(). The main steps is described - as following: -

- -

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); - // - // Setup Output Management - // - String[] outdir = SurfaceAreaQuery.getOutputDirectory(); - OutputManager.update(getProject(), outdir[1], outdir[0]); - - updateIncludesAndLibraries(); - - if (GlobalData.isModuleBuilt(baseName, arch)) { - return; - } else { - GlobalData.registerBuiltModule(baseName, arch); - } - // - // Call AutoGen - // - AutoGen autogen = new AutoGen(getProject().getProperty("DEST_DIR_DEBUG"), baseName, arch); - autogen.genAutogen(); - // - // Update parameters + // + // set Logger // - updateParameters(); - // - // Update flags like CC_FLAGS, LIB_FLAGS etc. - // - flagsSetup(); - GlobalData.addLibrary(baseName, getProject().getProperty("BIN_DIR") + File.separatorChar + baseName + ".lib"); - GlobalData.addModuleLibrary(baseName, libraries); + GenBuildLogger logger = new GenBuildLogger(getProject()); + EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL")); + EdkLog.setLogger(logger); + // remove !! + try { + pushProperties(); // - // If ComponentType is USER_DEFINED, - // then call the exist BaseName_build.xml directly. + // Enable all specified properties // - 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; + Iterator iter = properties.iterator(); + while (iter.hasNext()) { + Property item = iter.next(); + getProject().setProperty(item.getName(), item.getValue()); } + // - // Generate ${BASE_NAME}_build.xml file + // GenBuild should specify either msaFile or moduleGuid & packageGuid // - 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(); - } - - /** - 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 + "${ARCH}"); + 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 parameters 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(); } - 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()); - } + else { + Map doc = GlobalData.getNativeMsa(msaFile); + SurfaceAreaQuery.setDoc(doc); + moduleId = SurfaceAreaQuery.getMsaHeader(); } - 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[] producedLibraryClasses = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED",null); + if (producedLibraryClasses.length == 0) { + moduleId.setLibrary(false); } - 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()); + else { + moduleId.setLibrary(true); } - } - - /** - 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 whether it is single module build or not // - if (getProject().getProperty("PACKAGE_DIR") == null) { - ToolChainFactory toolChainFactory = new ToolChainFactory(getProject()); - toolChainFactory.setupToolChain(); + if (isSingleModuleBuild) { // - // PACKAGE PACKAGE_DIR ARCH (Default) COMMON_FILE BUILD_MACRO + // Single Module build // - if (getProject().getProperty("ARCH") == null) { - getProject().setProperty("ARCH", "IA32"); - } - 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()); + prepareSingleModuleBuild(); + } + else { + // + // Platform build. Restore the platform related info + // + 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("(\\\\)", "/")); - getProject().setProperty("MODULE_DIR", - getProject().replaceProperties(getProject().getProperty("MODULE_DIR"))); + String packageGuid = getProject().getProperty("PACKAGE_GUID"); + String packageVersion = getProject().getProperty("PACKAGE_VERSION"); + PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion); + moduleId.setPackage(packageId); } - if (OutputManager.PLATFORM != null) { - getProject().setProperty("PLATFORM", OutputManager.PLATFORM); + + // + // If single module : intersection MSA supported ARCHs and tools def!! + // else, get arch from pass down + // + String[] archList = new String[0]; + if ( getProject().getProperty("ARCH") != null ) { + archList = getProject().getProperty("ARCH").split(" "); } - if (OutputManager.PLATFORM_DIR != null) { - getProject().setProperty("PLATFORM_DIR", OutputManager.PLATFORM_DIR); + else { + archList = GlobalData.getToolChainInfo().getArchs(); } - } - - /** - 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()); + + + // + // 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 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 + + 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 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); + popProperties(); + }catch (Exception e){ + throw new BuildException(e.getMessage()); } } /** - Generate the dependent library instances 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 - **/ - 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); - } - Element expand = document.createElement("Expand"); - root.appendChild(expand); - } - - /** - Generate the build source files elements for BaseName_build.xml. - - @param document current BaseName_build.xml XML document - @param root Root element for current +

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 (Call FpdParserTask's method) // - 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("Plese set ACTIVE_PLATFORM if you want to build a single module. "); } + + PlatformIdentification platformId = GlobalData.getPlatform(filename); + // - // Parse all source files + // Read FPD file // - 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); + getProject().setProperty("PLATFORM", platformId.getName()); + getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/")); + getProject().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. - - @param document current BaseName_build.xml XML document - @param root Root element for current + Set Module-Related information to properties. **/ - 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 // + PackageIdentification packageId = moduleId.getPackage(); + getProject().setProperty("PACKAGE", packageId.getName()); + getProject().setProperty("PACKAGE_GUID", packageId.getGuid()); + getProject().setProperty("PACKAGE_VERSION", packageId.getVersion()); + getProject().setProperty("PACKAGE_DIR", packageId.getPackageDir().replaceAll("(\\\\)", "/")); + getProject().setProperty("PACKAGE_RELATIVE_DIR", packageId.getPackageRelativeDir().replaceAll("(\\\\)", "/")); + + // + // MODULE or BASE_NAME, GUID or FILE_GUID, VERSION, MODULE_TYPE + // MODULE_DIR, MODULE_RELATIVE_DIR + // + getProject().setProperty("MODULE", moduleId.getName()); + String baseName = SurfaceAreaQuery.getModuleOutputFileBasename(); + if (baseName == null) { + getProject().setProperty("BASE_NAME", moduleId.getName()); + } else { - if (fp.getFfsNode() != null) { - root.appendChild(fp.getFfsNode()); + getProject().setProperty("BASE_NAME", baseName); + } + getProject().setProperty("GUID", moduleId.getGuid()); + getProject().setProperty("FILE_GUID", moduleId.getGuid()); + getProject().setProperty("VERSION", moduleId.getVersion()); + getProject().setProperty("MODULE_TYPE", moduleId.getModuleType()); + getProject().setProperty("MODULE_DIR", moduleId.getMsaFile().getParent().replaceAll("(\\\\)", "/")); + getProject().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 ; } } - } - - /** - 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; - } 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; - } - 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"); } - Vector vector = new Vector(); - for (int i = 0; i < files.length; i++) { - vector.addElement(files[i].getDomNode()); + else { + getProject().setProperty("ENTRYPOINT", "_ModuleEntryPoint"); } + // - // To be consider sourcefiles from Sections + // LIBS, OBJECTS, SDB_FILES // - 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; - } - - /** - Set MSA surface area file. For ANT use. - - @param msaFilename Surface Area file - **/ - public void setMsaFilename(File msaFilename) { - this.msaFilename = msaFilename; + getProject().setProperty("OBJECTS", ""); + getProject().setProperty("SDB_FILES", ""); + getProject().setProperty("LIBS", ""); } - /** - 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]); - // - // Command line path+command name - // - if (str != null) { - project.setProperty(cmd[i], str); - } - // - // ARCH_CMD_STD_FLAGS + private void getCompilerFlags(String target, String toolchain, FpdModuleIdentification fpdModuleId) throws EdkException { + String[] cmd = GlobalData.getToolChainInfo().getCommands(); + for ( int m = 0; m < cmd.length; m++) { // - 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); - } + // Set cmd, like CC, DLINK // - // ARCH_CMD_GLOBAL_SUB_FLAGS - // - str = ToolChainFactory.getValue(arch + "_" + cmd[i] + "_GLOBAL_SUB_FLAGS"); - if (str != null) { - putFlagsToSet(subSet, str); - } + String[] key = new String[]{target, toolchain, fpdModuleId.getArch(), cmd[m], null}; + key[4] = "PATH"; + String cmdPath = GlobalData.getCommandSetting(key, fpdModuleId); + key[4] = "NAME"; + String cmdName = GlobalData.getCommandSetting(key, fpdModuleId); + File cmdFile = new File(cmdPath + File.separatorChar + cmdName); + getProject().setProperty(cmd[m], cmdFile.getPath().replaceAll("(\\\\)", "/")); + // - // ARCH_CMD_PROJ_FLAGS + // set CC_FLAGS // - str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); - } + key[4] = "FLAGS"; + String cmdFlags = GlobalData.getCommandSetting(key, fpdModuleId); + Set addset = new LinkedHashSet(); + Set subset = new LinkedHashSet(); + putFlagsToSet(addset, cmdFlags); + getProject().setProperty(cmd[m] + "_FLAGS", getProject().replaceProperties(getFlags(addset, subset))); + // - // ARCH_CMD_PROG_FLAGS + // Set CC_EXT // - str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_ADD_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); + key[4] = "EXT"; + String extName = GlobalData.getCommandSetting(key, fpdModuleId); + if ( extName != null && ! extName.equalsIgnoreCase("")) { + getProject().setProperty(cmd[m] + "_EXT", extName); } - // - // ARCH_CMD_PROG_FLAGS - // - str = project.getProperty(arch + "_" + cmd[i] + "_PROJ_SUB_FLAGS"); - if (str != null) { - putFlagsToSet(subSet, str); + else { + getProject().setProperty(cmd[m] + "_EXT", ""); } + // - // CMD_PROJ_FLAGS + // set CC_FAMILY // - str = project.getProperty(cmd[i] + "_PROJ_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); + key[4] = "FAMILY"; + String toolChainFamily = GlobalData.getCommandSetting(key, fpdModuleId); + if (toolChainFamily != null) { + getProject().setProperty(cmd[m] + "_FAMILY", toolChainFamily); } + // - // CMD_PROG_FLAGS + // set CC_SPATH // - str = project.getProperty(cmd[i] + "_PROJ_ADD_FLAGS"); - if (str != null) { - putFlagsToSet(addSet, str); + key[4] = "SPATH"; + String spath = GlobalData.getCommandSetting(key, fpdModuleId); + if (spath != null) { + getProject().setProperty(cmd[m] + "_SPATH", spath.replaceAll("(\\\\)", "/")); } - // - // CMD_PROG_FLAGS - // - str = project.getProperty(cmd[i] + "_PROJ_SUB_FLAGS"); - if (str != null) { - putFlagsToSet(subSet, str); + else { + getProject().setProperty(cmd[m] + "_SPATH", ""); } + // - // If IA32_CC_FLAGS or IA32_LIB_FLAGS .. has defined in BuildOptions + // set CC_DPATH // - 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] = "DPATH"; + String dpath = GlobalData.getCommandSetting(key, fpdModuleId); + if (dpath != null) { + getProject().setProperty(cmd[m] + "_DPATH", dpath.replaceAll("(\\\\)", "/")); } - // - // If CC_FLAGS or LIB_FLAGS .. has defined in BuildOptions - // - 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(); - } else { - project.setProperty(cmd[i] + "_FLAGS", getFlags(addSet, subSet)); - addSet.clear(); - subSet.clear(); + else { + getProject().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) { - flag = GlobalData.MSA_AND_MBD; - MsaHeaderDocument.MsaHeader header = ((MsaHeaderDocument) map.get("MsaHeader")).getMsaHeader(); - 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 EdkException{ + // + // AutoGen + // + + AutoGen autogen = new AutoGen(getProject().getProperty("FV_DIR"), getProject().getProperty("DEST_DIR_DEBUG"), fpdModuleId.getModule(),fpdModuleId.getArch()); + autogen.genAutogen(); - 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(); + + // + // Get compiler flags + // + getCompilerFlags(buildTarget, buildTagname, fpdModuleId); + + // + // 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"; } + getProject().setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/")); - if (componentType != null) { - getProject().setProperty("COMPONENT_TYPE", componentType); + // + // if it is CUSTOM_BUILD + // then call the exist BaseName_build.xml directly. + // + if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) { + GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml"); + Ant ant = new Ant(); + ant.setProject(getProject()); + ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml"); + ant.setInheritAll(true); + ant.init(); + ant.execute(); + return ; } - if (guid != null) { - getProject().setProperty("FILE_GUID", guid); + // + // Generate ${BASE_NAME}_build.xml + // TBD + // + String ffsKeyword = SurfaceAreaQuery.getModuleFfsKeyword(); + ModuleBuildFileGenerator fileGenerator = new ModuleBuildFileGenerator(getProject(), ffsKeyword, fpdModuleId); + String buildFilename = getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml"; + fileGenerator.genBuildFile(buildFilename); + + // + // Ant call ${BASE_NAME}_build.xml + // + Ant ant = new Ant(); + ant.setProject(getProject()); + ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml"); + ant.setInheritAll(true); + ant.init(); + ant.execute(); + } + + private void applyClean(FpdModuleIdentification fpdModuleId){ + // + // if it is CUSTOM_BUILD + // then call the exist BaseName_build.xml directly. + // + if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) { + GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml"); + Ant ant = new Ant(); + ant.setProject(getProject()); + ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml"); + ant.setTarget("clean"); + ant.setInheritAll(true); + ant.init(); + ant.execute(); + return ; } + + Ant ant = new Ant(); + ant.setProject(getProject()); + ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml"); + ant.setTarget("clean"); + ant.setInheritAll(true); + ant.init(); + ant.execute(); + + // + // Delete current module's DEST_DIR_OUTPUT + // TBD + } + + private void applyCleanall(FpdModuleIdentification fpdModuleId){ // - // Get all options and set to properties + // if it is CUSTOM_BUILD + // then call the exist BaseName_build.xml directly. // - 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])); - } + if (moduleId.getModuleType().equalsIgnoreCase("USER_DEFINED")) { + GlobalData.log.info("Call user-defined " + moduleId.getName() + "_build.xml"); + Ant ant = new Ant(); + ant.setProject(getProject()); + ant.setAntfile(getProject().getProperty("MODULE_DIR") + File.separatorChar + moduleId.getName() + "_build.xml"); + ant.setTarget("cleanall"); + ant.setInheritAll(true); + ant.init(); + ant.execute(); + return ; } + + Ant ant = new Ant(); + ant.setProject(getProject()); + ant.setAntfile(getProject().getProperty("DEST_DIR_OUTPUT") + File.separatorChar + moduleId.getName() + "_build.xml"); + ant.setTarget("cleanall"); + ant.setInheritAll(true); + ant.init(); + ant.execute(); + + // + // Delete current module's DEST_DIR_OUTPUT + // TBD + } + - buildType = getProject().getProperty("BUILD_TYPE"); - if (buildType == null) { - buildType = componentType; - } - } /** Separate the string and instore in set. @@ -1104,13 +670,15 @@ public class GenBuildTask extends Task { @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); } } @@ -1126,7 +694,7 @@ 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; @@ -1148,23 +716,59 @@ public class GenBuildTask extends Task { @return flags with original format **/ private String getRawFlags(Set add, Set sub) { - String result = ""; + String result = null; 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; } - /** - Set base name. For ANT use. - - @param baseName Base name - **/ - public void setBaseName(String baseName) { - this.baseName = baseName; + private String parseOptionString(String optionString, Set addSet, Set subSet) { + boolean overrideOption = false; + Pattern pattern = Pattern.compile("ADD\\.\\[(.+)\\]"); + Matcher matcher = pattern.matcher(optionString); + + while (matcher.find()) { + overrideOption = true; + String addOption = optionString.substring(matcher.start(1), matcher.end(1)).trim(); + putFlagsToSet(addSet, addOption); + + } + + pattern = Pattern.compile("SUB\\.\\[(.+)\\]"); + matcher = pattern.matcher(optionString); + + while (matcher.find()) { + overrideOption = true; + String subOption = optionString.substring(matcher.start(1), matcher.end(1)).trim(); + putFlagsToSet(subSet, subOption); + } + + if (overrideOption == true) { + return null; + } + + return optionString; + } + + private void pushProperties() { + backupPropertiesStack.push(getProject().getProperties()); + } + + private void popProperties() { + Hashtable backupProperties = backupPropertiesStack.pop(); + Set keys = backupProperties.keySet(); + Iterator iter = keys.iterator(); + while (iter.hasNext()) { + String item = (String)iter.next(); + getProject().setProperty(item, (String)backupProperties.get(item)); + } } + public void setSingleModuleBuild(boolean isSingleModuleBuild) { + this.isSingleModuleBuild = isSingleModuleBuild; + } }