4 This file is to define ToolChainInfo class.
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
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.
16 package org
.tianocore
.build
.toolchain
;
18 import java
.util
.LinkedHashSet
;
22 ToolChainInfo collects valid build targets, tool chain tag, ARCHs and commands
23 information for real build use.
25 public class ToolChainInfo
{
29 private Set
<String
> targets
= new LinkedHashSet
<String
>();
31 // tool chain tag name set
33 private Set
<String
> tagnames
= new LinkedHashSet
<String
>();
37 private Set
<String
> archs
= new LinkedHashSet
<String
>();
41 private Set
<String
> commands
= new LinkedHashSet
<String
>();
44 Add a list of targets in the form of string separated by space
46 @param targetList target list string
48 public void addTargets(String targetList
) {
50 // targetList some targets separated by space " "
52 if (targetList
== null || targetList
.length() == 0) {
55 addTargets(targetList
.split(" "));
60 Add a list of targets in the form of string array
62 @param targetArray target string array
64 public void addTargets(String
[] targetArray
) {
65 if (targetArray
!= null ) {
66 for (int i
= 0; i
< targetArray
.length
; i
++) {
67 targets
.add(targetArray
[i
]);
73 Add a list of target in the form of set
75 @param targetSet target string set
77 public void addTargets(Set
<String
> targetSet
) {
78 if (targetSet
!= null) {
79 targets
.addAll(targetSet
);
84 Add a list of tool chain tag name in the form of string separated by space
86 @param tagnameList Tool chain tag name list string
88 public void addTagnames(String tagnameList
) {
90 // tagnameList some tagnames separated by space " "
92 if (tagnameList
== null || tagnameList
.length() == 0) {
95 addTagnames(tagnameList
.split(" "));
100 Add a list of tool chain tag name in the form of string array
102 @param tagnameArray Tool chain tag names array
104 public void addTagnames(String
[] tagnameArray
) {
105 if (tagnameArray
!= null ) {
106 for (int i
= 0; i
< tagnameArray
.length
; i
++) {
107 tagnames
.add(tagnameArray
[i
]);
113 Add a list of tool chain tag name in the form of Set
115 @param tagnameSet Tool chain tag names set
117 public void addTagnames(Set
<String
> tagnameSet
) {
118 if (tagnameSet
!= null) {
119 tagnames
.addAll(tagnameSet
);
124 Add a list of ARCH in the form of string
126 @param archList ARCH string
128 public void addArchs(String archList
) {
130 // archList some archs separated by space " "
132 if (archList
== null || archList
.length() == 0) {
135 addArchs(archList
.split(" "));
140 Add a list of ARCH in the form of string array
142 @param archArray ARCH array
144 public void addArchs(String
[] archArray
) {
145 if (archArray
!= null ) {
146 for (int i
= 0; i
< archArray
.length
; i
++) {
147 archs
.add(archArray
[i
]);
153 Add a list of ARCH in the form of set
155 @param archSet ARCH set
157 public void addArchs(Set
<String
> archSet
) {
158 if (archSet
!= null) {
159 archs
.addAll(archSet
);
164 Add a list of command in the form of string
166 @param commandList Command list string
168 public void addCommands(String commandList
) {
170 // archList some archs separated by space " "
172 if (commandList
== null || commandList
.length() == 0) {
175 addCommands(commandList
.split(" "));
180 Add a list of ARCH in the form of array
182 @param commandArray Commands array
184 public void addCommands(String
[] commandArray
) {
185 if (commandArray
!= null ) {
186 for (int i
= 0; i
< commandArray
.length
; i
++) {
187 commands
.add(commandArray
[i
]);
193 Add a list of ARCH in the form of set
195 @param commandSet Commands set
197 public void addCommands(Set
<String
> commandSet
) {
198 if (commandSet
!= null) {
199 commands
.addAll(commandSet
);
204 Make a union operation on this ToolChainInfo and the given one.
206 @param info Another ToolChainInfo object to merge with
208 @return ToolChainInfo Merged ToolChainInfo object
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
));
219 Make a intersection operation on this ToolChainInfo and the given one
221 @param info Another ToolChainInfo object to intersect with
223 @return ToolChainInfo Intersected ToolChainInfo object
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
));
234 Make a union operation on two Sets
237 @param set2 Another Set
239 @return Set<String> Merged Set object
241 private Set
<String
> union(Set
<String
> set1
, Set
<String
> set2
) {
242 Set
<String
> result
= new LinkedHashSet
<String
>();
250 Make a intersection operation on two Sets with the consideration of wildcard.
253 @param set2 Another Set
255 @return Set<String> The intersected Set object
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("*");
262 if (set1HasWildcard
&& set2HasWildcard
) {
264 // Both Sets have wildcard, the result will have all elements in them
268 } else if (set1HasWildcard
) {
270 // Only set1 has wildcard, then result will have only set2 elements.
273 } else if (set2HasWildcard
) {
275 // Only set2 has wildcard, then result will have only set1 elements.
280 // No wildcard in both Sets, the result will have the elements in both Sets.
283 result
.retainAll(set2
);
294 public String
[] getTargets() {
295 return (String
[])targets
.toArray(new String
[targets
.size()]);
299 Get tool chain tag name array.
303 public String
[] getTagnames() {
304 return (String
[])tagnames
.toArray(new String
[tagnames
.size()]);
312 public String
[] getArchs() {
313 return (String
[])archs
.toArray(new String
[archs
.size()]);
317 Get command name array.
321 public String
[] getCommands() {
322 return (String
[])commands
.toArray(new String
[commands
.size()]);
326 Override the Object's toString().
330 public String
toString() {
331 return " TARGET :" + targets
+ "\n" +
332 " TAGNAME:" + tagnames
+ "\n" +
333 " ARCH :" + archs
+ "\n" +
334 " COMMAND:" + commands
;
338 Remove the wildcard element in the tool chain information because they
339 are useless when retrieved.
341 public void normalize() {
343 tagnames
.remove("*");
345 commands
.remove("*");