Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / Common / DecClassObject.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to define each component of DEC file\r
3#\r
4# Copyright (c) 2007, Intel Corporation\r
5# All rights reserved. This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14##\r
15# Import Modules\r
16#\r
17import os\r
18from String import *\r
19from DataType import *\r
20from Identification import *\r
21from Dictionary import *\r
22from CommonDataClass.PackageClass import *\r
23from CommonDataClass.CommonClass import PcdClass\r
24from BuildToolError import *\r
25from Table.TableDec import TableDec\r
26import Database\r
27from Parsing import *\r
28import GlobalData\r
29\r
30#\r
31# Global variable\r
32#\r
33Section = {TAB_UNKNOWN.upper() : MODEL_UNKNOWN,\r
34 TAB_DEC_DEFINES.upper() : MODEL_META_DATA_HEADER,\r
35 TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,\r
36 TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\r
37 TAB_COMPONENTS.upper() : MODEL_META_DATA_COMPONENT,\r
38 TAB_GUIDS.upper() : MODEL_EFI_GUID,\r
39 TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,\r
40 TAB_PPIS.upper() : MODEL_EFI_PPI,\r
41 TAB_PCDS_FIXED_AT_BUILD_NULL.upper() : MODEL_PCD_FIXED_AT_BUILD,\r
42 TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,\r
43 TAB_PCDS_FEATURE_FLAG_NULL.upper() : MODEL_PCD_FEATURE_FLAG,\r
44 TAB_PCDS_DYNAMIC_EX_NULL.upper() : MODEL_PCD_DYNAMIC_EX,\r
45 TAB_PCDS_DYNAMIC_NULL.upper() : MODEL_PCD_DYNAMIC,\r
46 TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION\r
47 }\r
48\r
49\r
50## DecObject\r
51#\r
52# This class defined basic Dec object which is used by inheriting\r
53# \r
54# @param object: Inherited from object class\r
55#\r
56class DecObject(object):\r
57 def __init__(self):\r
58 object.__init__()\r
59\r
60## Dec\r
61#\r
62# This class defined the structure used in Dec object\r
63# \r
64# @param DecObject: Inherited from DecObject class\r
65# @param Filename: Input value for Filename of Dec file, default is None\r
66# @param IsMergeAllArches: Input value for IsMergeAllArches\r
67# True is to merge all arches\r
68# Fales is not to merge all arches\r
69# default is False\r
70# @param IsToPackage: Input value for IsToPackage\r
71# True is to transfer to PackageObject automatically\r
72# False is not to transfer to PackageObject automatically\r
73# default is False\r
74# @param WorkspaceDir: Input value for current workspace directory, default is None\r
75#\r
76# @var Identification: To store value for Identification, it is a structure as Identification\r
77# @var Defines: To store value for Defines, it is a structure as DecDefines\r
78# @var UserExtensions: To store value for UserExtensions\r
79# @var Package: To store value for Package, it is a structure as PackageClass\r
80# @var WorkspaceDir: To store value for WorkspaceDir\r
81# @var Contents: To store value for Contents, it is a structure as DecContents\r
82# @var KeyList: To store value for KeyList, a list for all Keys used in Dec\r
83#\r
84class Dec(DecObject):\r
85 def __init__(self, Filename = None, IsToDatabase = False, IsToPackage = False, WorkspaceDir = None, Database = None, SupArchList = DataType.ARCH_LIST):\r
86 self.Identification = Identification()\r
87 self.Package = PackageClass()\r
88 self.UserExtensions = ''\r
89 self.WorkspaceDir = WorkspaceDir\r
90 self.SupArchList = SupArchList\r
91 self.IsToDatabase = IsToDatabase\r
92 \r
93 self.Cur = Database.Cur\r
94 self.TblFile = Database.TblFile\r
95 self.TblDec = Database.TblDec\r
96 self.FileID = -1\r
97\r
98 self.KeyList = [\r
99 TAB_INCLUDES, TAB_GUIDS, TAB_PROTOCOLS, TAB_PPIS, TAB_LIBRARY_CLASSES, \\r
100 TAB_PCDS_FIXED_AT_BUILD_NULL, TAB_PCDS_PATCHABLE_IN_MODULE_NULL, TAB_PCDS_FEATURE_FLAG_NULL, \\r
101 TAB_PCDS_DYNAMIC_NULL, TAB_PCDS_DYNAMIC_EX_NULL, TAB_DEC_DEFINES\r
102 ]\r
103 #\r
104 # Upper all KEYs to ignore case sensitive when parsing\r
105 #\r
106 self.KeyList = map(lambda c: c.upper(), self.KeyList)\r
107 \r
108 #\r
109 # Init RecordSet\r
110 #\r
111 self.RecordSet = {} \r
112 for Key in self.KeyList:\r
113 self.RecordSet[Section[Key]] = []\r
114 \r
115 #\r
116 # Load Dec file if filename is not None\r
117 #\r
118 if Filename != None:\r
119 self.LoadDecFile(Filename)\r
120 \r
121 #\r
122 # Transfer to Package Object if IsToPackage is True\r
123 #\r
124 if IsToPackage:\r
125 self.DecToPackage()\r
126 \r
127 ## Load Dec file\r
128 #\r
129 # Load the file if it exists\r
130 #\r
131 # @param Filename: Input value for filename of Dec file\r
132 #\r
133 def LoadDecFile(self, Filename):\r
134 #\r
135 # Insert a record for file\r
136 #\r
137 Filename = NormPath(Filename)\r
138 self.Identification.FileFullPath = Filename\r
139 (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)\r
140 self.FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_DEC)\r
141 \r
142 #\r
143 # Init DecTable\r
144 #\r
145 #self.TblDec.Table = "Dec%s" % self.FileID\r
146 #self.TblDec.Create()\r
147 \r
148 #\r
149 # Init common datas\r
150 #\r
151 IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \\r
152 [], [], TAB_UNKNOWN, [], [], []\r
153 LineNo = 0\r
154 \r
155 #\r
156 # Parse file content\r
157 #\r
158 IsFindBlockComment = False\r
159 ReservedLine = ''\r
160 for Line in open(Filename, 'r'):\r
161 LineNo = LineNo + 1\r
162 #\r
163 # Remove comment block\r
164 #\r
165 if Line.find(TAB_COMMENT_R8_START) > -1:\r
166 ReservedLine = GetSplitValueList(Line, TAB_COMMENT_R8_START, 1)[0]\r
167 IsFindBlockComment = True\r
168 if Line.find(TAB_COMMENT_R8_END) > -1:\r
169 Line = ReservedLine + GetSplitValueList(Line, TAB_COMMENT_R8_END, 1)[1]\r
170 ReservedLine = ''\r
171 IsFindBlockComment = False\r
172 if IsFindBlockComment:\r
173 continue\r
174\r
175 #\r
176 # Remove comments at tail and remove spaces again\r
177 #\r
178 Line = CleanString(Line)\r
179 if Line == '':\r
180 continue\r
181 \r
182 #\r
183 # Find a new section tab\r
184 # First insert previous section items\r
185 # And then parse the content of the new section\r
186 #\r
187 if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):\r
188 #\r
189 # Insert items data of previous section\r
190 #\r
191 Model = Section[CurrentSection.upper()]\r
192 InsertSectionItemsIntoDatabase(self.TblDec, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)\r
193\r
194 #\r
195 # Parse the new section\r
196 #\r
197 SectionItemList = []\r
198 ArchList = []\r
199 ThirdList = []\r
200 \r
201 CurrentSection = ''\r
202 LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)\r
203 for Item in LineList:\r
204 ItemList = GetSplitValueList(Item, TAB_SPLIT)\r
205 if CurrentSection == '':\r
206 CurrentSection = ItemList[0]\r
207 else:\r
208 if CurrentSection != ItemList[0]:\r
209 EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
210 if CurrentSection.upper() not in self.KeyList:\r
211 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
212 ItemList.append('')\r
213 ItemList.append('')\r
214 if len(ItemList) > 5:\r
215 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
216 else:\r
217 if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:\r
218 EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
219 ArchList.append(ItemList[1].upper())\r
220 ThirdList.append(ItemList[2])\r
221\r
222 continue\r
223 \r
224 #\r
225 # Not in any defined section\r
226 #\r
227 if CurrentSection == TAB_UNKNOWN:\r
228 ErrorMsg = "%s is not in any defined section" % Line\r
229 EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
230\r
231 #\r
232 # Add a section item\r
233 #\r
234 SectionItemList.append([Line, LineNo])\r
235 # End of parse\r
236 #End of For\r
237 \r
238 #\r
239 # Insert items data of last section\r
240 #\r
241 Model = Section[CurrentSection.upper()]\r
242 InsertSectionItemsIntoDatabase(self.TblDec, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)\r
243 \r
244 #\r
245 # Replace all DEFINE macros with its actual values\r
246 #\r
247 ParseDefineMacro2(self.TblDec, self.RecordSet, GlobalData.gGlobalDefines)\r
248\r
249 ## Transfer to Package Object\r
250 # \r
251 # Transfer all contents of a Dec file to a standard Package Object\r
252 #\r
253 def DecToPackage(self):\r
254 #\r
255 # Init global information for the file\r
256 #\r
257 ContainerFile = self.Identification.FileFullPath\r
258 \r
259 #\r
260 # Generate Package Header\r
261 #\r
262 self.GenPackageHeader(ContainerFile)\r
263 \r
264 #\r
265 # Generate Includes\r
266 #\r
267 self.GenIncludes(ContainerFile)\r
268\r
269 #\r
270 # Generate Guids\r
271 #\r
272 self.GenGuidProtocolPpis(DataType.TAB_GUIDS, ContainerFile)\r
273\r
274 #\r
275 # Generate Protocols\r
276 #\r
277 self.GenGuidProtocolPpis(DataType.TAB_PROTOCOLS, ContainerFile)\r
278\r
279 #\r
280 # Generate Ppis\r
281 #\r
282 self.GenGuidProtocolPpis(DataType.TAB_PPIS, ContainerFile)\r
283 \r
284 #\r
285 # Generate LibraryClasses\r
286 #\r
287 self.GenLibraryClasses(ContainerFile)\r
288 \r
289 #\r
290 # Generate Pcds\r
291 #\r
292 self.GenPcds(ContainerFile)\r
293 \r
294 ## Get Package Header\r
295 #\r
296 # Gen Package Header of Dec as <Key> = <Value>\r
297 #\r
298 # @param ContainerFile: The Dec file full path \r
299 #\r
300 def GenPackageHeader(self, ContainerFile):\r
301 EdkLogger.debug(2, "Generate PackageHeader ...")\r
302 #\r
303 # Update all defines item in database\r
304 #\r
305 RecordSet = self.RecordSet[MODEL_META_DATA_HEADER]\r
306 for Record in RecordSet:\r
307 ValueList = GetSplitValueList(Record[0], TAB_EQUAL_SPLIT)\r
308 if len(ValueList) != 2:\r
309 RaiseParserError(Record[0], 'Defines', ContainerFile, '<Key> = <Value>', Record[2])\r
310 ID, Value1, Value2, Arch, LineNo = Record[3], ValueList[0], ValueList[1], Record[1], Record[2]\r
311 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
312 where ID = %s""" % (self.TblDec.Table, ConvertToSqlString2(Value1), ConvertToSqlString2(Value2), ID)\r
313 self.TblDec.Exec(SqlCommand)\r
314 \r
315 #\r
316 # Get detailed information\r
317 #\r
318 for Arch in self.SupArchList:\r
319 PackageHeader = PackageHeaderClass()\r
320 \r
321 PackageHeader.Name = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_NAME, Arch, self.FileID)[0]\r
322 PackageHeader.Guid = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_GUID, Arch, self.FileID)[0]\r
323 PackageHeader.Version = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_VERSION, Arch, self.FileID)[0]\r
324 PackageHeader.FileName = self.Identification.FileName\r
325 PackageHeader.FullPath = self.Identification.FileFullPath\r
326 PackageHeader.DecSpecification = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_DEC_SPECIFICATION, Arch, self.FileID)[0]\r
327 \r
328 self.Package.Header[Arch] = PackageHeader\r
329 \r
330 ## GenIncludes\r
331 #\r
332 # Gen Includes of Dec\r
333 # \r
334 #\r
335 # @param ContainerFile: The Dec file full path \r
336 #\r
337 def GenIncludes(self, ContainerFile):\r
338 EdkLogger.debug(2, "Generate %s ..." % TAB_INCLUDES)\r
339 Includes = {}\r
340 #\r
341 # Get all Includes\r
342 #\r
343 RecordSet = self.RecordSet[MODEL_EFI_INCLUDE]\r
344 \r
345 #\r
346 # Go through each arch\r
347 #\r
348 for Arch in self.SupArchList:\r
349 for Record in RecordSet:\r
350 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
351 MergeArches(Includes, Record[0], Arch)\r
352\r
353 for Key in Includes.keys():\r
354 Include = IncludeClass()\r
355 Include.FilePath = NormPath(Key)\r
356 Include.SupArchList = Includes[Key]\r
357 self.Package.Includes.append(Include)\r
358 \r
359 ## GenPpis\r
360 #\r
361 # Gen Ppis of Dec\r
362 # <CName>=<GuidValue>\r
363 #\r
364 # @param ContainerFile: The Dec file full path \r
365 #\r
366 def GenGuidProtocolPpis(self, Type, ContainerFile):\r
367 EdkLogger.debug(2, "Generate %s ..." % Type)\r
368 Lists = {}\r
369 #\r
370 # Get all Items\r
371 #\r
372 RecordSet = self.RecordSet[Section[Type.upper()]]\r
373 \r
374 #\r
375 # Go through each arch\r
376 #\r
377 for Arch in self.SupArchList:\r
378 for Record in RecordSet:\r
379 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
380 (Name, Value) = GetGuidsProtocolsPpisOfDec(Record[0], Type, ContainerFile, Record[2])\r
381 MergeArches(Lists, (Name, Value), Arch)\r
382 if self.IsToDatabase:\r
383 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
384 where ID = %s""" % (self.TblDec.Table, ConvertToSqlString2(Name), ConvertToSqlString2(Value), Record[3])\r
385 self.TblDec.Exec(SqlCommand)\r
386 \r
387 ListMember = None\r
388 if Type == TAB_GUIDS:\r
389 ListMember = self.Package.GuidDeclarations\r
390 elif Type == TAB_PROTOCOLS:\r
391 ListMember = self.Package.ProtocolDeclarations\r
392 elif Type == TAB_PPIS:\r
393 ListMember = self.Package.PpiDeclarations\r
394 \r
395 for Key in Lists.keys():\r
396 ListClass = GuidProtocolPpiCommonClass()\r
397 ListClass.CName = Key[0]\r
398 ListClass.Guid = Key[1]\r
399 ListClass.SupArchList = Lists[Key]\r
400 ListMember.append(ListClass)\r
401 \r
402 \r
403 ## GenLibraryClasses\r
404 #\r
405 # Gen LibraryClasses of Dec\r
406 # <CName>=<GuidValue>\r
407 #\r
408 # @param ContainerFile: The Dec file full path \r
409 #\r
410 def GenLibraryClasses(self, ContainerFile):\r
411 EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)\r
412 LibraryClasses = {}\r
413 #\r
414 # Get all Guids\r
415 #\r
416 RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_CLASS]\r
417 \r
418 #\r
419 # Go through each arch\r
420 #\r
421 for Arch in self.SupArchList:\r
422 for Record in RecordSet:\r
423 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
424 List = GetSplitValueList(Record[0], DataType.TAB_VALUE_SPLIT)\r
425 if len(List) != 2:\r
426 RaiseParserError(Record[0], 'LibraryClasses', ContainerFile, '<LibraryClassName>|<LibraryClassInstanceFilename>', Record[2])\r
427 else:\r
428 CheckFileExist(self.Identification.FileRelativePath, List[1], ContainerFile, 'LibraryClasses', Record[0])\r
429 MergeArches(LibraryClasses, (List[0], List[1]), Arch)\r
430 if self.IsToDatabase:\r
431 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
432 where ID = %s""" % (self.TblDec.Table, ConvertToSqlString2(List[0]), ConvertToSqlString2(List[1]), SUP_MODULE_LIST_STRING, Record[3])\r
433 self.TblDec.Exec(SqlCommand)\r
434\r
435 \r
436 for Key in LibraryClasses.keys():\r
437 LibraryClass = LibraryClassClass()\r
438 LibraryClass.LibraryClass = Key[0]\r
439 LibraryClass.RecommendedInstance = NormPath(Key[1])\r
440 LibraryClass.SupModuleList = SUP_MODULE_LIST\r
441 LibraryClass.SupArchList = LibraryClasses[Key]\r
442 self.Package.LibraryClassDeclarations.append(LibraryClass)\r
443 \r
444 ## GenPcds\r
445 #\r
446 # Gen Pcds of Dec\r
447 # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token>\r
448 #\r
449 # @param ContainerFile: The Dec file full path \r
450 #\r
451 def GenPcds(self, ContainerFile):\r
452 EdkLogger.debug(2, "Generate %s ..." % TAB_PCDS)\r
453 Pcds = {}\r
454 PcdToken = {}\r
455 #\r
456 # Get all Guids\r
457 #\r
458 RecordSet1 = self.RecordSet[MODEL_PCD_FIXED_AT_BUILD]\r
459 RecordSet2 = self.RecordSet[MODEL_PCD_PATCHABLE_IN_MODULE]\r
460 RecordSet3 = self.RecordSet[MODEL_PCD_FEATURE_FLAG]\r
461 RecordSet4 = self.RecordSet[MODEL_PCD_DYNAMIC_EX]\r
462 RecordSet5 = self.RecordSet[MODEL_PCD_DYNAMIC]\r
463 \r
464 #\r
465 # Go through each arch\r
466 #\r
467 for Arch in self.SupArchList:\r
468 for Record in RecordSet1:\r
469 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
470 (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2])\r
471 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
472 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
473 for Record in RecordSet2:\r
474 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
475 (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2])\r
476 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
477 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
478 for Record in RecordSet3:\r
479 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
480 (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2])\r
481 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
482 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
483 for Record in RecordSet4:\r
484 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
485 (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2])\r
486 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
487 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
488 for Record in RecordSet5:\r
489 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
490 (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC, ContainerFile, Record[2])\r
491 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
492 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
493 #\r
494 # Update to database\r
495 #\r
496 if self.IsToDatabase:\r
497 for Key in PcdToken.keys():\r
498 SqlCommand = """update %s set Value2 = '%s' where ID = %s""" % (self.TblDec.Table, ".".join((PcdToken[Key][0], PcdToken[Key][1])), Key)\r
499 self.TblDec.Exec(SqlCommand)\r
500\r
501 for Key in Pcds.keys():\r
502 Pcd = PcdClass()\r
503 Pcd.CName = Key[1]\r
504 Pcd.Token = Key[4]\r
505 Pcd.TokenSpaceGuidCName = Key[0]\r
506 Pcd.DatumType = Key[3]\r
507 Pcd.DefaultValue = Key[2]\r
508 Pcd.ItemType = Key[5]\r
509 Pcd.SupArchList = Pcds[Key]\r
510 self.Package.PcdDeclarations.append(Pcd)\r
511 \r
512 ## Show detailed information of Package\r
513 #\r
514 # Print all members and their values of Package class\r
515 #\r
516 def ShowPackage(self):\r
517 M = self.Package\r
518 for Arch in M.Header.keys():\r
519 print '\nArch =', Arch\r
520 print 'Filename =', M.Header[Arch].FileName\r
521 print 'FullPath =', M.Header[Arch].FullPath\r
522 print 'BaseName =', M.Header[Arch].Name\r
523 print 'Guid =', M.Header[Arch].Guid\r
524 print 'Version =', M.Header[Arch].Version\r
525 print 'DecSpecification =', M.Header[Arch].DecSpecification\r
526 print '\nIncludes =', M.Includes\r
527 for Item in M.Includes:\r
528 print Item.FilePath, Item.SupArchList\r
529 print '\nGuids =', M.GuidDeclarations\r
530 for Item in M.GuidDeclarations:\r
531 print Item.CName, Item.Guid, Item.SupArchList\r
532 print '\nProtocols =', M.ProtocolDeclarations\r
533 for Item in M.ProtocolDeclarations:\r
534 print Item.CName, Item.Guid, Item.SupArchList\r
535 print '\nPpis =', M.PpiDeclarations\r
536 for Item in M.PpiDeclarations:\r
537 print Item.CName, Item.Guid, Item.SupArchList\r
538 print '\nLibraryClasses =', M.LibraryClassDeclarations\r
539 for Item in M.LibraryClassDeclarations:\r
540 print Item.LibraryClass, Item.RecommendedInstance, Item.SupModuleList, Item.SupArchList\r
541 print '\nPcds =', M.PcdDeclarations\r
542 for Item in M.PcdDeclarations:\r
543 print 'CName=', Item.CName, 'TokenSpaceGuidCName=', Item.TokenSpaceGuidCName, 'DefaultValue=', Item.DefaultValue, 'ItemType=', Item.ItemType, 'Token=', Item.Token, 'DatumType=', Item.DatumType, Item.SupArchList\r
544\r
545##\r
546#\r
547# This acts like the main() function for the script, unless it is 'import'ed into another\r
548# script.\r
549#\r
550if __name__ == '__main__':\r
551 EdkLogger.Initialize()\r
552 EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
553 \r
554 W = os.getenv('WORKSPACE')\r
555 F = os.path.join(W, 'Nt32Pkg/Nt32Pkg.dec')\r
556\r
557 Db = Database.Database('Dec.db')\r
558 Db.InitDatabase()\r
559 \r
560 P = Dec(os.path.normpath(F), True, True, W, Db)\r
561 P.ShowPackage()\r
562 \r
563 Db.Close()\r