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