]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainConfig.java
Added support for macro/property in tools_def.txt. Now you can define a property...
[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
a29c47e0 18import java.io.File;\r
19import java.util.Iterator;\r
20import java.util.Set;\r
21\r
2251a360 22import org.apache.tools.ant.Project;\r
23import org.tianocore.build.exception.GenBuildException;\r
24import org.tianocore.build.toolchain.ToolChainKey;\r
25import org.tianocore.build.toolchain.ToolChainMap;\r
26\r
a29c47e0 27\r
28/**\r
d2059d05 29 \r
30 ToolChainConfig class parse all config files and get tool chain information.\r
31 \r
5f42a4ba 32 **/\r
a29c47e0 33public class ToolChainConfig {\r
d2059d05 34 //\r
35 // tool chain definitions\r
36 //\r
a29c47e0 37 private ToolChainMap config = null;\r
d2059d05 38 //\r
39 // tool chain information (how many targets, archs, etc.)\r
40 // \r
a29c47e0 41 private ToolChainInfo info = new ToolChainInfo();\r
42\r
43 /**\r
44 Public construct method.\r
d2059d05 45 \r
46 @param toolChainFile File object representing the tool chain configuration file\r
47 **/\r
2251a360 48 public ToolChainConfig (Project prj, File toolChainFile) throws GenBuildException {\r
49 config = getToolChainConfig(prj, toolChainFile);\r
d2059d05 50 parseToolChainDefKey(config.keySet());\r
a29c47e0 51 }\r
52\r
53 /**\r
d2059d05 54 Read tool chain definitions from specified file and put them in \r
55 ToolChainMap class.\r
ff225cbb 56\r
d2059d05 57 @param ConfigFile The file containing tool chain definitions\r
58 \r
59 @return ToolChainMap\r
60 **/\r
2251a360 61 private ToolChainMap getToolChainConfig(Project prj, File ConfigFile) throws GenBuildException {\r
d2059d05 62 ToolChainMap map = new ToolChainMap();\r
2251a360 63 String[][] toolChainDef = ConfigReader.parse(prj, ConfigFile);\r
d2059d05 64 \r
65 for (int i = 0; i < toolChainDef[0].length; ++i) {\r
66 map.put(toolChainDef[0][i], toolChainDef[1][i]);\r
a29c47e0 67 }\r
d2059d05 68\r
69 return map;\r
a29c47e0 70 }\r
71\r
5f42a4ba 72 /**\r
73 Collect target, tool chain tag, arch and command information from key part\r
74 of configuration\r
d2059d05 75 \r
5f42a4ba 76 @param toolChainDefKey The set of keys in tool chain configuration\r
77 **/\r
78 private void parseToolChainDefKey (Set<ToolChainKey> toolChainDefKey) {\r
a29c47e0 79 Iterator it = toolChainDefKey.iterator();\r
80 while (it.hasNext()) {\r
81 ToolChainKey key = (ToolChainKey)it.next();\r
82 String[] keySet = key.getKeySet();\r
d2059d05 83 info.addTargets(keySet[ToolChainElement.TARGET.value]);\r
84 info.addTagnames(keySet[ToolChainElement.TOOLCHAIN.value]);\r
85 info.addArchs(keySet[ToolChainElement.ARCH.value]);\r
86 info.addCommands(keySet[ToolChainElement.TOOLCODE.value]);\r
2b0fe8b4 87 info.normalize();\r
a29c47e0 88 }\r
89 }\r
90\r
5f42a4ba 91 /**\r
d2059d05 92 Return the tool chain configuration information in a Map form \r
93 \r
5f42a4ba 94 @return ToolChainMap Tool chain configurations in a ToolChainMap\r
95 **/\r
a29c47e0 96 public ToolChainMap getConfig() {\r
97 return config;\r
98 }\r
99\r
5f42a4ba 100 /**\r
101 Return the tool chain's target, arch, tag and commands information\r
d2059d05 102 \r
103 @return ToolChainInfo Tool chain information summary\r
5f42a4ba 104 **/\r
a29c47e0 105 public ToolChainInfo getConfigInfo() {\r
106 return info;\r
107 }\r
108\r
5f42a4ba 109 /**\r
110 override toString()\r
d2059d05 111 \r
5f42a4ba 112 @return String The converted configuration string in name=value form\r
113 **/\r
a29c47e0 114 public String toString() {\r
115 StringBuffer ts = new StringBuffer(10240);\r
116\r
117 Iterator it = config.keySet().iterator();\r
118 while (it.hasNext()) {\r
119 ToolChainKey key = (ToolChainKey)it.next();\r
120 ts.append(key.toString() + " = ");\r
5f42a4ba 121 ts.append(config.get(key) + "\n");\r
a29c47e0 122 }\r
123\r
124 return ts.toString();\r
125 }\r
126}\r
127\r