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