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