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