--- /dev/null
+/** @file\r
+ ToolChainConfig class.\r
+ \r
+ ToolChainConfig class parse all config files and get tool chain information.\r
+ \r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+package org.tianocore.build.toolchain;\r
+\r
+import org.tianocore.build.exception.GenBuildException;\r
+import org.tianocore.build.toolchain.ToolChainKey;\r
+import org.tianocore.build.toolchain.ToolChainMap;\r
+\r
+import java.io.File;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
+\r
+\r
+/**\r
+ \r
+ ToolChainConfig class parse all config files and get tool chain information.\r
+ \r
+ **/\r
+public class ToolChainConfig {\r
+ //\r
+ // tool chain definitions\r
+ //\r
+ private ToolChainMap config = null;\r
+ //\r
+ // tool chain information (how many targets, archs, etc.)\r
+ // \r
+ private ToolChainInfo info = new ToolChainInfo();\r
+\r
+ /**\r
+ Public construct method.\r
+ \r
+ @param toolChainFile File object representing the tool chain configuration file\r
+ **/\r
+ public ToolChainConfig (File toolChainFile) throws GenBuildException {\r
+ config = getToolChainConfig(toolChainFile);\r
+ parseToolChainDefKey(config.keySet());\r
+ }\r
+\r
+ /**\r
+ Read tool chain definitions from specified file and put them in \r
+ ToolChainMap class.\r
+\r
+ @param ConfigFile The file containing tool chain definitions\r
+ \r
+ @return ToolChainMap\r
+ **/\r
+ private ToolChainMap getToolChainConfig(File ConfigFile) throws GenBuildException {\r
+ ToolChainMap map = new ToolChainMap();\r
+ String[][] toolChainDef = ConfigReader.parse(ConfigFile);\r
+ \r
+ for (int i = 0; i < toolChainDef[0].length; ++i) {\r
+ map.put(toolChainDef[0][i], toolChainDef[1][i]);\r
+ }\r
+\r
+ return map;\r
+ }\r
+\r
+ /**\r
+ Collect target, tool chain tag, arch and command information from key part\r
+ of configuration\r
+ \r
+ @param toolChainDefKey The set of keys in tool chain configuration\r
+ **/\r
+ private void parseToolChainDefKey (Set<ToolChainKey> toolChainDefKey) {\r
+ Iterator it = toolChainDefKey.iterator();\r
+ while (it.hasNext()) {\r
+ ToolChainKey key = (ToolChainKey)it.next();\r
+ String[] keySet = key.getKeySet();\r
+ info.addTargets(keySet[ToolChainElement.TARGET.value]);\r
+ info.addTagnames(keySet[ToolChainElement.TOOLCHAIN.value]);\r
+ info.addArchs(keySet[ToolChainElement.ARCH.value]);\r
+ info.addCommands(keySet[ToolChainElement.TOOLCODE.value]);\r
+ }\r
+ }\r
+\r
+ /**\r
+ Return the tool chain configuration information in a Map form \r
+ \r
+ @return ToolChainMap Tool chain configurations in a ToolChainMap\r
+ **/\r
+ public ToolChainMap getConfig() {\r
+ return config;\r
+ }\r
+\r
+ /**\r
+ Return the tool chain's target, arch, tag and commands information\r
+ \r
+ @return ToolChainInfo Tool chain information summary\r
+ **/\r
+ public ToolChainInfo getConfigInfo() {\r
+ return info;\r
+ }\r
+\r
+ /**\r
+ override toString()\r
+ \r
+ @return String The converted configuration string in name=value form\r
+ **/\r
+ public String toString() {\r
+ StringBuffer ts = new StringBuffer(10240);\r
+\r
+ Iterator it = config.keySet().iterator();\r
+ while (it.hasNext()) {\r
+ ToolChainKey key = (ToolChainKey)it.next();\r
+ ts.append(key.toString() + " = ");\r
+ ts.append(config.get(key) + "\n");\r
+ }\r
+\r
+ return ts.toString();\r
+ }\r
+}\r
+\r