b12c43662c5ab884ad628dd279eec9c1507a5bdd
[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 }
87 }
88
89 /**
90 Return the tool chain configuration information in a Map form
91
92 @return ToolChainMap Tool chain configurations in a ToolChainMap
93 **/
94 public ToolChainMap getConfig() {
95 return config;
96 }
97
98 /**
99 Return the tool chain's target, arch, tag and commands information
100
101 @return ToolChainInfo Tool chain information summary
102 **/
103 public ToolChainInfo getConfigInfo() {
104 return info;
105 }
106
107 /**
108 override toString()
109
110 @return String The converted configuration string in name=value form
111 **/
112 public String toString() {
113 StringBuffer ts = new StringBuffer(10240);
114
115 Iterator it = config.keySet().iterator();
116 while (it.hasNext()) {
117 ToolChainKey key = (ToolChainKey)it.next();
118 ts.append(key.toString() + " = ");
119 ts.append(config.get(key) + "\n");
120 }
121
122 return ts.toString();
123 }
124 }
125