]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainConfig.java
Added code to check that the definitions in target.txt are valid against tools_def.txt
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / toolchain / ToolChainConfig.java
CommitLineData
a29c47e0 1/** @file\r
5f42a4ba 2 ToolChainConfig class.\r
d2059d05 3 \r
4 ToolChainConfig class parse all config files and get tool chain information.\r
5 \r
a29c47e0 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
2279b26c 18import org.tianocore.build.exception.GenBuildException;\r
a29c47e0 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
d2059d05 28 \r
29 ToolChainConfig class parse all config files and get tool chain information.\r
30 \r
5f42a4ba 31 **/\r
a29c47e0 32public class ToolChainConfig {\r
d2059d05 33 //\r
34 // tool chain definitions\r
35 //\r
a29c47e0 36 private ToolChainMap config = null;\r
d2059d05 37 //\r
38 // tool chain information (how many targets, archs, etc.)\r
39 // \r
a29c47e0 40 private ToolChainInfo info = new ToolChainInfo();\r
41\r
42 /**\r
43 Public construct method.\r
d2059d05 44 \r
45 @param toolChainFile File object representing the tool chain configuration file\r
46 **/\r
2279b26c 47 public ToolChainConfig (File toolChainFile) throws GenBuildException {\r
d2059d05 48 config = getToolChainConfig(toolChainFile);\r
49 parseToolChainDefKey(config.keySet());\r
a29c47e0 50 }\r
51\r
52 /**\r
d2059d05 53 Read tool chain definitions from specified file and put them in \r
54 ToolChainMap class.\r
ff225cbb 55\r
d2059d05 56 @param ConfigFile The file containing tool chain definitions\r
57 \r
58 @return ToolChainMap\r
59 **/\r
2279b26c 60 private ToolChainMap getToolChainConfig(File ConfigFile) throws GenBuildException {\r
d2059d05 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
a29c47e0 66 }\r
d2059d05 67\r
68 return map;\r
a29c47e0 69 }\r
70\r
5f42a4ba 71 /**\r
72 Collect target, tool chain tag, arch and command information from key part\r
73 of configuration\r
d2059d05 74 \r
5f42a4ba 75 @param toolChainDefKey The set of keys in tool chain configuration\r
76 **/\r
77 private void parseToolChainDefKey (Set<ToolChainKey> toolChainDefKey) {\r
a29c47e0 78 Iterator it = toolChainDefKey.iterator();\r
79 while (it.hasNext()) {\r
80 ToolChainKey key = (ToolChainKey)it.next();\r
81 String[] keySet = key.getKeySet();\r
d2059d05 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
2b0fe8b4 86 info.normalize();\r
a29c47e0 87 }\r
88 }\r
89\r
5f42a4ba 90 /**\r
d2059d05 91 Return the tool chain configuration information in a Map form \r
92 \r
5f42a4ba 93 @return ToolChainMap Tool chain configurations in a ToolChainMap\r
94 **/\r
a29c47e0 95 public ToolChainMap getConfig() {\r
96 return config;\r
97 }\r
98\r
5f42a4ba 99 /**\r
100 Return the tool chain's target, arch, tag and commands information\r
d2059d05 101 \r
102 @return ToolChainInfo Tool chain information summary\r
5f42a4ba 103 **/\r
a29c47e0 104 public ToolChainInfo getConfigInfo() {\r
105 return info;\r
106 }\r
107\r
5f42a4ba 108 /**\r
109 override toString()\r
d2059d05 110 \r
5f42a4ba 111 @return String The converted configuration string in name=value form\r
112 **/\r
a29c47e0 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
5f42a4ba 120 ts.append(config.get(key) + "\n");\r
a29c47e0 121 }\r
122\r
123 return ts.toString();\r
124 }\r
125}\r
126\r