2 # This file is used to define each component of DSC file
4 # Copyright (c) 2007 - 2010, 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.
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
35 Section
= {TAB_UNKNOWN
.upper() : MODEL_UNKNOWN
,
36 TAB_DSC_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
37 TAB_BUILD_OPTIONS
.upper() : MODEL_META_DATA_BUILD_OPTION
,
38 TAB_SKUIDS
.upper() : MODEL_EFI_SKU_ID
,
39 TAB_LIBRARIES
.upper() : MODEL_EFI_LIBRARY_INSTANCE
,
40 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
41 TAB_PCDS_FIXED_AT_BUILD_NULL
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
42 TAB_PCDS_PATCHABLE_IN_MODULE_NULL
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
43 TAB_PCDS_FEATURE_FLAG_NULL
.upper() : MODEL_PCD_FEATURE_FLAG
,
44 TAB_PCDS_DYNAMIC_EX_NULL
.upper() : MODEL_PCD_DYNAMIC_EX
,
45 TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_DEFAULT
,
46 TAB_PCDS_DYNAMIC_EX_VPD_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_VPD
,
47 TAB_PCDS_DYNAMIC_EX_HII_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_HII
,
48 TAB_PCDS_DYNAMIC_NULL
.upper() : MODEL_PCD_DYNAMIC
,
49 TAB_PCDS_DYNAMIC_DEFAULT_NULL
.upper() : MODEL_PCD_DYNAMIC_DEFAULT
,
50 TAB_PCDS_DYNAMIC_VPD_NULL
.upper() : MODEL_PCD_DYNAMIC_VPD
,
51 TAB_PCDS_DYNAMIC_HII_NULL
.upper() : MODEL_PCD_DYNAMIC_HII
,
52 TAB_COMPONENTS
.upper() : MODEL_META_DATA_COMPONENT
,
53 TAB_USER_EXTENSIONS
.upper() : MODEL_META_DATA_USER_EXTENSION
58 # This class defined basic Dsc object which is used by inheriting
60 # @param object: Inherited from object class
62 class DscObject(object):
68 # This class defined the structure used in Dsc object
70 # @param DscObject: Inherited from InfObject class
71 # @param Ffilename: Input value for Ffilename of Inf file, default is None
72 # @param IsMergeAllArches: Input value for IsMergeAllArches
73 # True is to merge all arches
74 # Fales is not to merge all arches
76 # @param IsToPlatform: Input value for IsToPlatform
77 # True is to transfer to ModuleObject automatically
78 # False is not to transfer to ModuleObject automatically
80 # @param WorkspaceDir: Input value for current workspace directory, default is None
82 # @var _NullClassIndex: To store value for _NullClassIndex, default is 0
83 # @var Identification: To store value for Identification, it is a structure as Identification
84 # @var Defines: To store value for Defines, it is a structure as DscDefines
85 # @var Contents: To store value for Contents, it is a structure as DscContents
86 # @var UserExtensions: To store value for UserExtensions
87 # @var Platform: To store value for Platform, it is a structure as PlatformClass
88 # @var WorkspaceDir: To store value for WorkspaceDir
89 # @var KeyList: To store value for KeyList, a list for all Keys used in Dec
94 def __init__(self
, Filename
=None, IsToDatabase
=False, IsToPlatform
=False, WorkspaceDir
=None, Database
=None):
95 self
.Identification
= Identification()
96 self
.Platform
= PlatformClass()
97 self
.UserExtensions
= ''
98 self
.WorkspaceDir
= WorkspaceDir
99 self
.IsToDatabase
= IsToDatabase
101 self
.Cur
= Database
.Cur
102 self
.TblFile
= Database
.TblFile
103 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
257 # Gen BuildOptions of Dsc
258 # [<Family>:]<ToolFlag>=Flag
260 # @param ContainerFile: The Dsc file full path
262 def GenBuildOptions(self
, ContainerFile
):
263 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
266 # Get all include files
268 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_BUILD_OPTION
, self
.FileID
)
271 # Get all BuildOptions
273 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, -1, self
.FileID
)
276 # Go through each arch
278 for Arch
in DataType
.ARCH_LIST
:
279 for IncludeFile
in IncludeFiles
:
280 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
281 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_BUILD_OPTIONS
, '', IncludeFile
[2])
282 for NewItem
in open(Filename
, 'r').readlines():
283 if CleanString(NewItem
) == '':
285 (Family
, ToolChain
, Flag
) = GetBuildOption(NewItem
, Filename
, -1)
286 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
288 for Record
in RecordSet
:
289 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
290 (Family
, ToolChain
, Flag
) = GetBuildOption(Record
[0], ContainerFile
, Record
[2])
291 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
295 if self
.IsToDatabase
:
296 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
297 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(Family
), ConvertToSqlString2(ToolChain
), ConvertToSqlString2(Flag
), Record
[3])
298 self
.TblDsc
.Exec(SqlCommand
)
300 for Key
in BuildOptions
.keys():
301 BuildOption
= BuildOptionClass(Key
[0], Key
[1], Key
[2])
302 BuildOption
.SupArchList
= BuildOptions
[Key
]
303 self
.Platform
.BuildOptions
.BuildOptionList
.append(BuildOption
)
307 # Gen SkuInfos of Dsc
310 # @param ContainerFile: The Dsc file full path
312 def GenSkuInfos(self
, ContainerFile
):
313 EdkLogger
.debug(2, "Generate %s ..." % TAB_SKUIDS
)
318 self
.Platform
.SkuInfos
.SkuInfoList
['DEFAULT'] = '0'
321 # Get all include files
323 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_SKU_ID
, self
.FileID
)
328 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_SKU_ID
, -1, self
.FileID
)
331 # Go through each arch
333 for Arch
in DataType
.ARCH_LIST
:
334 for IncludeFile
in IncludeFiles
:
335 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
336 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_SKUIDS
, '', IncludeFile
[2])
337 for NewItem
in open(Filename
, 'r').readlines():
338 if CleanString(NewItem
) == '':
340 List
= GetSplitValueList(NewItem
)
342 RaiseParserError(NewItem
, TAB_SKUIDS
, Filename
, '<Integer>|<UiName>')
344 self
.Platform
.SkuInfos
.SkuInfoList
[List
[1]] = List
[0]
346 for Record
in RecordSet
:
347 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
348 List
= GetSplitValueList(Record
[0])
350 RaiseParserError(Record
[0], TAB_SKUIDS
, ContainerFile
, '<Integer>|<UiName>')
352 self
.Platform
.SkuInfos
.SkuInfoList
[List
[1]] = List
[0]
356 if self
.IsToDatabase
:
357 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
358 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(List
[0]), ConvertToSqlString2(List
[1]), Record
[3])
359 self
.TblDsc
.Exec(SqlCommand
)
363 # Gen Libraries of Dsc
366 # @param ContainerFile: The Dsc file full path
368 def GenLibraries(self
, ContainerFile
):
369 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARIES
)
372 # Get all include files
374 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_INSTANCE
, self
.FileID
)
379 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_INSTANCE
, -1, self
.FileID
)
382 # Go through each arch
384 for Arch
in DataType
.ARCH_LIST
:
385 for IncludeFile
in IncludeFiles
:
386 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
387 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_LIBRARIES
, '', IncludeFile
[2])
388 if os
.path
.exists(Filename
):
389 for NewItem
in open(Filename
, 'r').readlines():
390 if CleanString(NewItem
) == '':
392 MergeArches(Libraries
, NewItem
, Arch
)
394 for Record
in RecordSet
:
395 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
396 MergeArches(Libraries
, Record
[0], Arch
)
398 for Key
in Libraries
.keys():
399 Library
= PlatformLibraryClass()
400 Library
.FilePath
= NormPath(Key
)
401 Library
.SupArchList
= Libraries
[Key
]
402 self
.Platform
.Libraries
.LibraryList
.append(Library
)
406 # Get LibraryClasses of Dsc
407 # <LibraryClassKeyWord>|<LibraryInstance>
409 # @param ContainerFile: The Dsc file full path
411 def GenLibraryClasses(self
, ContainerFile
):
412 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
415 # Get all include files
417 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_CLASS
, self
.FileID
)
420 # Get all LibraryClasses
422 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, -1, self
.FileID
)
425 # Go through each arch
427 for Arch
in DataType
.ARCH_LIST
:
428 for IncludeFile
in IncludeFiles
:
429 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
430 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_LIBRARY_CLASSES
, '', IncludeFile
[2])
431 for NewItem
in open(Filename
, 'r').readlines():
432 if CleanString(NewItem
) == '':
434 MergeArches(LibraryClasses
, GetLibraryClass([NewItem
, IncludeFile
[4]], Filename
, self
.WorkspaceDir
, -1), Arch
)
436 for Record
in RecordSet
:
437 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
438 (LibClassName
, LibClassIns
, SupModelList
) = GetLibraryClass([Record
[0], Record
[4]], ContainerFile
, self
.WorkspaceDir
, Record
[2])
439 MergeArches(LibraryClasses
, (LibClassName
, LibClassIns
, SupModelList
), Arch
)
443 if self
.IsToDatabase
:
444 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
445 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(LibClassName
), ConvertToSqlString2(LibClassIns
), ConvertToSqlString2(SupModelList
), Record
[3])
446 self
.TblDsc
.Exec(SqlCommand
)
448 for Key
in LibraryClasses
.keys():
449 Library
= PlatformLibraryClass()
450 Library
.Name
= Key
[0]
451 Library
.FilePath
= NormPath(Key
[1])
452 Library
.SupModuleList
= GetSplitValueList(Key
[2])
453 Library
.SupArchList
= LibraryClasses
[Key
]
454 self
.Platform
.LibraryClasses
.LibraryList
.append(Library
)
458 # Gen Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]
460 # @param Type: The type of Pcd
461 # @param ContainerFile: The file which describes the pcd, used for error report
463 def GenPcds(self
, Type
='', ContainerFile
=''):
465 if Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
466 Model
= MODEL_PCD_PATCHABLE_IN_MODULE
467 elif Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
:
468 Model
= MODEL_PCD_FIXED_AT_BUILD
471 EdkLogger
.debug(2, "Generate %s ..." % Type
)
474 # Get all include files
476 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
481 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
484 # Go through each arch
486 for Arch
in DataType
.ARCH_LIST
:
487 for IncludeFile
in IncludeFiles
:
488 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
489 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
490 for NewItem
in open(Filename
, 'r').readlines():
491 if CleanString(NewItem
) == '':
493 (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
) = GetPcd(NewItem
, Type
, Filename
, -1)
494 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
), Arch
)
495 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
497 for Record
in RecordSet
:
498 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
499 (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
) = GetPcd(Record
[0], Type
, ContainerFile
, Record
[2])
500 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
), Arch
)
501 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
504 Pcd
= PcdClass(Key
[0], '', Key
[1], Key
[3], Key
[4], Key
[2], Key
[5], [], {}, [])
505 Pcd
.SupArchList
= Pcds
[Key
]
506 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
508 ## Gen FeatureFlagPcds
510 # Gen FeatureFlagPcds of Dsc file as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE
512 # @param Type: The type of Pcd
513 # @param ContainerFile: The file which describes the pcd, used for error report
515 def GenFeatureFlagPcds(self
, Type
='', ContainerFile
=''):
517 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
518 Model
= MODEL_PCD_FEATURE_FLAG
521 EdkLogger
.debug(2, "Generate %s ..." % Type
)
524 # Get all include files
526 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
529 # Get all FeatureFlagPcds
531 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
534 # Go through each arch
536 for Arch
in DataType
.ARCH_LIST
:
537 for IncludeFile
in IncludeFiles
:
538 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
539 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
540 for NewItem
in open(Filename
, 'r').readlines():
541 if CleanString(NewItem
) == '':
543 (TokenName
, TokenGuidCName
, Value
, Type
) = GetFeatureFlagPcd(NewItem
, Type
, Filename
, -1)
544 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, Type
), Arch
)
545 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
547 for Record
in RecordSet
:
548 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
549 (TokenName
, TokenGuidCName
, Value
, Type
) = GetFeatureFlagPcd(Record
[0], Type
, ContainerFile
, Record
[2])
550 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, Type
), Arch
)
551 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
554 Pcd
= PcdClass(Key
[0], '', Key
[1], '', '', Key
[2], Key
[3], [], {}, [])
555 Pcd
.SupArchList
= Pcds
[Key
]
556 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
558 ## Gen DynamicDefaultPcds
560 # Gen DynamicDefaultPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]
562 # @param Type: The type of Pcd
563 # @param ContainerFile: The file which describes the pcd, used for error report
565 def GenDynamicDefaultPcds(self
, Type
='', ContainerFile
=''):
568 if Type
== DataType
.TAB_PCDS_DYNAMIC_DEFAULT
:
569 Model
= MODEL_PCD_DYNAMIC_DEFAULT
570 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_DEFAULT
:
571 Model
= MODEL_PCD_DYNAMIC_EX_DEFAULT
574 EdkLogger
.debug(2, "Generate %s ..." % Type
)
577 # Get all include files
579 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
582 # Get all DynamicDefaultPcds
584 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
587 # Go through each arch
589 for Arch
in DataType
.ARCH_LIST
:
590 for IncludeFile
in IncludeFiles
:
591 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
592 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
593 for NewItem
in open(Filename
, 'r').readlines():
594 if CleanString(NewItem
) == '':
596 (K1
, K2
, K3
, K4
, K5
, K6
) = GetDynamicDefaultPcd(NewItem
, Type
, Filename
, -1)
597 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, IncludeFile
[4]), Arch
)
598 self
.PcdToken
[Record
[3]] = (K2
, K1
)
600 for Record
in RecordSet
:
601 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
602 (K1
, K2
, K3
, K4
, K5
, K6
) = GetDynamicDefaultPcd(Record
[0], Type
, ContainerFile
, Record
[2])
603 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, Record
[4]), Arch
)
604 self
.PcdToken
[Record
[3]] = (K2
, K1
)
607 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[6], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', '', Key
[2])
609 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
610 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
611 Pcd
= PcdClass(Key
[0], '', Key
[1], Key
[3], Key
[4], Key
[2], Key
[5], [], SkuInfoList
, [])
612 Pcd
.SupArchList
= Pcds
[Key
]
613 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
615 ## Gen DynamicHiiPcds
617 # Gen DynamicHiiPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]
619 # @param Type: The type of Pcd
620 # @param ContainerFile: The file which describes the pcd, used for error report
622 def GenDynamicHiiPcds(self
, Type
='', ContainerFile
=''):
625 if Type
== DataType
.TAB_PCDS_DYNAMIC_HII
:
626 Model
= MODEL_PCD_DYNAMIC_HII
627 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_HII
:
628 Model
= MODEL_PCD_DYNAMIC_EX_HII
631 EdkLogger
.debug(2, "Generate %s ..." % Type
)
634 # Get all include files
636 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
639 # Get all DynamicHiiPcds
641 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
644 # Go through each arch
646 for Arch
in DataType
.ARCH_LIST
:
647 for IncludeFile
in IncludeFiles
:
648 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
649 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
650 for NewItem
in open(Filename
, 'r').readlines():
651 if CleanString(NewItem
) == '':
653 (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
) = GetDynamicHiiPcd(NewItem
, Type
, Filename
, -1)
654 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
, IncludeFile
[4]), Arch
)
655 self
.PcdToken
[Record
[3]] = (K2
, K1
)
657 for Record
in RecordSet
:
658 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
659 (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
) = GetDynamicHiiPcd(Record
[0], Type
, ContainerFile
, Record
[2])
660 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
, Record
[4]), Arch
)
661 self
.PcdToken
[Record
[3]] = (K2
, K1
)
664 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[8], self
.Platform
.SkuInfos
.SkuInfoList
, Key
[2], Key
[3], Key
[4], Key
[5], '', '')
666 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
667 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
668 Pcd
= PcdClass(Key
[0], '', Key
[1], '', Key
[6], Key
[5], Key
[7], [], SkuInfoList
, [])
669 Pcd
.SupArchList
= Pcds
[Key
]
670 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
672 ## Gen DynamicVpdPcds
674 # Gen DynamicVpdPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]
676 # @param Type: The type of Pcd
677 # @param ContainerFile: The file which describes the pcd, used for error report
679 def GenDynamicVpdPcds(self
, Type
='', ContainerFile
=''):
682 if Type
== DataType
.TAB_PCDS_DYNAMIC_VPD
:
683 Model
= MODEL_PCD_DYNAMIC_VPD
684 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_VPD
:
685 Model
= MODEL_PCD_DYNAMIC_EX_VPD
688 EdkLogger
.debug(2, "Generate %s ..." % Type
)
691 # Get all include files
693 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
696 # Get all DynamicVpdPcds
698 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
701 # Go through each arch
703 for Arch
in DataType
.ARCH_LIST
:
704 for IncludeFile
in IncludeFiles
:
705 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
706 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
707 for NewItem
in open(Filename
, 'r').readlines():
708 if CleanString(NewItem
) == '':
710 (K1
, K2
, K3
, K4
, K5
) = GetDynamicVpdPcd(NewItem
, Type
, Filename
, -1)
711 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, IncludeFile
[4]), Arch
)
712 self
.PcdToken
[Record
[3]] = (K2
, K1
)
714 for Record
in RecordSet
:
715 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
716 (K1
, K2
, K3
, K4
, K5
) = GetDynamicVpdPcd(Record
[0], Type
, ContainerFile
, Record
[2])
717 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, Record
[4]), Arch
)
718 self
.PcdToken
[Record
[3]] = (K2
, K1
)
721 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[5], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', Key
[2], '')
723 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
724 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
725 Pcd
= PcdClass(Key
[0], '', Key
[1], '', Key
[3], '', Key
[4], [], SkuInfoList
, [])
726 Pcd
.SupArchList
= Pcds
[Key
]
727 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
732 # Get Component section defined in Dsc file
734 # @param ContainerFile: The file which describes the Components, used for error report
736 # @retval PlatformModuleClass() A instance for PlatformModuleClass
738 def GenComponents(self
, ContainerFile
):
739 EdkLogger
.debug(2, "Generate %s ..." % TAB_COMPONENTS
)
742 # Get all include files
744 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_COMPONENT
, self
.FileID
)
749 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_COMPONENT
, -1, self
.FileID
)
752 # Go through each arch
754 for Arch
in DataType
.ARCH_LIST
:
755 for IncludeFile
in IncludeFiles
:
756 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
757 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_COMPONENTS
, '', IncludeFile
[2])
758 for NewItem
in open(Filename
, 'r').readlines():
759 if CleanString(NewItem
) == '':
762 GetComponents(open(Filename
, 'r').read(), TAB_COMPONENTS
, NewItems
, TAB_COMMENT_SPLIT
)
763 for NewComponent
in NewItems
:
764 MergeArches(Components
, self
.GenComponent(NewComponent
, Filename
), Arch
)
766 for Record
in RecordSet
:
767 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
768 Lib
, Bo
, Pcd
= [], [], []
770 SubLibSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, Record
[3], self
.FileID
)
771 for SubLib
in SubLibSet
:
772 Lib
.append(TAB_VALUE_SPLIT
.join([SubLib
[0], SubLib
[4]]))
774 SubBoSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, Record
[3], self
.FileID
)
775 for SubBo
in SubBoSet
:
778 SubPcdSet1
= QueryDscItem(self
.TblDsc
, MODEL_PCD_FIXED_AT_BUILD
, Record
[3], self
.FileID
)
779 SubPcdSet2
= QueryDscItem(self
.TblDsc
, MODEL_PCD_PATCHABLE_IN_MODULE
, Record
[3], self
.FileID
)
780 SubPcdSet3
= QueryDscItem(self
.TblDsc
, MODEL_PCD_FEATURE_FLAG
, Record
[3], self
.FileID
)
781 SubPcdSet4
= QueryDscItem(self
.TblDsc
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, Record
[3], self
.FileID
)
782 SubPcdSet5
= QueryDscItem(self
.TblDsc
, MODEL_PCD_DYNAMIC_DEFAULT
, Record
[3], self
.FileID
)
783 for SubPcd
in SubPcdSet1
:
784 Pcd
.append([DataType
.TAB_PCDS_FIXED_AT_BUILD
, SubPcd
[0], SubPcd
[3]])
785 for SubPcd
in SubPcdSet2
:
786 Pcd
.append([DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
, SubPcd
[0], SubPcd
[3]])
787 for SubPcd
in SubPcdSet3
:
788 Pcd
.append([DataType
.TAB_PCDS_FEATURE_FLAG
, SubPcd
[0], SubPcd
[3]])
789 for SubPcd
in SubPcdSet4
:
790 Pcd
.append([DataType
.TAB_PCDS_DYNAMIC_EX
, SubPcd
[0], SubPcd
[3]])
791 for SubPcd
in SubPcdSet5
:
792 Pcd
.append([DataType
.TAB_PCDS_DYNAMIC
, SubPcd
[0], SubPcd
[3]])
793 Item
= [Record
[0], Lib
, Bo
, Pcd
]
794 MergeArches(Components
, self
.GenComponent(Item
, ContainerFile
), Arch
)
796 for Key
in Components
.keys():
797 Key
.SupArchList
= Components
[Key
]
798 self
.Platform
.Modules
.ModuleList
.append(Key
)
802 # Get Component section defined in Dsc file
804 # @param Item: Contents includes a component block
805 # @param ContainerFile: The file which describes the library class, used for error report
807 # @retval PlatformModuleClass() A instance for PlatformModuleClass
809 def GenComponent(self
, Item
, ContainerFile
, LineNo
= -1):
810 (InfFilename
, ExecFilename
) = GetExec(Item
[0])
811 LibraryClasses
= Item
[1]
812 BuildOptions
= Item
[2]
814 Component
= PlatformModuleClass()
815 Component
.FilePath
= NormPath(InfFilename
)
816 Component
.ExecFilePath
= NormPath(ExecFilename
)
817 CheckFileType(Component
.FilePath
, '.Inf', ContainerFile
, 'component name', Item
[0], LineNo
)
818 CheckFileExist(self
.WorkspaceDir
, Component
.FilePath
, ContainerFile
, 'component', Item
[0], LineNo
)
819 for Lib
in LibraryClasses
:
820 List
= GetSplitValueList(Lib
)
822 RaiseParserError(Lib
, 'LibraryClasses', ContainerFile
, '<ClassName>|<InfFilename>')
824 LibFile
= NormPath(List
[1])
825 if LibName
== "" or LibName
== "NULL":
826 LibName
= "NULL%d" % self
._NullClassIndex
827 self
._NullClassIndex
+= 1
828 CheckFileType(List
[1], '.Inf', ContainerFile
, 'library instance of component ', Lib
, LineNo
)
829 CheckFileExist(self
.WorkspaceDir
, LibFile
, ContainerFile
, 'library instance of component', Lib
, LineNo
)
830 Component
.LibraryClasses
.LibraryList
.append(PlatformLibraryClass(LibName
, LibFile
))
831 for BuildOption
in BuildOptions
:
832 Key
= GetBuildOption(BuildOption
, ContainerFile
)
833 Component
.ModuleSaBuildOption
.BuildOptionList
.append(BuildOptionClass(Key
[0], Key
[1], Key
[2]))
836 List
= GetSplitValueList(Pcd
[1])
843 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
845 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|TRUE/FALSE')
847 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
848 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
849 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', List
[1], Type
, [], {}, []))
851 # For FixedAtBuild or PatchableInModule
853 if Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
or Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
855 if len(List
) != 3 and len(List
) != 4:
856 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|<Value>[|<MaxDatumSize>]')
858 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
859 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
860 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', List
[2], List
[1], Type
, [], {}, []))
863 # For Dynamic or DynamicEx
865 if Type
== DataType
.TAB_PCDS_DYNAMIC
or Type
== DataType
.TAB_PCDS_DYNAMIC_EX
:
867 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>')
869 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
870 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
871 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', '', Type
, [], {}, []))
876 self
.PcdToken
[PcdId
] = (TokenInfo
[0], TokenInfo
[1])
883 # Gen SkuInfoList section defined in Dsc file
885 # @param SkuNameList: Input value for SkuNameList
886 # @param SkuInfo: Input value for SkuInfo
887 # @param VariableName: Input value for VariableName
888 # @param VariableGuid: Input value for VariableGuid
889 # @param VariableOffset: Input value for VariableOffset
890 # @param HiiDefaultValue: Input value for HiiDefaultValue
891 # @param VpdOffset: Input value for VpdOffset
892 # @param DefaultValue: Input value for DefaultValue
894 # @retval (False, SkuName) Not found in section SkuId Dsc file
895 # @retval (True, SkuInfoList) Found in section SkuId of Dsc file
897 def GenSkuInfoList(self
, SkuNameList
, SkuInfo
, VariableName
='', VariableGuid
='', VariableOffset
='', HiiDefaultValue
='', VpdOffset
='', DefaultValue
=''):
898 SkuNameList
= GetSplitValueList(SkuNameList
)
899 if SkuNameList
== None or SkuNameList
== [] or SkuNameList
== ['']:
900 SkuNameList
= ['DEFAULT']
902 for Item
in SkuNameList
:
903 if Item
not in SkuInfo
:
905 Sku
= SkuInfoClass(Item
, SkuInfo
[Item
], VariableName
, VariableGuid
, VariableOffset
, HiiDefaultValue
, VpdOffset
, DefaultValue
)
906 SkuInfoList
[Item
] = Sku
908 return True, SkuInfoList
910 ## Parse Include statement
912 # Get include file path
914 # 1. Insert a record into TblFile ???
915 # 2. Insert a record into TblDsc
916 # Value1: IncludeFilePath
918 # @param LineValue: The line of incude statement
919 def ParseInclude(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
920 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "!include statement '%s' found in section %s" % (LineValue
, SectionName
))
921 SectionModel
= Section
[SectionName
.upper()]
922 IncludeFile
= CleanString(LineValue
[LineValue
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') + len(DataType
.TAB_INCLUDE
+ ' ') : ])
923 Table
.Insert(Model
, IncludeFile
, '', '', Arch
, SectionModel
, FileID
, StartLine
, -1, StartLine
, -1, 0)
925 ## Parse DEFINE statement
929 # 1. Insert a record into TblDsc
931 # Value2: Macro Value
933 def ParseDefine(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
934 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "DEFINE statement '%s' found in section %s" % (LineValue
, SectionName
))
935 SectionModel
= Section
[SectionName
.upper()]
936 Define
= GetSplitValueList(CleanString(LineValue
[LineValue
.upper().find(DataType
.TAB_DEFINE
.upper() + ' ') + len(DataType
.TAB_DEFINE
+ ' ') : ]), TAB_EQUAL_SPLIT
, 1)
937 Table
.Insert(Model
, Define
[0], Define
[1], '', Arch
, SectionModel
, FileID
, StartLine
, -1, StartLine
, -1, 0)
939 ## Parse Defines section
941 # Get one item in defines section
946 def ParseDefinesSection(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
947 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "Parse '%s' found in section %s" % (LineValue
, SectionName
))
948 Defines
= GetSplitValueList(LineValue
, TAB_EQUAL_SPLIT
, 1)
949 if len(Defines
) != 2:
950 RaiseParserError(LineValue
, SectionName
, Filename
, '', StartLine
)
951 self
.TblDsc
.Insert(Model
, Defines
[0], Defines
[1], '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
953 ## Insert conditional statements
955 # Pop an item from IfDefList
956 # Insert conditional statements to database
958 # @param Filename: Path of parsing file
959 # @param IfDefList: A list stored current conditional statements
960 # @param EndLine: The end line no
961 # @param ArchList: Support arch list
963 def InsertConditionalStatement(self
, Filename
, FileID
, BelongsToItem
, IfDefList
, EndLine
, ArchList
):
964 (Value1
, Value2
, Value3
, Model
, StartColumn
, EndColumn
, Enabled
) = ('', '', '', -1, -1, -1, 0)
966 ErrorMsg
= 'Not suited conditional statement in file %s' % Filename
967 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, Filename
, RaiseError
=EdkLogger
.IsRaiseError
)
970 # Get New Dsc item ID
972 DscID
= self
.TblDsc
.GetCount() + 1
975 # Pop the conditional statements which is closed
977 PreviousIf
= IfDefList
.pop()
978 EdkLogger
.debug(EdkLogger
.DEBUG_5
, 'Previous IfDef: ' + str(PreviousIf
))
983 if PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
):
984 Value1
= PreviousIf
[0]
985 Model
= PreviousIf
[2]
986 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
990 elif PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, Model
):
991 List
= PreviousIf
[0].split(' ')
992 Value1
, Value2
, Value3
= '', '==', '0'
997 Value3
= SplitString(Value3
)
1000 Model
= PreviousIf
[2]
1001 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
1005 elif PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, Model
):
1006 Value1
= PreviousIf
[0].strip()
1007 Model
= PreviousIf
[2]
1008 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
1012 # Load the file if it exists
1014 # @param Filename: Input value for filename of Dsc file
1016 def LoadDscFile(self
, Filename
):
1018 # Insert a record for file
1020 Filename
= NormPath(Filename
)
1021 self
.Identification
.FileFullPath
= Filename
1022 (self
.Identification
.FileRelativePath
, self
.Identification
.FileName
) = os
.path
.split(Filename
)
1023 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_DSC
)
1028 #self.TblDsc.Table = "Dsc%s" % FileID
1029 #self.TblDsc.Create()
1034 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
1035 [], [], TAB_UNKNOWN
, [], [], []
1039 # Parse file content
1041 IsFindBlockComment
= False
1043 for Line
in open(Filename
, 'r'):
1046 # Remove comment block
1048 if Line
.find(TAB_COMMENT_EDK_START
) > -1:
1049 ReservedLine
= GetSplitList(Line
, TAB_COMMENT_EDK_START
, 1)[0]
1050 IsFindBlockComment
= True
1051 if Line
.find(TAB_COMMENT_EDK_END
) > -1:
1052 Line
= ReservedLine
+ GetSplitList(Line
, TAB_COMMENT_EDK_END
, 1)[1]
1054 IsFindBlockComment
= False
1055 if IsFindBlockComment
:
1059 # Remove comments at tail and remove spaces again
1061 Line
= CleanString(Line
)
1066 # Find a new section tab
1067 # First insert previous section items
1068 # And then parse the content of the new section
1070 if Line
.startswith(TAB_SECTION_START
) and Line
.endswith(TAB_SECTION_END
):
1072 # Insert items data of previous section
1074 self
.InsertSectionItemsIntoDatabase(self
.FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
)
1076 # Parse the new section
1078 SectionItemList
= []
1083 LineList
= GetSplitValueList(Line
[len(TAB_SECTION_START
):len(Line
) - len(TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
1084 for Item
in LineList
:
1085 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
1086 if CurrentSection
== '':
1087 CurrentSection
= ItemList
[0]
1089 if CurrentSection
!= ItemList
[0]:
1090 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
)
1091 if CurrentSection
.upper() not in self
.KeyList
:
1092 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
1093 CurrentSection
= TAB_UNKNOWN
1097 if len(ItemList
) > 5:
1098 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
1100 if ItemList
[1] != '' and ItemList
[1].upper() not in ARCH_LIST_FULL
:
1101 EdkLogger
.error("Parser", PARSER_ERROR
, "Invalid Arch definition '%s' found" % ItemList
[1], File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
1102 ArchList
.append(ItemList
[1].upper())
1103 ThirdList
.append(ItemList
[2])
1108 # Not in any defined section
1110 if CurrentSection
== TAB_UNKNOWN
:
1111 ErrorMsg
= "%s is not in any defined section" % Line
1112 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
1115 # Add a section item
1117 SectionItemList
.append([Line
, LineNo
])
1122 # Insert items data of last section
1124 self
.InsertSectionItemsIntoDatabase(self
.FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
)
1127 # Parse conditional statements
1129 self
.ParseConditionalStatement()
1132 # Replace all DEFINE macros with its actual values
1134 #ParseDefineMacro2(self.TblDsc, self.RecordSet, GlobalData.gGlobalDefines)
1135 ParseDefineMacro(self
.TblDsc
, GlobalData
.gGlobalDefines
)
1138 ## ParseConditionalStatement
1140 # Search all conditional statement and disable no match records
1142 def ParseConditionalStatement(self
):
1144 # Disabled all !if/!elif/!ifdef statements without DEFINE
1146 SqlCommand
= """select A.StartLine, A.EndLine from %s as A
1147 where A.Model in (%s, %s, %s)
1149 and A.BelongsToFile = %s
1150 and A.Value1 not in (select B.Value1 from %s as B
1153 and A.StartLine > B.StartLine
1155 and A.BelongsToItem = B.BelongsToItem
1156 and A.BelongsToFile = B.BelongsToFile) """ % \
1157 (self
.TblDsc
.Table
, \
1158 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
, \
1160 self
.TblDsc
.Table
, \
1161 MODEL_META_DATA_DEFINE
)
1162 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1163 for Record
in RecordSet
:
1164 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[0], Record
[1])
1165 self
.TblDsc
.Exec(SqlCommand
)
1168 # Disabled !ifndef with DEFINE
1170 SqlCommand
= """select A.StartLine, A.EndLine from %s as A
1173 and A.BelongsToFile = %s
1174 and A.Value1 in (select B.Value1 from %s as B
1177 and A.StartLine > B.StartLine
1179 and A.BelongsToItem = B.BelongsToItem
1180 and A.BelongsToFile = B.BelongsToFile)""" % \
1181 (self
.TblDsc
.Table
, \
1182 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
, \
1184 self
.TblDsc
.Table
, \
1185 MODEL_META_DATA_DEFINE
)
1186 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1187 for Record
in RecordSet
:
1188 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[0], Record
[1])
1189 EdkLogger
.debug(4, "SqlCommand: %s" % SqlCommand
)
1190 self
.Cur
.execute(SqlCommand
)
1193 # Disabled !if, !elif and !else with un-match value
1195 SqlCommand
= """select A.Model, A.Value1, A.Value2, A.Value3, A.StartLine, A.EndLine, B.Value2 from %s as A join %s as B
1196 where A.Model in (%s, %s)
1198 and A.BelongsToFile = %s
1201 and A.Value1 = B.Value1
1202 and A.StartLine > B.StartLine
1203 and A.BelongsToItem = B.BelongsToItem
1204 and A.BelongsToFile = B.BelongsToFile""" % \
1205 (self
.TblDsc
.Table
, self
.TblDsc
.Table
, \
1206 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, \
1207 self
.FileID
, MODEL_META_DATA_DEFINE
)
1208 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1210 for Record
in RecordSet
:
1211 if Record
[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
:
1212 if not self
.Compare(Record
[6], Record
[2], Record
[3]):
1213 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[4], Record
[5])
1214 self
.TblDsc
.Exec(SqlCommand
)
1216 DisabledList
.append(Record
[1])
1218 if Record
[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
and Record
[1] in DisabledList
:
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
)
1224 # Compare two values
1226 # @param CompareType:
1229 def Compare(self
, Value1
, CompareType
, Value2
):
1230 Command
= """Value1 %s Value2""" % CompareType
1231 return eval(Command
)
1233 ## First time to insert records to database
1235 # Insert item data of a section to database
1236 # @param FileID: The ID of belonging file
1237 # @param Filename: The name of belonging file
1238 # @param CurrentSection: The name of currect section
1239 # @param SectionItemList: A list of items of the section
1240 # @param ArchList: A list of arches
1241 # @param ThirdList: A list of third parameters, ModuleType for LibraryClass and SkuId for Dynamic Pcds
1242 # @param IfDefList: A list of all conditional statements
1244 def InsertSectionItemsIntoDatabase(self
, FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
):
1246 # Insert each item data of a section
1248 for Index
in range(0, len(ArchList
)):
1249 Arch
= ArchList
[Index
]
1250 Third
= ThirdList
[Index
]
1252 Arch
= TAB_ARCH_COMMON
.upper()
1254 Model
= Section
[CurrentSection
.upper()]
1255 #Records = self.RecordSet[Model]
1257 for SectionItem
in SectionItemList
:
1258 BelongsToItem
, EndLine
, EndColumn
= -1, -1, -1
1259 LineValue
, StartLine
, EndLine
= SectionItem
[0], SectionItem
[1], SectionItem
[1]
1262 EdkLogger
.debug(4, "Parsing %s ..." % LineValue
)
1266 if LineValue
.upper().find(TAB_IF_DEF
.upper()) > -1:
1267 IfDefList
.append((LineValue
[len(TAB_IF_N_DEF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
))
1273 if LineValue
.upper().find(TAB_IF_N_DEF
.upper()) > -1:
1274 IfDefList
.append((LineValue
[len(TAB_IF_N_DEF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
))
1280 if LineValue
.upper().find(TAB_END_IF
.upper()) > -1:
1281 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
, Arch
)
1286 if LineValue
.upper().find(TAB_IF
.upper()) > -1:
1287 IfDefList
.append((LineValue
[len(TAB_IF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
))
1293 if LineValue
.upper().find(TAB_ELSE_IF
.upper()) > -1:
1294 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
- 1, Arch
)
1295 IfDefList
.append((LineValue
[len(TAB_ELSE_IF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
))
1301 if LineValue
.upper().find(TAB_ELSE
.upper()) > -1:
1302 Key
= IfDefList
[-1][0].split(' ' , 1)[0].strip()
1303 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
, Arch
)
1304 IfDefList
.append((Key
, StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
))
1308 # Parse !include statement first
1310 if LineValue
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') > -1:
1311 self
.ParseInclude(LineValue
, StartLine
, self
.TblDsc
, FileID
, Filename
, CurrentSection
, MODEL_META_DATA_INCLUDE
, Arch
)
1315 # And then parse DEFINE statement
1317 if LineValue
.upper().find(DataType
.TAB_DEFINE
.upper() + ' ') > -1:
1318 self
.ParseDefine(LineValue
, StartLine
, self
.TblDsc
, FileID
, Filename
, CurrentSection
, MODEL_META_DATA_DEFINE
, Arch
)
1322 # At last parse other sections
1324 if CurrentSection
== TAB_LIBRARY_CLASSES
or CurrentSection
in TAB_PCD_DYNAMIC_TYPE_LIST
or CurrentSection
in TAB_PCD_DYNAMIC_EX_TYPE_LIST
:
1325 ID
= self
.TblDsc
.Insert(Model
, LineValue
, Third
, '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1326 #Records.append([LineValue, Arch, StartLine, ID, Third])
1328 elif CurrentSection
!= TAB_COMPONENTS
:
1329 ID
= self
.TblDsc
.Insert(Model
, LineValue
, '', '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1330 #Records.append([LineValue, Arch, StartLine, ID, Third])
1334 # Parse COMPONENT section
1336 if CurrentSection
== TAB_COMPONENTS
:
1338 GetComponent(SectionItemList
, Components
)
1339 for Component
in Components
:
1340 EdkLogger
.debug(4, "Parsing component %s ..." % Component
)
1341 DscItmeID
= self
.TblDsc
.Insert(MODEL_META_DATA_COMPONENT
, Component
[0], '', '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1342 for Item
in Component
[1]:
1343 List
= GetSplitValueList(Item
, MaxSplit
=2)
1344 LibName
, LibIns
= '', ''
1350 self
.TblDsc
.Insert(MODEL_EFI_LIBRARY_CLASS
, LibName
, LibIns
, '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1351 for Item
in Component
[2]:
1352 self
.TblDsc
.Insert(MODEL_META_DATA_BUILD_OPTION
, Item
, '', '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1353 for Item
in Component
[3]:
1354 Model
= Section
[Item
[0].upper()]
1355 self
.TblDsc
.Insert(Model
, Item
[1], '', '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1357 ## Show detailed information of Dsc
1359 # Print all members and their values of Dsc class
1362 print TAB_SECTION_START
+ TAB_INF_DEFINES
+ TAB_SECTION_END
1363 printDict(self
.Defines
.DefinesDictionary
)
1365 for Key
in self
.KeyList
:
1366 for Arch
in DataType
.ARCH_LIST_FULL
:
1367 Command
= "printList(TAB_SECTION_START + '" + \
1368 Key
+ DataType
.TAB_SPLIT
+ Arch
+ \
1369 "' + TAB_SECTION_END, self.Contents[arch]." + Key
+ ')'
1372 ## Show detailed information of Platform
1374 # Print all members and their values of Platform class
1376 def ShowPlatform(self
):
1378 for Arch
in M
.Header
.keys():
1379 print '\nArch =', Arch
1380 print 'Filename =', M
.Header
[Arch
].FileName
1381 print 'FullPath =', M
.Header
[Arch
].FullPath
1382 print 'BaseName =', M
.Header
[Arch
].Name
1383 print 'Guid =', M
.Header
[Arch
].Guid
1384 print 'Version =', M
.Header
[Arch
].Version
1385 print 'DscSpecification =', M
.Header
[Arch
].DscSpecification
1386 print 'SkuId =', M
.Header
[Arch
].SkuIdName
1387 print 'SupArchList =', M
.Header
[Arch
].SupArchList
1388 print 'BuildTargets =', M
.Header
[Arch
].BuildTargets
1389 print 'OutputDirectory =', M
.Header
[Arch
].OutputDirectory
1390 print 'BuildNumber =', M
.Header
[Arch
].BuildNumber
1391 print 'MakefileName =', M
.Header
[Arch
].MakefileName
1392 print 'BsBaseAddress =', M
.Header
[Arch
].BsBaseAddress
1393 print 'RtBaseAddress =', M
.Header
[Arch
].RtBaseAddress
1394 print 'Define =', M
.Header
[Arch
].Define
1395 print 'Fdf =', M
.FlashDefinitionFile
.FilePath
1396 print '\nBuildOptions =', M
.BuildOptions
, M
.BuildOptions
.IncludeFiles
1397 for Item
in M
.BuildOptions
.BuildOptionList
:
1398 print '\t', 'ToolChainFamily =', Item
.ToolChainFamily
, 'ToolChain =', Item
.ToolChain
, 'Option =', Item
.Option
, 'Arch =', Item
.SupArchList
1399 print '\nSkuIds =', M
.SkuInfos
.SkuInfoList
, M
.SkuInfos
.IncludeFiles
1400 print '\nLibraries =', M
.Libraries
, M
.Libraries
.IncludeFiles
1401 for Item
in M
.Libraries
.LibraryList
:
1402 print '\t', Item
.FilePath
, Item
.SupArchList
, Item
.Define
1403 print '\nLibraryClasses =', M
.LibraryClasses
, M
.LibraryClasses
.IncludeFiles
1404 for Item
in M
.LibraryClasses
.LibraryList
:
1405 print '\t', Item
.Name
, Item
.FilePath
, Item
.SupModuleList
, Item
.SupArchList
, Item
.Define
1406 print '\nPcds =', M
.DynamicPcdBuildDefinitions
1407 for Item
in M
.DynamicPcdBuildDefinitions
:
1408 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
1409 for Sku
in Item
.SkuInfoList
.values():
1410 print '\t\t', str(Sku
)
1411 print '\nComponents =', M
.Modules
.ModuleList
, M
.Modules
.IncludeFiles
1412 for Item
in M
.Modules
.ModuleList
:
1413 print '\t', Item
.FilePath
, Item
.ExecFilePath
, Item
.SupArchList
1414 for Lib
in Item
.LibraryClasses
.LibraryList
:
1415 print '\t\tLib:', Lib
.Name
, Lib
.FilePath
1416 for Bo
in Item
.ModuleSaBuildOption
.BuildOptionList
:
1417 print '\t\tBuildOption:', Bo
.ToolChainFamily
, Bo
.ToolChain
, Bo
.Option
1418 for Pcd
in Item
.PcdBuildDefinitions
:
1419 print '\t\tPcd:', Pcd
.CName
, Pcd
.TokenSpaceGuidCName
, Pcd
.MaxDatumSize
, Pcd
.DefaultValue
, Pcd
.ItemType
1423 # This acts like the main() function for the script, unless it is 'import'ed into another
1426 if __name__
== '__main__':
1427 EdkLogger
.Initialize()
1428 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
1430 W
= os
.getenv('WORKSPACE')
1431 F
= os
.path
.join(W
, 'Nt32Pkg/Nt32Pkg.dsc')
1433 Db
= Database
.Database('Dsc.db')
1436 P
= Dsc(os
.path
.normpath(F
), True, True, W
, Db
)