]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | ToolChainInfo class\r | |
3 | \r | |
4 | This file is to define ToolChainInfo class.\r | |
5 | \r | |
6 | Copyright (c) 2006, Intel Corporation\r | |
7 | All rights reserved. This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | **/\r | |
15 | \r | |
16 | package org.tianocore.build.toolchain;\r | |
17 | \r | |
18 | import java.util.HashMap;\r | |
19 | import java.util.LinkedHashSet;\r | |
20 | import java.util.Map;\r | |
21 | import java.util.Set;\r | |
22 | \r | |
23 | /**\r | |
24 | ToolChainInfo collects valid build targets, tool chain tag, ARCHs and commands \r | |
25 | information for real build use.\r | |
26 | **/\r | |
27 | public class ToolChainInfo {\r | |
28 | //\r | |
29 | // build target set\r | |
30 | // \r | |
31 | private Set<String> targets = new LinkedHashSet<String>();\r | |
32 | //\r | |
33 | // tool chain tag name set\r | |
34 | // \r | |
35 | private Set<String> tagnames = new LinkedHashSet<String>();\r | |
36 | //\r | |
37 | // build archs set\r | |
38 | // \r | |
39 | private Set<String> archs = new LinkedHashSet<String>();\r | |
40 | //\r | |
41 | // build commands set\r | |
42 | // \r | |
43 | private Set<String> commands = new LinkedHashSet<String>();\r | |
44 | \r | |
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 | |
50 | public void addTargets(String targetList) {\r | |
51 | //\r | |
52 | // targetList some targets separated by space " "\r | |
53 | //\r | |
54 | if (targetList == null || targetList.length() == 0) {\r | |
55 | targets.add("*");\r | |
56 | } else {\r | |
57 | addTargets(targetList.split(" "));\r | |
58 | }\r | |
59 | }\r | |
60 | \r | |
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 | |
66 | public void addTargets(String[] targetArray) {\r | |
67 | if (targetArray != null ) {\r | |
68 | for (int i = 0; i < targetArray.length; i++) {\r | |
69 | targets.add(targetArray[i]);\r | |
70 | }\r | |
71 | }\r | |
72 | }\r | |
73 | \r | |
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 | |
79 | public void addTargets(Set<String> targetSet) {\r | |
80 | if (targetSet != null) {\r | |
81 | targets.addAll(targetSet);\r | |
82 | }\r | |
83 | }\r | |
84 | \r | |
85 | /**\r | |
86 | Add a list of tool chain tag name in the form of string separated by space\r | |
87 | \r | |
88 | @param tagnameList Tool chain tag name list string\r | |
89 | **/\r | |
90 | public void addTagnames(String tagnameList) {\r | |
91 | //\r | |
92 | // tagnameList some tagnames separated by space " "\r | |
93 | //\r | |
94 | if (tagnameList == null || tagnameList.length() == 0) {\r | |
95 | tagnames.add("*");\r | |
96 | } else {\r | |
97 | addTagnames(tagnameList.split(" "));\r | |
98 | }\r | |
99 | }\r | |
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 | |
106 | public void addTagnames(String[] tagnameArray) {\r | |
107 | if (tagnameArray != null ) {\r | |
108 | for (int i = 0; i < tagnameArray.length; i++) {\r | |
109 | tagnames.add(tagnameArray[i]);\r | |
110 | }\r | |
111 | }\r | |
112 | }\r | |
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 | |
119 | public void addTagnames(Set<String> tagnameSet) {\r | |
120 | if (tagnameSet != null) {\r | |
121 | tagnames.addAll(tagnameSet);\r | |
122 | }\r | |
123 | }\r | |
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 | |
130 | public void addArchs(String archList) {\r | |
131 | //\r | |
132 | // archList some archs separated by space " "\r | |
133 | //\r | |
134 | if (archList == null || archList.length() == 0) {\r | |
135 | archs.add("*");\r | |
136 | } else {\r | |
137 | addArchs(archList.split(" "));\r | |
138 | }\r | |
139 | }\r | |
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 | |
146 | public void addArchs(String[] archArray) {\r | |
147 | if (archArray != null ) {\r | |
148 | for (int i = 0; i < archArray.length; i++) {\r | |
149 | archs.add(archArray[i]);\r | |
150 | }\r | |
151 | }\r | |
152 | }\r | |
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 | |
159 | public void addArchs(Set<String> archSet) {\r | |
160 | if (archSet != null) {\r | |
161 | archs.addAll(archSet);\r | |
162 | }\r | |
163 | }\r | |
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 | |
171 | //\r | |
172 | // archList some archs separated by space " "\r | |
173 | //\r | |
174 | if (commandList == null || commandList.length() == 0) {\r | |
175 | commands.add("*");\r | |
176 | } else {\r | |
177 | addCommands(commandList.split(" "));\r | |
178 | }\r | |
179 | }\r | |
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 | |
186 | public void addCommands(String[] commandArray) {\r | |
187 | if (commandArray != null ) {\r | |
188 | for (int i = 0; i < commandArray.length; i++) {\r | |
189 | commands.add(commandArray[i]);\r | |
190 | }\r | |
191 | }\r | |
192 | }\r | |
193 | \r | |
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 | |
202 | }\r | |
203 | }\r | |
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 | |
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 | |
217 | return result;\r | |
218 | }\r | |
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 | |
227 | public ToolChainInfo intersection(ToolChainInfo info) {\r | |
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 | |
232 | return result;\r | |
233 | }\r | |
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 | |
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 | |
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 | |
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 | |
265 | //\r | |
266 | // Both Sets have wildcard, the result will have all elements in them\r | |
267 | // \r | |
268 | result.addAll(set1);\r | |
269 | result.addAll(set2);\r | |
270 | } else if (set1HasWildcard) {\r | |
271 | //\r | |
272 | // Only set1 has wildcard, then result will have only set2 elements.\r | |
273 | // \r | |
274 | result.addAll(set2);\r | |
275 | } else if (set2HasWildcard) {\r | |
276 | //\r | |
277 | // Only set2 has wildcard, then result will have only set1 elements.\r | |
278 | // \r | |
279 | result.addAll(set1);\r | |
280 | } else {\r | |
281 | //\r | |
282 | // No wildcard in both Sets, the result will have the elements in both Sets.\r | |
283 | // \r | |
284 | result.addAll(set1);\r | |
285 | result.retainAll(set2);\r | |
286 | }\r | |
287 | \r | |
288 | return result;\r | |
289 | }\r | |
290 | \r | |
291 | /**\r | |
292 | Get target array.\r | |
293 | \r | |
294 | @return String[]\r | |
295 | **/\r | |
296 | public String[] getTargets() {\r | |
297 | return (String[])targets.toArray(new String[targets.size()]);\r | |
298 | }\r | |
299 | \r | |
300 | /**\r | |
301 | Get tool chain tag name array.\r | |
302 | \r | |
303 | @return String[]\r | |
304 | **/\r | |
305 | public String[] getTagnames() {\r | |
306 | return (String[])tagnames.toArray(new String[tagnames.size()]);\r | |
307 | }\r | |
308 | \r | |
309 | /**\r | |
310 | Get ARCH array.\r | |
311 | \r | |
312 | @return String[]\r | |
313 | **/\r | |
314 | public String[] getArchs() {\r | |
315 | return (String[])archs.toArray(new String[archs.size()]);\r | |
316 | }\r | |
317 | \r | |
318 | /**\r | |
319 | Get command name array.\r | |
320 | \r | |
321 | @return String[]\r | |
322 | **/\r | |
323 | public String[] getCommands() {\r | |
324 | return (String[])commands.toArray(new String[commands.size()]);\r | |
325 | }\r | |
326 | \r | |
327 | /**\r | |
328 | Override the Object's toString().\r | |
329 | \r | |
330 | @return String\r | |
331 | **/\r | |
332 | public String toString() {\r | |
333 | return targets + "\n" + tagnames + "\n" + archs + "\n" + commands;\r | |
334 | }\r | |
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 | |
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 |