]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java
Fix EDKT140(CompressDll.dll does not build under cygwin gcc).
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / PlatformPcdPreprocessActionForBuilding.java
CommitLineData
af98370e 1/** @file\r
2 PlatformPcdPreprocessActionForBuilding class.\r
3\r
4 This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
5 This class will be used for wizard and build tools, So it can *not* inherit\r
6 from buildAction or wizardAction.\r
7\r
8Copyright (c) 2006, Intel Corporation\r
9All rights reserved. This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18package org.tianocore.build.pcd.action;\r
19\r
20import java.io.File;\r
21import java.io.IOException;\r
22import java.math.BigInteger;\r
23import java.util.ArrayList;\r
24import java.util.Iterator;\r
25import java.util.List;\r
26import java.util.Map;\r
27\r
28import org.apache.xmlbeans.XmlException;\r
29import org.apache.xmlbeans.XmlObject;\r
30import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
31import org.tianocore.PlatformSurfaceAreaDocument;\r
32import org.tianocore.build.fpd.FpdParserTask;\r
33import org.tianocore.build.global.GlobalData;\r
34import org.tianocore.build.id.FpdModuleIdentification;\r
35import org.tianocore.pcd.action.ActionMessage;\r
36import org.tianocore.pcd.entity.ModulePcdInfoFromFpd;\r
37import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
38import org.tianocore.pcd.entity.Token;\r
39import org.tianocore.pcd.entity.UsageIdentification;\r
40import org.tianocore.pcd.exception.EntityException;\r
41import org.tianocore.pcd.action.PlatformPcdPreprocessAction;\r
42\r
43/**\r
44 This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
45 This class will be used for wizard and build tools, So it can *not* inherit\r
46 from buildAction or UIAction.\r
47**/\r
48public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreprocessAction {\r
49 ///\r
50 /// Workspacepath hold the workspace information.\r
51 ///\r
52 private String workspacePath;\r
53\r
54 ///\r
55 /// FPD file is the root file.\r
56 ///\r
57 private String fpdFilePath;\r
58\r
59 ///\r
60 /// Message level for CollectPCDAction.\r
61 ///\r
62 private int originalMessageLevel;\r
63\r
64 ///\r
65 /// Cache the fpd docment instance for private usage.\r
66 ///\r
67 private PlatformSurfaceAreaDocument fpdDocInstance;\r
68\r
69 /**\r
70 Set WorkspacePath parameter for this action class.\r
71\r
72 @param workspacePath parameter for this action\r
73 **/\r
74 public void setWorkspacePath(String workspacePath) {\r
75 this.workspacePath = workspacePath;\r
76 }\r
77\r
78 /**\r
79 Set action message level for CollectPcdAction tool.\r
80\r
81 The message should be restored when this action exit.\r
82\r
83 @param actionMessageLevel parameter for this action\r
84 **/\r
85 public void setActionMessageLevel(int actionMessageLevel) {\r
86 originalMessageLevel = ActionMessage.messageLevel;\r
87 ActionMessage.messageLevel = actionMessageLevel;\r
88 }\r
89\r
90 /**\r
91 Set FPDFileName parameter for this action class.\r
92\r
93 @param fpdFilePath fpd file path\r
94 **/\r
95 public void setFPDFilePath(String fpdFilePath) {\r
96 this.fpdFilePath = fpdFilePath;\r
97 }\r
98\r
99 /**\r
100 Common function interface for outer.\r
101\r
102 @param workspacePath The path of workspace of current build or analysis.\r
103 @param fpdFilePath The fpd file path of current build or analysis.\r
104 @param messageLevel The message level for this Action.\r
105\r
106 @throws Exception The exception of this function. Because it can *not* be predict\r
107 where the action class will be used. So only Exception can be throw.\r
108\r
109 **/\r
110 public void perform(String workspacePath, String fpdFilePath,\r
111 int messageLevel) throws Exception {\r
112 setWorkspacePath(workspacePath);\r
113 setFPDFilePath(fpdFilePath);\r
114 setActionMessageLevel(messageLevel);\r
115 checkParameter();\r
116 execute();\r
117 ActionMessage.messageLevel = originalMessageLevel;\r
118 }\r
119\r
120 /**\r
121 Core execution function for this action class.\r
122\r
123 This function work flows will be:\r
124 1) Collect and prepocess PCD information from FPD file, all PCD\r
125 information will be stored into memory database.\r
126 2) Generate 3 strings for\r
127 a) All modules using Dynamic(Ex) PCD entry.(Token Number)\r
128 b) PEI PCDDatabase (C Structure) for PCD Service PEIM.\r
129 c) DXE PCD Database (C structure) for PCD Service DXE.\r
130\r
131\r
132 @throws EntityException Exception indicate failed to execute this action.\r
133\r
134 **/\r
135 public void execute() throws EntityException {\r
136 MemoryDatabaseManager pcdDbManager = null;\r
137\r
138 //\r
139 // Get memoryDatabaseManager instance from GlobalData.\r
140 // The memoryDatabaseManager should be initialized for whatever build\r
141 // tools or wizard tools\r
142 //\r
143 if((pcdDbManager = GlobalData.getPCDMemoryDBManager()) == null) {\r
144 throw new EntityException("The instance of PCD memory database manager is null");\r
145 }\r
146\r
147 this.setPcdDbManager(pcdDbManager);\r
148\r
149 //\r
150 // Collect all PCD information defined in FPD file.\r
151 // Evenry token defind in FPD will be created as an token into\r
152 // memory database.\r
153 //\r
154 initPcdMemoryDbWithPlatformInfo();\r
155\r
156 //\r
157 // Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
158 //\r
159 genPcdDatabaseSourceCode ();\r
160\r
161 }\r
162\r
163 /**\r
164 Override function: implementate the method of get Guid string information from SPD file.\r
165\r
166 @param guidCName Guid CName string.\r
167\r
168 @return String[] Guid information from SPD file.\r
169 **/\r
170 public String[] getGuidInfoFromSpd(String guidCName) throws EntityException {\r
171 String[] tokenSpaceStrRet = null;\r
172 try {\r
173 tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(guidCName);\r
174 } catch ( Exception e ) {\r
175 throw new EntityException ("Failed get Guid CName " + guidCName + "from SPD file!");\r
176 }\r
177 return tokenSpaceStrRet;\r
178 }\r
179\r
180 /**\r
181 This function generates source code for PCD Database.\r
182\r
183 @param void\r
184 @throws EntityException If the token does *not* exist in memory database.\r
185\r
186 **/\r
187 private void genPcdDatabaseSourceCode()\r
188 throws EntityException {\r
189 String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions();\r
190\r
191 ArrayList<Token> alPei = new ArrayList<Token> ();\r
192 ArrayList<Token> alDxe = new ArrayList<Token> ();\r
193\r
194 getPcdDbManager().getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
195 PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
196 pcdPeiDatabase.genCode();\r
197 MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString() +\r
198 PcdDatabase.getPcdPeiDatabaseDefinitions();\r
199 MemoryDatabaseManager.PcdPeimCString = pcdPeiDatabase.getCString();\r
200\r
201 PcdDatabase pcdDxeDatabase = new PcdDatabase(alDxe, "DXE", alPei.size());\r
202 pcdDxeDatabase.genCode();\r
203 MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() +\r
204 PcdDatabase.getPcdDxeDatabaseDefinitions();\r
205 MemoryDatabaseManager.PcdDxeCString = pcdDxeDatabase.getCString();\r
206 }\r
207\r
208 /**\r
209 Override function: Get component array from FPD.\r
210\r
211 This function maybe provided by some Global class.\r
212\r
213 @return List<ModuleInfo> the component array.\r
214\r
215 */\r
216 public List<ModulePcdInfoFromFpd> getComponentsFromFpd()\r
217 throws EntityException {\r
218 List<ModulePcdInfoFromFpd> allModules = new ArrayList<ModulePcdInfoFromFpd>();\r
219 Map<FpdModuleIdentification, XmlObject> pcdBuildDefinitions = null;\r
220 UsageIdentification usageId = null;\r
221\r
222 pcdBuildDefinitions = GlobalData.getFpdPcdBuildDefinitions();\r
223 if (pcdBuildDefinitions == null) {\r
224 return null;\r
225 }\r
226\r
227 //\r
228 // Loop map to retrieve all PCD build definition and Module id\r
229 //\r
230 Iterator item = pcdBuildDefinitions.keySet().iterator();\r
231 while (item.hasNext()){\r
232 FpdModuleIdentification id = (FpdModuleIdentification) item.next();\r
233 usageId = new UsageIdentification(id.getModule().getName(),\r
234 id.getModule().getGuid(),\r
235 id.getModule().getPackage().getName(),\r
236 id.getModule().getPackage().getGuid(),\r
237 id.getArch(),\r
238 id.getModule().getVersion(),\r
239 id.getModule().getModuleType());\r
240 allModules.add(new ModulePcdInfoFromFpd(usageId, pcdBuildDefinitions.get(id)));\r
241 }\r
242 return allModules;\r
243 }\r
244\r
245 /**\r
246 Override function: Verify the datum value according its datum size and datum type, this\r
247 function maybe moved to FPD verification tools in future.\r
248\r
249 @param cName\r
250 @param moduleName\r
251 @param datum\r
252 @param datumType\r
253 @param maxDatumSize\r
254\r
255 @return String\r
256 */\r
257 /***/\r
258 public String verifyDatum(String cName,\r
259 String moduleName,\r
260 String datum,\r
261 Token.DATUM_TYPE datumType,\r
262 int maxDatumSize) {\r
263 String exceptionString = null;\r
264 int value;\r
265 BigInteger value64;\r
266 String subStr;\r
267 int index;\r
268\r
269 if (moduleName == null) {\r
270 moduleName = "section <DynamicPcdBuildDefinitions>";\r
271 } else {\r
272 moduleName = "module " + moduleName;\r
273 }\r
274\r
275 if (maxDatumSize == 0) {\r
276 exceptionString = String.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in %s",\r
277 cName,\r
278 moduleName);\r
279 return exceptionString;\r
280 }\r
281\r
282 switch (datumType) {\r
283 case UINT8:\r
284 if (maxDatumSize != 1) {\r
285 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
286 "is UINT8, but datum size is %d, they are not matched!",\r
287 cName,\r
288 moduleName,\r
289 maxDatumSize);\r
290 return exceptionString;\r
291 }\r
292\r
293 if (datum != null) {\r
294 try {\r
295 value = Integer.decode(datum);\r
296 } catch (NumberFormatException nfeExp) {\r
297 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid "+\r
298 "digital format of UINT8",\r
299 cName,\r
300 moduleName);\r
301 return exceptionString;\r
302 }\r
303 if (value > 0xFF) {\r
304 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s exceed"+\r
305 " the max size of UINT8 - 0xFF",\r
306 cName,\r
307 moduleName,\r
308 datum);\r
309 return exceptionString;\r
310 }\r
311 }\r
312 break;\r
313 case UINT16:\r
314 if (maxDatumSize != 2) {\r
315 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
316 "is UINT16, but datum size is %d, they are not matched!",\r
317 cName,\r
318 moduleName,\r
319 maxDatumSize);\r
320 return exceptionString;\r
321 }\r
322 if (datum != null) {\r
323 try {\r
324 value = Integer.decode(datum);\r
325 } catch (NumberFormatException nfeExp) {\r
326 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is "+\r
327 "not valid digital of UINT16",\r
328 cName,\r
329 moduleName);\r
330 return exceptionString;\r
331 }\r
332 if (value > 0xFFFF) {\r
333 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
334 "which exceed the range of UINT16 - 0xFFFF",\r
335 cName,\r
336 moduleName,\r
337 datum);\r
338 return exceptionString;\r
339 }\r
340 }\r
341 break;\r
342 case UINT32:\r
343 if (maxDatumSize != 4) {\r
344 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
345 "is UINT32, but datum size is %d, they are not matched!",\r
346 cName,\r
347 moduleName,\r
348 maxDatumSize);\r
349 return exceptionString;\r
350 }\r
351\r
352 if (datum != null) {\r
353 try {\r
354 if (datum.length() > 2) {\r
355 if ((datum.charAt(0) == '0') &&\r
356 ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
357 subStr = datum.substring(2, datum.length());\r
358 value64 = new BigInteger(subStr, 16);\r
359 } else {\r
360 value64 = new BigInteger(datum);\r
361 }\r
362 } else {\r
363 value64 = new BigInteger(datum);\r
364 }\r
365 } catch (NumberFormatException nfeExp) {\r
366 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not "+\r
367 "valid digital of UINT32",\r
368 cName,\r
369 moduleName);\r
370 return exceptionString;\r
371 }\r
372\r
373 if (value64.bitLength() > 32) {\r
374 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s which "+\r
375 "exceed the range of UINT32 - 0xFFFFFFFF",\r
376 cName,\r
377 moduleName,\r
378 datum);\r
379 return exceptionString;\r
380 }\r
381 }\r
382 break;\r
383 case UINT64:\r
384 if (maxDatumSize != 8) {\r
385 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
386 "is UINT64, but datum size is %d, they are not matched!",\r
387 cName,\r
388 moduleName,\r
389 maxDatumSize);\r
390 return exceptionString;\r
391 }\r
392\r
393 if (datum != null) {\r
394 try {\r
395 if (datum.length() > 2) {\r
396 if ((datum.charAt(0) == '0') &&\r
397 ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
398 subStr = datum.substring(2, datum.length());\r
399 value64 = new BigInteger(subStr, 16);\r
400 } else {\r
401 value64 = new BigInteger(datum);\r
402 }\r
403 } else {\r
404 value64 = new BigInteger(datum);\r
405 }\r
406 } catch (NumberFormatException nfeExp) {\r
407 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid"+\r
408 " digital of UINT64",\r
409 cName,\r
410 moduleName);\r
411 return exceptionString;\r
412 }\r
413\r
414 if (value64.bitLength() > 64) {\r
415 exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
416 "exceed the range of UINT64 - 0xFFFFFFFFFFFFFFFF",\r
417 cName,\r
418 moduleName,\r
419 datum);\r
420 return exceptionString;\r
421 }\r
422 }\r
423 break;\r
424 case BOOLEAN:\r
425 if (maxDatumSize != 1) {\r
426 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
427 "is BOOLEAN, but datum size is %d, they are not matched!",\r
428 cName,\r
429 moduleName,\r
430 maxDatumSize);\r
431 return exceptionString;\r
432 }\r
433\r
434 if (datum != null) {\r
435 if (!(datum.equalsIgnoreCase("TRUE") ||\r
436 datum.equalsIgnoreCase("FALSE"))) {\r
437 exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
438 "is BOOELAN, but value is not 'true'/'TRUE' or 'FALSE'/'false'",\r
439 cName,\r
440 moduleName);\r
441 return exceptionString;\r
442 }\r
443\r
444 }\r
445 break;\r
446 case POINTER:\r
447 if (datum == null) {\r
448 break;\r
449 }\r
450\r
451 char ch = datum.charAt(0);\r
452 int start, end;\r
453 String strValue;\r
454 //\r
455 // For void* type PCD, only three datum is support:\r
456 // 1) Unicode: string with start char is "L"\r
457 // 2) Ansci: String start char is ""\r
458 // 3) byte array: String start char "{"\r
459 //\r
460 if (ch == 'L') {\r
461 start = datum.indexOf('\"');\r
462 end = datum.lastIndexOf('\"');\r
463 if ((start > end) ||\r
464 (end > datum.length())||\r
465 ((start == end) && (datum.length() > 0))) {\r
466 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+\r
467 "a UNICODE string because start with L\", but format maybe"+\r
468 "is not right, correct UNICODE string is L\"...\"!",\r
469 cName,\r
470 moduleName);\r
471 return exceptionString;\r
472 }\r
473\r
474 strValue = datum.substring(start + 1, end);\r
475 if ((strValue.length() * 2) > maxDatumSize) {\r
476 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+\r
477 "a UNICODE string, but the datum size is %d exceed to <MaxDatumSize> : %d",\r
478 cName,\r
479 moduleName,\r
480 strValue.length() * 2,\r
481 maxDatumSize);\r
482 return exceptionString;\r
483 }\r
484 } else if (ch == '\"'){\r
485 start = datum.indexOf('\"');\r
486 end = datum.lastIndexOf('\"');\r
487 if ((start > end) ||\r
488 (end > datum.length())||\r
489 ((start == end) && (datum.length() > 0))) {\r
490 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+\r
491 "a ANSCII string because start with \", but format maybe"+\r
492 "is not right, correct ANSIC string is \"...\"!",\r
493 cName,\r
494 moduleName);\r
495 return exceptionString;\r
496 }\r
497 strValue = datum.substring(start + 1, end);\r
498 if ((strValue.length()) > maxDatumSize) {\r
499 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+\r
500 "a ANSCI string, but the datum size is %d which exceed to <MaxDatumSize> : %d",\r
501 cName,\r
502 moduleName,\r
503 strValue.length(),\r
504 maxDatumSize);\r
505 return exceptionString;\r
506 }\r
507 } else if (ch =='{') {\r
508 String[] strValueArray;\r
509\r
510 start = datum.indexOf('{');\r
511 end = datum.lastIndexOf('}');\r
512 strValue = datum.substring(start + 1, end);\r
513 strValue = strValue.trim();\r
514 if (strValue.length() == 0) {\r
515 exceptionString = String.format ("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
516 "it is byte array in fact, but '{}' is not valid for NULL datam but"+\r
517 " need use '{0}'",\r
518 cName,\r
519 moduleName);\r
520 return exceptionString;\r
521 }\r
522 strValueArray = strValue.split(",");\r
523 for (index = 0; index < strValueArray.length; index ++) {\r
524 try{\r
525 value = Integer.decode(strValueArray[index].trim());\r
526 } catch (NumberFormatException nfeEx) {\r
527 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
528 "it is byte array in fact. For every byte in array should be a valid"+\r
529 "byte digital, but element %s is not a valid byte digital!",\r
530 cName,\r
531 moduleName,\r
532 strValueArray[index]);\r
533 return exceptionString;\r
534 }\r
535 if (value > 0xFF) {\r
536 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r
537 "it is byte array in fact. But the element of %s exceed the byte range",\r
538 cName,\r
539 moduleName,\r
540 strValueArray[index]);\r
541 return exceptionString;\r
542 }\r
543 }\r
544\r
545 if (strValueArray.length > maxDatumSize) {\r
546 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is byte"+\r
547 "array, but the number of bytes is %d which exceed to <MaxDatumSzie> : %d!",\r
548 cName,\r
549 moduleName,\r
550 strValueArray.length,\r
551 maxDatumSize);\r
552 return exceptionString;\r
553 }\r
554 } else {\r
555 exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r
556 "1) UNICODE string: like L\"xxxx\";\r\n"+\r
557 "2) ANSIC string: like \"xxx\";\r\n"+\r
558 "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r
559 "But the datum in seems does not following above format!",\r
560 cName,\r
561 moduleName);\r
562 return exceptionString;\r
563 }\r
564 break;\r
565 default:\r
566 exceptionString = String.format("[FPD file error] For PCD entry %s in %s, datum type is unknown, it should be one of "+\r
567 "UINT8, UINT16, UINT32, UINT64, VOID*, BOOLEAN",\r
568 cName,\r
569 moduleName);\r
570 return exceptionString;\r
571 }\r
572 return null;\r
573 }\r
574\r
575 /**\r
576 Override function: Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.\r
577\r
578 This function should be implemented in GlobalData in future.\r
579\r
580 @param token The token instance which has hold module's PCD information\r
581 @param moduleName The name of module who will use this Dynamic PCD.\r
582\r
583 @return DynamicPcdBuildDefinitions.PcdBuildData\r
584 **/\r
585 public DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFpd(Token token,\r
586 String moduleName)\r
587 throws EntityException {\r
588 int index = 0;\r
589 String exceptionString = null;\r
590 String dynamicPrimaryKey = null;\r
591 DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r
592 List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray = null;\r
593 String[] tokenSpaceStrRet = null;\r
594\r
595 //\r
596 // If FPD document is not be opened, open and initialize it.\r
597 // BUGBUG: The code should be moved into GlobalData in future.\r
598 //\r
599 if (fpdDocInstance == null) {\r
600 try {\r
601 fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
602 } catch(IOException ioE) {\r
603 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
604 } catch(XmlException xmlE) {\r
605 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
606 }\r
607 }\r
608\r
609 dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
610 if (dynamicPcdBuildDefinitions == null) {\r
611 exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
612 "PCD entry %s in module %s!",\r
613 token.cName,\r
614 moduleName);\r
615 throw new EntityException(exceptionString);\r
616 }\r
617\r
618 dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
619 for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r
620 try {\r
621 tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName());\r
622 } catch (Exception e) {\r
623 throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
624 }\r
625\r
626 if (tokenSpaceStrRet == null) {\r
627 throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
628 }\r
629\r
630 dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
631 tokenSpaceStrRet[1]);\r
632 if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
633 return dynamicPcdBuildDataArray.get(index);\r
634 }\r
635 }\r
636\r
637 return null;\r
638 }\r
639\r
640 /**\r
641 Override function: get all <DynamicPcdBuildDefinition> from FPD file.\r
642\r
643 @return List<DynamicPcdBuildDefinitions.PcdBuildData>\r
644 **/\r
645 public List<DynamicPcdBuildDefinitions.PcdBuildData>\r
646 getAllDynamicPcdInfoFromFpd()\r
647 throws EntityException {\r
648 DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r
649\r
650 //\r
651 // Open fpd document to get <DynamicPcdBuildDefinition> Section.\r
652 // BUGBUG: the function should be move GlobalData in furture.\r
653 //\r
654 if (fpdDocInstance == null) {\r
655 try {\r
656 fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
657 } catch(IOException ioE) {\r
658 throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
659 } catch(XmlException xmlE) {\r
660 throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
661 }\r
662 }\r
663\r
664 dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
665 if (dynamicPcdBuildDefinitions == null) {\r
666 return null;\r
667 }\r
668\r
669 return dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
670 }\r
671\r
672 /**\r
673 check parameter for this action.\r
674\r
675 @throws EntityException Bad parameter.\r
676 **/\r
677 private void checkParameter() throws EntityException {\r
678 File file = null;\r
679\r
680 if((fpdFilePath == null) ||(workspacePath == null)) {\r
681 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
682 }\r
683\r
684 if(fpdFilePath.length() == 0 || workspacePath.length() == 0) {\r
685 throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
686 }\r
687\r
688 file = new File(workspacePath);\r
689 if(!file.exists()) {\r
690 throw new EntityException("WorkpacePath " + workspacePath + " does not exist!");\r
691 }\r
692\r
693 file = new File(fpdFilePath);\r
694\r
695 if(!file.exists()) {\r
696 throw new EntityException("FPD File " + fpdFilePath + " does not exist!");\r
697 }\r
698 }\r
699\r
700 /**\r
701 Test case function\r
702\r
703 @param argv parameter from command line\r
704 **/\r
705 public static void main(String argv[]) throws EntityException {\r
706 PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();\r
707 String projectDir = "x:/edk2";\r
708 ca.setWorkspacePath(projectDir);\r
709 ca.setFPDFilePath(projectDir + "/EdkNt32Pkg/Nt32.fpd");\r
710 ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
711 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
712 projectDir,\r
713 "tools_def.txt");\r
714 System.out.println("After initInfo!");\r
715 FpdParserTask fpt = new FpdParserTask();\r
716 fpt.parseFpdFile(new File(projectDir + "/EdkNt32Pkg/Nt32.fpd"));\r
717 ca.execute();\r
718 }\r
719}\r