]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/toolchain/ToolChainInfo.java
Added comments and polished the code.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / toolchain / ToolChainInfo.java
1 /** @file
2 ToolChainInfo class
3
4 This file is to define ToolChainInfo class.
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.util.HashMap;
19 import java.util.LinkedHashSet;
20 import java.util.Map;
21 import java.util.Set;
22
23 /**
24 ToolChainInfo collects valid build targets, tool chain tag, ARCHs and commands
25 information for real build use.
26 **/
27 public class ToolChainInfo {
28 //
29 // build target set
30 //
31 private Set<String> targets = new LinkedHashSet<String>();
32 //
33 // tool chain tag name set
34 //
35 private Set<String> tagnames = new LinkedHashSet<String>();
36 //
37 // build archs set
38 //
39 private Set<String> archs = new LinkedHashSet<String>();
40 //
41 // build commands set
42 //
43 private Set<String> commands = new LinkedHashSet<String>();
44
45 /**
46 Add a list of targets in the form of string separated by space
47
48 @param targetList target list string
49 **/
50 public void addTargets(String targetList) {
51 //
52 // targetList some targets separated by space " "
53 //
54 if (targetList == null || targetList.length() == 0) {
55 targets.add("*");
56 } else {
57 addTargets(targetList.split(" "));
58 }
59 }
60
61 /**
62 Add a list of targets in the form of string array
63
64 @param targetArray target string array
65 **/
66 public void addTargets(String[] targetArray) {
67 if (targetArray != null ) {
68 for (int i = 0; i < targetArray.length; i++) {
69 targets.add(targetArray[i]);
70 }
71 }
72 }
73
74 /**
75 Add a list of target in the form of set
76
77 @param targetSet target string set
78 **/
79 public void addTargets(Set<String> targetSet) {
80 if (targetSet != null) {
81 targets.addAll(targetSet);
82 }
83 }
84
85 /**
86 Add a list of tool chain tag name in the form of string separated by space
87
88 @param tagnameList Tool chain tag name list string
89 **/
90 public void addTagnames(String tagnameList) {
91 //
92 // tagnameList some tagnames separated by space " "
93 //
94 if (tagnameList == null || tagnameList.length() == 0) {
95 tagnames.add("*");
96 } else {
97 addTagnames(tagnameList.split(" "));
98 }
99 }
100
101 /**
102 Add a list of tool chain tag name in the form of string array
103
104 @param tagnameArray Tool chain tag names array
105 **/
106 public void addTagnames(String[] tagnameArray) {
107 if (tagnameArray != null ) {
108 for (int i = 0; i < tagnameArray.length; i++) {
109 tagnames.add(tagnameArray[i]);
110 }
111 }
112 }
113
114 /**
115 Add a list of tool chain tag name in the form of Set
116
117 @param tagnameSet Tool chain tag names set
118 **/
119 public void addTagnames(Set<String> tagnameSet) {
120 if (tagnameSet != null) {
121 tagnames.addAll(tagnameSet);
122 }
123 }
124
125 /**
126 Add a list of ARCH in the form of string
127
128 @param archList ARCH string
129 **/
130 public void addArchs(String archList) {
131 //
132 // archList some archs separated by space " "
133 //
134 if (archList == null || archList.length() == 0) {
135 archs.add("*");
136 } else {
137 addArchs(archList.split(" "));
138 }
139 }
140
141 /**
142 Add a list of ARCH in the form of string array
143
144 @param archArray ARCH array
145 **/
146 public void addArchs(String[] archArray) {
147 if (archArray != null ) {
148 for (int i = 0; i < archArray.length; i++) {
149 archs.add(archArray[i]);
150 }
151 }
152 }
153
154 /**
155 Add a list of ARCH in the form of set
156
157 @param archSet ARCH set
158 **/
159 public void addArchs(Set<String> archSet) {
160 if (archSet != null) {
161 archs.addAll(archSet);
162 }
163 }
164
165 /**
166 Add a list of command in the form of string
167
168 @param commandList Command list string
169 **/
170 public void addCommands(String commandList) {
171 //
172 // archList some archs separated by space " "
173 //
174 if (commandList == null || commandList.length() == 0) {
175 commands.add("*");
176 } else {
177 addCommands(commandList.split(" "));
178 }
179 }
180
181 /**
182 Add a list of ARCH in the form of array
183
184 @param commandArray Commands array
185 **/
186 public void addCommands(String[] commandArray) {
187 if (commandArray != null ) {
188 for (int i = 0; i < commandArray.length; i++) {
189 commands.add(commandArray[i]);
190 }
191 }
192 }
193
194 /**
195 Add a list of ARCH in the form of set
196
197 @param commandSet Commands set
198 **/
199 public void addCommands(Set<String> commandSet) {
200 if (commandSet != null) {
201 commands.addAll(commandSet);
202 }
203 }
204
205 /**
206 Make a union operation on this ToolChainInfo and the given one.
207
208 @param info Another ToolChainInfo object to merge with
209
210 @return ToolChainInfo Merged ToolChainInfo object
211 **/
212 public ToolChainInfo union(ToolChainInfo info) {
213 ToolChainInfo result = new ToolChainInfo();
214 result.addTargets(union(this.targets, info.targets));
215 result.addTagnames(union(this.tagnames, info.tagnames));
216 result.addArchs(union(this.archs, info.archs));
217 return result;
218 }
219
220 /**
221 Make a intersection operation on this ToolChainInfo and the given one
222
223 @param info Another ToolChainInfo object to intersect with
224
225 @return ToolChainInfo Intersected ToolChainInfo object
226 **/
227 public ToolChainInfo intersection(ToolChainInfo info) {
228 ToolChainInfo result = new ToolChainInfo();
229 result.addTargets(intersection(this.targets, info.targets));
230 result.addTagnames(intersection(this.tagnames, info.tagnames));
231 result.addArchs(intersection(this.archs, info.archs));
232 return result;
233 }
234
235 /**
236 Make a union operation on two Sets
237
238 @param set1 One Set
239 @param set2 Another Set
240
241 @return Set<String> Merged Set object
242 **/
243 private Set<String> union(Set<String> set1, Set<String> set2) {
244 Set<String> result = new LinkedHashSet<String>();
245 result.addAll(set1);
246 result.addAll(set2);
247 result.remove("*");
248 return result;
249 }
250
251 /**
252 Make a intersection operation on two Sets with the consideration of wildcard.
253
254 @param set1 One Set
255 @param set2 Another Set
256
257 @return Set<String> The intersected Set object
258 **/
259 private Set<String> intersection(Set<String> set1, Set<String> set2) {
260 Set<String> result = new LinkedHashSet<String>();
261 boolean set1HasWildcard = set1.contains("*");
262 boolean set2HasWildcard = set2.contains("*");
263
264 if (set1HasWildcard && set2HasWildcard) {
265 //
266 // Both Sets have wildcard, the result will have all elements in them
267 //
268 result.addAll(set1);
269 result.addAll(set2);
270 } else if (set1HasWildcard) {
271 //
272 // Only set1 has wildcard, then result will have only set2 elements.
273 //
274 result.addAll(set2);
275 } else if (set2HasWildcard) {
276 //
277 // Only set2 has wildcard, then result will have only set1 elements.
278 //
279 result.addAll(set1);
280 } else {
281 //
282 // No wildcard in both Sets, the result will have the elements in both Sets.
283 //
284 result.addAll(set1);
285 result.retainAll(set2);
286 }
287
288 return result;
289 }
290
291 /**
292 Get target array.
293
294 @return String[]
295 **/
296 public String[] getTargets() {
297 return (String[])targets.toArray(new String[targets.size()]);
298 }
299
300 /**
301 Get tool chain tag name array.
302
303 @return String[]
304 **/
305 public String[] getTagnames() {
306 return (String[])tagnames.toArray(new String[tagnames.size()]);
307 }
308
309 /**
310 Get ARCH array.
311
312 @return String[]
313 **/
314 public String[] getArchs() {
315 return (String[])archs.toArray(new String[archs.size()]);
316 }
317
318 /**
319 Get command name array.
320
321 @return String[]
322 **/
323 public String[] getCommands() {
324 return (String[])commands.toArray(new String[commands.size()]);
325 }
326
327 /**
328 Override the Object's toString().
329
330 @return String
331 **/
332 public String toString() {
333 return targets + "\n" + tagnames + "\n" + archs + "\n" + commands;
334 }
335
336 /**
337 Remove the wildcard element in the tool chain information because they
338 are useless when retrieved.
339 **/
340 public void normalize() {
341 targets.remove("*");
342 tagnames.remove("*");
343 archs.remove("*");
344 commands.remove("*");
345 }
346 }