2 # This file is used to define each component of DSC file
4 # Copyright (c) 2007 - 2014, 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
108 TAB_SKUIDS
, TAB_LIBRARIES
, TAB_LIBRARY_CLASSES
, TAB_BUILD_OPTIONS
, TAB_PCDS_FIXED_AT_BUILD_NULL
, \
109 TAB_PCDS_PATCHABLE_IN_MODULE_NULL
, TAB_PCDS_FEATURE_FLAG_NULL
, \
110 TAB_PCDS_DYNAMIC_DEFAULT_NULL
, TAB_PCDS_DYNAMIC_HII_NULL
, TAB_PCDS_DYNAMIC_VPD_NULL
, \
111 TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL
, TAB_PCDS_DYNAMIC_EX_HII_NULL
, TAB_PCDS_DYNAMIC_EX_VPD_NULL
, \
112 TAB_COMPONENTS
, TAB_DSC_DEFINES
118 # Upper all KEYs to ignore case sensitive when parsing
120 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
125 # self.RecordSet = {}
126 # for Key in self.KeyList:
127 # self.RecordSet[Section[Key]] = []
130 # Load Dsc file if filename is not None
133 self
.LoadDscFile(Filename
)
136 # Transfer to Platform Object if IsToPlatform is True
141 ## Transfer to Platform Object
143 # Transfer all contents of an Inf file to a standard Module Object
145 def DscToPlatform(self
):
147 # Init global information for the file
149 ContainerFile
= self
.Identification
.FileFullPath
152 # Generate Platform Header
154 self
.GenPlatformHeader(ContainerFile
)
157 # Generate BuildOptions
159 self
.GenBuildOptions(ContainerFile
)
164 self
.GenSkuInfos(ContainerFile
)
169 self
.GenLibraries(ContainerFile
)
172 # Generate LibraryClasses
174 self
.GenLibraryClasses(ContainerFile
)
179 self
.GenPcds(DataType
.TAB_PCDS_FIXED_AT_BUILD
, ContainerFile
)
180 self
.GenPcds(DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
, ContainerFile
)
181 self
.GenFeatureFlagPcds(DataType
.TAB_PCDS_FEATURE_FLAG
, ContainerFile
)
182 self
.GenDynamicDefaultPcds(DataType
.TAB_PCDS_DYNAMIC_DEFAULT
, ContainerFile
)
183 self
.GenDynamicDefaultPcds(DataType
.TAB_PCDS_DYNAMIC_EX_DEFAULT
, ContainerFile
)
184 self
.GenDynamicHiiPcds(DataType
.TAB_PCDS_DYNAMIC_HII
, ContainerFile
)
185 self
.GenDynamicHiiPcds(DataType
.TAB_PCDS_DYNAMIC_EX_HII
, ContainerFile
)
186 self
.GenDynamicVpdPcds(DataType
.TAB_PCDS_DYNAMIC_VPD
, ContainerFile
)
187 self
.GenDynamicVpdPcds(DataType
.TAB_PCDS_DYNAMIC_EX_VPD
, ContainerFile
)
190 # Generate Components
192 self
.GenComponents(ContainerFile
)
197 if self
.IsToDatabase
:
198 for Key
in self
.PcdToken
.keys():
199 SqlCommand
= """update %s set Value2 = '%s' where ID = %s""" % (self
.TblDsc
.Table
, ".".join((self
.PcdToken
[Key
][0], self
.PcdToken
[Key
][1])), Key
)
200 self
.TblDsc
.Exec(SqlCommand
)
201 #End of DscToPlatform
203 ## Get Platform Header
205 # Gen Platform Header of Dsc as <Key> = <Value>
207 # @param ContainerFile: The Dsc file full path
209 def GenPlatformHeader(self
, ContainerFile
):
210 EdkLogger
.debug(2, "Generate PlatformHeader ...")
212 # Update all defines item in database
214 SqlCommand
= """select ID, Value1, Arch, StartLine from %s
216 and BelongsToFile = %s
217 and Enabled > -1""" % (self
.TblDsc
.Table
, MODEL_META_DATA_HEADER
, self
.FileID
)
218 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
219 for Record
in RecordSet
:
220 ValueList
= GetSplitValueList(Record
[1], TAB_EQUAL_SPLIT
)
221 if len(ValueList
) != 2:
222 RaiseParserError(Record
[1], 'Defines', ContainerFile
, '<Key> = <Value>', Record
[3])
223 ID
, Value1
, Value2
, Arch
= Record
[0], ValueList
[0], ValueList
[1], Record
[2]
224 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
225 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(Value1
), ConvertToSqlString2(Value2
), ID
)
226 self
.TblDsc
.Exec(SqlCommand
)
229 # Get detailed information
231 for Arch
in DataType
.ARCH_LIST
:
232 PlatformHeader
= PlatformHeaderClass()
234 PlatformHeader
.Name
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_PLATFORM_NAME
, Arch
, self
.FileID
)[0]
235 PlatformHeader
.Guid
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_PLATFORM_GUID
, Arch
, self
.FileID
)[0]
236 PlatformHeader
.Version
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_PLATFORM_VERSION
, Arch
, self
.FileID
)[0]
237 PlatformHeader
.FileName
= self
.Identification
.FileName
238 PlatformHeader
.FullPath
= self
.Identification
.FileFullPath
239 PlatformHeader
.DscSpecification
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_DSC_SPECIFICATION
, Arch
, self
.FileID
)[0]
241 PlatformHeader
.SkuIdName
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_SKUID_IDENTIFIER
, Arch
, self
.FileID
)
242 PlatformHeader
.SupArchList
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
, Arch
, self
.FileID
)
243 PlatformHeader
.BuildTargets
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_BUILD_TARGETS
, Arch
, self
.FileID
)
244 PlatformHeader
.OutputDirectory
= NormPath(QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_OUTPUT_DIRECTORY
, Arch
, self
.FileID
)[0])
245 PlatformHeader
.BuildNumber
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_BUILD_NUMBER
, Arch
, self
.FileID
)[0]
246 PlatformHeader
.MakefileName
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_MAKEFILE_NAME
, Arch
, self
.FileID
)[0]
248 PlatformHeader
.BsBaseAddress
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_BS_BASE_ADDRESS
, Arch
, self
.FileID
)[0]
249 PlatformHeader
.RtBaseAddress
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_RT_BASE_ADDRESS
, Arch
, self
.FileID
)[0]
251 self
.Platform
.Header
[Arch
] = PlatformHeader
252 Fdf
= PlatformFlashDefinitionFileClass()
253 Fdf
.FilePath
= NormPath(QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_FLASH_DEFINITION
, Arch
, self
.FileID
)[0])
254 self
.Platform
.FlashDefinitionFile
= Fdf
258 # Gen BuildOptions of Dsc
259 # [<Family>:]<ToolFlag>=Flag
261 # @param ContainerFile: The Dsc file full path
263 def GenBuildOptions(self
, ContainerFile
):
264 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
267 # Get all include files
269 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_BUILD_OPTION
, self
.FileID
)
272 # Get all BuildOptions
274 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, -1, self
.FileID
)
277 # Go through each arch
279 for Arch
in DataType
.ARCH_LIST
:
280 for IncludeFile
in IncludeFiles
:
281 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
282 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_BUILD_OPTIONS
, '', IncludeFile
[2])
283 for NewItem
in open(Filename
, 'r').readlines():
284 if CleanString(NewItem
) == '':
286 (Family
, ToolChain
, Flag
) = GetBuildOption(NewItem
, Filename
, -1)
287 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
289 for Record
in RecordSet
:
290 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
291 (Family
, ToolChain
, Flag
) = GetBuildOption(Record
[0], ContainerFile
, Record
[2])
292 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
296 if self
.IsToDatabase
:
297 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
298 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(Family
), ConvertToSqlString2(ToolChain
), ConvertToSqlString2(Flag
), Record
[3])
299 self
.TblDsc
.Exec(SqlCommand
)
301 for Key
in BuildOptions
.keys():
302 BuildOption
= BuildOptionClass(Key
[0], Key
[1], Key
[2])
303 BuildOption
.SupArchList
= BuildOptions
[Key
]
304 self
.Platform
.BuildOptions
.BuildOptionList
.append(BuildOption
)
308 # Gen SkuInfos of Dsc
311 # @param ContainerFile: The Dsc file full path
313 def GenSkuInfos(self
, ContainerFile
):
314 EdkLogger
.debug(2, "Generate %s ..." % TAB_SKUIDS
)
319 self
.Platform
.SkuInfos
.SkuInfoList
['DEFAULT'] = '0'
322 # Get all include files
324 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_SKU_ID
, self
.FileID
)
329 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_SKU_ID
, -1, self
.FileID
)
332 # Go through each arch
334 for Arch
in DataType
.ARCH_LIST
:
335 for IncludeFile
in IncludeFiles
:
336 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
337 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_SKUIDS
, '', IncludeFile
[2])
338 for NewItem
in open(Filename
, 'r').readlines():
339 if CleanString(NewItem
) == '':
341 List
= GetSplitValueList(NewItem
)
343 RaiseParserError(NewItem
, TAB_SKUIDS
, Filename
, '<Integer>|<UiName>')
345 self
.Platform
.SkuInfos
.SkuInfoList
[List
[1]] = List
[0]
347 for Record
in RecordSet
:
348 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
349 List
= GetSplitValueList(Record
[0])
351 RaiseParserError(Record
[0], TAB_SKUIDS
, ContainerFile
, '<Integer>|<UiName>')
353 self
.Platform
.SkuInfos
.SkuInfoList
[List
[1]] = List
[0]
357 if self
.IsToDatabase
:
358 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
359 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(List
[0]), ConvertToSqlString2(List
[1]), Record
[3])
360 self
.TblDsc
.Exec(SqlCommand
)
364 # Gen Libraries of Dsc
367 # @param ContainerFile: The Dsc file full path
369 def GenLibraries(self
, ContainerFile
):
370 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARIES
)
373 # Get all include files
375 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_INSTANCE
, self
.FileID
)
380 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_INSTANCE
, -1, self
.FileID
)
383 # Go through each arch
385 for Arch
in DataType
.ARCH_LIST
:
386 for IncludeFile
in IncludeFiles
:
387 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
388 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_LIBRARIES
, '', IncludeFile
[2])
389 if os
.path
.exists(Filename
):
390 for NewItem
in open(Filename
, 'r').readlines():
391 if CleanString(NewItem
) == '':
393 MergeArches(Libraries
, NewItem
, Arch
)
395 for Record
in RecordSet
:
396 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
397 MergeArches(Libraries
, Record
[0], Arch
)
399 for Key
in Libraries
.keys():
400 Library
= PlatformLibraryClass()
401 Library
.FilePath
= NormPath(Key
)
402 Library
.SupArchList
= Libraries
[Key
]
403 self
.Platform
.Libraries
.LibraryList
.append(Library
)
407 # Get LibraryClasses of Dsc
408 # <LibraryClassKeyWord>|<LibraryInstance>
410 # @param ContainerFile: The Dsc file full path
412 def GenLibraryClasses(self
, ContainerFile
):
413 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
416 # Get all include files
418 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_CLASS
, self
.FileID
)
421 # Get all LibraryClasses
423 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, -1, self
.FileID
)
426 # Go through each arch
428 for Arch
in DataType
.ARCH_LIST
:
429 for IncludeFile
in IncludeFiles
:
430 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
431 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_LIBRARY_CLASSES
, '', IncludeFile
[2])
432 for NewItem
in open(Filename
, 'r').readlines():
433 if CleanString(NewItem
) == '':
435 MergeArches(LibraryClasses
, GetLibraryClass([NewItem
, IncludeFile
[4]], Filename
, self
.WorkspaceDir
, -1), Arch
)
437 for Record
in RecordSet
:
438 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
439 (LibClassName
, LibClassIns
, SupModelList
) = GetLibraryClass([Record
[0], Record
[4]], ContainerFile
, self
.WorkspaceDir
, Record
[2])
440 MergeArches(LibraryClasses
, (LibClassName
, LibClassIns
, SupModelList
), Arch
)
444 if self
.IsToDatabase
:
445 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
446 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(LibClassName
), ConvertToSqlString2(LibClassIns
), ConvertToSqlString2(SupModelList
), Record
[3])
447 self
.TblDsc
.Exec(SqlCommand
)
449 for Key
in LibraryClasses
.keys():
450 Library
= PlatformLibraryClass()
451 Library
.Name
= Key
[0]
452 Library
.FilePath
= NormPath(Key
[1])
453 Library
.SupModuleList
= GetSplitValueList(Key
[2])
454 Library
.SupArchList
= LibraryClasses
[Key
]
455 self
.Platform
.LibraryClasses
.LibraryList
.append(Library
)
459 # Gen Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]
461 # @param Type: The type of Pcd
462 # @param ContainerFile: The file which describes the pcd, used for error report
464 def GenPcds(self
, Type
='', ContainerFile
=''):
466 if Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
467 Model
= MODEL_PCD_PATCHABLE_IN_MODULE
468 elif Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
:
469 Model
= MODEL_PCD_FIXED_AT_BUILD
472 EdkLogger
.debug(2, "Generate %s ..." % Type
)
475 # Get all include files
477 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
482 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
485 # Go through each arch
487 for Arch
in DataType
.ARCH_LIST
:
488 for IncludeFile
in IncludeFiles
:
489 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
490 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
491 for NewItem
in open(Filename
, 'r').readlines():
492 if CleanString(NewItem
) == '':
494 (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
) = GetPcd(NewItem
, Type
, Filename
, -1)
495 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
), Arch
)
496 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
498 for Record
in RecordSet
:
499 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
500 (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
) = GetPcd(Record
[0], Type
, ContainerFile
, Record
[2])
501 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
), Arch
)
502 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
505 Pcd
= PcdClass(Key
[0], '', Key
[1], Key
[3], Key
[4], Key
[2], Key
[5], [], {}, [])
506 Pcd
.SupArchList
= Pcds
[Key
]
507 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
509 ## Gen FeatureFlagPcds
511 # Gen FeatureFlagPcds of Dsc file as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE
513 # @param Type: The type of Pcd
514 # @param ContainerFile: The file which describes the pcd, used for error report
516 def GenFeatureFlagPcds(self
, Type
='', ContainerFile
=''):
518 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
519 Model
= MODEL_PCD_FEATURE_FLAG
522 EdkLogger
.debug(2, "Generate %s ..." % Type
)
525 # Get all include files
527 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
530 # Get all FeatureFlagPcds
532 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
535 # Go through each arch
537 for Arch
in DataType
.ARCH_LIST
:
538 for IncludeFile
in IncludeFiles
:
539 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
540 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
541 for NewItem
in open(Filename
, 'r').readlines():
542 if CleanString(NewItem
) == '':
544 (TokenName
, TokenGuidCName
, Value
, Type
) = GetFeatureFlagPcd(NewItem
, Type
, Filename
, -1)
545 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, Type
), Arch
)
546 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
548 for Record
in RecordSet
:
549 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
550 (TokenName
, TokenGuidCName
, Value
, Type
) = GetFeatureFlagPcd(Record
[0], Type
, ContainerFile
, Record
[2])
551 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, Type
), Arch
)
552 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
555 Pcd
= PcdClass(Key
[0], '', Key
[1], '', '', Key
[2], Key
[3], [], {}, [])
556 Pcd
.SupArchList
= Pcds
[Key
]
557 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
559 ## Gen DynamicDefaultPcds
561 # Gen DynamicDefaultPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]
563 # @param Type: The type of Pcd
564 # @param ContainerFile: The file which describes the pcd, used for error report
566 def GenDynamicDefaultPcds(self
, Type
='', ContainerFile
=''):
569 if Type
== DataType
.TAB_PCDS_DYNAMIC_DEFAULT
:
570 Model
= MODEL_PCD_DYNAMIC_DEFAULT
571 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_DEFAULT
:
572 Model
= MODEL_PCD_DYNAMIC_EX_DEFAULT
575 EdkLogger
.debug(2, "Generate %s ..." % Type
)
578 # Get all include files
580 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
583 # Get all DynamicDefaultPcds
585 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
588 # Go through each arch
590 for Arch
in DataType
.ARCH_LIST
:
591 for IncludeFile
in IncludeFiles
:
592 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
593 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
594 for NewItem
in open(Filename
, 'r').readlines():
595 if CleanString(NewItem
) == '':
597 (K1
, K2
, K3
, K4
, K5
, K6
) = GetDynamicDefaultPcd(NewItem
, Type
, Filename
, -1)
598 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, IncludeFile
[4]), Arch
)
599 self
.PcdToken
[Record
[3]] = (K2
, K1
)
601 for Record
in RecordSet
:
602 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
603 (K1
, K2
, K3
, K4
, K5
, K6
) = GetDynamicDefaultPcd(Record
[0], Type
, ContainerFile
, Record
[2])
604 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, Record
[4]), Arch
)
605 self
.PcdToken
[Record
[3]] = (K2
, K1
)
608 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[6], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', '', Key
[2])
610 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
611 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
612 Pcd
= PcdClass(Key
[0], '', Key
[1], Key
[3], Key
[4], Key
[2], Key
[5], [], SkuInfoList
, [])
613 Pcd
.SupArchList
= Pcds
[Key
]
614 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
616 ## Gen DynamicHiiPcds
618 # Gen DynamicHiiPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]
620 # @param Type: The type of Pcd
621 # @param ContainerFile: The file which describes the pcd, used for error report
623 def GenDynamicHiiPcds(self
, Type
='', ContainerFile
=''):
626 if Type
== DataType
.TAB_PCDS_DYNAMIC_HII
:
627 Model
= MODEL_PCD_DYNAMIC_HII
628 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_HII
:
629 Model
= MODEL_PCD_DYNAMIC_EX_HII
632 EdkLogger
.debug(2, "Generate %s ..." % Type
)
635 # Get all include files
637 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
640 # Get all DynamicHiiPcds
642 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
645 # Go through each arch
647 for Arch
in DataType
.ARCH_LIST
:
648 for IncludeFile
in IncludeFiles
:
649 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
650 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
651 for NewItem
in open(Filename
, 'r').readlines():
652 if CleanString(NewItem
) == '':
654 (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
) = GetDynamicHiiPcd(NewItem
, Type
, Filename
, -1)
655 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
, IncludeFile
[4]), Arch
)
656 self
.PcdToken
[Record
[3]] = (K2
, K1
)
658 for Record
in RecordSet
:
659 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
660 (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
) = GetDynamicHiiPcd(Record
[0], Type
, ContainerFile
, Record
[2])
661 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
, Record
[4]), Arch
)
662 self
.PcdToken
[Record
[3]] = (K2
, K1
)
665 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[8], self
.Platform
.SkuInfos
.SkuInfoList
, Key
[2], Key
[3], Key
[4], Key
[5], '', '')
667 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
668 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
669 Pcd
= PcdClass(Key
[0], '', Key
[1], '', Key
[6], Key
[5], Key
[7], [], SkuInfoList
, [])
670 Pcd
.SupArchList
= Pcds
[Key
]
671 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
673 ## Gen DynamicVpdPcds
675 # Gen DynamicVpdPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]
677 # @param Type: The type of Pcd
678 # @param ContainerFile: The file which describes the pcd, used for error report
680 def GenDynamicVpdPcds(self
, Type
='', ContainerFile
=''):
683 if Type
== DataType
.TAB_PCDS_DYNAMIC_VPD
:
684 Model
= MODEL_PCD_DYNAMIC_VPD
685 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_VPD
:
686 Model
= MODEL_PCD_DYNAMIC_EX_VPD
689 EdkLogger
.debug(2, "Generate %s ..." % Type
)
692 # Get all include files
694 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
697 # Get all DynamicVpdPcds
699 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
702 # Go through each arch
704 for Arch
in DataType
.ARCH_LIST
:
705 for IncludeFile
in IncludeFiles
:
706 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
707 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
708 for NewItem
in open(Filename
, 'r').readlines():
709 if CleanString(NewItem
) == '':
711 (K1
, K2
, K3
, K4
, K5
) = GetDynamicVpdPcd(NewItem
, Type
, Filename
, -1)
712 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, IncludeFile
[4]), Arch
)
713 self
.PcdToken
[Record
[3]] = (K2
, K1
)
715 for Record
in RecordSet
:
716 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
717 (K1
, K2
, K3
, K4
, K5
) = GetDynamicVpdPcd(Record
[0], Type
, ContainerFile
, Record
[2])
718 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, Record
[4]), Arch
)
719 self
.PcdToken
[Record
[3]] = (K2
, K1
)
722 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[5], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', Key
[2], '')
724 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
725 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
726 Pcd
= PcdClass(Key
[0], '', Key
[1], '', Key
[3], '', Key
[4], [], SkuInfoList
, [])
727 Pcd
.SupArchList
= Pcds
[Key
]
728 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
733 # Get Component section defined in Dsc file
735 # @param ContainerFile: The file which describes the Components, used for error report
737 # @retval PlatformModuleClass() A instance for PlatformModuleClass
739 def GenComponents(self
, ContainerFile
):
740 EdkLogger
.debug(2, "Generate %s ..." % TAB_COMPONENTS
)
743 # Get all include files
745 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_COMPONENT
, self
.FileID
)
750 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_COMPONENT
, -1, self
.FileID
)
753 # Go through each arch
755 for Arch
in DataType
.ARCH_LIST
:
756 for IncludeFile
in IncludeFiles
:
757 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
758 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_COMPONENTS
, '', IncludeFile
[2])
759 for NewItem
in open(Filename
, 'r').readlines():
760 if CleanString(NewItem
) == '':
763 GetComponents(open(Filename
, 'r').read(), TAB_COMPONENTS
, NewItems
, TAB_COMMENT_SPLIT
)
764 for NewComponent
in NewItems
:
765 MergeArches(Components
, self
.GenComponent(NewComponent
, Filename
), Arch
)
767 for Record
in RecordSet
:
768 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
769 Lib
, Bo
, Pcd
= [], [], []
771 SubLibSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, Record
[3], self
.FileID
)
772 for SubLib
in SubLibSet
:
773 Lib
.append(TAB_VALUE_SPLIT
.join([SubLib
[0], SubLib
[4]]))
775 SubBoSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, Record
[3], self
.FileID
)
776 for SubBo
in SubBoSet
:
779 SubPcdSet1
= QueryDscItem(self
.TblDsc
, MODEL_PCD_FIXED_AT_BUILD
, Record
[3], self
.FileID
)
780 SubPcdSet2
= QueryDscItem(self
.TblDsc
, MODEL_PCD_PATCHABLE_IN_MODULE
, Record
[3], self
.FileID
)
781 SubPcdSet3
= QueryDscItem(self
.TblDsc
, MODEL_PCD_FEATURE_FLAG
, Record
[3], self
.FileID
)
782 SubPcdSet4
= QueryDscItem(self
.TblDsc
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, Record
[3], self
.FileID
)
783 SubPcdSet5
= QueryDscItem(self
.TblDsc
, MODEL_PCD_DYNAMIC_DEFAULT
, Record
[3], self
.FileID
)
784 for SubPcd
in SubPcdSet1
:
785 Pcd
.append([DataType
.TAB_PCDS_FIXED_AT_BUILD
, SubPcd
[0], SubPcd
[3]])
786 for SubPcd
in SubPcdSet2
:
787 Pcd
.append([DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
, SubPcd
[0], SubPcd
[3]])
788 for SubPcd
in SubPcdSet3
:
789 Pcd
.append([DataType
.TAB_PCDS_FEATURE_FLAG
, SubPcd
[0], SubPcd
[3]])
790 for SubPcd
in SubPcdSet4
:
791 Pcd
.append([DataType
.TAB_PCDS_DYNAMIC_EX
, SubPcd
[0], SubPcd
[3]])
792 for SubPcd
in SubPcdSet5
:
793 Pcd
.append([DataType
.TAB_PCDS_DYNAMIC
, SubPcd
[0], SubPcd
[3]])
794 Item
= [Record
[0], Lib
, Bo
, Pcd
]
795 MergeArches(Components
, self
.GenComponent(Item
, ContainerFile
), Arch
)
797 for Key
in Components
.keys():
798 Key
.SupArchList
= Components
[Key
]
799 self
.Platform
.Modules
.ModuleList
.append(Key
)
803 # Get Component section defined in Dsc file
805 # @param Item: Contents includes a component block
806 # @param ContainerFile: The file which describes the library class, used for error report
808 # @retval PlatformModuleClass() A instance for PlatformModuleClass
810 def GenComponent(self
, Item
, ContainerFile
, LineNo
= -1):
811 (InfFilename
, ExecFilename
) = GetExec(Item
[0])
812 LibraryClasses
= Item
[1]
813 BuildOptions
= Item
[2]
815 Component
= PlatformModuleClass()
816 Component
.FilePath
= NormPath(InfFilename
)
817 Component
.ExecFilePath
= NormPath(ExecFilename
)
818 CheckFileType(Component
.FilePath
, '.Inf', ContainerFile
, 'component name', Item
[0], LineNo
)
819 CheckFileExist(self
.WorkspaceDir
, Component
.FilePath
, ContainerFile
, 'component', Item
[0], LineNo
)
820 for Lib
in LibraryClasses
:
821 List
= GetSplitValueList(Lib
)
823 RaiseParserError(Lib
, 'LibraryClasses', ContainerFile
, '<ClassName>|<InfFilename>')
825 LibFile
= NormPath(List
[1])
826 if LibName
== "" or LibName
== "NULL":
827 LibName
= "NULL%d" % self
._NullClassIndex
828 self
._NullClassIndex
+= 1
829 CheckFileType(List
[1], '.Inf', ContainerFile
, 'library instance of component ', Lib
, LineNo
)
830 CheckFileExist(self
.WorkspaceDir
, LibFile
, ContainerFile
, 'library instance of component', Lib
, LineNo
)
831 Component
.LibraryClasses
.LibraryList
.append(PlatformLibraryClass(LibName
, LibFile
))
832 for BuildOption
in BuildOptions
:
833 Key
= GetBuildOption(BuildOption
, ContainerFile
)
834 Component
.ModuleSaBuildOption
.BuildOptionList
.append(BuildOptionClass(Key
[0], Key
[1], Key
[2]))
837 List
= GetSplitValueList(Pcd
[1])
844 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
846 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|TRUE/FALSE')
848 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
849 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
850 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', List
[1], Type
, [], {}, []))
852 # For FixedAtBuild or PatchableInModule
854 if Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
or Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
856 if len(List
) != 3 and len(List
) != 4:
857 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|<Value>[|<MaxDatumSize>]')
859 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
860 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
861 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', List
[2], List
[1], Type
, [], {}, []))
864 # For Dynamic or DynamicEx
866 if Type
== DataType
.TAB_PCDS_DYNAMIC
or Type
== DataType
.TAB_PCDS_DYNAMIC_EX
:
868 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>')
870 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
871 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
872 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', '', Type
, [], {}, []))
877 self
.PcdToken
[PcdId
] = (TokenInfo
[0], TokenInfo
[1])
884 # Gen SkuInfoList section defined in Dsc file
886 # @param SkuNameList: Input value for SkuNameList
887 # @param SkuInfo: Input value for SkuInfo
888 # @param VariableName: Input value for VariableName
889 # @param VariableGuid: Input value for VariableGuid
890 # @param VariableOffset: Input value for VariableOffset
891 # @param HiiDefaultValue: Input value for HiiDefaultValue
892 # @param VpdOffset: Input value for VpdOffset
893 # @param DefaultValue: Input value for DefaultValue
895 # @retval (False, SkuName) Not found in section SkuId Dsc file
896 # @retval (True, SkuInfoList) Found in section SkuId of Dsc file
898 def GenSkuInfoList(self
, SkuNameList
, SkuInfo
, VariableName
='', VariableGuid
='', VariableOffset
='', HiiDefaultValue
='', VpdOffset
='', DefaultValue
=''):
899 SkuNameList
= GetSplitValueList(SkuNameList
)
900 if SkuNameList
== None or SkuNameList
== [] or SkuNameList
== ['']:
901 SkuNameList
= ['DEFAULT']
903 for Item
in SkuNameList
:
904 if Item
not in SkuInfo
:
906 Sku
= SkuInfoClass(Item
, SkuInfo
[Item
], VariableName
, VariableGuid
, VariableOffset
, HiiDefaultValue
, VpdOffset
, DefaultValue
)
907 SkuInfoList
[Item
] = Sku
909 return True, SkuInfoList
911 ## Parse Include statement
913 # Get include file path
915 # 1. Insert a record into TblFile ???
916 # 2. Insert a record into TblDsc
917 # Value1: IncludeFilePath
919 # @param LineValue: The line of incude statement
920 def ParseInclude(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
921 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "!include statement '%s' found in section %s" % (LineValue
, SectionName
))
922 SectionModel
= Section
[SectionName
.upper()]
923 IncludeFile
= CleanString(LineValue
[LineValue
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') + len(DataType
.TAB_INCLUDE
+ ' ') : ])
924 Table
.Insert(Model
, IncludeFile
, '', '', Arch
, SectionModel
, FileID
, StartLine
, -1, StartLine
, -1, 0)
926 ## Parse DEFINE statement
930 # 1. Insert a record into TblDsc
932 # Value2: Macro Value
934 def ParseDefine(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
935 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "DEFINE statement '%s' found in section %s" % (LineValue
, SectionName
))
936 SectionModel
= Section
[SectionName
.upper()]
937 Define
= GetSplitValueList(CleanString(LineValue
[LineValue
.upper().find(DataType
.TAB_DEFINE
.upper() + ' ') + len(DataType
.TAB_DEFINE
+ ' ') : ]), TAB_EQUAL_SPLIT
, 1)
938 Table
.Insert(Model
, Define
[0], Define
[1], '', Arch
, SectionModel
, FileID
, StartLine
, -1, StartLine
, -1, 0)
940 ## Parse Defines section
942 # Get one item in defines section
947 def ParseDefinesSection(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
948 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "Parse '%s' found in section %s" % (LineValue
, SectionName
))
949 Defines
= GetSplitValueList(LineValue
, TAB_EQUAL_SPLIT
, 1)
950 if len(Defines
) != 2:
951 RaiseParserError(LineValue
, SectionName
, Filename
, '', StartLine
)
952 self
.TblDsc
.Insert(Model
, Defines
[0], Defines
[1], '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
954 ## Insert conditional statements
956 # Pop an item from IfDefList
957 # Insert conditional statements to database
959 # @param Filename: Path of parsing file
960 # @param IfDefList: A list stored current conditional statements
961 # @param EndLine: The end line no
962 # @param ArchList: Support arch list
964 def InsertConditionalStatement(self
, Filename
, FileID
, BelongsToItem
, IfDefList
, EndLine
, ArchList
):
965 (Value1
, Value2
, Value3
, Model
, StartColumn
, EndColumn
, Enabled
) = ('', '', '', -1, -1, -1, 0)
967 ErrorMsg
= 'Not suited conditional statement in file %s' % Filename
968 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, Filename
, RaiseError
=EdkLogger
.IsRaiseError
)
971 # Get New Dsc item ID
973 DscID
= self
.TblDsc
.GetCount() + 1
976 # Pop the conditional statements which is closed
978 PreviousIf
= IfDefList
.pop()
979 EdkLogger
.debug(EdkLogger
.DEBUG_5
, 'Previous IfDef: ' + str(PreviousIf
))
984 if PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
):
985 Value1
= PreviousIf
[0]
986 Model
= PreviousIf
[2]
987 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
991 elif PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, Model
):
992 List
= PreviousIf
[0].split(' ')
993 Value1
, Value2
, Value3
= '', '==', '0'
998 Value3
= SplitString(Value3
)
1001 Model
= PreviousIf
[2]
1002 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
1006 elif PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, Model
):
1007 Value1
= PreviousIf
[0].strip()
1008 Model
= PreviousIf
[2]
1009 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
1013 # Load the file if it exists
1015 # @param Filename: Input value for filename of Dsc file
1017 def LoadDscFile(self
, Filename
):
1019 # Insert a record for file
1021 Filename
= NormPath(Filename
)
1022 self
.Identification
.FileFullPath
= Filename
1023 (self
.Identification
.FileRelativePath
, self
.Identification
.FileName
) = os
.path
.split(Filename
)
1024 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_DSC
)
1029 #self.TblDsc.Table = "Dsc%s" % FileID
1030 #self.TblDsc.Create()
1035 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
1036 [], [], TAB_UNKNOWN
, [], [], []
1040 # Parse file content
1042 IsFindBlockComment
= False
1044 for Line
in open(Filename
, 'r'):
1047 # Remove comment block
1049 if Line
.find(TAB_COMMENT_EDK_START
) > -1:
1050 ReservedLine
= GetSplitList(Line
, TAB_COMMENT_EDK_START
, 1)[0]
1051 IsFindBlockComment
= True
1052 if Line
.find(TAB_COMMENT_EDK_END
) > -1:
1053 Line
= ReservedLine
+ GetSplitList(Line
, TAB_COMMENT_EDK_END
, 1)[1]
1055 IsFindBlockComment
= False
1056 if IsFindBlockComment
:
1060 # Remove comments at tail and remove spaces again
1062 Line
= CleanString(Line
)
1067 # Find a new section tab
1068 # First insert previous section items
1069 # And then parse the content of the new section
1071 if Line
.startswith(TAB_SECTION_START
) and Line
.endswith(TAB_SECTION_END
):
1073 # Insert items data of previous section
1075 self
.InsertSectionItemsIntoDatabase(self
.FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
)
1077 # Parse the new section
1079 SectionItemList
= []
1084 LineList
= GetSplitValueList(Line
[len(TAB_SECTION_START
):len(Line
) - len(TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
1085 for Item
in LineList
:
1086 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
1087 if CurrentSection
== '':
1088 CurrentSection
= ItemList
[0]
1090 if CurrentSection
!= ItemList
[0]:
1091 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
)
1092 if CurrentSection
.upper() not in self
.KeyList
:
1093 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
1094 CurrentSection
= TAB_UNKNOWN
1098 if len(ItemList
) > 5:
1099 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
1101 if ItemList
[1] != '' and ItemList
[1].upper() not in ARCH_LIST_FULL
:
1102 EdkLogger
.error("Parser", PARSER_ERROR
, "Invalid Arch definition '%s' found" % ItemList
[1], File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
1103 ArchList
.append(ItemList
[1].upper())
1104 ThirdList
.append(ItemList
[2])
1109 # Not in any defined section
1111 if CurrentSection
== TAB_UNKNOWN
:
1112 ErrorMsg
= "%s is not in any defined section" % Line
1113 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
1116 # Add a section item
1118 SectionItemList
.append([Line
, LineNo
])
1123 # Insert items data of last section
1125 self
.InsertSectionItemsIntoDatabase(self
.FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
)
1128 # Parse conditional statements
1130 self
.ParseConditionalStatement()
1133 # Replace all DEFINE macros with its actual values
1135 #ParseDefineMacro2(self.TblDsc, self.RecordSet, GlobalData.gGlobalDefines)
1136 ParseDefineMacro(self
.TblDsc
, GlobalData
.gGlobalDefines
)
1139 ## ParseConditionalStatement
1141 # Search all conditional statement and disable no match records
1143 def ParseConditionalStatement(self
):
1145 # Disabled all !if/!elif/!ifdef statements without DEFINE
1147 SqlCommand
= """select A.StartLine, A.EndLine from %s as A
1148 where A.Model in (%s, %s, %s)
1150 and A.BelongsToFile = %s
1151 and A.Value1 not in (select B.Value1 from %s as B
1154 and A.StartLine > B.StartLine
1156 and A.BelongsToItem = B.BelongsToItem
1157 and A.BelongsToFile = B.BelongsToFile) """ % \
1158 (self
.TblDsc
.Table
, \
1159 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
, \
1161 self
.TblDsc
.Table
, \
1162 MODEL_META_DATA_DEFINE
)
1163 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1164 for Record
in RecordSet
:
1165 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[0], Record
[1])
1166 self
.TblDsc
.Exec(SqlCommand
)
1169 # Disabled !ifndef with DEFINE
1171 SqlCommand
= """select A.StartLine, A.EndLine from %s as A
1174 and A.BelongsToFile = %s
1175 and A.Value1 in (select B.Value1 from %s as B
1178 and A.StartLine > B.StartLine
1180 and A.BelongsToItem = B.BelongsToItem
1181 and A.BelongsToFile = B.BelongsToFile)""" % \
1182 (self
.TblDsc
.Table
, \
1183 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
, \
1185 self
.TblDsc
.Table
, \
1186 MODEL_META_DATA_DEFINE
)
1187 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1188 for Record
in RecordSet
:
1189 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[0], Record
[1])
1190 EdkLogger
.debug(4, "SqlCommand: %s" % SqlCommand
)
1191 self
.Cur
.execute(SqlCommand
)
1194 # Disabled !if, !elif and !else with un-match value
1196 SqlCommand
= """select A.Model, A.Value1, A.Value2, A.Value3, A.StartLine, A.EndLine, B.Value2 from %s as A join %s as B
1197 where A.Model in (%s, %s)
1199 and A.BelongsToFile = %s
1202 and A.Value1 = B.Value1
1203 and A.StartLine > B.StartLine
1204 and A.BelongsToItem = B.BelongsToItem
1205 and A.BelongsToFile = B.BelongsToFile""" % \
1206 (self
.TblDsc
.Table
, self
.TblDsc
.Table
, \
1207 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, \
1208 self
.FileID
, MODEL_META_DATA_DEFINE
)
1209 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1211 for Record
in RecordSet
:
1212 if Record
[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
:
1213 if not self
.Compare(Record
[6], Record
[2], Record
[3]):
1214 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[4], Record
[5])
1215 self
.TblDsc
.Exec(SqlCommand
)
1217 DisabledList
.append(Record
[1])
1219 if Record
[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
and Record
[1] in DisabledList
:
1220 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[4], Record
[5])
1221 self
.TblDsc
.Exec(SqlCommand
)
1225 # Compare two values
1227 # @param CompareType:
1230 def Compare(self
, Value1
, CompareType
, Value2
):
1231 Command
= """Value1 %s Value2""" % CompareType
1232 return eval(Command
)
1234 ## First time to insert records to database
1236 # Insert item data of a section to database
1237 # @param FileID: The ID of belonging file
1238 # @param Filename: The name of belonging file
1239 # @param CurrentSection: The name of currect section
1240 # @param SectionItemList: A list of items of the section
1241 # @param ArchList: A list of arches
1242 # @param ThirdList: A list of third parameters, ModuleType for LibraryClass and SkuId for Dynamic Pcds
1243 # @param IfDefList: A list of all conditional statements
1245 def InsertSectionItemsIntoDatabase(self
, FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
):
1247 # Insert each item data of a section
1249 for Index
in range(0, len(ArchList
)):
1250 Arch
= ArchList
[Index
]
1251 Third
= ThirdList
[Index
]
1253 Arch
= TAB_ARCH_COMMON
.upper()
1255 Model
= Section
[CurrentSection
.upper()]
1256 #Records = self.RecordSet[Model]
1258 for SectionItem
in SectionItemList
:
1259 BelongsToItem
, EndLine
, EndColumn
= -1, -1, -1
1260 LineValue
, StartLine
, EndLine
= SectionItem
[0], SectionItem
[1], SectionItem
[1]
1263 EdkLogger
.debug(4, "Parsing %s ..." % LineValue
)
1267 if LineValue
.upper().find(TAB_IF_DEF
.upper()) > -1:
1268 IfDefList
.append((LineValue
[len(TAB_IF_N_DEF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
))
1274 if LineValue
.upper().find(TAB_IF_N_DEF
.upper()) > -1:
1275 IfDefList
.append((LineValue
[len(TAB_IF_N_DEF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
))
1281 if LineValue
.upper().find(TAB_END_IF
.upper()) > -1:
1282 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
, Arch
)
1287 if LineValue
.upper().find(TAB_IF
.upper()) > -1:
1288 IfDefList
.append((LineValue
[len(TAB_IF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
))
1294 if LineValue
.upper().find(TAB_ELSE_IF
.upper()) > -1:
1295 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
- 1, Arch
)
1296 IfDefList
.append((LineValue
[len(TAB_ELSE_IF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
))
1302 if LineValue
.upper().find(TAB_ELSE
.upper()) > -1:
1303 Key
= IfDefList
[-1][0].split(' ' , 1)[0].strip()
1304 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
, Arch
)
1305 IfDefList
.append((Key
, StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
))
1309 # Parse !include statement first
1311 if LineValue
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') > -1:
1312 self
.ParseInclude(LineValue
, StartLine
, self
.TblDsc
, FileID
, Filename
, CurrentSection
, MODEL_META_DATA_INCLUDE
, Arch
)
1316 # And then parse DEFINE statement
1318 if LineValue
.upper().find(DataType
.TAB_DEFINE
.upper() + ' ') > -1:
1319 self
.ParseDefine(LineValue
, StartLine
, self
.TblDsc
, FileID
, Filename
, CurrentSection
, MODEL_META_DATA_DEFINE
, Arch
)
1323 # At last parse other sections
1325 if CurrentSection
== TAB_LIBRARY_CLASSES
or CurrentSection
in TAB_PCD_DYNAMIC_TYPE_LIST
or CurrentSection
in TAB_PCD_DYNAMIC_EX_TYPE_LIST
:
1326 ID
= self
.TblDsc
.Insert(Model
, LineValue
, Third
, '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1327 #Records.append([LineValue, Arch, StartLine, ID, Third])
1329 elif CurrentSection
!= TAB_COMPONENTS
:
1330 ID
= self
.TblDsc
.Insert(Model
, LineValue
, '', '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1331 #Records.append([LineValue, Arch, StartLine, ID, Third])
1335 # Parse COMPONENT section
1337 if CurrentSection
== TAB_COMPONENTS
:
1339 GetComponent(SectionItemList
, Components
)
1340 for Component
in Components
:
1341 EdkLogger
.debug(4, "Parsing component %s ..." % Component
)
1342 DscItmeID
= self
.TblDsc
.Insert(MODEL_META_DATA_COMPONENT
, Component
[0], '', '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1343 for Item
in Component
[1]:
1344 List
= GetSplitValueList(Item
, MaxSplit
=2)
1345 LibName
, LibIns
= '', ''
1351 self
.TblDsc
.Insert(MODEL_EFI_LIBRARY_CLASS
, LibName
, LibIns
, '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1352 for Item
in Component
[2]:
1353 self
.TblDsc
.Insert(MODEL_META_DATA_BUILD_OPTION
, Item
, '', '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1354 for Item
in Component
[3]:
1355 Model
= Section
[Item
[0].upper()]
1356 self
.TblDsc
.Insert(Model
, Item
[1], '', '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1358 ## Show detailed information of Dsc
1360 # Print all members and their values of Dsc class
1363 print TAB_SECTION_START
+ TAB_INF_DEFINES
+ TAB_SECTION_END
1364 printDict(self
.Defines
.DefinesDictionary
)
1366 for Key
in self
.KeyList
:
1367 for Arch
in DataType
.ARCH_LIST_FULL
:
1368 Command
= "printList(TAB_SECTION_START + '" + \
1369 Key
+ DataType
.TAB_SPLIT
+ Arch
+ \
1370 "' + TAB_SECTION_END, self.Contents[arch]." + Key
+ ')'
1373 ## Show detailed information of Platform
1375 # Print all members and their values of Platform class
1377 def ShowPlatform(self
):
1379 for Arch
in M
.Header
.keys():
1380 print '\nArch =', Arch
1381 print 'Filename =', M
.Header
[Arch
].FileName
1382 print 'FullPath =', M
.Header
[Arch
].FullPath
1383 print 'BaseName =', M
.Header
[Arch
].Name
1384 print 'Guid =', M
.Header
[Arch
].Guid
1385 print 'Version =', M
.Header
[Arch
].Version
1386 print 'DscSpecification =', M
.Header
[Arch
].DscSpecification
1387 print 'SkuId =', M
.Header
[Arch
].SkuIdName
1388 print 'SupArchList =', M
.Header
[Arch
].SupArchList
1389 print 'BuildTargets =', M
.Header
[Arch
].BuildTargets
1390 print 'OutputDirectory =', M
.Header
[Arch
].OutputDirectory
1391 print 'BuildNumber =', M
.Header
[Arch
].BuildNumber
1392 print 'MakefileName =', M
.Header
[Arch
].MakefileName
1393 print 'BsBaseAddress =', M
.Header
[Arch
].BsBaseAddress
1394 print 'RtBaseAddress =', M
.Header
[Arch
].RtBaseAddress
1395 print 'Define =', M
.Header
[Arch
].Define
1396 print 'Fdf =', M
.FlashDefinitionFile
.FilePath
1397 print '\nBuildOptions =', M
.BuildOptions
, M
.BuildOptions
.IncludeFiles
1398 for Item
in M
.BuildOptions
.BuildOptionList
:
1399 print '\t', 'ToolChainFamily =', Item
.ToolChainFamily
, 'ToolChain =', Item
.ToolChain
, 'Option =', Item
.Option
, 'Arch =', Item
.SupArchList
1400 print '\nSkuIds =', M
.SkuInfos
.SkuInfoList
, M
.SkuInfos
.IncludeFiles
1401 print '\nLibraries =', M
.Libraries
, M
.Libraries
.IncludeFiles
1402 for Item
in M
.Libraries
.LibraryList
:
1403 print '\t', Item
.FilePath
, Item
.SupArchList
, Item
.Define
1404 print '\nLibraryClasses =', M
.LibraryClasses
, M
.LibraryClasses
.IncludeFiles
1405 for Item
in M
.LibraryClasses
.LibraryList
:
1406 print '\t', Item
.Name
, Item
.FilePath
, Item
.SupModuleList
, Item
.SupArchList
, Item
.Define
1407 print '\nPcds =', M
.DynamicPcdBuildDefinitions
1408 for Item
in M
.DynamicPcdBuildDefinitions
:
1409 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
1410 for Sku
in Item
.SkuInfoList
.values():
1411 print '\t\t', str(Sku
)
1412 print '\nComponents =', M
.Modules
.ModuleList
, M
.Modules
.IncludeFiles
1413 for Item
in M
.Modules
.ModuleList
:
1414 print '\t', Item
.FilePath
, Item
.ExecFilePath
, Item
.SupArchList
1415 for Lib
in Item
.LibraryClasses
.LibraryList
:
1416 print '\t\tLib:', Lib
.Name
, Lib
.FilePath
1417 for Bo
in Item
.ModuleSaBuildOption
.BuildOptionList
:
1418 print '\t\tBuildOption:', Bo
.ToolChainFamily
, Bo
.ToolChain
, Bo
.Option
1419 for Pcd
in Item
.PcdBuildDefinitions
:
1420 print '\t\tPcd:', Pcd
.CName
, Pcd
.TokenSpaceGuidCName
, Pcd
.MaxDatumSize
, Pcd
.DefaultValue
, Pcd
.ItemType
1424 # This acts like the main() function for the script, unless it is 'import'ed into another
1427 if __name__
== '__main__':
1428 EdkLogger
.Initialize()
1429 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
1431 W
= os
.getenv('WORKSPACE')
1432 F
= os
.path
.join(W
, 'Nt32Pkg/Nt32Pkg.dsc')
1434 Db
= Database
.Database('Dsc.db')
1437 P
= Dsc(os
.path
.normpath(F
), True, True, W
, Db
)