]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainConfig.java
Added copyright&license header.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / toolchain / ToolChainConfig.java
1 /** @file
2 ToolChainConfig class.
3
4 ToolChainFactory 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.apache.tools.ant.BuildException;
19 import org.tianocore.exception.EdkException;
20 import org.tianocore.build.toolchain.ToolChainKey;
21 import org.tianocore.build.toolchain.ToolChainMap;
22
23 import java.io.File;
24 import java.util.Iterator;
25 import java.util.Set;
26
27
28 /**
29
30 ToolChainFactory 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 public ToolChainConfig () {
47 }
48
49 /**
50 Public construct method.
51
52 @param toolChainFile File object representing the tool chain configuration file
53 **/
54 public ToolChainConfig (File toolChainFile) {
55 try {
56 config = ConfigReader.parseToolChainConfig(toolChainFile);
57 parseToolChainDefKey(config.keySet());
58 }
59 catch (EdkException ex) {
60 throw new BuildException(ex.getMessage());
61 }
62 }
63
64 /**
65 Collect target, tool chain tag, arch and command information from key part
66 of configuration
67
68 @param toolChainDefKey The set of keys in tool chain configuration
69 **/
70 private void parseToolChainDefKey (Set<ToolChainKey> toolChainDefKey) {
71 Iterator it = toolChainDefKey.iterator();
72 while (it.hasNext()) {
73 ToolChainKey key = (ToolChainKey)it.next();
74 String[] keySet = key.getKeySet();
75 info.addTargets(keySet[0]);
76 info.addTagnames(keySet[1]);
77 info.addArchs(keySet[2]);
78 info.addCommands(keySet[1], keySet[3]);
79 }
80 }
81
82 /**
83 Return the tool chain configuration information in a Map form
84
85 @return ToolChainMap Tool chain configurations in a ToolChainMap
86 **/
87 public ToolChainMap getConfig() {
88 return config;
89 }
90
91 /**
92 Return the tool chain's target, arch, tag and commands information
93
94 @return ToolChainInfo
95 **/
96 public ToolChainInfo getConfigInfo() {
97 return info;
98 }
99
100 /**
101 override toString()
102
103 @return String The converted configuration string in name=value form
104 **/
105 public String toString() {
106 StringBuffer ts = new StringBuffer(10240);
107
108 Iterator it = config.keySet().iterator();
109 while (it.hasNext()) {
110 ToolChainKey key = (ToolChainKey)it.next();
111 ts.append(key.toString() + " = ");
112 ts.append(config.get(key) + "\n");
113 }
114
115 return ts.toString();
116 }
117 }
118