X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fglobal%2FGlobalData.java;h=ceb19d91db7d78c9400a26f819255e43feec0f1b;hp=f3f0a048d92332936ba114166bc81c0e6a297f8c;hb=0923e8b3b22a10416d9c8e0a192f0e88758a1b90;hpb=de4bb9f6edc1db82e0616b24e6685b27d2b66061 diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java index f3f0a048d9..ceb19d91db 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java +++ b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java @@ -1,10 +1,10 @@ /** @file - GlobalData class. - + GlobalData class. + GlobalData provide initializing, instoring, querying and update global data. It is a bridge to intercommunicate between multiple component, such as AutoGen, - PCD and so on. - + PCD and so on. + 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,64 +16,63 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ package org.tianocore.build.global; -import org.apache.tools.ant.BuildException; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; + +import org.tianocore.common.exception.EdkException; +import org.tianocore.common.logger.EdkLog; +import org.tianocore.pcd.entity.MemoryDatabaseManager; import org.tianocore.DbPathAndFilename; import org.tianocore.FrameworkDatabaseDocument; import org.tianocore.ModuleSurfaceAreaDocument; -import org.tianocore.PcdBuildDefinitionDocument; import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea; 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.pcd.entity.MemoryDatabaseManager; import org.tianocore.build.toolchain.ToolChainAttribute; import org.tianocore.build.toolchain.ToolChainConfig; import org.tianocore.build.toolchain.ToolChainElement; import org.tianocore.build.toolchain.ToolChainInfo; import org.tianocore.build.toolchain.ToolChainKey; import org.tianocore.build.toolchain.ToolChainMap; -import org.tianocore.exception.EdkException; -import org.tianocore.logger.EdkLog; - -import java.io.File; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Logger; /** GlobalData provide initializing, instoring, querying and update global data. It is a bridge to intercommunicate between multiple component, such as AutoGen, - PCD and so on. - -

Note that all global information are initialized incrementally. All data will + PCD and so on. + +

Note that all global information are initialized incrementally. All data will parse and record only of necessary during build time.

- + @since GenBuild 1.0 **/ public class GlobalData { - - public static Logger log = Logger.getAnonymousLogger(); - /// /// Record current WORKSPACE Directory /// private static String workspaceDir = ""; - + /// /// Be used to ensure Global data will be initialized only once. /// private static boolean globalFlag = false; - + /// /// Framework Database information: package list and platform list /// - private static Set packageList = new HashSet(); + private static Set packageList = new HashSet(); private static Set platformList = new HashSet(); @@ -91,24 +90,26 @@ public class GlobalData { private static Map> fpdModuleSA= new HashMap>(); + private static Map fpdBuildOptionsMap = new HashMap(); + private static XmlObject fpdBuildOptions; private static XmlObject fpdDynamicPcds; - + /// /// Parsed modules list /// private static Map> parsedModules = new HashMap>(); - + /// /// built modules list with ARCH, TARGET, TOOLCHAIN /// private static Set builtModules = new HashSet(); - + /// /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD. /// -// private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager(); + private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager(); /// /// build target + tool chain family/tag name + arch + command types + command options @@ -118,7 +119,7 @@ public class GlobalData { /// toolsDef - build tool program information /// fpdBuildOption - all modules's build options for tool tag or tool chain families /// moduleSaBuildOption - build options for a specific module - /// + /// private static ToolChainConfig toolsDef; private static ToolChainInfo toolChainInfo; @@ -131,21 +132,17 @@ public class GlobalData { private static Map moduleToolChainOption = new HashMap(); private static Map moduleToolChainFamilyOption = new HashMap(); - private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager(); - - - /** Parse framework database (DB) and all SPD files listed in DB to initialize the environment for next build. This method will only be executed only once - in the whole build process. - + in the whole build process. + @param workspaceDatabaseFile the file name of framework database @param workspaceDir current workspace directory path @throws BuildException Framework Dababase or SPD or MSA file is not valid **/ - public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename) throws BuildException { + public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws EdkException { // // ensure this method will be revoked only once // @@ -153,12 +150,12 @@ public class GlobalData { return; } globalFlag = true; - - // + + // // Backup workspace directory. It will be used by other method // GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/"); - + // // Parse tools definition file // @@ -167,9 +164,9 @@ public class GlobalData { // CONF dir + tools definition file name // File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename); - System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. "); + EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Using tool definition file [" + toolsDefFile.getPath() + "]."); toolsDef = new ToolChainConfig(toolsDefFile); - + // // Parse Framework Database // @@ -179,8 +176,8 @@ public class GlobalData { // // validate FrameworkDatabaseFile // - if (! db.validate()) { - throw new BuildException("Framework Database file [" + dbFile.getPath() + "] is invalid."); + if (!db.validate()) { + throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!"); } // // Get package list @@ -189,9 +186,18 @@ public class GlobalData { List packages = db.getFrameworkDatabase().getPackageList().getFilenameList(); Iterator iter = packages.iterator(); while (iter.hasNext()) { - String fileName = iter.next().getStringValue(); + String fileName = iter.next().getStringValue().trim(); Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName)); packageList.add(spd.getPackageId()); + // + // Report warning if existing two packages with same GUID and Version + // + if (spdTable.containsKey(spd.getPackageId())) { + // + // BUGBUG + // + EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two packages with same GUID and Version. They are ... " + spd.getPackageId().getSpdFile().getPath()); + } spdTable.put(spd.getPackageId(), spd); } } @@ -203,41 +209,52 @@ public class GlobalData { List platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList(); Iterator iter = platforms.iterator(); while (iter.hasNext()) { - String fileName = iter.next().getStringValue(); + String fileName = iter.next().getStringValue().trim(); File fpdFile = new File(workspaceDir + File.separatorChar + fileName); - if ( ! fpdFile.exists() ) { - throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. "); + if ( !fpdFile.exists() ) { + throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. "); } XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile); // // Verify FPD file, if is invalid, throw Exception // - if (! fpdDoc.validate()) { - throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] is invalid. "); + if (!fpdDoc.validate()) { + throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!"); } // // We can change Map to XmlObject // - // - // TBD check SPD or FPD is existed in FS - // Map fpdDocMap = new HashMap(); fpdDocMap.put("PlatformSurfaceArea", fpdDoc); - SurfaceAreaQuery.setDoc(fpdDocMap); - PlatformIdentification platformId = SurfaceAreaQuery.getFpdHeader(); + SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap); + PlatformIdentification platformId = saq.getFpdHeader(); platformId.setFpdFile(fpdFile); + // + // Report warning if existing two platfrom with same GUID and Version + // + if (platformList.contains(platformId)) { + // + // BUGBUG + // + EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile.getPath()); + } platformList.add(platformId); } } - } catch (Exception e) { - e.printStackTrace(); - throw new BuildException("Parse workspace Database [" + dbFile.getPath() + "] Error.\n" + e.getMessage()); + } catch(IOException ex) { + EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch(XmlException ex) { + EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } } - + /** - Get the current WORKSPACE Directory. - + Get the current WORKSPACE Directory. + @return current workspace directory **/ public synchronized static String getWorkspacePath() { @@ -248,10 +265,10 @@ public class GlobalData { /** Get the MSA file name with absolute path */ - public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException { + public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException { File msaFile = null; // - // TBD. Do only when package is null. + // TBD. Do only when package is null. // Iterator iter = packageList.iterator(); while (iter.hasNext()) { @@ -263,52 +280,54 @@ public class GlobalData { } } if (msaFile == null){ - throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. "); - } - else { + throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); + } else { return msaFile; } } - public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) { + public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException { // // If package already defined in module // if (moduleId.getPackage() != null) { return moduleId.getPackage(); } - + PackageIdentification packageId = null; Iterator iter = packageList.iterator(); while (iter.hasNext()) { packageId = (PackageIdentification)iter.next(); moduleId.setPackage(packageId); Spd spd = spdTable.get(packageId); - if (spd.getModuleFile(moduleId) != null ) { - break ; + File tempMsaFile = null; + if ((tempMsaFile = spd.getModuleFile(moduleId)) != null ) { + if (tempMsaFile.getParent().equalsIgnoreCase(moduleId.getMsaFile().getParent())) { + break ; + } + tempMsaFile = null; } } if (packageId == null){ - throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. "); - } - else { + throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); + } else { return packageId; } } - + /** Difference between build and parse: ToolChain and Target **/ public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) { return builtModules.contains(moduleId); } - + public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) { builtModules.add(fpdModuleId); } - - public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map doc) { + + public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map doc) throws EdkException{ Map result = new HashMap(); Set keySet = doc.keySet(); Iterator iter = keySet.iterator(); @@ -319,20 +338,22 @@ public class GlobalData { } fpdModuleSA.put(fpdModuleId, result); } - + + public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) { + return fpdModuleSA.containsKey(fpdModuleId); + } + /** - Query overrided module surface area information. If current is Package - or Platform build, also include the information from FPD file. - -

Note that surface area parsing is incremental. That means the method will - only parse the MSA and MBD files if necessary.

+ Query module surface area information. + +

Note that surface area parsing is incremental. That means the method will + only parse the MSA files if necessary.

- @param moduleName the base name of the module - @return the overrided module surface area information - @throws BuildException - MSA or MBD is not valid + @param fpdModuleId Module ID with arch + @return ModuleSA info and MSA info for fpdModuleId + @throws BuildException Can't find MSA **/ - public synchronized static Map getDoc(FpdModuleIdentification fpdModuleId) throws BuildException { + public synchronized static Map getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{ if (parsedModules.containsKey(fpdModuleId)) { return parsedModules.get(fpdModuleId); } @@ -342,12 +363,12 @@ public class GlobalData { // First part: get the MSA files info // doc.putAll(getNativeMsa(moduleId)); - + // // Second part: put build options // doc.put("BuildOptions", fpdBuildOptions); - + // // Third part: get Module info from FPD, such as Library instances, PCDs // @@ -362,22 +383,23 @@ public class GlobalData { return doc; } - public synchronized static Map getDoc(ModuleIdentification moduleId, String arch) throws BuildException { + public synchronized static Map getDoc(ModuleIdentification moduleId, String arch) throws EdkException{ FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch); return getDoc(fpdModuleId); } + /** - Query the native MSA information with module base name. - -

Note that MSA parsing is incremental. That means the method will + Query the native MSA information with module base name. + +

Note that MSA parsing is incremental. That means the method will only to parse the MSA files when never parsed before.

- + @param moduleName the base name of the module @return the native MSA information @throws BuildException MSA file is not valid **/ - public synchronized static Map getNativeMsa(ModuleIdentification moduleId) throws BuildException { + public synchronized static Map getNativeMsa(ModuleIdentification moduleId) throws EdkException { if (nativeMsa.containsKey(moduleId)) { return nativeMsa.get(moduleId); } @@ -386,18 +408,18 @@ public class GlobalData { nativeMsa.put(moduleId, msaMap); return msaMap; } - - public synchronized static Map getNativeMsa(File msaFile) throws BuildException { - if (! msaFile.exists()) { - throw new BuildException("Surface Area file [" + msaFile.getPath() + "] can't found."); + + public synchronized static Map getNativeMsa(File msaFile) throws EdkException { + if (!msaFile.exists()) { + throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!"); } try { ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile); // // Validate File if they accord with XML Schema // - if ( ! doc.validate()){ - throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] is invalid."); + if ( !doc.validate()){ + throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!"); } // // parse MSA file @@ -415,20 +437,24 @@ public class GlobalData { msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true)); msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true)); return msaMap; - } - catch (Exception ex){ - throw new BuildException(ex.getMessage()); + } catch(IOException ex) { + EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch(XmlException ex) { + EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } } - - public static Map getFpdBuildOptions() { - Map map = new HashMap(); - map.put("BuildOptions", fpdBuildOptions); - return map; + + public static Map getFpdBuildOptionsMap() { + return fpdBuildOptionsMap; } - - public static void setFpdBuildOptions(XmlObject fpdBuildOptions) { + + public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException { GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true); + fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions); } public static XmlObject getFpdDynamicPcds() { @@ -439,16 +465,12 @@ public class GlobalData { GlobalData.fpdDynamicPcds = fpdDynamicPcds; } - ////////////////////////////////////////////// - ////////////////////////////////////////////// - public static Set getModules(PackageIdentification packageId){ Spd spd = spdTable.get(packageId); if (spd == null ) { Set dummy = new HashSet(); return dummy; - } - else { + } else { return spd.getModules(); } } @@ -457,8 +479,7 @@ public class GlobalData { * The header file path is relative to workspace dir */ public static String[] getLibraryClassHeaderFiles( - PackageIdentification[] packages, String name) - throws BuildException { + PackageIdentification[] packages, String name) throws EdkException{ if (packages == null) { // throw Exception or not???? return new String[0]; @@ -476,15 +497,15 @@ public class GlobalData { // // If can't find library class declaration in every package // - throw new BuildException("Can not find library class [" + name - + "] declaration in every packages. "); + throw new EdkException("Can not find library class [" + name + + "] declaration in any SPD package!"); } /** * The header file path is relative to workspace dir */ public static String getPackageHeaderFiles(PackageIdentification packages, - String moduleType) throws BuildException { + String moduleType) { if (packages == null) { return new String(""); } @@ -508,8 +529,7 @@ public class GlobalData { /** * return two values: {cName, GuidValue} */ - public static String[] getGuid(List packages, String name) - throws BuildException { + public static String[] getGuid(List packages, String name) { if (packages == null) { // throw Exception or not???? return new String[0]; @@ -533,7 +553,7 @@ public class GlobalData { * return two values: {cName, GuidValue} */ public static String[] getPpiGuid(List packages, - String name) throws BuildException { + String name) { if (packages == null) { return new String[0]; } @@ -549,14 +569,13 @@ public class GlobalData { } } return null; - } /** * return two values: {cName, GuidValue} */ public static String[] getProtocolGuid(List packages, - String name) throws BuildException { + String name) { if (packages == null) { return new String[0]; } @@ -574,8 +593,8 @@ public class GlobalData { return null; } - - public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException { + + public synchronized static PlatformIdentification getPlatformByName(String name) throws EdkException { Iterator iter = platformList.iterator(); while(iter.hasNext()){ PlatformIdentification platformId = (PlatformIdentification)iter.next(); @@ -583,10 +602,10 @@ public class GlobalData { return platformId; } } - throw new BuildException("Can't find platform [" + name + "] in current workspace database. "); + throw new EdkException("Can't find platform [" + name + "] in the current WORKSPACE database!"); } - - public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException { + + public synchronized static PlatformIdentification getPlatform(String filename) throws EdkException { File file = new File(workspaceDir + File.separatorChar + filename); Iterator iter = platformList.iterator(); while(iter.hasNext()){ @@ -595,10 +614,10 @@ public class GlobalData { return platformId; } } - throw new BuildException("Can't find platform file [" + filename + "] in current workspace database. "); + throw new EdkException("Can't find platform file [" + filename + "] in the current WORKSPACE database!"); } - - public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException { + + public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws EdkException { Iterator iter = packageList.iterator(); while(iter.hasNext()){ PackageIdentification packageItem = (PackageIdentification)iter.next(); @@ -608,18 +627,15 @@ public class GlobalData { return packageId; } } - throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. "); + throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); } - - public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException { -// System.out.println("1"); -// System.out.println("##" + moduleId.getGuid()); + + public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws EdkException { PackageIdentification packageId = getPackageForModule(moduleId); -// System.out.println("" + packageId.getGuid()); moduleId.setPackage(packageId); Spd spd = spdTable.get(packageId); if (spd == null) { - throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. "); + throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); } Set modules = spd.getModules(); Iterator iter = modules.iterator(); @@ -632,14 +648,23 @@ public class GlobalData { return moduleId; } } - throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. "); + throw new EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!"); } - + public synchronized static Set getPackageList(){ return packageList; } - ///// remove!! - private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException { + + /** + BUGBUG: It is a walk around method. If do not clone, can't query info with + XPath correctly. + + @param object XmlObject + @param deep flag for deep clone + @return XmlObject after clone + @throws BuildException parse original XmlObject error. + **/ + private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws EdkException { if ( object == null) { return null; } @@ -647,16 +672,18 @@ public class GlobalData { try { result = XmlObject.Factory.parse(object.getDomNode() .cloneNode(deep)); - } catch (Exception ex) { - throw new BuildException(ex.getMessage()); + } catch (XmlException ex) { + EdkException edkException = new EdkException(ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } return result; } - ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory - - public static ToolChainInfo getToolChainInfo() { -// GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo); + /// + /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory + /// + public synchronized static ToolChainInfo getToolChainInfo() { if (toolChainInfo == null) { toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo); if (toolChainPlatformInfo != null) { @@ -664,13 +691,12 @@ public class GlobalData { } toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands()); toolChainInfo.normalize(); - GlobalData.log.info(toolChainInfo + ""); + EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Current build tool chain information summary: "); + EdkLog.log("Init", EdkLog.EDK_ALWAYS, toolChainInfo + ""); } return toolChainInfo; } - - public static void setPlatformToolChainFamilyOption(ToolChainMap map) { platformToolChainFamilyOption = map; } @@ -689,16 +715,29 @@ public class GlobalData { moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption); } - public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException { + public static boolean isCommandSet(String target, String toolchain, String arch) { + String[] commands = getToolChainInfo().getCommands(); + + for (int i = 0; i < commands.length; ++i) { + String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()}); + if (cmdName != null && cmdName.length() != 0) { + return true; + } + } + + return false; + } + + public synchronized static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException { ToolChainKey toolChainKey = new ToolChainKey(commandDescription); - ToolChainMap toolChainConfig = toolsDef.getConfig(); + ToolChainMap toolChainConfig = toolsDef.getConfig(); String setting = null; + setting = toolChainConfig.get(toolChainKey); + if (setting == null) { + setting = ""; + } if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) { - setting = toolChainConfig.get(toolChainKey); - if (setting == null) { - setting = ""; - } return setting; } @@ -709,7 +748,98 @@ public class GlobalData { ToolChainMap option = moduleToolChainOption.get(fpdModuleId); ToolChainKey toolChainFamilyKey = null; - if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) { + if (option != null && option.get(toolChainKey) != null) + { + String str = option.get(toolChainKey); + + Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); + Matcher matcher = myPattern.matcher(str + " "); + while (matcher.find()) + { + setting = setting + " " + str.substring(matcher.start(1), matcher.end(1)); + } + } +// else +// { + if (toolChainFamilyKey == null) + { + toolChainFamilyKey = new ToolChainKey(commandDescription); + toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value); + String family = toolChainConfig.get(toolChainFamilyKey); + toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value); + toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value); + } + + option = moduleToolChainFamilyOption.get(fpdModuleId); + if (option != null && option.get(toolChainFamilyKey) != null) + { + String str = option.get(toolChainFamilyKey); + + Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); + Matcher matcher = myPattern.matcher(str + " "); + while (matcher.find()) + { + setting = setting + " " + str.substring(matcher.start(1), matcher.end(1)); + } + } +// } + + // + // get platform options, if any + // + // tool tag first +// if (platformToolChainOption != null && platformToolChainOption.get(toolChainKey) != null) + if (platformToolChainOption.get(toolChainKey) != null) + { + String str = platformToolChainOption.get(toolChainKey); + + Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); + Matcher matcher = myPattern.matcher(str + " "); + while (matcher.find()) + { + setting = setting + " " + str.substring(matcher.start(1), matcher.end(1)); + } + } +// else +// { + // then tool chain family + if (toolChainFamilyKey == null) + { + toolChainFamilyKey = new ToolChainKey(commandDescription); + toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value); + String family = toolChainConfig.get(toolChainFamilyKey); + toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value); + toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value); + } + +// if (platformToolChainFamilyOption != null && platformToolChainFamilyOption.get(toolChainFamilyKey) != null) + if (platformToolChainFamilyOption.get(toolChainFamilyKey) != null) + { + String str = platformToolChainFamilyOption.get(toolChainFamilyKey); + + setting = setting + " " + str; + +// Pattern myPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); +// Matcher matcher = myPattern.matcher(str + " "); +// while (matcher.find()) +// { +// setting = setting + " " + str.substring(matcher.start(1), matcher.end(1)); +// } + } +// } + + return setting; + +/* + // + // get module specific options, if any + // + // tool tag first + ToolChainMap option = moduleToolChainOption.get(fpdModuleId); + ToolChainKey toolChainFamilyKey = null; + + if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) + { // // then tool chain family // @@ -720,7 +850,7 @@ public class GlobalData { toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value); option = moduleToolChainFamilyOption.get(fpdModuleId); - if (option != null) { + if (option != null) { setting = option.get(toolChainFamilyKey); } } @@ -749,8 +879,9 @@ public class GlobalData { } return setting; +*/ } - + public static void setToolChainEnvInfo(ToolChainInfo envInfo) { toolChainEnvInfo = envInfo; } @@ -768,8 +899,8 @@ public class GlobalData { // // For PCD get tokenSpaceGUid // - public synchronized static String[] getGuidInfoFromCname(String cName){ - String cNameGuid[] = null; + public synchronized static String getGuidInfoFromCname(String cName){ + String cNameGuid = null; String guid = null; Set set = spdTable.keySet(); Iterator iter = set.iterator(); @@ -782,9 +913,7 @@ public class GlobalData { Spd spd = (Spd) spdTable.get(iter.next()); guid = spd.getGuidFromCname(cName); if (guid != null){ - cNameGuid = new String[2]; - cNameGuid[0] = cName; - cNameGuid[1] = guid; + cNameGuid = guid; break; } } @@ -794,33 +923,36 @@ public class GlobalData { // // For PCD // - public synchronized static Map getFpdModuleSaXmlObject( - String xmlObjectName) { + public synchronized static Map + getFpdModuleSaXmlObject(String xmlObjectName) { Set fpdModuleSASet = fpdModuleSA.keySet(); Iterator item = fpdModuleSASet.iterator(); - + Map SAPcdBuildDef = new HashMap(); Map SANode = new HashMap(); FpdModuleIdentification moduleId; while (item.hasNext()) { - + moduleId = (FpdModuleIdentification) item.next(); SANode = fpdModuleSA.get(moduleId); try{ if (SANode.get(xmlObjectName)!= null){ SAPcdBuildDef.put(moduleId, - (XmlObject) SANode - .get(xmlObjectName)); + (XmlObject) SANode.get(xmlObjectName)); } - - } catch (Exception e){ EdkLog.log(EdkLog.EDK_INFO, e.getMessage()); } - } + } return SAPcdBuildDef; } + + public synchronized static Map getFpdPcdBuildDefinitions() { + Map pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition"); + + return pcdBuildDef; + } }