]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | Spd class.\r | |
3 | \r | |
4 | This class is to generate a global table for the content of spd file.\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.global;\r | |
17 | import java.util.HashMap;\r | |
18 | import java.util.List;\r | |
19 | import java.util.Map;\r | |
20 | \r | |
878ddf1f | 21 | import org.tianocore.GuidDeclarationsDocument.GuidDeclarations;\r |
22 | import org.tianocore.IncludeHeaderDocument.IncludeHeader;\r | |
23 | import org.tianocore.LibraryClassDeclarationDocument.LibraryClassDeclaration;\r | |
24 | import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;\r | |
25 | import org.tianocore.PackageHeadersDocument.PackageHeaders;\r | |
250258de | 26 | import org.tianocore.PackageSurfaceAreaDocument;\r |
878ddf1f | 27 | import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r |
28 | import org.tianocore.PpiDeclarationsDocument.PpiDeclarations;\r | |
250258de | 29 | import org.tianocore.PpiDeclarationsDocument.PpiDeclarations.Entry;\r |
878ddf1f | 30 | import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations;\r |
31 | \r | |
32 | /**\r | |
33 | \r | |
34 | This class is to generate a global table for the content of spd file.\r | |
35 | \r | |
36 | **/\r | |
37 | public class Spd {\r | |
38 | ///\r | |
39 | /// Map of module name and package it belongs to.\r | |
40 | /// Key : Module BaseName\r | |
41 | /// Value: Relative Path to Package\r | |
42 | ///\r | |
43 | Map<String, String[]> msaInfo = new HashMap<String, String[]>();\r | |
44 | \r | |
45 | ///\r | |
46 | /// Map of module info. \r | |
47 | /// Key : moduletype\r | |
48 | /// Value: moduletype related include file\r | |
49 | ///\r | |
50 | Map<String, String> moduleInfo = new HashMap<String, String>();\r | |
51 | \r | |
52 | ///\r | |
53 | /// Map of PPI info.\r | |
54 | /// Key : PPI name\r | |
55 | /// value: String[] a. PPI C_NAME; b. PPI GUID;\r | |
56 | ///\r | |
57 | Map<String, String[]> ppiInfo = new HashMap<String, String[]>();\r | |
58 | \r | |
59 | ///\r | |
60 | /// Map of Protocol info.\r | |
61 | /// Key : Protocol name\r | |
62 | /// value: String[] a. Protocol C_NAME; b. Protocol GUID;\r | |
63 | ///\r | |
64 | Map<String, String[]> protocolInfo = new HashMap<String, String[]>();\r | |
65 | \r | |
66 | ///\r | |
67 | /// Map of Guid info.\r | |
68 | /// Key : Guid name\r | |
69 | /// value: String[] a. Guid C_NAME; b. Guid's GUID;\r | |
70 | ///\r | |
71 | Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r | |
72 | \r | |
73 | \r | |
74 | ///\r | |
75 | /// Map of library class and its exposed header file.\r | |
76 | /// Key : library class name\r | |
77 | /// value : library class corresponding header file\r | |
78 | ///\r | |
79 | Map<String, String> libClassHeaderList = new HashMap<String, String>();\r | |
80 | \r | |
81 | ///\r | |
82 | /// Package path.\r | |
83 | ///\r | |
84 | String packagePath = null;\r | |
85 | \r | |
86 | /**\r | |
87 | Constructor function\r | |
88 | \r | |
89 | This function mainly initialize some member variables. \r | |
90 | \r | |
91 | @param spdDoc Handle of spd document.\r | |
92 | @param spdPath Path of spd file.\r | |
93 | **/\r | |
94 | Spd (PackageSurfaceAreaDocument spdDoc, String spdPath) {\r | |
95 | \r | |
96 | PackageSurfaceArea spd = spdDoc.getPackageSurfaceArea();\r | |
97 | this.packagePath = spdPath;\r | |
98 | \r | |
99 | GuidDeclarations spdGuidInfo = spd.getGuidDeclarations();\r | |
100 | genGuidInfoList(spdGuidInfo);\r | |
101 | \r | |
102 | PpiDeclarations spdPpiInfo = spd.getPpiDeclarations();\r | |
103 | genPpiInfoList(spdPpiInfo);\r | |
104 | \r | |
105 | ProtocolDeclarations spdProtocolInfo = spd.getProtocolDeclarations();\r | |
106 | genProtocolInfoList(spdProtocolInfo);\r | |
107 | \r | |
108 | LibraryClassDeclarations spdLibClassDeclare = spd\r | |
109 | .getLibraryClassDeclarations();\r | |
110 | genLibClassDeclare(spdLibClassDeclare);\r | |
111 | \r | |
112 | PackageHeaders spdPackageHeaderInfo = spd.getPackageHeaders();\r | |
113 | genModuleInfoList(spdPackageHeaderInfo);\r | |
114 | \r | |
115 | }\r | |
116 | \r | |
117 | /**\r | |
118 | genModuleInfoList\r | |
119 | \r | |
120 | This function is to generate Module info map.\r | |
121 | \r | |
122 | @param packageHeader The information of packageHeader which descripted\r | |
123 | in spd file. \r | |
124 | **/\r | |
125 | public void genModuleInfoList(PackageHeaders packageHeader) {\r | |
126 | \r | |
127 | if (packageHeader != null) {\r | |
128 | List<IncludeHeader> headerList = packageHeader.getIncludeHeaderList();\r | |
250258de | 129 | IncludeHeader header;\r |
130 | \r | |
878ddf1f | 131 | for (int i = 0; i < headerList.size(); i++) {\r |
250258de | 132 | header = (IncludeHeader)headerList.get(i);\r |
878ddf1f | 133 | try {\r |
250258de | 134 | this.moduleInfo.put(header.getModuleType().toString(), header.getStringValue());\r |
878ddf1f | 135 | } catch (Exception e) {\r |
250258de | 136 | System.out.print("can't find ModuleHeaders ModuleType & includeHeader!\n");\r |
878ddf1f | 137 | }\r |
138 | }\r | |
139 | }\r | |
140 | }\r | |
141 | \r | |
142 | /**\r | |
143 | genPpiInfoList\r | |
144 | \r | |
145 | This function is to generate Ppi info map.\r | |
146 | \r | |
147 | @param ppiInfo The information of PpiDeclarations which descripted\r | |
148 | in spd file. \r | |
149 | **/\r | |
150 | public void genPpiInfoList(PpiDeclarations ppiInfo) {\r | |
151 | String[] cNameGuid = new String[2];\r | |
250258de | 152 | String guidString;\r |
878ddf1f | 153 | \r |
154 | if (ppiInfo != null) {\r | |
155 | List<PpiDeclarations.Entry> ppiEntryList = ppiInfo.getEntryList();\r | |
250258de | 156 | PpiDeclarations.Entry ppiEntry;\r |
157 | \r | |
878ddf1f | 158 | for (int i = 0; i < ppiEntryList.size(); i++) {\r |
250258de | 159 | ppiEntry = (PpiDeclarations.Entry)ppiEntryList.get(i);\r |
878ddf1f | 160 | try {\r |
250258de | 161 | if (ppiEntry.isSetGuidValue()) {\r |
162 | guidString = ppiEntry.getGuidValue();\r | |
163 | } else {\r | |
164 | guidString = ppiEntry.getGuid().getStringValue();\r | |
165 | }\r | |
166 | \r | |
167 | cNameGuid[0] = ppiEntry.getCName();\r | |
168 | cNameGuid[1] = formatGuidName(guidString);\r | |
169 | this.ppiInfo.put(ppiEntry.getName(), new String[] { cNameGuid[0], cNameGuid[1] });\r | |
878ddf1f | 170 | } catch (Exception e) {\r |
250258de | 171 | System.out.print("can't find GuidDeclarations C_Name & Guid!\n");\r |
878ddf1f | 172 | }\r |
173 | }\r | |
174 | }\r | |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | genProtocolInfoList \r | |
179 | \r | |
180 | This function is to generate Protocol info map.\r | |
181 | \r | |
182 | @param proInfo The information of ProtocolDeclarations which \r | |
183 | descripted in spd file.\r | |
184 | **/\r | |
185 | public void genProtocolInfoList(ProtocolDeclarations proInfo) {\r | |
186 | String[] cNameGuid = new String[2];\r | |
250258de | 187 | String guidString;\r |
188 | \r | |
878ddf1f | 189 | if (proInfo != null) {\r |
190 | List<ProtocolDeclarations.Entry> protocolEntryList = proInfo.getEntryList();\r | |
250258de | 191 | ProtocolDeclarations.Entry protocolEntry;\r |
878ddf1f | 192 | for (int i = 0; i < protocolEntryList.size(); i++) {\r |
250258de | 193 | protocolEntry = (ProtocolDeclarations.Entry)protocolEntryList.get(i);\r |
878ddf1f | 194 | try {\r |
250258de | 195 | if (protocolEntry.isSetGuidValue()) {\r |
196 | guidString = protocolEntry.getGuidValue();\r | |
197 | } else {\r | |
198 | guidString = protocolEntry.getGuid().getStringValue();\r | |
199 | }\r | |
200 | cNameGuid[0] = protocolEntry.getCName();\r | |
201 | cNameGuid[1] = formatGuidName(guidString);\r | |
202 | \r | |
203 | String temp = new String(protocolEntry.getName());\r | |
204 | this.protocolInfo.put(temp, new String[] { cNameGuid[0], cNameGuid[1] });\r | |
878ddf1f | 205 | } catch (Exception e) {\r |
250258de | 206 | System.out.print("can't find ProtocolDeclarations C_Name & Guid!\n");\r |
878ddf1f | 207 | }\r |
208 | }\r | |
209 | }\r | |
210 | }\r | |
211 | \r | |
212 | /**\r | |
213 | genGuidInfoList\r | |
214 | \r | |
215 | This function is to generate GUID inf map.\r | |
216 | \r | |
217 | @param guidInfo The information of GuidDeclarations which descripted\r | |
218 | in spd file.\r | |
219 | \r | |
220 | **/\r | |
221 | public void genGuidInfoList(GuidDeclarations guidInfo) {\r | |
222 | String[] cNameGuid = new String[2];\r | |
250258de | 223 | String guidString;\r |
224 | \r | |
878ddf1f | 225 | if (guidInfo != null) {\r |
226 | \r | |
250258de | 227 | List<GuidDeclarations.Entry> guidEntryList = guidInfo.getEntryList();\r |
228 | GuidDeclarations.Entry guidEntry;\r | |
878ddf1f | 229 | for (int i = 0; i < guidEntryList.size(); i++) {\r |
250258de | 230 | guidEntry = (GuidDeclarations.Entry)guidEntryList.get(i);\r |
231 | if (guidEntry.isSetGuidValue()) {\r | |
232 | guidString = guidEntry.getGuidValue();\r | |
233 | } else {\r | |
234 | guidString = guidEntry.getGuid().getStringValue();\r | |
235 | }\r | |
236 | \r | |
237 | cNameGuid[0] = guidEntry.getCName();\r | |
238 | cNameGuid[1] = formatGuidName(guidString);\r | |
239 | this.guidInfo.put(guidEntry.getName(), new String[] {cNameGuid[0], cNameGuid[1] });\r | |
878ddf1f | 240 | }\r |
241 | }\r | |
242 | }\r | |
243 | \r | |
244 | /**\r | |
245 | genLibClassDeclare\r | |
246 | \r | |
247 | This function is to generate the libClassHeader list.\r | |
248 | \r | |
249 | @param libClassDeclares The information of LibraryClassDeclarations which\r | |
250 | descripted in spd file.\r | |
251 | **/\r | |
252 | public void genLibClassDeclare(LibraryClassDeclarations libClassDeclares) {\r | |
253 | if (libClassDeclares != null && libClassDeclares.getLibraryClassDeclarationList() != null) {\r | |
254 | if (libClassDeclares.getLibraryClassDeclarationList().size() > 0) {\r | |
255 | List<LibraryClassDeclaration> libDeclareList = libClassDeclares.getLibraryClassDeclarationList();\r | |
256 | for (int i = 0; i < libDeclareList.size(); i++) {\r | |
257 | libClassHeaderList.put(libDeclareList.get(i).getLibraryClass()\r | |
258 | .getStringValue(), libDeclareList.get(i)\r | |
259 | .getIncludeHeader().getStringValue());\r | |
260 | }\r | |
261 | }\r | |
262 | }\r | |
263 | }\r | |
264 | \r | |
265 | /**\r | |
266 | getPpiGuid\r | |
267 | \r | |
268 | This function is to get ppi GUID according ppi name.\r | |
269 | \r | |
270 | @param ppiStr Name of ppi.\r | |
271 | @return PPi's GUID.\r | |
272 | **/\r | |
273 | public String getPpiGuid(String ppiStr) {\r | |
274 | if (ppiInfo.get(ppiStr) != null) {\r | |
275 | return ppiInfo.get(ppiStr)[1];\r | |
276 | } else {\r | |
277 | return null;\r | |
278 | }\r | |
279 | \r | |
280 | }\r | |
281 | \r | |
282 | /**\r | |
283 | getPpiCnameGuidArray\r | |
284 | \r | |
285 | This function is to get the ppi CName and it's GUID according to ppi name.\r | |
286 | \r | |
287 | @param ppiName Name of ppi.\r | |
288 | @return Ppi CName and it's GUID.\r | |
289 | **/\r | |
290 | public String[] getPpiCnameGuidArray(String ppiName) {\r | |
291 | return this.ppiInfo.get(ppiName);\r | |
292 | }\r | |
293 | \r | |
294 | /**\r | |
295 | getProtocolGuid\r | |
296 | \r | |
297 | This function is to get the protocol GUID according to protocol's name.\r | |
298 | \r | |
299 | @param protocolStr Name of protocol.\r | |
300 | @return Protocol's GUID.\r | |
301 | **/\r | |
302 | public String getProtocolGuid(String protocolStr) {\r | |
303 | if (protocolInfo.get(protocolStr) != null) {\r | |
304 | return this.protocolInfo.get(protocolStr)[0];\r | |
305 | } else {\r | |
306 | return null;\r | |
307 | }\r | |
308 | }\r | |
309 | \r | |
310 | /**\r | |
311 | getProtocolNameGuidArray\r | |
312 | \r | |
313 | This function is to get the protocol's CName ant it's GUID according to\r | |
314 | protocol's namej.\r | |
315 | \r | |
316 | @param protocolName Name of protocl.\r | |
317 | @return Protocol's CName and it's GUID.\r | |
318 | **/\r | |
319 | public String[] getProtocolNameGuidArray(String protocolName) {\r | |
320 | return this.protocolInfo.get(protocolName);\r | |
321 | }\r | |
322 | \r | |
323 | /**\r | |
324 | getGUIDGuid\r | |
325 | \r | |
326 | This function is to get the GUID according to GUID's name\r | |
327 | \r | |
328 | @param guidStr Name of GUID\r | |
329 | @return GUID.\r | |
330 | **/\r | |
331 | public String getGUIDGuid(String guidStr) {\r | |
332 | if (guidInfo.get(guidStr) != null) {\r | |
333 | return guidInfo.get(guidStr)[1];\r | |
334 | } else {\r | |
335 | return null;\r | |
336 | }\r | |
337 | \r | |
338 | }\r | |
339 | \r | |
340 | /**\r | |
341 | getGuidNameArray\r | |
342 | \r | |
343 | This function is to get the GUID's CName and it's GUID according to \r | |
344 | GUID's name\r | |
345 | \r | |
346 | @param guidName Name of GUID\r | |
347 | @return CName and GUID.\r | |
348 | **/\r | |
349 | public String[] getGuidNameArray(String guidName) {\r | |
350 | return this.guidInfo.get(guidName);\r | |
351 | }\r | |
352 | \r | |
353 | /**\r | |
354 | getLibClassInclude \r | |
355 | \r | |
356 | This function is to get the library exposed header file name according \r | |
357 | library class name.\r | |
358 | \r | |
359 | @param libName Name of library class \r | |
360 | @return Name of header file\r | |
361 | **/\r | |
362 | String getLibClassIncluder(String libName) {\r | |
363 | return libClassHeaderList.get(libName);\r | |
364 | }\r | |
365 | \r | |
366 | /**\r | |
367 | getModuleTypeIncluder\r | |
368 | \r | |
369 | This function is to get the header file name from module info map \r | |
370 | according to module type.\r | |
371 | \r | |
372 | @param moduleType Module type.\r | |
373 | @return Name of header file.\r | |
374 | **/\r | |
375 | String getModuleTypeIncluder(String moduleType) {\r | |
376 | return moduleInfo.get(moduleType);\r | |
377 | }\r | |
378 | \r | |
379 | /**\r | |
380 | formateGuidName\r | |
381 | \r | |
382 | This function is to formate GUID to ANSI c form.\r | |
383 | \r | |
384 | @param guidNameCon String of GUID.\r | |
385 | @return Formated GUID.\r | |
386 | **/\r | |
387 | public static String formatGuidName (String guidNameConv) {\r | |
388 | String[] strList;\r | |
389 | String guid = "";\r | |
390 | int index = 0;\r | |
391 | if (guidNameConv\r | |
392 | .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {\r | |
393 | strList = guidNameConv.split("-");\r | |
394 | guid = "0x" + strList[0] + ", ";\r | |
395 | guid = guid + "0x" + strList[1] + ", ";\r | |
396 | guid = guid + "0x" + strList[2] + ", ";\r | |
397 | guid = guid + "{";\r | |
398 | guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r | |
399 | guid = guid + "0x" + strList[3].substring(2, 4);\r | |
400 | \r | |
401 | while (index < strList[4].length()) {\r | |
402 | guid = guid + ", ";\r | |
403 | guid = guid + "0x" + strList[4].substring(index, index + 2);\r | |
404 | index = index + 2;\r | |
405 | }\r | |
406 | guid = guid + "}";\r | |
407 | return guid;\r | |
408 | } else if (guidNameConv\r | |
409 | .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {\r | |
410 | strList = guidNameConv.split(",");\r | |
411 | \r | |
412 | //\r | |
413 | // chang Microsoft specific form to ANSI c form\r | |
414 | //\r | |
415 | for (int i = 0; i < 3; i++){\r | |
416 | guid = guid + strList[i] + ",";\r | |
417 | }\r | |
418 | guid = guid + "{";\r | |
419 | \r | |
420 | for (int i = 3; i < strList.length; i++){\r | |
421 | if (i == strList.length - 1){\r | |
422 | guid = guid + strList[i];\r | |
423 | } else {\r | |
424 | guid = guid + strList[i] + ",";\r | |
425 | }\r | |
426 | }\r | |
427 | guid = guid + "}"; \r | |
428 | return guid;\r | |
429 | } else {\r | |
430 | System.out.println("Check GUID Value, it don't conform to the schema!!!");\r | |
431 | return "0";\r | |
432 | \r | |
433 | }\r | |
434 | }\r | |
435 | }\r |