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