From 8c84e1b1aca1f2eac14ba331f3fec892210a70c4 Mon Sep 17 00:00:00 2001 From: jwang36 Date: Fri, 13 Oct 2006 09:21:14 +0000 Subject: a) Cleaned tools_def.template b) Changed overriding priority of tool chain definition. Now right non-* has higher priority. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1744 6f19259b-4bc3-4df7-8a09-765794883524 --- .../org/tianocore/build/global/GlobalData.java | 167 ++++++--------------- .../tianocore/build/toolchain/ToolChainMap.java | 128 ++++++++-------- 2 files changed, 106 insertions(+), 189 deletions(-) (limited to 'Tools/Java') 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..9138036c78 100644 --- a/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java +++ b/Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java @@ -132,6 +132,7 @@ public class GlobalData { private static Map moduleToolChainOption = new HashMap(); private static Map moduleToolChainFamilyOption = new HashMap(); + private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+"); /** 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 @@ -733,153 +734,71 @@ public class GlobalData { 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())) { return 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(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); -/* // - // get module specific options, if any + // Platform's tool chain family option // - // 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 - // - 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); - } + optionString = platformToolChainFamilyOption.get(toolChainFamilyKey); + if (optionString != null) { + setting += (" " + optionString); } // - // get platform options, if any + // Platform's tool chain tag 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 = platformToolChainOption.get(toolChainKey); + if (optionString != null) { + Matcher matcher = flagPattern.matcher(optionString + " "); + while (matcher.find()) { + setting += (" " + optionString.substring(matcher.start(1), matcher.end(1))); + } + } - setting = platformToolChainFamilyOption.get(toolChainFamilyKey); + // + // Module's tool chain family option + // + 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))); } } - if (setting == null) { - setting = ""; + // + // Module's tool chain tag option + // + 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))); + } } return setting; -*/ } public static void setToolChainEnvInfo(ToolChainInfo envInfo) { diff --git a/Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java b/Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java index b9d24eb0b9..f3f07797bc 100644 --- a/Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java +++ b/Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java @@ -29,7 +29,7 @@ public class ToolChainMap { // // From which part of key can be used to match "*" // - private int matchLevel = ToolChainKey.keyLength - 2; + private int matchLevel = ToolChainKey.keyLength - 1; // // A Map object in which tool chain configuration information will be stored @@ -211,98 +211,96 @@ public class ToolChainMap { /// /// In the current tool chain definition format (in name/value pair), /// there're five parts in the "name". The last part of the "name" must - /// not be "wildcard". So we should start combining "*" from the fourth part. + /// not be "wildcard". We should start combining "*" from left to right. /// We'll try all the possible combinations until the value can be fetched. /// /// The following code implements the logic which will try to use, for example, /// following key parts combinations sequentially to get the value. /// /// TARGET_TOOLCHAIN_ARCH_TOOLCODE_ATTRIBUTE - /// TARGET_TOOLCHAIN_ARCH_*_ATTRIBUTE - /// TARGET_TOOLCHAIN_*_TOOLCODE_ATTRIBUTE - /// TARGET_TOOLCHAIN_*_*_ATTRIBUTE - /// TARGET_*_ARCH_TOOLCODE_ATTRIBUTE - /// TARGET_*_ARCH_*_ATTRIBUTE - /// TARGET_*_*_TOOLCODE_ATTRIBUTE - /// TARGET_*_*_*_ATTRIBUTE - /// *_TOOLCHAIN_ARCH_TOOLCODE_ATTRIBUTE - /// *_TOOLCHAIN_ARCH_*_ATTRIBUTE - /// *_TOOLCHAIN_*_TOOLCODE_ATTRIBUTE - /// *_TOOLCHAIN_*_*_ATTRIBUTE - /// *_*_ARCH_TOOLCODE_ATTRIBUTE - /// *_*_ARCH_*_ATTRIBUTE - /// *_*_*_TOOLCODE_ATTRIBUTE - /// *_*_*_*_ATTRIBUTE + /// ******_TOOLCHAIN_ARCH_TOOLCODE_ATTRIBUTE + /// TARGET_*********_ARCH_TOOLCODE_ATTRIBUTE + /// ******_*********_ARCH_TOOLCODE_ATTRIBUTE + /// TARGET_TOOLCHAIN_****_TOOLCODE_ATTRIBUTE + /// ******_TOOLCHAIN_****_TOOLCODE_ATTRIBUTE + /// TARGET_*********_****_TOOLCODE_ATTRIBUTE + /// ******_*********_****_TOOLCODE_ATTRIBUTE + /// TARGET_TOOLCHAIN_ARCH_********_ATTRIBUTE + /// ******_TOOLCHAIN_ARCH_********_ATTRIBUTE + /// TARGET_*********_ARCH_********_ATTRIBUTE + /// ******_*********_ARCH_********_ATTRIBUTE + /// TARGET_TOOLCHAIN_****_********_ATTRIBUTE + /// ******_TOOLCHAIN_****_********_ATTRIBUTE + /// TARGET_*********_****_********_ATTRIBUTE + /// ******_*********_****_********_ATTRIBUTE /// // - // level is used to control if all parts of "name" have been "wildcarded" + // The wildcard "*" appears regularly (2^n). "*" in TARGET appears 2^0 + // times at every 2^0 TARGET, "*" in TOOLCHAIN appears 2^1 times at + // every 2^1 TOOLCHAIN, and "*" in TOOLCODE appears 2^3 times at every + // 2^3 TOOLCODE. We're going to use this to form all the combinations of key. // - int level = matchLevel; - while (level >= 0) { + int[] combinations = new int[matchLevel]; + for (int i = 0; i < matchLevel; ++i) { // - // tmplevel is used to control if all parts of "name" between first - // "*" and fourth name part have been "wildcarded". + // initialize the array with 2^n // - int tmpLevel = level; - while (tmpLevel >= level) { - String[] tmpKeySet = tmpKey.getKeySet(); + combinations[i] = 1 << (i + 1); + } + + // + // when last part goes down to zero, we tried all combinations of key + // + int lastIndex = matchLevel - 1; + while (combinations[lastIndex] > 0) { + // + // form the key which has "*" in it + // + for (int i = 0; i < matchLevel; ++i) { + // + // start again if not finished + // + if (combinations[i] == 0) { + combinations[i] = 1 << (i + 1); + } + + // + // half of 2^n is "*", the rest is non-* + // try { - if (!tmpKeySet[tmpLevel].equals("*")) { - // - // If "tmplevel" part is not "*", set it to "*". - // For example, at first loop, the key will become - // TARGET_TOOLCHAIN_ARCH_*_ATTRIBUTE, and at next loop, - // become TARGET_TOOLCHAIN_*_ARCH_ATTRIBUTE - // - tmpKey.setKey("*", tmpLevel); - // - // We'll try all possible combinations between current - // part and the fourth part. - // - tmpLevel = matchLevel; + if (combinations[i] > (1 << i)) { + tmpKey.setKey(keySet[i], i); } else { - // - // Restore original value of key if "*" at "tmplevel" - // part of "name" has been checked - // - tmpKey.setKey(keySet[tmpLevel], tmpLevel); - // - // Try "*" at part left to "tmplevel" part of "name" - // - --tmpLevel; - continue; + tmpKey.setKey("*", i); } } catch (Exception e) { return null; } + combinations[i] -= 1; + } + + // + // Try get the value from the map + // + result = map.get(tmpKey); + if (result != null) { // - // Try get the value from the map + // The map actually has no exact key as the given "key", + // putting it back into map can speed up the get() next time // - result = map.get(tmpKey); - if (result != null) { - // - // The map actually has no exact key as the given "key", - // putting it back into map can speed up the get() next time - // - map.put(key, result); - return result; - } + map.put(key, result); + return result; } - /// - /// If all possible combinations of "wildcard" between "level" and - /// the fourth part of "name" have been tried, try the left part - /// - --level; } // // The map actually has no exact key as the given "key", putting it back // into map can speed up the get() next time even we got nothing. // - map.put(key, result); - return result; + map.put(key, null); + return null; } /** -- cgit v1.2.3