BaseTools: cleanup class heirarchy
[mirror_edk2.git] / BaseTools / Source / Python / Common / DscClassObject.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to define each component of DSC file\r
3#\r
f0dc69e6 4# Copyright (c) 2007 - 2016, 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
18import EdkLogger as EdkLogger\r
19import Database\r
20from String import *\r
21from Parsing import *\r
22from DataType import *\r
23from Identification import *\r
24from Dictionary import *\r
25from CommonDataClass.PlatformClass import *\r
26from CommonDataClass.CommonClass import SkuInfoClass\r
27from BuildToolError import *\r
28from Misc import sdict\r
29import GlobalData\r
30from Table.TableDsc import TableDsc\r
1be2ed90 31from Common.LongFilePathSupport import OpenLongFilePath as open\r
30fdf114
LG
32\r
33#\r
34# Global variable\r
35#\r
36Section = {TAB_UNKNOWN.upper() : MODEL_UNKNOWN,\r
37 TAB_DSC_DEFINES.upper() : MODEL_META_DATA_HEADER,\r
38 TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,\r
39 TAB_SKUIDS.upper() : MODEL_EFI_SKU_ID,\r
40 TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,\r
41 TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\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_EX_DEFAULT_NULL.upper() : MODEL_PCD_DYNAMIC_EX_DEFAULT,\r
47 TAB_PCDS_DYNAMIC_EX_VPD_NULL.upper() : MODEL_PCD_DYNAMIC_EX_VPD,\r
48 TAB_PCDS_DYNAMIC_EX_HII_NULL.upper() : MODEL_PCD_DYNAMIC_EX_HII,\r
49 TAB_PCDS_DYNAMIC_NULL.upper() : MODEL_PCD_DYNAMIC,\r
50 TAB_PCDS_DYNAMIC_DEFAULT_NULL.upper() : MODEL_PCD_DYNAMIC_DEFAULT,\r
51 TAB_PCDS_DYNAMIC_VPD_NULL.upper() : MODEL_PCD_DYNAMIC_VPD,\r
52 TAB_PCDS_DYNAMIC_HII_NULL.upper() : MODEL_PCD_DYNAMIC_HII,\r
53 TAB_COMPONENTS.upper() : MODEL_META_DATA_COMPONENT,\r
54 TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION\r
55 }\r
56\r
30fdf114
LG
57## Dsc\r
58#\r
59# This class defined the structure used in Dsc object\r
60#\r
30fdf114
LG
61# @param Ffilename: Input value for Ffilename of Inf file, default is None\r
62# @param IsMergeAllArches: Input value for IsMergeAllArches\r
63# True is to merge all arches\r
64# Fales is not to merge all arches\r
65# default is False\r
66# @param IsToPlatform: Input value for IsToPlatform\r
67# True is to transfer to ModuleObject automatically\r
68# False is not to transfer to ModuleObject automatically\r
69# default is False\r
70# @param WorkspaceDir: Input value for current workspace directory, default is None\r
71#\r
72# @var _NullClassIndex: To store value for _NullClassIndex, default is 0\r
73# @var Identification: To store value for Identification, it is a structure as Identification\r
74# @var Defines: To store value for Defines, it is a structure as DscDefines\r
75# @var Contents: To store value for Contents, it is a structure as DscContents\r
76# @var UserExtensions: To store value for UserExtensions\r
77# @var Platform: To store value for Platform, it is a structure as PlatformClass\r
78# @var WorkspaceDir: To store value for WorkspaceDir\r
79# @var KeyList: To store value for KeyList, a list for all Keys used in Dec\r
80#\r
0b560b98 81class Dsc(object):\r
30fdf114
LG
82 _NullClassIndex = 0\r
83\r
d40b2ee6 84 def __init__(self, Filename=None, IsToDatabase=False, IsToPlatform=False, WorkspaceDir=None, Database=None):\r
30fdf114
LG
85 self.Identification = Identification()\r
86 self.Platform = PlatformClass()\r
87 self.UserExtensions = ''\r
88 self.WorkspaceDir = WorkspaceDir\r
89 self.IsToDatabase = IsToDatabase\r
f0dc69e6
YZ
90 if Database:\r
91 self.Cur = Database.Cur\r
92 self.TblFile = Database.TblFile\r
93 self.TblDsc = Database.TblDsc\r
30fdf114
LG
94\r
95 self.KeyList = [\r
96 TAB_SKUIDS, TAB_LIBRARIES, TAB_LIBRARY_CLASSES, TAB_BUILD_OPTIONS, TAB_PCDS_FIXED_AT_BUILD_NULL, \\r
97 TAB_PCDS_PATCHABLE_IN_MODULE_NULL, TAB_PCDS_FEATURE_FLAG_NULL, \\r
98 TAB_PCDS_DYNAMIC_DEFAULT_NULL, TAB_PCDS_DYNAMIC_HII_NULL, TAB_PCDS_DYNAMIC_VPD_NULL, \\r
99 TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL, TAB_PCDS_DYNAMIC_EX_HII_NULL, TAB_PCDS_DYNAMIC_EX_VPD_NULL, \\r
100 TAB_COMPONENTS, TAB_DSC_DEFINES\r
101 ]\r
102\r
103 self.PcdToken = {}\r
104\r
105 #\r
106 # Upper all KEYs to ignore case sensitive when parsing\r
107 #\r
108 self.KeyList = map(lambda c: c.upper(), self.KeyList)\r
109\r
110 #\r
111 # Init RecordSet\r
112 #\r
113# self.RecordSet = {}\r
114# for Key in self.KeyList:\r
115# self.RecordSet[Section[Key]] = []\r
116\r
117 #\r
118 # Load Dsc file if filename is not None\r
119 #\r
4231a819 120 if Filename is not None:\r
30fdf114
LG
121 self.LoadDscFile(Filename)\r
122\r
123 #\r
124 # Transfer to Platform Object if IsToPlatform is True\r
125 #\r
126 if IsToPlatform:\r
127 self.DscToPlatform()\r
128\r
129 ## Transfer to Platform Object\r
130 #\r
131 # Transfer all contents of an Inf file to a standard Module Object\r
132 #\r
133 def DscToPlatform(self):\r
134 #\r
135 # Init global information for the file\r
136 #\r
137 ContainerFile = self.Identification.FileFullPath\r
138\r
139 #\r
140 # Generate Platform Header\r
141 #\r
142 self.GenPlatformHeader(ContainerFile)\r
143\r
144 #\r
145 # Generate BuildOptions\r
146 #\r
147 self.GenBuildOptions(ContainerFile)\r
148\r
149 #\r
150 # Generate SkuInfos\r
151 #\r
152 self.GenSkuInfos(ContainerFile)\r
153\r
154 #\r
155 # Generate Libraries\r
156 #\r
157 self.GenLibraries(ContainerFile)\r
158\r
159 #\r
160 # Generate LibraryClasses\r
161 #\r
162 self.GenLibraryClasses(ContainerFile)\r
163\r
164 #\r
165 # Generate Pcds\r
166 #\r
167 self.GenPcds(DataType.TAB_PCDS_FIXED_AT_BUILD, ContainerFile)\r
168 self.GenPcds(DataType.TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile)\r
169 self.GenFeatureFlagPcds(DataType.TAB_PCDS_FEATURE_FLAG, ContainerFile)\r
170 self.GenDynamicDefaultPcds(DataType.TAB_PCDS_DYNAMIC_DEFAULT, ContainerFile)\r
171 self.GenDynamicDefaultPcds(DataType.TAB_PCDS_DYNAMIC_EX_DEFAULT, ContainerFile)\r
172 self.GenDynamicHiiPcds(DataType.TAB_PCDS_DYNAMIC_HII, ContainerFile)\r
173 self.GenDynamicHiiPcds(DataType.TAB_PCDS_DYNAMIC_EX_HII, ContainerFile)\r
174 self.GenDynamicVpdPcds(DataType.TAB_PCDS_DYNAMIC_VPD, ContainerFile)\r
175 self.GenDynamicVpdPcds(DataType.TAB_PCDS_DYNAMIC_EX_VPD, ContainerFile)\r
176\r
177 #\r
178 # Generate Components\r
179 #\r
180 self.GenComponents(ContainerFile)\r
181\r
182 #\r
183 # Update to database\r
184 #\r
185 if self.IsToDatabase:\r
186 for Key in self.PcdToken.keys():\r
187 SqlCommand = """update %s set Value2 = '%s' where ID = %s""" % (self.TblDsc.Table, ".".join((self.PcdToken[Key][0], self.PcdToken[Key][1])), Key)\r
188 self.TblDsc.Exec(SqlCommand)\r
189 #End of DscToPlatform\r
190\r
191 ## Get Platform Header\r
192 #\r
193 # Gen Platform Header of Dsc as <Key> = <Value>\r
194 #\r
195 # @param ContainerFile: The Dsc file full path\r
196 #\r
197 def GenPlatformHeader(self, ContainerFile):\r
198 EdkLogger.debug(2, "Generate PlatformHeader ...")\r
199 #\r
200 # Update all defines item in database\r
201 #\r
202 SqlCommand = """select ID, Value1, Arch, StartLine from %s\r
203 where Model = %s\r
204 and BelongsToFile = %s\r
205 and Enabled > -1""" % (self.TblDsc.Table, MODEL_META_DATA_HEADER, self.FileID)\r
206 RecordSet = self.TblDsc.Exec(SqlCommand)\r
207 for Record in RecordSet:\r
208 ValueList = GetSplitValueList(Record[1], TAB_EQUAL_SPLIT)\r
209 if len(ValueList) != 2:\r
210 RaiseParserError(Record[1], 'Defines', ContainerFile, '<Key> = <Value>', Record[3])\r
211 ID, Value1, Value2, Arch = Record[0], ValueList[0], ValueList[1], Record[2]\r
212 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
213 where ID = %s""" % (self.TblDsc.Table, ConvertToSqlString2(Value1), ConvertToSqlString2(Value2), ID)\r
214 self.TblDsc.Exec(SqlCommand)\r
215\r
216 #\r
217 # Get detailed information\r
218 #\r
219 for Arch in DataType.ARCH_LIST:\r
220 PlatformHeader = PlatformHeaderClass()\r
221\r
222 PlatformHeader.Name = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_PLATFORM_NAME, Arch, self.FileID)[0]\r
223 PlatformHeader.Guid = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_PLATFORM_GUID, Arch, self.FileID)[0]\r
224 PlatformHeader.Version = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_PLATFORM_VERSION, Arch, self.FileID)[0]\r
225 PlatformHeader.FileName = self.Identification.FileName\r
226 PlatformHeader.FullPath = self.Identification.FileFullPath\r
227 PlatformHeader.DscSpecification = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_DSC_SPECIFICATION, Arch, self.FileID)[0]\r
228\r
229 PlatformHeader.SkuIdName = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_SKUID_IDENTIFIER, Arch, self.FileID)\r
230 PlatformHeader.SupArchList = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES, Arch, self.FileID)\r
231 PlatformHeader.BuildTargets = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_BUILD_TARGETS, Arch, self.FileID)\r
232 PlatformHeader.OutputDirectory = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_OUTPUT_DIRECTORY, Arch, self.FileID)[0])\r
233 PlatformHeader.BuildNumber = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_BUILD_NUMBER, Arch, self.FileID)[0]\r
234 PlatformHeader.MakefileName = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_MAKEFILE_NAME, Arch, self.FileID)[0]\r
235\r
236 PlatformHeader.BsBaseAddress = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_BS_BASE_ADDRESS, Arch, self.FileID)[0]\r
237 PlatformHeader.RtBaseAddress = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_RT_BASE_ADDRESS, Arch, self.FileID)[0]\r
238\r
239 self.Platform.Header[Arch] = PlatformHeader\r
240 Fdf = PlatformFlashDefinitionFileClass()\r
241 Fdf.FilePath = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_FLASH_DEFINITION, Arch, self.FileID)[0])\r
242 self.Platform.FlashDefinitionFile = Fdf\r
f0dc69e6
YZ
243 Prebuild = BuildScriptClass()\r
244 Prebuild.FilePath = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_PREBUILD, Arch, self.FileID)[0])\r
245 self.Platform.Prebuild = Prebuild\r
246 Postbuild = BuildScriptClass()\r
247 Postbuild.FilePath = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_POSTBUILD, Arch, self.FileID)[0])\r
248 self.Platform.Postbuild = Postbuild\r
30fdf114
LG
249\r
250 ## GenBuildOptions\r
251 #\r
252 # Gen BuildOptions of Dsc\r
253 # [<Family>:]<ToolFlag>=Flag\r
254 #\r
255 # @param ContainerFile: The Dsc file full path\r
256 #\r
257 def GenBuildOptions(self, ContainerFile):\r
258 EdkLogger.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS)\r
259 BuildOptions = {}\r
260 #\r
261 # Get all include files\r
262 #\r
263 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_META_DATA_BUILD_OPTION, self.FileID)\r
264\r
265 #\r
266 # Get all BuildOptions\r
267 #\r
268 RecordSet = QueryDscItem(self.TblDsc, MODEL_META_DATA_BUILD_OPTION, -1, self.FileID)\r
269\r
270 #\r
271 # Go through each arch\r
272 #\r
273 for Arch in DataType.ARCH_LIST:\r
274 for IncludeFile in IncludeFiles:\r
275 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
276 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_BUILD_OPTIONS, '', IncludeFile[2])\r
277 for NewItem in open(Filename, 'r').readlines():\r
278 if CleanString(NewItem) == '':\r
279 continue\r
280 (Family, ToolChain, Flag) = GetBuildOption(NewItem, Filename, -1)\r
281 MergeArches(BuildOptions, (Family, ToolChain, Flag), Arch)\r
282\r
283 for Record in RecordSet:\r
284 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
285 (Family, ToolChain, Flag) = GetBuildOption(Record[0], ContainerFile, Record[2])\r
286 MergeArches(BuildOptions, (Family, ToolChain, Flag), Arch)\r
287 #\r
288 # Update to Database\r
289 #\r
290 if self.IsToDatabase:\r
291 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
292 where ID = %s""" % (self.TblDsc.Table, ConvertToSqlString2(Family), ConvertToSqlString2(ToolChain), ConvertToSqlString2(Flag), Record[3])\r
293 self.TblDsc.Exec(SqlCommand)\r
294\r
295 for Key in BuildOptions.keys():\r
296 BuildOption = BuildOptionClass(Key[0], Key[1], Key[2])\r
297 BuildOption.SupArchList = BuildOptions[Key]\r
298 self.Platform.BuildOptions.BuildOptionList.append(BuildOption)\r
299\r
300 ## GenSkuInfos\r
301 #\r
302 # Gen SkuInfos of Dsc\r
303 # <Integer>|<UiName>\r
304 #\r
305 # @param ContainerFile: The Dsc file full path\r
306 #\r
307 def GenSkuInfos(self, ContainerFile):\r
308 EdkLogger.debug(2, "Generate %s ..." % TAB_SKUIDS)\r
309 #\r
310 # SkuIds\r
311 # <Integer>|<UiName>\r
312 #\r
313 self.Platform.SkuInfos.SkuInfoList['DEFAULT'] = '0'\r
314\r
315 #\r
316 # Get all include files\r
317 #\r
318 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_EFI_SKU_ID, self.FileID)\r
319\r
320 #\r
321 # Get all SkuInfos\r
322 #\r
323 RecordSet = QueryDscItem(self.TblDsc, MODEL_EFI_SKU_ID, -1, self.FileID)\r
324\r
325 #\r
326 # Go through each arch\r
327 #\r
328 for Arch in DataType.ARCH_LIST:\r
329 for IncludeFile in IncludeFiles:\r
330 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
331 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_SKUIDS, '', IncludeFile[2])\r
332 for NewItem in open(Filename, 'r').readlines():\r
333 if CleanString(NewItem) == '':\r
334 continue\r
335 List = GetSplitValueList(NewItem)\r
336 if len(List) != 2:\r
337 RaiseParserError(NewItem, TAB_SKUIDS, Filename, '<Integer>|<UiName>')\r
338 else:\r
339 self.Platform.SkuInfos.SkuInfoList[List[1]] = List[0]\r
340\r
341 for Record in RecordSet:\r
342 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
343 List = GetSplitValueList(Record[0])\r
344 if len(List) != 2:\r
345 RaiseParserError(Record[0], TAB_SKUIDS, ContainerFile, '<Integer>|<UiName>')\r
346 else:\r
347 self.Platform.SkuInfos.SkuInfoList[List[1]] = List[0]\r
348 #\r
349 # Update to Database\r
350 #\r
351 if self.IsToDatabase:\r
352 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
353 where ID = %s""" % (self.TblDsc.Table, ConvertToSqlString2(List[0]), ConvertToSqlString2(List[1]), Record[3])\r
354 self.TblDsc.Exec(SqlCommand)\r
355\r
356 ## GenLibraries\r
357 #\r
358 # Gen Libraries of Dsc\r
359 # <PathAndFilename>\r
360 #\r
361 # @param ContainerFile: The Dsc file full path\r
362 #\r
363 def GenLibraries(self, ContainerFile):\r
364 EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARIES)\r
365 Libraries = {}\r
366 #\r
367 # Get all include files\r
368 #\r
369 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_EFI_LIBRARY_INSTANCE, self.FileID)\r
370\r
371 #\r
372 # Get all Libraries\r
373 #\r
374 RecordSet = QueryDscItem(self.TblDsc, MODEL_EFI_LIBRARY_INSTANCE, -1, self.FileID)\r
375\r
376 #\r
377 # Go through each arch\r
378 #\r
379 for Arch in DataType.ARCH_LIST:\r
380 for IncludeFile in IncludeFiles:\r
381 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
382 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_LIBRARIES, '', IncludeFile[2])\r
fd171542 383 if os.path.exists(Filename):\r
384 for NewItem in open(Filename, 'r').readlines():\r
385 if CleanString(NewItem) == '':\r
386 continue\r
387 MergeArches(Libraries, NewItem, Arch)\r
30fdf114
LG
388\r
389 for Record in RecordSet:\r
390 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
391 MergeArches(Libraries, Record[0], Arch)\r
392\r
393 for Key in Libraries.keys():\r
394 Library = PlatformLibraryClass()\r
395 Library.FilePath = NormPath(Key)\r
396 Library.SupArchList = Libraries[Key]\r
397 self.Platform.Libraries.LibraryList.append(Library)\r
398\r
399 ## GenLibraryClasses\r
400 #\r
401 # Get LibraryClasses of Dsc\r
402 # <LibraryClassKeyWord>|<LibraryInstance>\r
403 #\r
404 # @param ContainerFile: The Dsc file full path\r
405 #\r
406 def GenLibraryClasses(self, ContainerFile):\r
407 EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)\r
408 LibraryClasses = {}\r
409 #\r
410 # Get all include files\r
411 #\r
412 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_EFI_LIBRARY_CLASS, self.FileID)\r
413\r
414 #\r
415 # Get all LibraryClasses\r
416 #\r
417 RecordSet = QueryDscItem(self.TblDsc, MODEL_EFI_LIBRARY_CLASS, -1, self.FileID)\r
418\r
419 #\r
420 # Go through each arch\r
421 #\r
422 for Arch in DataType.ARCH_LIST:\r
423 for IncludeFile in IncludeFiles:\r
424 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
425 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_LIBRARY_CLASSES, '', IncludeFile[2])\r
426 for NewItem in open(Filename, 'r').readlines():\r
427 if CleanString(NewItem) == '':\r
428 continue\r
429 MergeArches(LibraryClasses, GetLibraryClass([NewItem, IncludeFile[4]], Filename, self.WorkspaceDir, -1), Arch)\r
430\r
431 for Record in RecordSet:\r
432 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
433 (LibClassName, LibClassIns, SupModelList) = GetLibraryClass([Record[0], Record[4]], ContainerFile, self.WorkspaceDir, Record[2])\r
434 MergeArches(LibraryClasses, (LibClassName, LibClassIns, SupModelList), Arch)\r
435 #\r
436 # Update to Database\r
437 #\r
438 if self.IsToDatabase:\r
439 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
440 where ID = %s""" % (self.TblDsc.Table, ConvertToSqlString2(LibClassName), ConvertToSqlString2(LibClassIns), ConvertToSqlString2(SupModelList), Record[3])\r
441 self.TblDsc.Exec(SqlCommand)\r
442\r
443 for Key in LibraryClasses.keys():\r
444 Library = PlatformLibraryClass()\r
445 Library.Name = Key[0]\r
446 Library.FilePath = NormPath(Key[1])\r
447 Library.SupModuleList = GetSplitValueList(Key[2])\r
448 Library.SupArchList = LibraryClasses[Key]\r
449 self.Platform.LibraryClasses.LibraryList.append(Library)\r
450\r
451 ## Gen Pcds\r
452 #\r
453 # Gen Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]\r
454 #\r
455 # @param Type: The type of Pcd\r
456 # @param ContainerFile: The file which describes the pcd, used for error report\r
457 #\r
d40b2ee6 458 def GenPcds(self, Type='', ContainerFile=''):\r
30fdf114
LG
459 Pcds = {}\r
460 if Type == DataType.TAB_PCDS_PATCHABLE_IN_MODULE:\r
461 Model = MODEL_PCD_PATCHABLE_IN_MODULE\r
462 elif Type == DataType.TAB_PCDS_FIXED_AT_BUILD:\r
463 Model = MODEL_PCD_FIXED_AT_BUILD\r
464 else:\r
465 pass\r
466 EdkLogger.debug(2, "Generate %s ..." % Type)\r
467\r
468 #\r
469 # Get all include files\r
470 #\r
471 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model, self.FileID)\r
472\r
473 #\r
474 # Get all Pcds\r
475 #\r
476 RecordSet = QueryDscItem(self.TblDsc, Model, -1, self.FileID)\r
477\r
478 #\r
479 # Go through each arch\r
480 #\r
481 for Arch in DataType.ARCH_LIST:\r
482 for IncludeFile in IncludeFiles:\r
483 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
484 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
485 for NewItem in open(Filename, 'r').readlines():\r
486 if CleanString(NewItem) == '':\r
487 continue\r
488 (TokenName, TokenGuidCName, Value, DatumType, MaxDatumSize, Type) = GetPcd(NewItem, Type, Filename, -1)\r
489 MergeArches(Pcds, (TokenName, TokenGuidCName, Value, DatumType, MaxDatumSize, Type), Arch)\r
490 self.PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
491\r
492 for Record in RecordSet:\r
493 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
494 (TokenName, TokenGuidCName, Value, DatumType, MaxDatumSize, Type) = GetPcd(Record[0], Type, ContainerFile, Record[2])\r
495 MergeArches(Pcds, (TokenName, TokenGuidCName, Value, DatumType, MaxDatumSize, Type), Arch)\r
496 self.PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
497\r
498 for Key in Pcds:\r
499 Pcd = PcdClass(Key[0], '', Key[1], Key[3], Key[4], Key[2], Key[5], [], {}, [])\r
500 Pcd.SupArchList = Pcds[Key]\r
501 self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
502\r
503 ## Gen FeatureFlagPcds\r
504 #\r
505 # Gen FeatureFlagPcds of Dsc file as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE\r
506 #\r
507 # @param Type: The type of Pcd\r
508 # @param ContainerFile: The file which describes the pcd, used for error report\r
509 #\r
d40b2ee6 510 def GenFeatureFlagPcds(self, Type='', ContainerFile=''):\r
30fdf114
LG
511 Pcds = {}\r
512 if Type == DataType.TAB_PCDS_FEATURE_FLAG:\r
513 Model = MODEL_PCD_FEATURE_FLAG\r
514 else:\r
515 pass\r
516 EdkLogger.debug(2, "Generate %s ..." % Type)\r
517\r
518 #\r
519 # Get all include files\r
520 #\r
521 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model, self.FileID)\r
522\r
523 #\r
524 # Get all FeatureFlagPcds\r
525 #\r
526 RecordSet = QueryDscItem(self.TblDsc, Model, -1, self.FileID)\r
527\r
528 #\r
529 # Go through each arch\r
530 #\r
531 for Arch in DataType.ARCH_LIST:\r
532 for IncludeFile in IncludeFiles:\r
533 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
534 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
535 for NewItem in open(Filename, 'r').readlines():\r
536 if CleanString(NewItem) == '':\r
537 continue\r
538 (TokenName, TokenGuidCName, Value, Type) = GetFeatureFlagPcd(NewItem, Type, Filename, -1)\r
539 MergeArches(Pcds, (TokenName, TokenGuidCName, Value, Type), Arch)\r
540 self.PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
541\r
542 for Record in RecordSet:\r
543 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
544 (TokenName, TokenGuidCName, Value, Type) = GetFeatureFlagPcd(Record[0], Type, ContainerFile, Record[2])\r
545 MergeArches(Pcds, (TokenName, TokenGuidCName, Value, Type), Arch)\r
546 self.PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
547\r
548 for Key in Pcds:\r
549 Pcd = PcdClass(Key[0], '', Key[1], '', '', Key[2], Key[3], [], {}, [])\r
550 Pcd.SupArchList = Pcds[Key]\r
551 self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
552\r
553 ## Gen DynamicDefaultPcds\r
554 #\r
555 # Gen DynamicDefaultPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]\r
556 #\r
557 # @param Type: The type of Pcd\r
558 # @param ContainerFile: The file which describes the pcd, used for error report\r
559 #\r
d40b2ee6 560 def GenDynamicDefaultPcds(self, Type='', ContainerFile=''):\r
30fdf114
LG
561 Pcds = {}\r
562 SkuInfoList = {}\r
563 if Type == DataType.TAB_PCDS_DYNAMIC_DEFAULT:\r
564 Model = MODEL_PCD_DYNAMIC_DEFAULT\r
565 elif Type == DataType.TAB_PCDS_DYNAMIC_EX_DEFAULT:\r
566 Model = MODEL_PCD_DYNAMIC_EX_DEFAULT\r
567 else:\r
568 pass\r
569 EdkLogger.debug(2, "Generate %s ..." % Type)\r
570\r
571 #\r
572 # Get all include files\r
573 #\r
574 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model, self.FileID)\r
575\r
576 #\r
577 # Get all DynamicDefaultPcds\r
578 #\r
579 RecordSet = QueryDscItem(self.TblDsc, Model, -1, self.FileID)\r
580\r
581 #\r
582 # Go through each arch\r
583 #\r
584 for Arch in DataType.ARCH_LIST:\r
585 for IncludeFile in IncludeFiles:\r
586 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
587 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
588 for NewItem in open(Filename, 'r').readlines():\r
589 if CleanString(NewItem) == '':\r
590 continue\r
591 (K1, K2, K3, K4, K5, K6) = GetDynamicDefaultPcd(NewItem, Type, Filename, -1)\r
d40b2ee6 592 MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, IncludeFile[4]), Arch)\r
30fdf114
LG
593 self.PcdToken[Record[3]] = (K2, K1)\r
594\r
595 for Record in RecordSet:\r
596 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
597 (K1, K2, K3, K4, K5, K6) = GetDynamicDefaultPcd(Record[0], Type, ContainerFile, Record[2])\r
d40b2ee6 598 MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, Record[4]), Arch)\r
30fdf114
LG
599 self.PcdToken[Record[3]] = (K2, K1)\r
600\r
601 for Key in Pcds:\r
602 (Status, SkuInfoList) = self.GenSkuInfoList(Key[6], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', '', Key[2])\r
603 if Status == False:\r
604 ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type)\r
d40b2ee6 605 EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError=EdkLogger.IsRaiseError)\r
30fdf114
LG
606 Pcd = PcdClass(Key[0], '', Key[1], Key[3], Key[4], Key[2], Key[5], [], SkuInfoList, [])\r
607 Pcd.SupArchList = Pcds[Key]\r
608 self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
609\r
610 ## Gen DynamicHiiPcds\r
611 #\r
612 # Gen DynamicHiiPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]\r
613 #\r
614 # @param Type: The type of Pcd\r
615 # @param ContainerFile: The file which describes the pcd, used for error report\r
616 #\r
d40b2ee6 617 def GenDynamicHiiPcds(self, Type='', ContainerFile=''):\r
30fdf114
LG
618 Pcds = {}\r
619 SkuInfoList = {}\r
620 if Type == DataType.TAB_PCDS_DYNAMIC_HII:\r
621 Model = MODEL_PCD_DYNAMIC_HII\r
622 elif Type == DataType.TAB_PCDS_DYNAMIC_EX_HII:\r
623 Model = MODEL_PCD_DYNAMIC_EX_HII\r
624 else:\r
625 pass\r
626 EdkLogger.debug(2, "Generate %s ..." % Type)\r
627\r
628 #\r
629 # Get all include files\r
630 #\r
631 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model, self.FileID)\r
632\r
633 #\r
634 # Get all DynamicHiiPcds\r
635 #\r
636 RecordSet = QueryDscItem(self.TblDsc, Model, -1, self.FileID)\r
637\r
638 #\r
639 # Go through each arch\r
640 #\r
641 for Arch in DataType.ARCH_LIST:\r
642 for IncludeFile in IncludeFiles:\r
643 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
644 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
645 for NewItem in open(Filename, 'r').readlines():\r
646 if CleanString(NewItem) == '':\r
647 continue\r
648 (K1, K2, K3, K4, K5, K6, K7, K8) = GetDynamicHiiPcd(NewItem, Type, Filename, -1)\r
d40b2ee6 649 MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, K7, K8, IncludeFile[4]), Arch)\r
30fdf114
LG
650 self.PcdToken[Record[3]] = (K2, K1)\r
651\r
652 for Record in RecordSet:\r
653 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
654 (K1, K2, K3, K4, K5, K6, K7, K8) = GetDynamicHiiPcd(Record[0], Type, ContainerFile, Record[2])\r
d40b2ee6 655 MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, K7, K8, Record[4]), Arch)\r
30fdf114
LG
656 self.PcdToken[Record[3]] = (K2, K1)\r
657\r
658 for Key in Pcds:\r
659 (Status, SkuInfoList) = self.GenSkuInfoList(Key[8], self.Platform.SkuInfos.SkuInfoList, Key[2], Key[3], Key[4], Key[5], '', '')\r
660 if Status == False:\r
661 ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type)\r
d40b2ee6 662 EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError=EdkLogger.IsRaiseError)\r
30fdf114
LG
663 Pcd = PcdClass(Key[0], '', Key[1], '', Key[6], Key[5], Key[7], [], SkuInfoList, [])\r
664 Pcd.SupArchList = Pcds[Key]\r
665 self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
666\r
667 ## Gen DynamicVpdPcds\r
668 #\r
669 # Gen DynamicVpdPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]\r
670 #\r
671 # @param Type: The type of Pcd\r
672 # @param ContainerFile: The file which describes the pcd, used for error report\r
673 #\r
d40b2ee6 674 def GenDynamicVpdPcds(self, Type='', ContainerFile=''):\r
30fdf114
LG
675 Pcds = {}\r
676 SkuInfoList = {}\r
677 if Type == DataType.TAB_PCDS_DYNAMIC_VPD:\r
678 Model = MODEL_PCD_DYNAMIC_VPD\r
679 elif Type == DataType.TAB_PCDS_DYNAMIC_EX_VPD:\r
680 Model = MODEL_PCD_DYNAMIC_EX_VPD\r
681 else:\r
682 pass\r
683 EdkLogger.debug(2, "Generate %s ..." % Type)\r
684\r
685 #\r
686 # Get all include files\r
687 #\r
688 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model, self.FileID)\r
689\r
690 #\r
691 # Get all DynamicVpdPcds\r
692 #\r
693 RecordSet = QueryDscItem(self.TblDsc, Model, -1, self.FileID)\r
694\r
695 #\r
696 # Go through each arch\r
697 #\r
698 for Arch in DataType.ARCH_LIST:\r
699 for IncludeFile in IncludeFiles:\r
700 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
701 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
702 for NewItem in open(Filename, 'r').readlines():\r
703 if CleanString(NewItem) == '':\r
704 continue\r
705 (K1, K2, K3, K4, K5) = GetDynamicVpdPcd(NewItem, Type, Filename, -1)\r
d40b2ee6 706 MergeArches(Pcds, (K1, K2, K3, K4, K5, IncludeFile[4]), Arch)\r
30fdf114
LG
707 self.PcdToken[Record[3]] = (K2, K1)\r
708\r
709 for Record in RecordSet:\r
710 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
711 (K1, K2, K3, K4, K5) = GetDynamicVpdPcd(Record[0], Type, ContainerFile, Record[2])\r
d40b2ee6 712 MergeArches(Pcds, (K1, K2, K3, K4, K5, Record[4]), Arch)\r
30fdf114
LG
713 self.PcdToken[Record[3]] = (K2, K1)\r
714\r
715 for Key in Pcds:\r
716 (Status, SkuInfoList) = self.GenSkuInfoList(Key[5], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', Key[2], '')\r
717 if Status == False:\r
718 ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type)\r
d40b2ee6 719 EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError=EdkLogger.IsRaiseError)\r
30fdf114
LG
720 Pcd = PcdClass(Key[0], '', Key[1], '', Key[3], '', Key[4], [], SkuInfoList, [])\r
721 Pcd.SupArchList = Pcds[Key]\r
722 self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
723\r
724\r
725 ## Get Component\r
726 #\r
727 # Get Component section defined in Dsc file\r
728 #\r
729 # @param ContainerFile: The file which describes the Components, used for error report\r
730 #\r
731 # @retval PlatformModuleClass() A instance for PlatformModuleClass\r
732 #\r
733 def GenComponents(self, ContainerFile):\r
734 EdkLogger.debug(2, "Generate %s ..." % TAB_COMPONENTS)\r
735 Components = sdict()\r
736 #\r
737 # Get all include files\r
738 #\r
739 IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_META_DATA_COMPONENT, self.FileID)\r
740\r
741 #\r
742 # Get all Components\r
743 #\r
744 RecordSet = QueryDscItem(self.TblDsc, MODEL_META_DATA_COMPONENT, -1, self.FileID)\r
745\r
746 #\r
747 # Go through each arch\r
748 #\r
749 for Arch in DataType.ARCH_LIST:\r
750 for IncludeFile in IncludeFiles:\r
751 if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
752 Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_COMPONENTS, '', IncludeFile[2])\r
753 for NewItem in open(Filename, 'r').readlines():\r
754 if CleanString(NewItem) == '':\r
755 continue\r
756 NewItems = []\r
757 GetComponents(open(Filename, 'r').read(), TAB_COMPONENTS, NewItems, TAB_COMMENT_SPLIT)\r
758 for NewComponent in NewItems:\r
759 MergeArches(Components, self.GenComponent(NewComponent, Filename), Arch)\r
760\r
761 for Record in RecordSet:\r
762 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
763 Lib, Bo, Pcd = [], [], []\r
764\r
765 SubLibSet = QueryDscItem(self.TblDsc, MODEL_EFI_LIBRARY_CLASS, Record[3], self.FileID)\r
766 for SubLib in SubLibSet:\r
d40b2ee6 767 Lib.append(TAB_VALUE_SPLIT.join([SubLib[0], SubLib[4]]))\r
30fdf114
LG
768\r
769 SubBoSet = QueryDscItem(self.TblDsc, MODEL_META_DATA_BUILD_OPTION, Record[3], self.FileID)\r
770 for SubBo in SubBoSet:\r
771 Bo.append(SubBo[0])\r
772\r
773 SubPcdSet1 = QueryDscItem(self.TblDsc, MODEL_PCD_FIXED_AT_BUILD, Record[3], self.FileID)\r
774 SubPcdSet2 = QueryDscItem(self.TblDsc, MODEL_PCD_PATCHABLE_IN_MODULE, Record[3], self.FileID)\r
775 SubPcdSet3 = QueryDscItem(self.TblDsc, MODEL_PCD_FEATURE_FLAG, Record[3], self.FileID)\r
776 SubPcdSet4 = QueryDscItem(self.TblDsc, MODEL_PCD_DYNAMIC_EX_DEFAULT, Record[3], self.FileID)\r
777 SubPcdSet5 = QueryDscItem(self.TblDsc, MODEL_PCD_DYNAMIC_DEFAULT, Record[3], self.FileID)\r
778 for SubPcd in SubPcdSet1:\r
779 Pcd.append([DataType.TAB_PCDS_FIXED_AT_BUILD, SubPcd[0], SubPcd[3]])\r
780 for SubPcd in SubPcdSet2:\r
781 Pcd.append([DataType.TAB_PCDS_PATCHABLE_IN_MODULE, SubPcd[0], SubPcd[3]])\r
782 for SubPcd in SubPcdSet3:\r
783 Pcd.append([DataType.TAB_PCDS_FEATURE_FLAG, SubPcd[0], SubPcd[3]])\r
784 for SubPcd in SubPcdSet4:\r
785 Pcd.append([DataType.TAB_PCDS_DYNAMIC_EX, SubPcd[0], SubPcd[3]])\r
786 for SubPcd in SubPcdSet5:\r
787 Pcd.append([DataType.TAB_PCDS_DYNAMIC, SubPcd[0], SubPcd[3]])\r
788 Item = [Record[0], Lib, Bo, Pcd]\r
789 MergeArches(Components, self.GenComponent(Item, ContainerFile), Arch)\r
790\r
791 for Key in Components.keys():\r
792 Key.SupArchList = Components[Key]\r
793 self.Platform.Modules.ModuleList.append(Key)\r
794\r
795 ## Get Component\r
796 #\r
797 # Get Component section defined in Dsc file\r
798 #\r
799 # @param Item: Contents includes a component block\r
800 # @param ContainerFile: The file which describes the library class, used for error report\r
801 #\r
802 # @retval PlatformModuleClass() A instance for PlatformModuleClass\r
803 #\r
d40b2ee6 804 def GenComponent(self, Item, ContainerFile, LineNo= -1):\r
30fdf114
LG
805 (InfFilename, ExecFilename) = GetExec(Item[0])\r
806 LibraryClasses = Item[1]\r
807 BuildOptions = Item[2]\r
808 Pcds = Item[3]\r
809 Component = PlatformModuleClass()\r
810 Component.FilePath = NormPath(InfFilename)\r
811 Component.ExecFilePath = NormPath(ExecFilename)\r
812 CheckFileType(Component.FilePath, '.Inf', ContainerFile, 'component name', Item[0], LineNo)\r
813 CheckFileExist(self.WorkspaceDir, Component.FilePath, ContainerFile, 'component', Item[0], LineNo)\r
814 for Lib in LibraryClasses:\r
815 List = GetSplitValueList(Lib)\r
816 if len(List) != 2:\r
817 RaiseParserError(Lib, 'LibraryClasses', ContainerFile, '<ClassName>|<InfFilename>')\r
818 LibName = List[0]\r
819 LibFile = NormPath(List[1])\r
820 if LibName == "" or LibName == "NULL":\r
821 LibName = "NULL%d" % self._NullClassIndex\r
822 self._NullClassIndex += 1\r
823 CheckFileType(List[1], '.Inf', ContainerFile, 'library instance of component ', Lib, LineNo)\r
824 CheckFileExist(self.WorkspaceDir, LibFile, ContainerFile, 'library instance of component', Lib, LineNo)\r
825 Component.LibraryClasses.LibraryList.append(PlatformLibraryClass(LibName, LibFile))\r
826 for BuildOption in BuildOptions:\r
827 Key = GetBuildOption(BuildOption, ContainerFile)\r
828 Component.ModuleSaBuildOption.BuildOptionList.append(BuildOptionClass(Key[0], Key[1], Key[2]))\r
829 for Pcd in Pcds:\r
830 Type = Pcd[0]\r
831 List = GetSplitValueList(Pcd[1])\r
832 PcdId = Pcd[2]\r
833\r
834 TokenInfo = None\r
835 #\r
836 # For FeatureFlag\r
837 #\r
838 if Type == DataType.TAB_PCDS_FEATURE_FLAG:\r
839 if len(List) != 2:\r
840 RaiseParserError(Pcd[1], 'Components', ContainerFile, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|TRUE/FALSE')\r
841\r
842 CheckPcdTokenInfo(List[0], 'Components', ContainerFile)\r
843 TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
844 Component.PcdBuildDefinitions.append(PcdClass(TokenInfo[1], '', TokenInfo[0], '', '', List[1], Type, [], {}, []))\r
845 #\r
846 # For FixedAtBuild or PatchableInModule\r
847 #\r
848 if Type == DataType.TAB_PCDS_FIXED_AT_BUILD or Type == DataType.TAB_PCDS_PATCHABLE_IN_MODULE:\r
849 List.append('')\r
850 if len(List) != 3 and len(List) != 4:\r
851 RaiseParserError(Pcd[1], 'Components', ContainerFile, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|<Value>[|<MaxDatumSize>]')\r
852\r
853 CheckPcdTokenInfo(List[0], 'Components', ContainerFile)\r
854 TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
855 Component.PcdBuildDefinitions.append(PcdClass(TokenInfo[1], '', TokenInfo[0], '', List[2], List[1], Type, [], {}, []))\r
856\r
857 #\r
858 # For Dynamic or DynamicEx\r
859 #\r
860 if Type == DataType.TAB_PCDS_DYNAMIC or Type == DataType.TAB_PCDS_DYNAMIC_EX:\r
861 if len(List) != 1:\r
862 RaiseParserError(Pcd[1], 'Components', ContainerFile, '<PcdTokenSpaceGuidCName>.<PcdTokenName>')\r
863\r
864 CheckPcdTokenInfo(List[0], 'Components', ContainerFile)\r
865 TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
866 Component.PcdBuildDefinitions.append(PcdClass(TokenInfo[1], '', TokenInfo[0], '', '', '', Type, [], {}, []))\r
867\r
868 #\r
869 # Add to PcdToken\r
870 #\r
871 self.PcdToken[PcdId] = (TokenInfo[0], TokenInfo[1])\r
872\r
873 return Component\r
874 #End of GenComponent\r
875\r
876 ## Gen SkuInfoList\r
877 #\r
878 # Gen SkuInfoList section defined in Dsc file\r
879 #\r
880 # @param SkuNameList: Input value for SkuNameList\r
881 # @param SkuInfo: Input value for SkuInfo\r
882 # @param VariableName: Input value for VariableName\r
883 # @param VariableGuid: Input value for VariableGuid\r
884 # @param VariableOffset: Input value for VariableOffset\r
885 # @param HiiDefaultValue: Input value for HiiDefaultValue\r
886 # @param VpdOffset: Input value for VpdOffset\r
887 # @param DefaultValue: Input value for DefaultValue\r
888 #\r
889 # @retval (False, SkuName) Not found in section SkuId Dsc file\r
890 # @retval (True, SkuInfoList) Found in section SkuId of Dsc file\r
891 #\r
d40b2ee6 892 def GenSkuInfoList(self, SkuNameList, SkuInfo, VariableName='', VariableGuid='', VariableOffset='', HiiDefaultValue='', VpdOffset='', DefaultValue=''):\r
30fdf114 893 SkuNameList = GetSplitValueList(SkuNameList)\r
4231a819 894 if SkuNameList is None or SkuNameList == [] or SkuNameList == ['']:\r
30fdf114
LG
895 SkuNameList = ['DEFAULT']\r
896 SkuInfoList = {}\r
897 for Item in SkuNameList:\r
898 if Item not in SkuInfo:\r
899 return False, Item\r
900 Sku = SkuInfoClass(Item, SkuInfo[Item], VariableName, VariableGuid, VariableOffset, HiiDefaultValue, VpdOffset, DefaultValue)\r
901 SkuInfoList[Item] = Sku\r
902\r
903 return True, SkuInfoList\r
904\r
905 ## Parse Include statement\r
906 #\r
907 # Get include file path\r
908 #\r
909 # 1. Insert a record into TblFile ???\r
910 # 2. Insert a record into TblDsc\r
911 # Value1: IncludeFilePath\r
912 #\r
913 # @param LineValue: The line of incude statement\r
914 def ParseInclude(self, LineValue, StartLine, Table, FileID, Filename, SectionName, Model, Arch):\r
915 EdkLogger.debug(EdkLogger.DEBUG_2, "!include statement '%s' found in section %s" % (LineValue, SectionName))\r
916 SectionModel = Section[SectionName.upper()]\r
917 IncludeFile = CleanString(LineValue[LineValue.upper().find(DataType.TAB_INCLUDE.upper() + ' ') + len(DataType.TAB_INCLUDE + ' ') : ])\r
918 Table.Insert(Model, IncludeFile, '', '', Arch, SectionModel, FileID, StartLine, -1, StartLine, -1, 0)\r
919\r
920 ## Parse DEFINE statement\r
921 #\r
922 # Get DEFINE macros\r
923 #\r
924 # 1. Insert a record into TblDsc\r
925 # Value1: Macro Name\r
926 # Value2: Macro Value\r
927 #\r
928 def ParseDefine(self, LineValue, StartLine, Table, FileID, Filename, SectionName, Model, Arch):\r
929 EdkLogger.debug(EdkLogger.DEBUG_2, "DEFINE statement '%s' found in section %s" % (LineValue, SectionName))\r
930 SectionModel = Section[SectionName.upper()]\r
931 Define = GetSplitValueList(CleanString(LineValue[LineValue.upper().find(DataType.TAB_DEFINE.upper() + ' ') + len(DataType.TAB_DEFINE + ' ') : ]), TAB_EQUAL_SPLIT, 1)\r
932 Table.Insert(Model, Define[0], Define[1], '', Arch, SectionModel, FileID, StartLine, -1, StartLine, -1, 0)\r
933\r
934 ## Parse Defines section\r
935 #\r
936 # Get one item in defines section\r
937 #\r
938 # Value1: Item Name\r
939 # Value2: Item Value\r
940 #\r
941 def ParseDefinesSection(self, LineValue, StartLine, Table, FileID, Filename, SectionName, Model, Arch):\r
942 EdkLogger.debug(EdkLogger.DEBUG_2, "Parse '%s' found in section %s" % (LineValue, SectionName))\r
943 Defines = GetSplitValueList(LineValue, TAB_EQUAL_SPLIT, 1)\r
944 if len(Defines) != 2:\r
945 RaiseParserError(LineValue, SectionName, Filename, '', StartLine)\r
946 self.TblDsc.Insert(Model, Defines[0], Defines[1], '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
947\r
948 ## Insert conditional statements\r
949 #\r
950 # Pop an item from IfDefList\r
951 # Insert conditional statements to database\r
952 #\r
953 # @param Filename: Path of parsing file\r
954 # @param IfDefList: A list stored current conditional statements\r
955 # @param EndLine: The end line no\r
956 # @param ArchList: Support arch list\r
957 #\r
958 def InsertConditionalStatement(self, Filename, FileID, BelongsToItem, IfDefList, EndLine, ArchList):\r
959 (Value1, Value2, Value3, Model, StartColumn, EndColumn, Enabled) = ('', '', '', -1, -1, -1, 0)\r
960 if IfDefList == []:\r
961 ErrorMsg = 'Not suited conditional statement in file %s' % Filename\r
d40b2ee6 962 EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, Filename, RaiseError=EdkLogger.IsRaiseError)\r
30fdf114
LG
963 else:\r
964 #\r
965 # Get New Dsc item ID\r
966 #\r
967 DscID = self.TblDsc.GetCount() + 1\r
968\r
969 #\r
970 # Pop the conditional statements which is closed\r
971 #\r
972 PreviousIf = IfDefList.pop()\r
973 EdkLogger.debug(EdkLogger.DEBUG_5, 'Previous IfDef: ' + str(PreviousIf))\r
974\r
975 #\r
976 # !ifdef and !ifndef\r
977 #\r
978 if PreviousIf[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF):\r
979 Value1 = PreviousIf[0]\r
980 Model = PreviousIf[2]\r
981 self.TblDsc.Insert(Model, Value1, Value2, Value3, ArchList, BelongsToItem, self.FileID, PreviousIf[1], StartColumn, EndLine, EndColumn, Enabled)\r
982 #\r
983 # !if and !elseif\r
984 #\r
985 elif PreviousIf[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, Model):\r
986 List = PreviousIf[0].split(' ')\r
636f2be6
LG
987 Value1, Value2, Value3 = '', '==', '0'\r
988 if len(List) == 3:\r
989 Value1 = List[0]\r
990 Value2 = List[1]\r
991 Value3 = List[2]\r
992 Value3 = SplitString(Value3)\r
993 if len(List) == 1:\r
994 Value1 = List[0]\r
30fdf114
LG
995 Model = PreviousIf[2]\r
996 self.TblDsc.Insert(Model, Value1, Value2, Value3, ArchList, BelongsToItem, self.FileID, PreviousIf[1], StartColumn, EndLine, EndColumn, Enabled)\r
997 #\r
998 # !else\r
999 #\r
1000 elif PreviousIf[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE, Model):\r
1001 Value1 = PreviousIf[0].strip()\r
1002 Model = PreviousIf[2]\r
1003 self.TblDsc.Insert(Model, Value1, Value2, Value3, ArchList, BelongsToItem, self.FileID, PreviousIf[1], StartColumn, EndLine, EndColumn, Enabled)\r
1004\r
1005 ## Load Dsc file\r
1006 #\r
1007 # Load the file if it exists\r
1008 #\r
1009 # @param Filename: Input value for filename of Dsc file\r
1010 #\r
1011 def LoadDscFile(self, Filename):\r
1012 #\r
1013 # Insert a record for file\r
1014 #\r
1015 Filename = NormPath(Filename)\r
1016 self.Identification.FileFullPath = Filename\r
1017 (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)\r
1018 self.FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_DSC)\r
1019\r
1020 #\r
1021 # Init DscTable\r
1022 #\r
1023 #self.TblDsc.Table = "Dsc%s" % FileID\r
1024 #self.TblDsc.Create()\r
1025\r
1026 #\r
1027 # Init common datas\r
1028 #\r
1029 IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \\r
1030 [], [], TAB_UNKNOWN, [], [], []\r
1031 LineNo = 0\r
1032\r
1033 #\r
1034 # Parse file content\r
1035 #\r
1036 IsFindBlockComment = False\r
1037 ReservedLine = ''\r
1038 for Line in open(Filename, 'r'):\r
1039 LineNo = LineNo + 1\r
1040 #\r
1041 # Remove comment block\r
1042 #\r
b36d134f 1043 if Line.find(TAB_COMMENT_EDK_START) > -1:\r
d40b2ee6 1044 ReservedLine = GetSplitList(Line, TAB_COMMENT_EDK_START, 1)[0]\r
30fdf114 1045 IsFindBlockComment = True\r
b36d134f 1046 if Line.find(TAB_COMMENT_EDK_END) > -1:\r
d40b2ee6 1047 Line = ReservedLine + GetSplitList(Line, TAB_COMMENT_EDK_END, 1)[1]\r
30fdf114
LG
1048 ReservedLine = ''\r
1049 IsFindBlockComment = False\r
1050 if IsFindBlockComment:\r
1051 continue\r
1052\r
1053 #\r
1054 # Remove comments at tail and remove spaces again\r
1055 #\r
1056 Line = CleanString(Line)\r
1057 if Line == '':\r
1058 continue\r
1059\r
1060 #\r
1061 # Find a new section tab\r
1062 # First insert previous section items\r
1063 # And then parse the content of the new section\r
1064 #\r
1065 if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):\r
1066 #\r
1067 # Insert items data of previous section\r
1068 #\r
1069 self.InsertSectionItemsIntoDatabase(self.FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
1070 #\r
1071 # Parse the new section\r
1072 #\r
1073 SectionItemList = []\r
1074 ArchList = []\r
1075 ThirdList = []\r
1076\r
1077 CurrentSection = ''\r
1078 LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)\r
1079 for Item in LineList:\r
1080 ItemList = GetSplitValueList(Item, TAB_SPLIT)\r
1081 if CurrentSection == '':\r
1082 CurrentSection = ItemList[0]\r
1083 else:\r
1084 if CurrentSection != ItemList[0]:\r
d40b2ee6 1085 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
1086 if CurrentSection.upper() not in self.KeyList:\r
1087 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
1088 CurrentSection = TAB_UNKNOWN\r
1089 continue\r
1090 ItemList.append('')\r
1091 ItemList.append('')\r
1092 if len(ItemList) > 5:\r
1093 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
1094 else:\r
1095 if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:\r
d40b2ee6 1096 EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError)\r
30fdf114
LG
1097 ArchList.append(ItemList[1].upper())\r
1098 ThirdList.append(ItemList[2])\r
1099\r
1100 continue\r
1101\r
1102 #\r
1103 # Not in any defined section\r
1104 #\r
1105 if CurrentSection == TAB_UNKNOWN:\r
1106 ErrorMsg = "%s is not in any defined section" % Line\r
d40b2ee6 1107 EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError)\r
30fdf114
LG
1108\r
1109 #\r
1110 # Add a section item\r
1111 #\r
1112 SectionItemList.append([Line, LineNo])\r
1113 # End of parse\r
1114 #End of For\r
1115\r
1116 #\r
1117 # Insert items data of last section\r
1118 #\r
1119 self.InsertSectionItemsIntoDatabase(self.FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
1120\r
1121 #\r
1122 # Parse conditional statements\r
1123 #\r
1124 self.ParseConditionalStatement()\r
1125\r
1126 #\r
1127 # Replace all DEFINE macros with its actual values\r
1128 #\r
1129 #ParseDefineMacro2(self.TblDsc, self.RecordSet, GlobalData.gGlobalDefines)\r
1130 ParseDefineMacro(self.TblDsc, GlobalData.gGlobalDefines)\r
1131\r
1132\r
1133 ## ParseConditionalStatement\r
1134 #\r
1135 # Search all conditional statement and disable no match records\r
1136 #\r
1137 def ParseConditionalStatement(self):\r
1138 #\r
1139 # Disabled all !if/!elif/!ifdef statements without DEFINE\r
1140 #\r
1141 SqlCommand = """select A.StartLine, A.EndLine from %s as A\r
1142 where A.Model in (%s, %s, %s)\r
1143 and A.Enabled = 0\r
1144 and A.BelongsToFile = %s\r
1145 and A.Value1 not in (select B.Value1 from %s as B\r
1146 where B.Model = %s\r
1147 and B.Enabled = 0\r
1148 and A.StartLine > B.StartLine\r
1149 and A.Arch = B.Arch\r
1150 and A.BelongsToItem = B.BelongsToItem\r
1151 and A.BelongsToFile = B.BelongsToFile) """ % \\r
1152 (self.TblDsc.Table, \\r
1153 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF, \\r
1154 self.FileID, \\r
1155 self.TblDsc.Table, \\r
1156 MODEL_META_DATA_DEFINE)\r
1157 RecordSet = self.TblDsc.Exec(SqlCommand)\r
1158 for Record in RecordSet:\r
d40b2ee6 1159 SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self.TblDsc.Table, Record[0], Record[1])\r
30fdf114
LG
1160 self.TblDsc.Exec(SqlCommand)\r
1161\r
1162 #\r
1163 # Disabled !ifndef with DEFINE\r
1164 #\r
1165 SqlCommand = """select A.StartLine, A.EndLine from %s as A\r
1166 where A.Model = %s\r
1167 and A.Enabled = 0\r
1168 and A.BelongsToFile = %s\r
1169 and A.Value1 in (select B.Value1 from %s as B\r
1170 where B.Model = %s\r
1171 and B.Enabled = 0\r
1172 and A.StartLine > B.StartLine\r
1173 and A.Arch = B.Arch\r
1174 and A.BelongsToItem = B.BelongsToItem\r
1175 and A.BelongsToFile = B.BelongsToFile)""" % \\r
1176 (self.TblDsc.Table, \\r
1177 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF, \\r
1178 self.FileID, \\r
1179 self.TblDsc.Table, \\r
1180 MODEL_META_DATA_DEFINE)\r
1181 RecordSet = self.TblDsc.Exec(SqlCommand)\r
1182 for Record in RecordSet:\r
d40b2ee6
LG
1183 SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self.TblDsc.Table, Record[0], Record[1])\r
1184 EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
30fdf114
LG
1185 self.Cur.execute(SqlCommand)\r
1186\r
1187 #\r
1188 # Disabled !if, !elif and !else with un-match value\r
1189 #\r
1190 SqlCommand = """select A.Model, A.Value1, A.Value2, A.Value3, A.StartLine, A.EndLine, B.Value2 from %s as A join %s as B\r
1191 where A.Model in (%s, %s)\r
1192 and A.Enabled = 0\r
1193 and A.BelongsToFile = %s\r
1194 and B.Enabled = 0\r
1195 and B.Model = %s\r
1196 and A.Value1 = B.Value1\r
1197 and A.StartLine > B.StartLine\r
1198 and A.BelongsToItem = B.BelongsToItem\r
1199 and A.BelongsToFile = B.BelongsToFile""" % \\r
1200 (self.TblDsc.Table, self.TblDsc.Table, \\r
1201 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE, \\r
1202 self.FileID, MODEL_META_DATA_DEFINE)\r
1203 RecordSet = self.TblDsc.Exec(SqlCommand)\r
1204 DisabledList = []\r
1205 for Record in RecordSet:\r
1206 if Record[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_IF:\r
1207 if not self.Compare(Record[6], Record[2], Record[3]):\r
d40b2ee6 1208 SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self.TblDsc.Table, Record[4], Record[5])\r
30fdf114
LG
1209 self.TblDsc.Exec(SqlCommand)\r
1210 else:\r
1211 DisabledList.append(Record[1])\r
1212 continue\r
1213 if Record[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE and Record[1] in DisabledList:\r
d40b2ee6 1214 SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self.TblDsc.Table, Record[4], Record[5])\r
30fdf114
LG
1215 self.TblDsc.Exec(SqlCommand)\r
1216\r
1217 ## Compare\r
1218 #\r
1219 # Compare two values\r
1220 # @param Value1:\r
1221 # @param CompareType:\r
1222 # @param Value2:\r
1223 #\r
1224 def Compare(self, Value1, CompareType, Value2):\r
d40b2ee6 1225 Command = """Value1 %s Value2""" % CompareType\r
30fdf114
LG
1226 return eval(Command)\r
1227\r
1228 ## First time to insert records to database\r
1229 #\r
1230 # Insert item data of a section to database\r
1231 # @param FileID: The ID of belonging file\r
1232 # @param Filename: The name of belonging file\r
1233 # @param CurrentSection: The name of currect section\r
1234 # @param SectionItemList: A list of items of the section\r
1235 # @param ArchList: A list of arches\r
1236 # @param ThirdList: A list of third parameters, ModuleType for LibraryClass and SkuId for Dynamic Pcds\r
1237 # @param IfDefList: A list of all conditional statements\r
1238 #\r
1239 def InsertSectionItemsIntoDatabase(self, FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList):\r
1240 #\r
1241 # Insert each item data of a section\r
1242 #\r
1243 for Index in range(0, len(ArchList)):\r
1244 Arch = ArchList[Index]\r
1245 Third = ThirdList[Index]\r
1246 if Arch == '':\r
1247 Arch = TAB_ARCH_COMMON.upper()\r
1248\r
1249 Model = Section[CurrentSection.upper()]\r
1250 #Records = self.RecordSet[Model]\r
1251\r
1252 for SectionItem in SectionItemList:\r
1253 BelongsToItem, EndLine, EndColumn = -1, -1, -1\r
1254 LineValue, StartLine, EndLine = SectionItem[0], SectionItem[1], SectionItem[1]\r
1255\r
1256\r
d40b2ee6 1257 EdkLogger.debug(4, "Parsing %s ..." % LineValue)\r
30fdf114
LG
1258 #\r
1259 # Parse '!ifdef'\r
1260 #\r
1261 if LineValue.upper().find(TAB_IF_DEF.upper()) > -1:\r
1262 IfDefList.append((LineValue[len(TAB_IF_N_DEF):].strip(), StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF))\r
1263 continue\r
1264\r
1265 #\r
1266 # Parse '!ifndef'\r
1267 #\r
1268 if LineValue.upper().find(TAB_IF_N_DEF.upper()) > -1:\r
1269 IfDefList.append((LineValue[len(TAB_IF_N_DEF):].strip(), StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF))\r
1270 continue\r
1271\r
1272 #\r
1273 # Parse '!endif'\r
1274 #\r
1275 if LineValue.upper().find(TAB_END_IF.upper()) > -1:\r
1276 self.InsertConditionalStatement(Filename, FileID, Model, IfDefList, StartLine, Arch)\r
1277 continue\r
1278 #\r
1279 # Parse '!if'\r
1280 #\r
1281 if LineValue.upper().find(TAB_IF.upper()) > -1:\r
1282 IfDefList.append((LineValue[len(TAB_IF):].strip(), StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF))\r
1283 continue\r
1284\r
1285 #\r
1286 # Parse '!elseif'\r
1287 #\r
1288 if LineValue.upper().find(TAB_ELSE_IF.upper()) > -1:\r
1289 self.InsertConditionalStatement(Filename, FileID, Model, IfDefList, StartLine - 1, Arch)\r
1290 IfDefList.append((LineValue[len(TAB_ELSE_IF):].strip(), StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF))\r
1291 continue\r
1292\r
1293 #\r
1294 # Parse '!else'\r
1295 #\r
1296 if LineValue.upper().find(TAB_ELSE.upper()) > -1:\r
1297 Key = IfDefList[-1][0].split(' ' , 1)[0].strip()\r
1298 self.InsertConditionalStatement(Filename, FileID, Model, IfDefList, StartLine, Arch)\r
1299 IfDefList.append((Key, StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE))\r
1300 continue\r
1301\r
1302 #\r
1303 # Parse !include statement first\r
1304 #\r
1305 if LineValue.upper().find(DataType.TAB_INCLUDE.upper() + ' ') > -1:\r
1306 self.ParseInclude(LineValue, StartLine, self.TblDsc, FileID, Filename, CurrentSection, MODEL_META_DATA_INCLUDE, Arch)\r
1307 continue\r
1308\r
1309 #\r
1310 # And then parse DEFINE statement\r
1311 #\r
1312 if LineValue.upper().find(DataType.TAB_DEFINE.upper() + ' ') > -1:\r
1313 self.ParseDefine(LineValue, StartLine, self.TblDsc, FileID, Filename, CurrentSection, MODEL_META_DATA_DEFINE, Arch)\r
1314 continue\r
1315\r
1316 #\r
1317 # At last parse other sections\r
1318 #\r
1319 if CurrentSection == TAB_LIBRARY_CLASSES or CurrentSection in TAB_PCD_DYNAMIC_TYPE_LIST or CurrentSection in TAB_PCD_DYNAMIC_EX_TYPE_LIST:\r
1320 ID = self.TblDsc.Insert(Model, LineValue, Third, '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
1321 #Records.append([LineValue, Arch, StartLine, ID, Third])\r
1322 continue\r
1323 elif CurrentSection != TAB_COMPONENTS:\r
1324 ID = self.TblDsc.Insert(Model, LineValue, '', '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
1325 #Records.append([LineValue, Arch, StartLine, ID, Third])\r
1326 continue\r
1327\r
1328 #\r
1329 # Parse COMPONENT section\r
1330 #\r
1331 if CurrentSection == TAB_COMPONENTS:\r
1332 Components = []\r
1333 GetComponent(SectionItemList, Components)\r
1334 for Component in Components:\r
d40b2ee6 1335 EdkLogger.debug(4, "Parsing component %s ..." % Component)\r
30fdf114
LG
1336 DscItmeID = self.TblDsc.Insert(MODEL_META_DATA_COMPONENT, Component[0], '', '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
1337 for Item in Component[1]:\r
d40b2ee6 1338 List = GetSplitValueList(Item, MaxSplit=2)\r
30fdf114
LG
1339 LibName, LibIns = '', ''\r
1340 if len(List) == 2:\r
1341 LibName = List[0]\r
1342 LibIns = List[1]\r
1343 else:\r
1344 LibName = List[0]\r
1345 self.TblDsc.Insert(MODEL_EFI_LIBRARY_CLASS, LibName, LibIns, '', Arch, DscItmeID, FileID, StartLine, -1, StartLine, -1, 0)\r
1346 for Item in Component[2]:\r
1347 self.TblDsc.Insert(MODEL_META_DATA_BUILD_OPTION, Item, '', '', Arch, DscItmeID, FileID, StartLine, -1, StartLine, -1, 0)\r
1348 for Item in Component[3]:\r
1349 Model = Section[Item[0].upper()]\r
1350 self.TblDsc.Insert(Model, Item[1], '', '', Arch, DscItmeID, FileID, StartLine, -1, StartLine, -1, 0)\r
1351\r
1352 ## Show detailed information of Dsc\r
1353 #\r
1354 # Print all members and their values of Dsc class\r
1355 #\r
1356 def ShowDsc(self):\r
1357 print TAB_SECTION_START + TAB_INF_DEFINES + TAB_SECTION_END\r
1358 printDict(self.Defines.DefinesDictionary)\r
1359\r
1360 for Key in self.KeyList:\r
1361 for Arch in DataType.ARCH_LIST_FULL:\r
1362 Command = "printList(TAB_SECTION_START + '" + \\r
1363 Key + DataType.TAB_SPLIT + Arch + \\r
1364 "' + TAB_SECTION_END, self.Contents[arch]." + Key + ')'\r
1365 eval(Command)\r
1366\r
1367 ## Show detailed information of Platform\r
1368 #\r
1369 # Print all members and their values of Platform class\r
1370 #\r
1371 def ShowPlatform(self):\r
1372 M = self.Platform\r
1373 for Arch in M.Header.keys():\r
1374 print '\nArch =', Arch\r
1375 print 'Filename =', M.Header[Arch].FileName\r
1376 print 'FullPath =', M.Header[Arch].FullPath\r
1377 print 'BaseName =', M.Header[Arch].Name\r
1378 print 'Guid =', M.Header[Arch].Guid\r
1379 print 'Version =', M.Header[Arch].Version\r
1380 print 'DscSpecification =', M.Header[Arch].DscSpecification\r
1381 print 'SkuId =', M.Header[Arch].SkuIdName\r
1382 print 'SupArchList =', M.Header[Arch].SupArchList\r
1383 print 'BuildTargets =', M.Header[Arch].BuildTargets\r
1384 print 'OutputDirectory =', M.Header[Arch].OutputDirectory\r
1385 print 'BuildNumber =', M.Header[Arch].BuildNumber\r
1386 print 'MakefileName =', M.Header[Arch].MakefileName\r
1387 print 'BsBaseAddress =', M.Header[Arch].BsBaseAddress\r
1388 print 'RtBaseAddress =', M.Header[Arch].RtBaseAddress\r
1389 print 'Define =', M.Header[Arch].Define\r
1390 print 'Fdf =', M.FlashDefinitionFile.FilePath\r
1391 print '\nBuildOptions =', M.BuildOptions, M.BuildOptions.IncludeFiles\r
1392 for Item in M.BuildOptions.BuildOptionList:\r
1393 print '\t', 'ToolChainFamily =', Item.ToolChainFamily, 'ToolChain =', Item.ToolChain, 'Option =', Item.Option, 'Arch =', Item.SupArchList\r
1394 print '\nSkuIds =', M.SkuInfos.SkuInfoList, M.SkuInfos.IncludeFiles\r
1395 print '\nLibraries =', M.Libraries, M.Libraries.IncludeFiles\r
1396 for Item in M.Libraries.LibraryList:\r
1397 print '\t', Item.FilePath, Item.SupArchList, Item.Define\r
1398 print '\nLibraryClasses =', M.LibraryClasses, M.LibraryClasses.IncludeFiles\r
1399 for Item in M.LibraryClasses.LibraryList:\r
1400 print '\t', Item.Name, Item.FilePath, Item.SupModuleList, Item.SupArchList, Item.Define\r
1401 print '\nPcds =', M.DynamicPcdBuildDefinitions\r
1402 for Item in M.DynamicPcdBuildDefinitions:\r
1403 print '\tCname=', Item.CName, 'TSG=', Item.TokenSpaceGuidCName, 'Value=', Item.DefaultValue, 'Token=', Item.Token, 'Type=', Item.ItemType, 'Datum=', Item.DatumType, 'Size=', Item.MaxDatumSize, 'Arch=', Item.SupArchList, Item.SkuInfoList\r
1404 for Sku in Item.SkuInfoList.values():\r
1405 print '\t\t', str(Sku)\r
1406 print '\nComponents =', M.Modules.ModuleList, M.Modules.IncludeFiles\r
1407 for Item in M.Modules.ModuleList:\r
1408 print '\t', Item.FilePath, Item.ExecFilePath, Item.SupArchList\r
1409 for Lib in Item.LibraryClasses.LibraryList:\r
1410 print '\t\tLib:', Lib.Name, Lib.FilePath\r
1411 for Bo in Item.ModuleSaBuildOption.BuildOptionList:\r
1412 print '\t\tBuildOption:', Bo.ToolChainFamily, Bo.ToolChain, Bo.Option\r
1413 for Pcd in Item.PcdBuildDefinitions:\r
1414 print '\t\tPcd:', Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.MaxDatumSize, Pcd.DefaultValue, Pcd.ItemType\r
1415\r
1416##\r
1417#\r
1418# This acts like the main() function for the script, unless it is 'import'ed into another\r
1419# script.\r
1420#\r
1421if __name__ == '__main__':\r
1422 EdkLogger.Initialize()\r
1423 EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
1424\r
1425 W = os.getenv('WORKSPACE')\r
1426 F = os.path.join(W, 'Nt32Pkg/Nt32Pkg.dsc')\r
1427\r
1428 Db = Database.Database('Dsc.db')\r
1429 Db.InitDatabase()\r
1430\r
1431 P = Dsc(os.path.normpath(F), True, True, W, Db)\r
1432 P.ShowPlatform()\r
1433\r
1434 Db.Close()\r