]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainConfig.java
Fix the showstopper track 435 that console can not be switched into text mode when...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / toolchain / ToolChainConfig.java
... / ...
CommitLineData
1/** @file\r
2 ToolChainConfig class.\r
3 \r
4 ToolChainConfig class parse all config files and get tool chain information.\r
5 \r
6Copyright (c) 2006, Intel Corporation\r
7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16package org.tianocore.build.toolchain;\r
17\r
18import org.tianocore.build.exception.GenBuildException;\r
19import org.tianocore.build.toolchain.ToolChainKey;\r
20import org.tianocore.build.toolchain.ToolChainMap;\r
21\r
22import java.io.File;\r
23import java.util.Iterator;\r
24import java.util.Set;\r
25\r
26\r
27/**\r
28 \r
29 ToolChainConfig class parse all config files and get tool chain information.\r
30 \r
31 **/\r
32public class ToolChainConfig {\r
33 //\r
34 // tool chain definitions\r
35 //\r
36 private ToolChainMap config = null;\r
37 //\r
38 // tool chain information (how many targets, archs, etc.)\r
39 // \r
40 private ToolChainInfo info = new ToolChainInfo();\r
41\r
42 /**\r
43 Public construct method.\r
44 \r
45 @param toolChainFile File object representing the tool chain configuration file\r
46 **/\r
47 public ToolChainConfig (File toolChainFile) throws GenBuildException {\r
48 config = getToolChainConfig(toolChainFile);\r
49 parseToolChainDefKey(config.keySet());\r
50 }\r
51\r
52 /**\r
53 Read tool chain definitions from specified file and put them in \r
54 ToolChainMap class.\r
55\r
56 @param ConfigFile The file containing tool chain definitions\r
57 \r
58 @return ToolChainMap\r
59 **/\r
60 private ToolChainMap getToolChainConfig(File ConfigFile) throws GenBuildException {\r
61 ToolChainMap map = new ToolChainMap();\r
62 String[][] toolChainDef = ConfigReader.parse(ConfigFile);\r
63 \r
64 for (int i = 0; i < toolChainDef[0].length; ++i) {\r
65 map.put(toolChainDef[0][i], toolChainDef[1][i]);\r
66 }\r
67\r
68 return map;\r
69 }\r
70\r
71 /**\r
72 Collect target, tool chain tag, arch and command information from key part\r
73 of configuration\r
74 \r
75 @param toolChainDefKey The set of keys in tool chain configuration\r
76 **/\r
77 private void parseToolChainDefKey (Set<ToolChainKey> toolChainDefKey) {\r
78 Iterator it = toolChainDefKey.iterator();\r
79 while (it.hasNext()) {\r
80 ToolChainKey key = (ToolChainKey)it.next();\r
81 String[] keySet = key.getKeySet();\r
82 info.addTargets(keySet[ToolChainElement.TARGET.value]);\r
83 info.addTagnames(keySet[ToolChainElement.TOOLCHAIN.value]);\r
84 info.addArchs(keySet[ToolChainElement.ARCH.value]);\r
85 info.addCommands(keySet[ToolChainElement.TOOLCODE.value]);\r
86 info.normalize();\r
87 }\r
88 }\r
89\r
90 /**\r
91 Return the tool chain configuration information in a Map form \r
92 \r
93 @return ToolChainMap Tool chain configurations in a ToolChainMap\r
94 **/\r
95 public ToolChainMap getConfig() {\r
96 return config;\r
97 }\r
98\r
99 /**\r
100 Return the tool chain's target, arch, tag and commands information\r
101 \r
102 @return ToolChainInfo Tool chain information summary\r
103 **/\r
104 public ToolChainInfo getConfigInfo() {\r
105 return info;\r
106 }\r
107\r
108 /**\r
109 override toString()\r
110 \r
111 @return String The converted configuration string in name=value form\r
112 **/\r
113 public String toString() {\r
114 StringBuffer ts = new StringBuffer(10240);\r
115\r
116 Iterator it = config.keySet().iterator();\r
117 while (it.hasNext()) {\r
118 ToolChainKey key = (ToolChainKey)it.next();\r
119 ts.append(key.toString() + " = ");\r
120 ts.append(config.get(key) + "\n");\r
121 }\r
122\r
123 return ts.toString();\r
124 }\r
125}\r
126\r