X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FJava%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fglobal%2FGlobalData.java;h=96558876e4b0f08a765353381db20db58c31f8ce;hp=ceb19d91db7d78c9400a26f819255e43feec0f1b;hb=05b52e966543caf1ef30ed0513c8b62173db0fa4;hpb=feccee87a78e68d575dbdf44b34ca0cb5a21ea8d diff --git a/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java b/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java index ceb19d91db..96558876e4 100644 --- a/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java +++ b/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java @@ -18,21 +18,19 @@ package org.tianocore.build.global; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashSet; 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.apache.xmlbeans.XmlOptions; import org.tianocore.DbPathAndFilename; import org.tianocore.FrameworkDatabaseDocument; import org.tianocore.ModuleSurfaceAreaDocument; @@ -41,12 +39,15 @@ 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.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.common.definitions.ToolDefinitions; +import org.tianocore.common.exception.EdkException; +import org.tianocore.common.logger.EdkLog; +import org.tianocore.pcd.entity.MemoryDatabaseManager; /** GlobalData provide initializing, instoring, querying and update global data. @@ -132,6 +133,9 @@ public class GlobalData { private static Map moduleToolChainOption = new HashMap(); private static Map moduleToolChainFamilyOption = new HashMap(); + private static Map msaBuildOption = new HashMap(); + private static Map msaFamilyBuildOption = new HashMap(); + /** 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 @@ -171,14 +175,9 @@ public class GlobalData { // Parse Framework Database // File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile); + FrameworkDatabaseDocument db = null; try { - FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile); - // - // validate FrameworkDatabaseFile - // - if (!db.validate()) { - throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!"); - } + db = (FrameworkDatabaseDocument)parseXmlFile(dbFile); // // Get package list // @@ -201,7 +200,18 @@ public class GlobalData { spdTable.put(spd.getPackageId(), spd); } } + } catch(IOException ex) { + EdkException edkException = new EdkException("Parse of WORKSPACE Database file [" + dbFile.getPath() + "] failed!\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch(XmlException ex) { + EdkException edkException = new EdkException("Parse of WORKSPACE Database file [" + dbFile.getPath() + "] failed!\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } + File fpdFile = null; + try { // // Get platform list // @@ -210,17 +220,11 @@ public class GlobalData { Iterator iter = platforms.iterator(); while (iter.hasNext()) { String fileName = iter.next().getStringValue().trim(); - File fpdFile = new File(workspaceDir + File.separatorChar + fileName); + fpdFile = new File(workspaceDir + File.separatorChar + fileName); 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 EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!"); - } + XmlObject fpdDoc = parseXmlFile(fpdFile); // // We can change Map to XmlObject // @@ -242,11 +246,11 @@ public class GlobalData { } } } catch(IOException ex) { - EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage()); + EdkException edkException = new EdkException("Parse of platform definition file [" + fpdFile.getPath() + "] failed!\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 edkException = new EdkException("Parse of platform definition file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage()); edkException.setStackTrace(ex.getStackTrace()); throw edkException; } @@ -414,13 +418,7 @@ public class GlobalData { 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 EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!"); - } + ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)parseXmlFile(msaFile); // // parse MSA file // @@ -436,13 +434,14 @@ public class GlobalData { msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true)); msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true)); msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true)); + msaMap.put("ModuleBuildOptions", cloneXmlObject(msa.getModuleBuildOptions(), true)); return msaMap; } catch(IOException ex) { - EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); + EdkException edkException = new EdkException("Parse of MSA file [" + msaFile.getPath() + "] failed!\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 edkException = new EdkException("Parse of MSA file [" + msaFile.getPath() + "] failed!\n" + ex.getMessage()); edkException.setStackTrace(ex.getStackTrace()); throw edkException; } @@ -691,6 +690,7 @@ public class GlobalData { } toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands()); toolChainInfo.normalize(); + EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Current build tool chain information summary: "); EdkLog.log("Init", EdkLog.EDK_ALWAYS, toolChainInfo + ""); } @@ -714,12 +714,22 @@ public class GlobalData { ToolChainMap toolChainOption) { moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption); } - - public static boolean isCommandSet(String target, String toolchain, String arch) { + + public static void addMsaBuildOption(ModuleIdentification moduleId, + ToolChainMap toolChainOption) { + msaBuildOption.put(moduleId, toolChainOption); + } + + public static void addMsaFamilyBuildOption(ModuleIdentification moduleId, + ToolChainMap toolChainOption) { + msaFamilyBuildOption.put(moduleId, toolChainOption); + } + + public static boolean isCommandSet(String target, String toolchain, String arch) throws EdkException { 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()}); + String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME}); if (cmdName != null && cmdName.length() != 0) { return true; } @@ -728,158 +738,106 @@ public class GlobalData { return false; } + /** + Except FLAGS, all attribute are from TOOLS_DEF file. + + For FLAGS, information from four places, they are: +
+        1. tools_def.txt
+        2. MSA <BuildOptions>/<Options>
+        3. FPD <BuildOptions>/<Options>
+        4. FPD <FrameworkModules>/<ModuleSaBuildOptions>/<Options>
+      
+ + @param commandDescription Key: TARGET, TAGNAME, ARCH, COMMANDTYPE, ATTRIBUTE + @param fpdModuleId Module Identification with Arch + @return The corresponding String + @throws EdkException If build option definition error + **/ public synchronized static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException { ToolChainKey toolChainKey = new ToolChainKey(commandDescription); ToolChainMap toolChainConfig = toolsDef.getConfig(); String setting = null; + // + // Default in tools_def.txt + // setting = toolChainConfig.get(toolChainKey); if (setting == null) { - setting = ""; + setting = ""; } - if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) { + if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS)) { return setting; } + Set flagSet = new LinkedHashSet(); + flagSet.add(setting); + // - // get module specific options, if any - // - // tool tag first - ToolChainMap option = moduleToolChainOption.get(fpdModuleId); - ToolChainKey toolChainFamilyKey = 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)); -// } - } -// } + // Tool's option can be in .fpd and/or .msa file + // + String optionString; + ToolChainMap option = null; + ToolChainKey toolChainFamilyKey = new ToolChainKey(commandDescription); - return setting; + toolChainFamilyKey.setKey(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY, ToolChainElement.ATTRIBUTE.value); + String family = toolChainConfig.get(toolChainFamilyKey); + toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value); + toolChainFamilyKey.setKey(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS, ToolChainElement.ATTRIBUTE.value); -/* // - // get module specific options, if any + // MSA's tool chain family option // - // tool tag first - ToolChainMap option = moduleToolChainOption.get(fpdModuleId); - ToolChainKey toolChainFamilyKey = null; + option = msaFamilyBuildOption.get(fpdModuleId.getModule()); + if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) { + flagSet.add(optionString); + } - if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) - { - // - // then tool chain family - // - 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) { - setting = option.get(toolChainFamilyKey); - } + // + // MSA's tool chain option + // + option = msaBuildOption.get(fpdModuleId.getModule()); + if (option != null && (optionString = option.get(toolChainKey)) != null) { + flagSet.add(optionString); } - + // - // get platform options, if any + // Platform's tool chain family option // - if (setting == null) { - // tool tag first - if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) { - // 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); - } + optionString = platformToolChainFamilyOption.get(toolChainFamilyKey); + if (optionString != null) { + flagSet.add(optionString); + } - setting = platformToolChainFamilyOption.get(toolChainFamilyKey); - } + // + // Platform's tool chain tag option + // + optionString = platformToolChainOption.get(toolChainKey); + if (optionString != null) { + flagSet.add(optionString); } - if (setting == null) { - setting = ""; + // + // Module's tool chain family option + // + option = moduleToolChainFamilyOption.get(fpdModuleId); + if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) { + flagSet.add(optionString); } + // + // Module's tool chain tag option + // + option = moduleToolChainOption.get(fpdModuleId); + if (option != null && (optionString = option.get(toolChainKey)) != null) { + flagSet.add(optionString); + } + + setting = ""; + for(Iterator iter = flagSet.iterator(); iter.hasNext();) { + setting += iter.next() +" "; + } return setting; -*/ } public static void setToolChainEnvInfo(ToolChainInfo envInfo) { @@ -954,5 +912,29 @@ public class GlobalData { return pcdBuildDef; } + + public static XmlObject parseXmlFile(File xmlFile) throws IOException, XmlException { + Collection errors = new ArrayList(); + XmlOptions opt = new XmlOptions(); + + opt.setLoadLineNumbers(); + opt.setLoadMessageDigest(); + opt.setErrorListener(errors); + + XmlObject doc = XmlObject.Factory.parse(xmlFile, opt); + // + // Validate File if they accord with XML Schema + // + if (!doc.validate(opt)){ + StringBuilder errorMessage = new StringBuilder(1024); + for (Iterator it = errors.iterator(); it.hasNext(); ) { + errorMessage.append(it.next()); + errorMessage.append("\n"); + } + throw new XmlException(errorMessage.toString()); + } + + return doc; + } }