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