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=310381bc14b527f16b8c7bd871dc7269dd1803e9;hb=05b52e966543caf1ef30ed0513c8b62173db0fa4;hpb=b0a8056223d0fdb3cbd7abf93f872c7876354de7 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 310381bc14..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,22 +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.definitions.ToolDefinitions; -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; @@ -47,6 +44,10 @@ 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,7 +133,9 @@ public class GlobalData { private static Map moduleToolChainOption = new HashMap(); private static Map moduleToolChainFamilyOption = new HashMap(); - private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); + 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 @@ -172,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 // @@ -202,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 // @@ -211,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 // @@ -243,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; } @@ -415,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 // @@ -437,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; } @@ -692,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 + ""); } @@ -715,8 +714,18 @@ 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) { @@ -729,6 +738,22 @@ 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(); @@ -745,8 +770,11 @@ public class GlobalData { return setting; } + Set flagSet = new LinkedHashSet(); + flagSet.add(setting); + // - // tool's option can be in .fpd and/or .msa file + // Tool's option can be in .fpd and/or .msa file // String optionString; ToolChainMap option = null; @@ -757,12 +785,28 @@ public class GlobalData { toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value); toolChainFamilyKey.setKey(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS, ToolChainElement.ATTRIBUTE.value); + // + // MSA's tool chain family option + // + option = msaFamilyBuildOption.get(fpdModuleId.getModule()); + if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) { + flagSet.add(optionString); + } + + // + // MSA's tool chain option + // + option = msaBuildOption.get(fpdModuleId.getModule()); + if (option != null && (optionString = option.get(toolChainKey)) != null) { + flagSet.add(optionString); + } + // // Platform's tool chain family option // optionString = platformToolChainFamilyOption.get(toolChainFamilyKey); if (optionString != null) { - setting += (" " + optionString); + flagSet.add(optionString); } // @@ -770,10 +814,7 @@ public class GlobalData { // optionString = platformToolChainOption.get(toolChainKey); if (optionString != null) { - Matcher matcher = flagPattern.matcher(optionString + " "); - while (matcher.find()) { - setting += (" " + optionString.substring(matcher.start(1), matcher.end(1))); - } + flagSet.add(optionString); } // @@ -781,10 +822,7 @@ public class GlobalData { // option = moduleToolChainFamilyOption.get(fpdModuleId); if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) { - Matcher matcher = flagPattern.matcher(optionString + " "); - while (matcher.find()) { - setting += (" " + optionString.substring(matcher.start(1), matcher.end(1))); - } + flagSet.add(optionString); } // @@ -792,12 +830,13 @@ public class GlobalData { // option = moduleToolChainOption.get(fpdModuleId); if (option != null && (optionString = option.get(toolChainKey)) != null) { - Matcher matcher = flagPattern.matcher(optionString + " "); - while (matcher.find()) { - setting += (" " + optionString.substring(matcher.start(1), matcher.end(1))); - } + flagSet.add(optionString); + } + + setting = ""; + for(Iterator iter = flagSet.iterator(); iter.hasNext();) { + setting += iter.next() +" "; } - return setting; } @@ -873,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; + } }