2 # This file is used to define each component of DSC file
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
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.
17 import Common
.LongFilePathOs
as os
18 import EdkLogger
as EdkLogger
22 from DataType
import *
23 from Identification
import *
24 from Dictionary
import *
25 from CommonDataClass
.PlatformClass
import *
26 from CommonDataClass
.CommonClass
import SkuInfoClass
27 from BuildToolError
import *
28 from Misc
import sdict
30 from Table
.TableDsc
import TableDsc
31 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
36 Section
= {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
59 # This class defined basic Dsc object which is used by inheriting
61 # @param object: Inherited from object class
63 class DscObject(object):
69 # This class defined the structure used in Dsc object
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
77 # @param IsToPlatform: Input value for IsToPlatform
78 # True is to transfer to ModuleObject automatically
79 # False is not to transfer to ModuleObject automatically
81 # @param WorkspaceDir: Input value for current workspace directory, default is None
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
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
102 self
.Cur
= Database
.Cur
103 self
.TblFile
= Database
.TblFile
104 self
.TblDsc
= Database
.TblDsc
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
117 # Upper all KEYs to ignore case sensitive when parsing
119 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
124 # self.RecordSet = {}
125 # for Key in self.KeyList:
126 # self.RecordSet[Section[Key]] = []
129 # Load Dsc file if filename is not None
132 self
.LoadDscFile(Filename
)
135 # Transfer to Platform Object if IsToPlatform is True
140 ## Transfer to Platform Object
142 # Transfer all contents of an Inf file to a standard Module Object
144 def DscToPlatform(self
):
146 # Init global information for the file
148 ContainerFile
= self
.Identification
.FileFullPath
151 # Generate Platform Header
153 self
.GenPlatformHeader(ContainerFile
)
156 # Generate BuildOptions
158 self
.GenBuildOptions(ContainerFile
)
163 self
.GenSkuInfos(ContainerFile
)
168 self
.GenLibraries(ContainerFile
)
171 # Generate LibraryClasses
173 self
.GenLibraryClasses(ContainerFile
)
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
)
189 # Generate Components
191 self
.GenComponents(ContainerFile
)
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
202 ## Get Platform Header
204 # Gen Platform Header of Dsc as <Key> = <Value>
206 # @param ContainerFile: The Dsc file full path
208 def GenPlatformHeader(self
, ContainerFile
):
209 EdkLogger
.debug(2, "Generate PlatformHeader ...")
211 # Update all defines item in database
213 SqlCommand
= """select ID, Value1, Arch, StartLine from %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
)
228 # Get detailed information
230 for Arch
in DataType
.ARCH_LIST
:
231 PlatformHeader
= PlatformHeaderClass()
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]
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]
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]
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
263 # Gen BuildOptions of Dsc
264 # [<Family>:]<ToolFlag>=Flag
266 # @param ContainerFile: The Dsc file full path
268 def GenBuildOptions(self
, ContainerFile
):
269 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
272 # Get all include files
274 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_BUILD_OPTION
, self
.FileID
)
277 # Get all BuildOptions
279 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, -1, self
.FileID
)
282 # Go through each arch
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
) == '':
291 (Family
, ToolChain
, Flag
) = GetBuildOption(NewItem
, Filename
, -1)
292 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
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
)
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
)
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
)
313 # Gen SkuInfos of Dsc
316 # @param ContainerFile: The Dsc file full path
318 def GenSkuInfos(self
, ContainerFile
):
319 EdkLogger
.debug(2, "Generate %s ..." % TAB_SKUIDS
)
324 self
.Platform
.SkuInfos
.SkuInfoList
['DEFAULT'] = '0'
327 # Get all include files
329 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_SKU_ID
, self
.FileID
)
334 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_SKU_ID
, -1, self
.FileID
)
337 # Go through each arch
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
) == '':
346 List
= GetSplitValueList(NewItem
)
348 RaiseParserError(NewItem
, TAB_SKUIDS
, Filename
, '<Integer>|<UiName>')
350 self
.Platform
.SkuInfos
.SkuInfoList
[List
[1]] = List
[0]
352 for Record
in RecordSet
:
353 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
354 List
= GetSplitValueList(Record
[0])
356 RaiseParserError(Record
[0], TAB_SKUIDS
, ContainerFile
, '<Integer>|<UiName>')
358 self
.Platform
.SkuInfos
.SkuInfoList
[List
[1]] = List
[0]
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
)
369 # Gen Libraries of Dsc
372 # @param ContainerFile: The Dsc file full path
374 def GenLibraries(self
, ContainerFile
):
375 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARIES
)
378 # Get all include files
380 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_INSTANCE
, self
.FileID
)
385 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_INSTANCE
, -1, self
.FileID
)
388 # Go through each arch
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
) == '':
398 MergeArches(Libraries
, NewItem
, Arch
)
400 for Record
in RecordSet
:
401 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
402 MergeArches(Libraries
, Record
[0], Arch
)
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
)
412 # Get LibraryClasses of Dsc
413 # <LibraryClassKeyWord>|<LibraryInstance>
415 # @param ContainerFile: The Dsc file full path
417 def GenLibraryClasses(self
, ContainerFile
):
418 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
421 # Get all include files
423 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_CLASS
, self
.FileID
)
426 # Get all LibraryClasses
428 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, -1, self
.FileID
)
431 # Go through each arch
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
) == '':
440 MergeArches(LibraryClasses
, GetLibraryClass([NewItem
, IncludeFile
[4]], Filename
, self
.WorkspaceDir
, -1), Arch
)
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
)
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
)
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
)
464 # Gen Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]
466 # @param Type: The type of Pcd
467 # @param ContainerFile: The file which describes the pcd, used for error report
469 def GenPcds(self
, Type
='', ContainerFile
=''):
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
477 EdkLogger
.debug(2, "Generate %s ..." % Type
)
480 # Get all include files
482 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
487 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
490 # Go through each arch
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
) == '':
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
)
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
)
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
)
514 ## Gen FeatureFlagPcds
516 # Gen FeatureFlagPcds of Dsc file as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE
518 # @param Type: The type of Pcd
519 # @param ContainerFile: The file which describes the pcd, used for error report
521 def GenFeatureFlagPcds(self
, Type
='', ContainerFile
=''):
523 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
524 Model
= MODEL_PCD_FEATURE_FLAG
527 EdkLogger
.debug(2, "Generate %s ..." % Type
)
530 # Get all include files
532 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
535 # Get all FeatureFlagPcds
537 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
540 # Go through each arch
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
) == '':
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
)
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
)
560 Pcd
= PcdClass(Key
[0], '', Key
[1], '', '', Key
[2], Key
[3], [], {}, [])
561 Pcd
.SupArchList
= Pcds
[Key
]
562 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
564 ## Gen DynamicDefaultPcds
566 # Gen DynamicDefaultPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]
568 # @param Type: The type of Pcd
569 # @param ContainerFile: The file which describes the pcd, used for error report
571 def GenDynamicDefaultPcds(self
, Type
='', ContainerFile
=''):
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
580 EdkLogger
.debug(2, "Generate %s ..." % Type
)
583 # Get all include files
585 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
588 # Get all DynamicDefaultPcds
590 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
593 # Go through each arch
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
) == '':
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
)
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
)
613 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[6], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', '', Key
[2])
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
)
621 ## Gen DynamicHiiPcds
623 # Gen DynamicHiiPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]
625 # @param Type: The type of Pcd
626 # @param ContainerFile: The file which describes the pcd, used for error report
628 def GenDynamicHiiPcds(self
, Type
='', ContainerFile
=''):
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
637 EdkLogger
.debug(2, "Generate %s ..." % Type
)
640 # Get all include files
642 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
645 # Get all DynamicHiiPcds
647 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
650 # Go through each arch
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
) == '':
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
)
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
)
670 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[8], self
.Platform
.SkuInfos
.SkuInfoList
, Key
[2], Key
[3], Key
[4], Key
[5], '', '')
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
)
678 ## Gen DynamicVpdPcds
680 # Gen DynamicVpdPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]
682 # @param Type: The type of Pcd
683 # @param ContainerFile: The file which describes the pcd, used for error report
685 def GenDynamicVpdPcds(self
, Type
='', ContainerFile
=''):
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
694 EdkLogger
.debug(2, "Generate %s ..." % Type
)
697 # Get all include files
699 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
702 # Get all DynamicVpdPcds
704 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
707 # Go through each arch
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
) == '':
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
)
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
)
727 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[5], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', Key
[2], '')
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
)
738 # Get Component section defined in Dsc file
740 # @param ContainerFile: The file which describes the Components, used for error report
742 # @retval PlatformModuleClass() A instance for PlatformModuleClass
744 def GenComponents(self
, ContainerFile
):
745 EdkLogger
.debug(2, "Generate %s ..." % TAB_COMPONENTS
)
748 # Get all include files
750 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_COMPONENT
, self
.FileID
)
755 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_COMPONENT
, -1, self
.FileID
)
758 # Go through each arch
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
) == '':
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
)
772 for Record
in RecordSet
:
773 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
774 Lib
, Bo
, Pcd
= [], [], []
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]]))
780 SubBoSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, Record
[3], self
.FileID
)
781 for SubBo
in SubBoSet
:
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
)
802 for Key
in Components
.keys():
803 Key
.SupArchList
= Components
[Key
]
804 self
.Platform
.Modules
.ModuleList
.append(Key
)
808 # Get Component section defined in Dsc file
810 # @param Item: Contents includes a component block
811 # @param ContainerFile: The file which describes the library class, used for error report
813 # @retval PlatformModuleClass() A instance for PlatformModuleClass
815 def GenComponent(self
, Item
, ContainerFile
, LineNo
= -1):
816 (InfFilename
, ExecFilename
) = GetExec(Item
[0])
817 LibraryClasses
= Item
[1]
818 BuildOptions
= Item
[2]
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
)
828 RaiseParserError(Lib
, 'LibraryClasses', ContainerFile
, '<ClassName>|<InfFilename>')
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]))
842 List
= GetSplitValueList(Pcd
[1])
849 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
851 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|TRUE/FALSE')
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
, [], {}, []))
857 # For FixedAtBuild or PatchableInModule
859 if Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
or Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
861 if len(List
) != 3 and len(List
) != 4:
862 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|<Value>[|<MaxDatumSize>]')
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
, [], {}, []))
869 # For Dynamic or DynamicEx
871 if Type
== DataType
.TAB_PCDS_DYNAMIC
or Type
== DataType
.TAB_PCDS_DYNAMIC_EX
:
873 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>')
875 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
876 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
877 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', '', Type
, [], {}, []))
882 self
.PcdToken
[PcdId
] = (TokenInfo
[0], TokenInfo
[1])
889 # Gen SkuInfoList section defined in Dsc file
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
900 # @retval (False, SkuName) Not found in section SkuId Dsc file
901 # @retval (True, SkuInfoList) Found in section SkuId of Dsc file
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']
908 for Item
in SkuNameList
:
909 if Item
not in SkuInfo
:
911 Sku
= SkuInfoClass(Item
, SkuInfo
[Item
], VariableName
, VariableGuid
, VariableOffset
, HiiDefaultValue
, VpdOffset
, DefaultValue
)
912 SkuInfoList
[Item
] = Sku
914 return True, SkuInfoList
916 ## Parse Include statement
918 # Get include file path
920 # 1. Insert a record into TblFile ???
921 # 2. Insert a record into TblDsc
922 # Value1: IncludeFilePath
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)
931 ## Parse DEFINE statement
935 # 1. Insert a record into TblDsc
937 # Value2: Macro Value
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)
945 ## Parse Defines section
947 # Get one item in defines section
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)
959 ## Insert conditional statements
961 # Pop an item from IfDefList
962 # Insert conditional statements to database
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
969 def InsertConditionalStatement(self
, Filename
, FileID
, BelongsToItem
, IfDefList
, EndLine
, ArchList
):
970 (Value1
, Value2
, Value3
, Model
, StartColumn
, EndColumn
, Enabled
) = ('', '', '', -1, -1, -1, 0)
972 ErrorMsg
= 'Not suited conditional statement in file %s' % Filename
973 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, Filename
, RaiseError
=EdkLogger
.IsRaiseError
)
976 # Get New Dsc item ID
978 DscID
= self
.TblDsc
.GetCount() + 1
981 # Pop the conditional statements which is closed
983 PreviousIf
= IfDefList
.pop()
984 EdkLogger
.debug(EdkLogger
.DEBUG_5
, 'Previous IfDef: ' + str(PreviousIf
))
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
)
996 elif PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, Model
):
997 List
= PreviousIf
[0].split(' ')
998 Value1
, Value2
, Value3
= '', '==', '0'
1003 Value3
= SplitString(Value3
)
1006 Model
= PreviousIf
[2]
1007 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
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
)
1018 # Load the file if it exists
1020 # @param Filename: Input value for filename of Dsc file
1022 def LoadDscFile(self
, Filename
):
1024 # Insert a record for file
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
)
1034 #self.TblDsc.Table = "Dsc%s" % FileID
1035 #self.TblDsc.Create()
1040 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
1041 [], [], TAB_UNKNOWN
, [], [], []
1045 # Parse file content
1047 IsFindBlockComment
= False
1049 for Line
in open(Filename
, 'r'):
1052 # Remove comment block
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]
1060 IsFindBlockComment
= False
1061 if IsFindBlockComment
:
1065 # Remove comments at tail and remove spaces again
1067 Line
= CleanString(Line
)
1072 # Find a new section tab
1073 # First insert previous section items
1074 # And then parse the content of the new section
1076 if Line
.startswith(TAB_SECTION_START
) and Line
.endswith(TAB_SECTION_END
):
1078 # Insert items data of previous section
1080 self
.InsertSectionItemsIntoDatabase(self
.FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
)
1082 # Parse the new section
1084 SectionItemList
= []
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]
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
1103 if len(ItemList
) > 5:
1104 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
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])
1114 # Not in any defined section
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
)
1121 # Add a section item
1123 SectionItemList
.append([Line
, LineNo
])
1128 # Insert items data of last section
1130 self
.InsertSectionItemsIntoDatabase(self
.FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
)
1133 # Parse conditional statements
1135 self
.ParseConditionalStatement()
1138 # Replace all DEFINE macros with its actual values
1140 #ParseDefineMacro2(self.TblDsc, self.RecordSet, GlobalData.gGlobalDefines)
1141 ParseDefineMacro(self
.TblDsc
, GlobalData
.gGlobalDefines
)
1144 ## ParseConditionalStatement
1146 # Search all conditional statement and disable no match records
1148 def ParseConditionalStatement(self
):
1150 # Disabled all !if/!elif/!ifdef statements without DEFINE
1152 SqlCommand
= """select A.StartLine, A.EndLine from %s as A
1153 where A.Model in (%s, %s, %s)
1155 and A.BelongsToFile = %s
1156 and A.Value1 not in (select B.Value1 from %s as B
1159 and A.StartLine > B.StartLine
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
, \
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
)
1174 # Disabled !ifndef with DEFINE
1176 SqlCommand
= """select A.StartLine, A.EndLine from %s as A
1179 and A.BelongsToFile = %s
1180 and A.Value1 in (select B.Value1 from %s as B
1183 and A.StartLine > B.StartLine
1185 and A.BelongsToItem = B.BelongsToItem
1186 and A.BelongsToFile = B.BelongsToFile)""" % \
1187 (self
.TblDsc
.Table
, \
1188 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
, \
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
)
1199 # Disabled !if, !elif and !else with un-match value
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)
1204 and A.BelongsToFile = %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
)
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
)
1222 DisabledList
.append(Record
[1])
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
)
1230 # Compare two values
1232 # @param CompareType:
1235 def Compare(self
, Value1
, CompareType
, Value2
):
1236 Command
= """Value1 %s Value2""" % CompareType
1237 return eval(Command
)
1239 ## First time to insert records to database
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
1250 def InsertSectionItemsIntoDatabase(self
, FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
):
1252 # Insert each item data of a section
1254 for Index
in range(0, len(ArchList
)):
1255 Arch
= ArchList
[Index
]
1256 Third
= ThirdList
[Index
]
1258 Arch
= TAB_ARCH_COMMON
.upper()
1260 Model
= Section
[CurrentSection
.upper()]
1261 #Records = self.RecordSet[Model]
1263 for SectionItem
in SectionItemList
:
1264 BelongsToItem
, EndLine
, EndColumn
= -1, -1, -1
1265 LineValue
, StartLine
, EndLine
= SectionItem
[0], SectionItem
[1], SectionItem
[1]
1268 EdkLogger
.debug(4, "Parsing %s ..." % LineValue
)
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
))
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
))
1286 if LineValue
.upper().find(TAB_END_IF
.upper()) > -1:
1287 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
, Arch
)
1292 if LineValue
.upper().find(TAB_IF
.upper()) > -1:
1293 IfDefList
.append((LineValue
[len(TAB_IF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
))
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
))
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
))
1314 # Parse !include statement first
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
)
1321 # And then parse DEFINE statement
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
)
1328 # At last parse other sections
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])
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])
1340 # Parse COMPONENT section
1342 if CurrentSection
== TAB_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
= '', ''
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)
1363 ## Show detailed information of Dsc
1365 # Print all members and their values of Dsc class
1368 print TAB_SECTION_START
+ TAB_INF_DEFINES
+ TAB_SECTION_END
1369 printDict(self
.Defines
.DefinesDictionary
)
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
+ ')'
1378 ## Show detailed information of Platform
1380 # Print all members and their values of Platform class
1382 def ShowPlatform(self
):
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
1429 # This acts like the main() function for the script, unless it is 'import'ed into another
1432 if __name__
== '__main__':
1433 EdkLogger
.Initialize()
1434 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
1436 W
= os
.getenv('WORKSPACE')
1437 F
= os
.path
.join(W
, 'Nt32Pkg/Nt32Pkg.dsc')
1439 Db
= Database
.Database('Dsc.db')
1442 P
= Dsc(os
.path
.normpath(F
), True, True, W
, Db
)