2 # This file is used to define each component of DSC file
4 # Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 import Common
.LongFilePathOs
as os
18 import EdkLogger
as EdkLogger
22 from DataType
import *
23 from Identification
import *
24 from Dictionary
import *
25 from CommonDataClass
.PlatformClass
import *
26 from CommonDataClass
.CommonClass
import SkuInfoClass
27 from BuildToolError
import *
28 from collections
import OrderedDict
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 the structure used in Dsc object
61 # @param Ffilename: Input value for Ffilename of Inf file, default is None
62 # @param IsMergeAllArches: Input value for IsMergeAllArches
63 # True is to merge all arches
64 # Fales is not to merge all arches
66 # @param IsToPlatform: Input value for IsToPlatform
67 # True is to transfer to ModuleObject automatically
68 # False is not to transfer to ModuleObject automatically
70 # @param WorkspaceDir: Input value for current workspace directory, default is None
72 # @var _NullClassIndex: To store value for _NullClassIndex, default is 0
73 # @var Identification: To store value for Identification, it is a structure as Identification
74 # @var Defines: To store value for Defines, it is a structure as DscDefines
75 # @var Contents: To store value for Contents, it is a structure as DscContents
76 # @var UserExtensions: To store value for UserExtensions
77 # @var Platform: To store value for Platform, it is a structure as PlatformClass
78 # @var WorkspaceDir: To store value for WorkspaceDir
79 # @var KeyList: To store value for KeyList, a list for all Keys used in Dec
84 def __init__(self
, Filename
=None, IsToDatabase
=False, IsToPlatform
=False, WorkspaceDir
=None, Database
=None):
85 self
.Identification
= Identification()
86 self
.Platform
= PlatformClass()
87 self
.UserExtensions
= ''
88 self
.WorkspaceDir
= WorkspaceDir
89 self
.IsToDatabase
= IsToDatabase
91 self
.Cur
= Database
.Cur
92 self
.TblFile
= Database
.TblFile
93 self
.TblDsc
= Database
.TblDsc
96 TAB_SKUIDS
, TAB_LIBRARIES
, TAB_LIBRARY_CLASSES
, TAB_BUILD_OPTIONS
, TAB_PCDS_FIXED_AT_BUILD_NULL
, \
97 TAB_PCDS_PATCHABLE_IN_MODULE_NULL
, TAB_PCDS_FEATURE_FLAG_NULL
, \
98 TAB_PCDS_DYNAMIC_DEFAULT_NULL
, TAB_PCDS_DYNAMIC_HII_NULL
, TAB_PCDS_DYNAMIC_VPD_NULL
, \
99 TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL
, TAB_PCDS_DYNAMIC_EX_HII_NULL
, TAB_PCDS_DYNAMIC_EX_VPD_NULL
, \
100 TAB_COMPONENTS
, TAB_DSC_DEFINES
106 # Upper all KEYs to ignore case sensitive when parsing
108 self
.KeyList
= map(lambda c
: c
.upper(), self
.KeyList
)
113 # self.RecordSet = {}
114 # for Key in self.KeyList:
115 # self.RecordSet[Section[Key]] = []
118 # Load Dsc file if filename is not None
120 if Filename
is not None:
121 self
.LoadDscFile(Filename
)
124 # Transfer to Platform Object if IsToPlatform is True
129 ## Transfer to Platform Object
131 # Transfer all contents of an Inf file to a standard Module Object
133 def DscToPlatform(self
):
135 # Init global information for the file
137 ContainerFile
= self
.Identification
.FileFullPath
140 # Generate Platform Header
142 self
.GenPlatformHeader(ContainerFile
)
145 # Generate BuildOptions
147 self
.GenBuildOptions(ContainerFile
)
152 self
.GenSkuInfos(ContainerFile
)
157 self
.GenLibraries(ContainerFile
)
160 # Generate LibraryClasses
162 self
.GenLibraryClasses(ContainerFile
)
167 self
.GenPcds(DataType
.TAB_PCDS_FIXED_AT_BUILD
, ContainerFile
)
168 self
.GenPcds(DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
, ContainerFile
)
169 self
.GenFeatureFlagPcds(DataType
.TAB_PCDS_FEATURE_FLAG
, ContainerFile
)
170 self
.GenDynamicDefaultPcds(DataType
.TAB_PCDS_DYNAMIC_DEFAULT
, ContainerFile
)
171 self
.GenDynamicDefaultPcds(DataType
.TAB_PCDS_DYNAMIC_EX_DEFAULT
, ContainerFile
)
172 self
.GenDynamicHiiPcds(DataType
.TAB_PCDS_DYNAMIC_HII
, ContainerFile
)
173 self
.GenDynamicHiiPcds(DataType
.TAB_PCDS_DYNAMIC_EX_HII
, ContainerFile
)
174 self
.GenDynamicVpdPcds(DataType
.TAB_PCDS_DYNAMIC_VPD
, ContainerFile
)
175 self
.GenDynamicVpdPcds(DataType
.TAB_PCDS_DYNAMIC_EX_VPD
, ContainerFile
)
178 # Generate Components
180 self
.GenComponents(ContainerFile
)
185 if self
.IsToDatabase
:
186 for Key
in self
.PcdToken
.keys():
187 SqlCommand
= """update %s set Value2 = '%s' where ID = %s""" % (self
.TblDsc
.Table
, ".".join((self
.PcdToken
[Key
][0], self
.PcdToken
[Key
][1])), Key
)
188 self
.TblDsc
.Exec(SqlCommand
)
189 #End of DscToPlatform
191 ## Get Platform Header
193 # Gen Platform Header of Dsc as <Key> = <Value>
195 # @param ContainerFile: The Dsc file full path
197 def GenPlatformHeader(self
, ContainerFile
):
198 EdkLogger
.debug(2, "Generate PlatformHeader ...")
200 # Update all defines item in database
202 SqlCommand
= """select ID, Value1, Arch, StartLine from %s
204 and BelongsToFile = %s
205 and Enabled > -1""" % (self
.TblDsc
.Table
, MODEL_META_DATA_HEADER
, self
.FileID
)
206 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
207 for Record
in RecordSet
:
208 ValueList
= GetSplitValueList(Record
[1], TAB_EQUAL_SPLIT
)
209 if len(ValueList
) != 2:
210 RaiseParserError(Record
[1], 'Defines', ContainerFile
, '<Key> = <Value>', Record
[3])
211 ID
, Value1
, Value2
, Arch
= Record
[0], ValueList
[0], ValueList
[1], Record
[2]
212 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
213 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(Value1
), ConvertToSqlString2(Value2
), ID
)
214 self
.TblDsc
.Exec(SqlCommand
)
217 # Get detailed information
219 for Arch
in DataType
.ARCH_LIST
:
220 PlatformHeader
= PlatformHeaderClass()
222 PlatformHeader
.Name
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_PLATFORM_NAME
, Arch
, self
.FileID
)[0]
223 PlatformHeader
.Guid
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_PLATFORM_GUID
, Arch
, self
.FileID
)[0]
224 PlatformHeader
.Version
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_PLATFORM_VERSION
, Arch
, self
.FileID
)[0]
225 PlatformHeader
.FileName
= self
.Identification
.FileName
226 PlatformHeader
.FullPath
= self
.Identification
.FileFullPath
227 PlatformHeader
.DscSpecification
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_DSC_SPECIFICATION
, Arch
, self
.FileID
)[0]
229 PlatformHeader
.SkuIdName
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_SKUID_IDENTIFIER
, Arch
, self
.FileID
)
230 PlatformHeader
.SupArchList
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
, Arch
, self
.FileID
)
231 PlatformHeader
.BuildTargets
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_BUILD_TARGETS
, Arch
, self
.FileID
)
232 PlatformHeader
.OutputDirectory
= NormPath(QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_OUTPUT_DIRECTORY
, Arch
, self
.FileID
)[0])
233 PlatformHeader
.BuildNumber
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_BUILD_NUMBER
, Arch
, self
.FileID
)[0]
234 PlatformHeader
.MakefileName
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_MAKEFILE_NAME
, Arch
, self
.FileID
)[0]
236 PlatformHeader
.BsBaseAddress
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_BS_BASE_ADDRESS
, Arch
, self
.FileID
)[0]
237 PlatformHeader
.RtBaseAddress
= QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_RT_BASE_ADDRESS
, Arch
, self
.FileID
)[0]
239 self
.Platform
.Header
[Arch
] = PlatformHeader
240 Fdf
= PlatformFlashDefinitionFileClass()
241 Fdf
.FilePath
= NormPath(QueryDefinesItem(self
.TblDsc
, TAB_DSC_DEFINES_FLASH_DEFINITION
, Arch
, self
.FileID
)[0])
242 self
.Platform
.FlashDefinitionFile
= Fdf
243 Prebuild
= BuildScriptClass()
244 Prebuild
.FilePath
= NormPath(QueryDefinesItem(self
.TblDsc
, TAB_DSC_PREBUILD
, Arch
, self
.FileID
)[0])
245 self
.Platform
.Prebuild
= Prebuild
246 Postbuild
= BuildScriptClass()
247 Postbuild
.FilePath
= NormPath(QueryDefinesItem(self
.TblDsc
, TAB_DSC_POSTBUILD
, Arch
, self
.FileID
)[0])
248 self
.Platform
.Postbuild
= Postbuild
252 # Gen BuildOptions of Dsc
253 # [<Family>:]<ToolFlag>=Flag
255 # @param ContainerFile: The Dsc file full path
257 def GenBuildOptions(self
, ContainerFile
):
258 EdkLogger
.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS
)
261 # Get all include files
263 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_BUILD_OPTION
, self
.FileID
)
266 # Get all BuildOptions
268 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, -1, self
.FileID
)
271 # Go through each arch
273 for Arch
in DataType
.ARCH_LIST
:
274 for IncludeFile
in IncludeFiles
:
275 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
276 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_BUILD_OPTIONS
, '', IncludeFile
[2])
277 for NewItem
in open(Filename
, 'r').readlines():
278 if CleanString(NewItem
) == '':
280 (Family
, ToolChain
, Flag
) = GetBuildOption(NewItem
, Filename
, -1)
281 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
283 for Record
in RecordSet
:
284 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
285 (Family
, ToolChain
, Flag
) = GetBuildOption(Record
[0], ContainerFile
, Record
[2])
286 MergeArches(BuildOptions
, (Family
, ToolChain
, Flag
), Arch
)
290 if self
.IsToDatabase
:
291 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
292 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(Family
), ConvertToSqlString2(ToolChain
), ConvertToSqlString2(Flag
), Record
[3])
293 self
.TblDsc
.Exec(SqlCommand
)
295 for Key
in BuildOptions
.keys():
296 BuildOption
= BuildOptionClass(Key
[0], Key
[1], Key
[2])
297 BuildOption
.SupArchList
= BuildOptions
[Key
]
298 self
.Platform
.BuildOptions
.BuildOptionList
.append(BuildOption
)
302 # Gen SkuInfos of Dsc
305 # @param ContainerFile: The Dsc file full path
307 def GenSkuInfos(self
, ContainerFile
):
308 EdkLogger
.debug(2, "Generate %s ..." % TAB_SKUIDS
)
313 self
.Platform
.SkuInfos
.SkuInfoList
['DEFAULT'] = '0'
316 # Get all include files
318 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_SKU_ID
, self
.FileID
)
323 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_SKU_ID
, -1, self
.FileID
)
326 # Go through each arch
328 for Arch
in DataType
.ARCH_LIST
:
329 for IncludeFile
in IncludeFiles
:
330 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
331 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_SKUIDS
, '', IncludeFile
[2])
332 for NewItem
in open(Filename
, 'r').readlines():
333 if CleanString(NewItem
) == '':
335 List
= GetSplitValueList(NewItem
)
337 RaiseParserError(NewItem
, TAB_SKUIDS
, Filename
, '<Integer>|<UiName>')
339 self
.Platform
.SkuInfos
.SkuInfoList
[List
[1]] = List
[0]
341 for Record
in RecordSet
:
342 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
343 List
= GetSplitValueList(Record
[0])
345 RaiseParserError(Record
[0], TAB_SKUIDS
, ContainerFile
, '<Integer>|<UiName>')
347 self
.Platform
.SkuInfos
.SkuInfoList
[List
[1]] = List
[0]
351 if self
.IsToDatabase
:
352 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s'
353 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(List
[0]), ConvertToSqlString2(List
[1]), Record
[3])
354 self
.TblDsc
.Exec(SqlCommand
)
358 # Gen Libraries of Dsc
361 # @param ContainerFile: The Dsc file full path
363 def GenLibraries(self
, ContainerFile
):
364 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARIES
)
367 # Get all include files
369 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_INSTANCE
, self
.FileID
)
374 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_INSTANCE
, -1, self
.FileID
)
377 # Go through each arch
379 for Arch
in DataType
.ARCH_LIST
:
380 for IncludeFile
in IncludeFiles
:
381 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
382 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_LIBRARIES
, '', IncludeFile
[2])
383 if os
.path
.exists(Filename
):
384 for NewItem
in open(Filename
, 'r').readlines():
385 if CleanString(NewItem
) == '':
387 MergeArches(Libraries
, NewItem
, Arch
)
389 for Record
in RecordSet
:
390 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
391 MergeArches(Libraries
, Record
[0], Arch
)
393 for Key
in Libraries
.keys():
394 Library
= PlatformLibraryClass()
395 Library
.FilePath
= NormPath(Key
)
396 Library
.SupArchList
= Libraries
[Key
]
397 self
.Platform
.Libraries
.LibraryList
.append(Library
)
401 # Get LibraryClasses of Dsc
402 # <LibraryClassKeyWord>|<LibraryInstance>
404 # @param ContainerFile: The Dsc file full path
406 def GenLibraryClasses(self
, ContainerFile
):
407 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
410 # Get all include files
412 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_CLASS
, self
.FileID
)
415 # Get all LibraryClasses
417 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, -1, self
.FileID
)
420 # Go through each arch
422 for Arch
in DataType
.ARCH_LIST
:
423 for IncludeFile
in IncludeFiles
:
424 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
425 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_LIBRARY_CLASSES
, '', IncludeFile
[2])
426 for NewItem
in open(Filename
, 'r').readlines():
427 if CleanString(NewItem
) == '':
429 MergeArches(LibraryClasses
, GetLibraryClass([NewItem
, IncludeFile
[4]], Filename
, self
.WorkspaceDir
, -1), Arch
)
431 for Record
in RecordSet
:
432 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
433 (LibClassName
, LibClassIns
, SupModelList
) = GetLibraryClass([Record
[0], Record
[4]], ContainerFile
, self
.WorkspaceDir
, Record
[2])
434 MergeArches(LibraryClasses
, (LibClassName
, LibClassIns
, SupModelList
), Arch
)
438 if self
.IsToDatabase
:
439 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
440 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(LibClassName
), ConvertToSqlString2(LibClassIns
), ConvertToSqlString2(SupModelList
), Record
[3])
441 self
.TblDsc
.Exec(SqlCommand
)
443 for Key
in LibraryClasses
.keys():
444 Library
= PlatformLibraryClass()
445 Library
.Name
= Key
[0]
446 Library
.FilePath
= NormPath(Key
[1])
447 Library
.SupModuleList
= GetSplitValueList(Key
[2])
448 Library
.SupArchList
= LibraryClasses
[Key
]
449 self
.Platform
.LibraryClasses
.LibraryList
.append(Library
)
453 # Gen Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]
455 # @param Type: The type of Pcd
456 # @param ContainerFile: The file which describes the pcd, used for error report
458 def GenPcds(self
, Type
='', ContainerFile
=''):
460 if Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
461 Model
= MODEL_PCD_PATCHABLE_IN_MODULE
462 elif Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
:
463 Model
= MODEL_PCD_FIXED_AT_BUILD
466 EdkLogger
.debug(2, "Generate %s ..." % Type
)
469 # Get all include files
471 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
476 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
479 # Go through each arch
481 for Arch
in DataType
.ARCH_LIST
:
482 for IncludeFile
in IncludeFiles
:
483 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
484 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
485 for NewItem
in open(Filename
, 'r').readlines():
486 if CleanString(NewItem
) == '':
488 (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
) = GetPcd(NewItem
, Type
, Filename
, -1)
489 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
), Arch
)
490 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
492 for Record
in RecordSet
:
493 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
494 (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
) = GetPcd(Record
[0], Type
, ContainerFile
, Record
[2])
495 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
), Arch
)
496 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
499 Pcd
= PcdClass(Key
[0], '', Key
[1], Key
[3], Key
[4], Key
[2], Key
[5], [], {}, [])
500 Pcd
.SupArchList
= Pcds
[Key
]
501 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
503 ## Gen FeatureFlagPcds
505 # Gen FeatureFlagPcds of Dsc file as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE
507 # @param Type: The type of Pcd
508 # @param ContainerFile: The file which describes the pcd, used for error report
510 def GenFeatureFlagPcds(self
, Type
='', ContainerFile
=''):
512 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
513 Model
= MODEL_PCD_FEATURE_FLAG
516 EdkLogger
.debug(2, "Generate %s ..." % Type
)
519 # Get all include files
521 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
524 # Get all FeatureFlagPcds
526 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
529 # Go through each arch
531 for Arch
in DataType
.ARCH_LIST
:
532 for IncludeFile
in IncludeFiles
:
533 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
534 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
535 for NewItem
in open(Filename
, 'r').readlines():
536 if CleanString(NewItem
) == '':
538 (TokenName
, TokenGuidCName
, Value
, Type
) = GetFeatureFlagPcd(NewItem
, Type
, Filename
, -1)
539 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, Type
), Arch
)
540 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
542 for Record
in RecordSet
:
543 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
544 (TokenName
, TokenGuidCName
, Value
, Type
) = GetFeatureFlagPcd(Record
[0], Type
, ContainerFile
, Record
[2])
545 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, Type
), Arch
)
546 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
549 Pcd
= PcdClass(Key
[0], '', Key
[1], '', '', Key
[2], Key
[3], [], {}, [])
550 Pcd
.SupArchList
= Pcds
[Key
]
551 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
553 ## Gen DynamicDefaultPcds
555 # Gen DynamicDefaultPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]
557 # @param Type: The type of Pcd
558 # @param ContainerFile: The file which describes the pcd, used for error report
560 def GenDynamicDefaultPcds(self
, Type
='', ContainerFile
=''):
563 if Type
== DataType
.TAB_PCDS_DYNAMIC_DEFAULT
:
564 Model
= MODEL_PCD_DYNAMIC_DEFAULT
565 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_DEFAULT
:
566 Model
= MODEL_PCD_DYNAMIC_EX_DEFAULT
569 EdkLogger
.debug(2, "Generate %s ..." % Type
)
572 # Get all include files
574 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
577 # Get all DynamicDefaultPcds
579 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
582 # Go through each arch
584 for Arch
in DataType
.ARCH_LIST
:
585 for IncludeFile
in IncludeFiles
:
586 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
587 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
588 for NewItem
in open(Filename
, 'r').readlines():
589 if CleanString(NewItem
) == '':
591 (K1
, K2
, K3
, K4
, K5
, K6
) = GetDynamicDefaultPcd(NewItem
, Type
, Filename
, -1)
592 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, IncludeFile
[4]), Arch
)
593 self
.PcdToken
[Record
[3]] = (K2
, K1
)
595 for Record
in RecordSet
:
596 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
597 (K1
, K2
, K3
, K4
, K5
, K6
) = GetDynamicDefaultPcd(Record
[0], Type
, ContainerFile
, Record
[2])
598 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, Record
[4]), Arch
)
599 self
.PcdToken
[Record
[3]] = (K2
, K1
)
602 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[6], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', '', Key
[2])
604 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
605 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
606 Pcd
= PcdClass(Key
[0], '', Key
[1], Key
[3], Key
[4], Key
[2], Key
[5], [], SkuInfoList
, [])
607 Pcd
.SupArchList
= Pcds
[Key
]
608 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
610 ## Gen DynamicHiiPcds
612 # Gen DynamicHiiPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]
614 # @param Type: The type of Pcd
615 # @param ContainerFile: The file which describes the pcd, used for error report
617 def GenDynamicHiiPcds(self
, Type
='', ContainerFile
=''):
620 if Type
== DataType
.TAB_PCDS_DYNAMIC_HII
:
621 Model
= MODEL_PCD_DYNAMIC_HII
622 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_HII
:
623 Model
= MODEL_PCD_DYNAMIC_EX_HII
626 EdkLogger
.debug(2, "Generate %s ..." % Type
)
629 # Get all include files
631 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
634 # Get all DynamicHiiPcds
636 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
639 # Go through each arch
641 for Arch
in DataType
.ARCH_LIST
:
642 for IncludeFile
in IncludeFiles
:
643 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
644 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
645 for NewItem
in open(Filename
, 'r').readlines():
646 if CleanString(NewItem
) == '':
648 (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
) = GetDynamicHiiPcd(NewItem
, Type
, Filename
, -1)
649 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
, IncludeFile
[4]), Arch
)
650 self
.PcdToken
[Record
[3]] = (K2
, K1
)
652 for Record
in RecordSet
:
653 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
654 (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
) = GetDynamicHiiPcd(Record
[0], Type
, ContainerFile
, Record
[2])
655 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
, Record
[4]), Arch
)
656 self
.PcdToken
[Record
[3]] = (K2
, K1
)
659 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[8], self
.Platform
.SkuInfos
.SkuInfoList
, Key
[2], Key
[3], Key
[4], Key
[5], '', '')
661 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
662 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
663 Pcd
= PcdClass(Key
[0], '', Key
[1], '', Key
[6], Key
[5], Key
[7], [], SkuInfoList
, [])
664 Pcd
.SupArchList
= Pcds
[Key
]
665 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
667 ## Gen DynamicVpdPcds
669 # Gen DynamicVpdPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]
671 # @param Type: The type of Pcd
672 # @param ContainerFile: The file which describes the pcd, used for error report
674 def GenDynamicVpdPcds(self
, Type
='', ContainerFile
=''):
677 if Type
== DataType
.TAB_PCDS_DYNAMIC_VPD
:
678 Model
= MODEL_PCD_DYNAMIC_VPD
679 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_VPD
:
680 Model
= MODEL_PCD_DYNAMIC_EX_VPD
683 EdkLogger
.debug(2, "Generate %s ..." % Type
)
686 # Get all include files
688 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
691 # Get all DynamicVpdPcds
693 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
696 # Go through each arch
698 for Arch
in DataType
.ARCH_LIST
:
699 for IncludeFile
in IncludeFiles
:
700 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
701 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
702 for NewItem
in open(Filename
, 'r').readlines():
703 if CleanString(NewItem
) == '':
705 (K1
, K2
, K3
, K4
, K5
) = GetDynamicVpdPcd(NewItem
, Type
, Filename
, -1)
706 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, IncludeFile
[4]), Arch
)
707 self
.PcdToken
[Record
[3]] = (K2
, K1
)
709 for Record
in RecordSet
:
710 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
711 (K1
, K2
, K3
, K4
, K5
) = GetDynamicVpdPcd(Record
[0], Type
, ContainerFile
, Record
[2])
712 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, Record
[4]), Arch
)
713 self
.PcdToken
[Record
[3]] = (K2
, K1
)
716 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[5], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', Key
[2], '')
718 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
719 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
=EdkLogger
.IsRaiseError
)
720 Pcd
= PcdClass(Key
[0], '', Key
[1], '', Key
[3], '', Key
[4], [], SkuInfoList
, [])
721 Pcd
.SupArchList
= Pcds
[Key
]
722 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
727 # Get Component section defined in Dsc file
729 # @param ContainerFile: The file which describes the Components, used for error report
731 # @retval PlatformModuleClass() A instance for PlatformModuleClass
733 def GenComponents(self
, ContainerFile
):
734 EdkLogger
.debug(2, "Generate %s ..." % TAB_COMPONENTS
)
735 Components
= OrderedDict()
737 # Get all include files
739 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_COMPONENT
, self
.FileID
)
744 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_COMPONENT
, -1, self
.FileID
)
747 # Go through each arch
749 for Arch
in DataType
.ARCH_LIST
:
750 for IncludeFile
in IncludeFiles
:
751 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
752 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_COMPONENTS
, '', IncludeFile
[2])
753 for NewItem
in open(Filename
, 'r').readlines():
754 if CleanString(NewItem
) == '':
757 GetComponents(open(Filename
, 'r').read(), TAB_COMPONENTS
, NewItems
, TAB_COMMENT_SPLIT
)
758 for NewComponent
in NewItems
:
759 MergeArches(Components
, self
.GenComponent(NewComponent
, Filename
), Arch
)
761 for Record
in RecordSet
:
762 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
763 Lib
, Bo
, Pcd
= [], [], []
765 SubLibSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, Record
[3], self
.FileID
)
766 for SubLib
in SubLibSet
:
767 Lib
.append(TAB_VALUE_SPLIT
.join([SubLib
[0], SubLib
[4]]))
769 SubBoSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, Record
[3], self
.FileID
)
770 for SubBo
in SubBoSet
:
773 SubPcdSet1
= QueryDscItem(self
.TblDsc
, MODEL_PCD_FIXED_AT_BUILD
, Record
[3], self
.FileID
)
774 SubPcdSet2
= QueryDscItem(self
.TblDsc
, MODEL_PCD_PATCHABLE_IN_MODULE
, Record
[3], self
.FileID
)
775 SubPcdSet3
= QueryDscItem(self
.TblDsc
, MODEL_PCD_FEATURE_FLAG
, Record
[3], self
.FileID
)
776 SubPcdSet4
= QueryDscItem(self
.TblDsc
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, Record
[3], self
.FileID
)
777 SubPcdSet5
= QueryDscItem(self
.TblDsc
, MODEL_PCD_DYNAMIC_DEFAULT
, Record
[3], self
.FileID
)
778 for SubPcd
in SubPcdSet1
:
779 Pcd
.append([DataType
.TAB_PCDS_FIXED_AT_BUILD
, SubPcd
[0], SubPcd
[3]])
780 for SubPcd
in SubPcdSet2
:
781 Pcd
.append([DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
, SubPcd
[0], SubPcd
[3]])
782 for SubPcd
in SubPcdSet3
:
783 Pcd
.append([DataType
.TAB_PCDS_FEATURE_FLAG
, SubPcd
[0], SubPcd
[3]])
784 for SubPcd
in SubPcdSet4
:
785 Pcd
.append([DataType
.TAB_PCDS_DYNAMIC_EX
, SubPcd
[0], SubPcd
[3]])
786 for SubPcd
in SubPcdSet5
:
787 Pcd
.append([DataType
.TAB_PCDS_DYNAMIC
, SubPcd
[0], SubPcd
[3]])
788 Item
= [Record
[0], Lib
, Bo
, Pcd
]
789 MergeArches(Components
, self
.GenComponent(Item
, ContainerFile
), Arch
)
791 for Key
in Components
.keys():
792 Key
.SupArchList
= Components
[Key
]
793 self
.Platform
.Modules
.ModuleList
.append(Key
)
797 # Get Component section defined in Dsc file
799 # @param Item: Contents includes a component block
800 # @param ContainerFile: The file which describes the library class, used for error report
802 # @retval PlatformModuleClass() A instance for PlatformModuleClass
804 def GenComponent(self
, Item
, ContainerFile
, LineNo
= -1):
805 (InfFilename
, ExecFilename
) = GetExec(Item
[0])
806 LibraryClasses
= Item
[1]
807 BuildOptions
= Item
[2]
809 Component
= PlatformModuleClass()
810 Component
.FilePath
= NormPath(InfFilename
)
811 Component
.ExecFilePath
= NormPath(ExecFilename
)
812 CheckFileType(Component
.FilePath
, '.Inf', ContainerFile
, 'component name', Item
[0], LineNo
)
813 CheckFileExist(self
.WorkspaceDir
, Component
.FilePath
, ContainerFile
, 'component', Item
[0], LineNo
)
814 for Lib
in LibraryClasses
:
815 List
= GetSplitValueList(Lib
)
817 RaiseParserError(Lib
, 'LibraryClasses', ContainerFile
, '<ClassName>|<InfFilename>')
819 LibFile
= NormPath(List
[1])
820 if LibName
== "" or LibName
== "NULL":
821 LibName
= "NULL%d" % self
._NullClassIndex
822 self
._NullClassIndex
+= 1
823 CheckFileType(List
[1], '.Inf', ContainerFile
, 'library instance of component ', Lib
, LineNo
)
824 CheckFileExist(self
.WorkspaceDir
, LibFile
, ContainerFile
, 'library instance of component', Lib
, LineNo
)
825 Component
.LibraryClasses
.LibraryList
.append(PlatformLibraryClass(LibName
, LibFile
))
826 for BuildOption
in BuildOptions
:
827 Key
= GetBuildOption(BuildOption
, ContainerFile
)
828 Component
.ModuleSaBuildOption
.BuildOptionList
.append(BuildOptionClass(Key
[0], Key
[1], Key
[2]))
831 List
= GetSplitValueList(Pcd
[1])
838 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
840 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|TRUE/FALSE')
842 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
843 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
844 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', List
[1], Type
, [], {}, []))
846 # For FixedAtBuild or PatchableInModule
848 if Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
or Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
850 if len(List
) != 3 and len(List
) != 4:
851 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|<Value>[|<MaxDatumSize>]')
853 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
854 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
855 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', List
[2], List
[1], Type
, [], {}, []))
858 # For Dynamic or DynamicEx
860 if Type
== DataType
.TAB_PCDS_DYNAMIC
or Type
== DataType
.TAB_PCDS_DYNAMIC_EX
:
862 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>')
864 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
865 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
866 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', '', Type
, [], {}, []))
871 self
.PcdToken
[PcdId
] = (TokenInfo
[0], TokenInfo
[1])
878 # Gen SkuInfoList section defined in Dsc file
880 # @param SkuNameList: Input value for SkuNameList
881 # @param SkuInfo: Input value for SkuInfo
882 # @param VariableName: Input value for VariableName
883 # @param VariableGuid: Input value for VariableGuid
884 # @param VariableOffset: Input value for VariableOffset
885 # @param HiiDefaultValue: Input value for HiiDefaultValue
886 # @param VpdOffset: Input value for VpdOffset
887 # @param DefaultValue: Input value for DefaultValue
889 # @retval (False, SkuName) Not found in section SkuId Dsc file
890 # @retval (True, SkuInfoList) Found in section SkuId of Dsc file
892 def GenSkuInfoList(self
, SkuNameList
, SkuInfo
, VariableName
='', VariableGuid
='', VariableOffset
='', HiiDefaultValue
='', VpdOffset
='', DefaultValue
=''):
893 SkuNameList
= GetSplitValueList(SkuNameList
)
894 if SkuNameList
is None or SkuNameList
== [] or SkuNameList
== ['']:
895 SkuNameList
= ['DEFAULT']
897 for Item
in SkuNameList
:
898 if Item
not in SkuInfo
:
900 Sku
= SkuInfoClass(Item
, SkuInfo
[Item
], VariableName
, VariableGuid
, VariableOffset
, HiiDefaultValue
, VpdOffset
, DefaultValue
)
901 SkuInfoList
[Item
] = Sku
903 return True, SkuInfoList
905 ## Parse Include statement
907 # Get include file path
909 # 1. Insert a record into TblFile ???
910 # 2. Insert a record into TblDsc
911 # Value1: IncludeFilePath
913 # @param LineValue: The line of incude statement
914 def ParseInclude(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
915 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "!include statement '%s' found in section %s" % (LineValue
, SectionName
))
916 SectionModel
= Section
[SectionName
.upper()]
917 IncludeFile
= CleanString(LineValue
[LineValue
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') + len(DataType
.TAB_INCLUDE
+ ' ') : ])
918 Table
.Insert(Model
, IncludeFile
, '', '', Arch
, SectionModel
, FileID
, StartLine
, -1, StartLine
, -1, 0)
920 ## Parse DEFINE statement
924 # 1. Insert a record into TblDsc
926 # Value2: Macro Value
928 def ParseDefine(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
929 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "DEFINE statement '%s' found in section %s" % (LineValue
, SectionName
))
930 SectionModel
= Section
[SectionName
.upper()]
931 Define
= GetSplitValueList(CleanString(LineValue
[LineValue
.upper().find(DataType
.TAB_DEFINE
.upper() + ' ') + len(DataType
.TAB_DEFINE
+ ' ') : ]), TAB_EQUAL_SPLIT
, 1)
932 Table
.Insert(Model
, Define
[0], Define
[1], '', Arch
, SectionModel
, FileID
, StartLine
, -1, StartLine
, -1, 0)
934 ## Parse Defines section
936 # Get one item in defines section
941 def ParseDefinesSection(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
942 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "Parse '%s' found in section %s" % (LineValue
, SectionName
))
943 Defines
= GetSplitValueList(LineValue
, TAB_EQUAL_SPLIT
, 1)
944 if len(Defines
) != 2:
945 RaiseParserError(LineValue
, SectionName
, Filename
, '', StartLine
)
946 self
.TblDsc
.Insert(Model
, Defines
[0], Defines
[1], '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
948 ## Insert conditional statements
950 # Pop an item from IfDefList
951 # Insert conditional statements to database
953 # @param Filename: Path of parsing file
954 # @param IfDefList: A list stored current conditional statements
955 # @param EndLine: The end line no
956 # @param ArchList: Support arch list
958 def InsertConditionalStatement(self
, Filename
, FileID
, BelongsToItem
, IfDefList
, EndLine
, ArchList
):
959 (Value1
, Value2
, Value3
, Model
, StartColumn
, EndColumn
, Enabled
) = ('', '', '', -1, -1, -1, 0)
961 ErrorMsg
= 'Not suited conditional statement in file %s' % Filename
962 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, Filename
, RaiseError
=EdkLogger
.IsRaiseError
)
965 # Get New Dsc item ID
967 DscID
= self
.TblDsc
.GetCount() + 1
970 # Pop the conditional statements which is closed
972 PreviousIf
= IfDefList
.pop()
973 EdkLogger
.debug(EdkLogger
.DEBUG_5
, 'Previous IfDef: ' + str(PreviousIf
))
978 if PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
):
979 Value1
= PreviousIf
[0]
980 Model
= PreviousIf
[2]
981 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
985 elif PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, Model
):
986 List
= PreviousIf
[0].split(' ')
987 Value1
, Value2
, Value3
= '', '==', '0'
992 Value3
= SplitString(Value3
)
995 Model
= PreviousIf
[2]
996 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
1000 elif PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, Model
):
1001 Value1
= PreviousIf
[0].strip()
1002 Model
= PreviousIf
[2]
1003 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
1007 # Load the file if it exists
1009 # @param Filename: Input value for filename of Dsc file
1011 def LoadDscFile(self
, Filename
):
1013 # Insert a record for file
1015 Filename
= NormPath(Filename
)
1016 self
.Identification
.FileFullPath
= Filename
1017 (self
.Identification
.FileRelativePath
, self
.Identification
.FileName
) = os
.path
.split(Filename
)
1018 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_DSC
)
1023 #self.TblDsc.Table = "Dsc%s" % FileID
1024 #self.TblDsc.Create()
1029 IfDefList
, SectionItemList
, CurrentSection
, ArchList
, ThirdList
, IncludeFiles
= \
1030 [], [], TAB_UNKNOWN
, [], [], []
1034 # Parse file content
1036 IsFindBlockComment
= False
1038 for Line
in open(Filename
, 'r'):
1041 # Remove comment block
1043 if Line
.find(TAB_COMMENT_EDK_START
) > -1:
1044 ReservedLine
= GetSplitList(Line
, TAB_COMMENT_EDK_START
, 1)[0]
1045 IsFindBlockComment
= True
1046 if Line
.find(TAB_COMMENT_EDK_END
) > -1:
1047 Line
= ReservedLine
+ GetSplitList(Line
, TAB_COMMENT_EDK_END
, 1)[1]
1049 IsFindBlockComment
= False
1050 if IsFindBlockComment
:
1054 # Remove comments at tail and remove spaces again
1056 Line
= CleanString(Line
)
1061 # Find a new section tab
1062 # First insert previous section items
1063 # And then parse the content of the new section
1065 if Line
.startswith(TAB_SECTION_START
) and Line
.endswith(TAB_SECTION_END
):
1067 # Insert items data of previous section
1069 self
.InsertSectionItemsIntoDatabase(self
.FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
)
1071 # Parse the new section
1073 SectionItemList
= []
1078 LineList
= GetSplitValueList(Line
[len(TAB_SECTION_START
):len(Line
) - len(TAB_SECTION_END
)], TAB_COMMA_SPLIT
)
1079 for Item
in LineList
:
1080 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
1081 if CurrentSection
== '':
1082 CurrentSection
= ItemList
[0]
1084 if CurrentSection
!= ItemList
[0]:
1085 EdkLogger
.error("Parser", PARSER_ERROR
, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection
, ItemList
[0]), File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
1086 if CurrentSection
.upper() not in self
.KeyList
:
1087 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
1088 CurrentSection
= TAB_UNKNOWN
1092 if len(ItemList
) > 5:
1093 RaiseParserError(Line
, CurrentSection
, Filename
, '', LineNo
)
1095 if ItemList
[1] != '' and ItemList
[1].upper() not in ARCH_LIST_FULL
:
1096 EdkLogger
.error("Parser", PARSER_ERROR
, "Invalid Arch definition '%s' found" % ItemList
[1], File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
1097 ArchList
.append(ItemList
[1].upper())
1098 ThirdList
.append(ItemList
[2])
1103 # Not in any defined section
1105 if CurrentSection
== TAB_UNKNOWN
:
1106 ErrorMsg
= "%s is not in any defined section" % Line
1107 EdkLogger
.error("Parser", PARSER_ERROR
, ErrorMsg
, File
=Filename
, Line
=LineNo
, RaiseError
=EdkLogger
.IsRaiseError
)
1110 # Add a section item
1112 SectionItemList
.append([Line
, LineNo
])
1117 # Insert items data of last section
1119 self
.InsertSectionItemsIntoDatabase(self
.FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
)
1122 # Parse conditional statements
1124 self
.ParseConditionalStatement()
1127 # Replace all DEFINE macros with its actual values
1129 #ParseDefineMacro2(self.TblDsc, self.RecordSet, GlobalData.gGlobalDefines)
1130 ParseDefineMacro(self
.TblDsc
, GlobalData
.gGlobalDefines
)
1133 ## ParseConditionalStatement
1135 # Search all conditional statement and disable no match records
1137 def ParseConditionalStatement(self
):
1139 # Disabled all !if/!elif/!ifdef statements without DEFINE
1141 SqlCommand
= """select A.StartLine, A.EndLine from %s as A
1142 where A.Model in (%s, %s, %s)
1144 and A.BelongsToFile = %s
1145 and A.Value1 not in (select B.Value1 from %s as B
1148 and A.StartLine > B.StartLine
1150 and A.BelongsToItem = B.BelongsToItem
1151 and A.BelongsToFile = B.BelongsToFile) """ % \
1152 (self
.TblDsc
.Table
, \
1153 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
, \
1155 self
.TblDsc
.Table
, \
1156 MODEL_META_DATA_DEFINE
)
1157 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1158 for Record
in RecordSet
:
1159 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[0], Record
[1])
1160 self
.TblDsc
.Exec(SqlCommand
)
1163 # Disabled !ifndef with DEFINE
1165 SqlCommand
= """select A.StartLine, A.EndLine from %s as A
1168 and A.BelongsToFile = %s
1169 and A.Value1 in (select B.Value1 from %s as B
1172 and A.StartLine > B.StartLine
1174 and A.BelongsToItem = B.BelongsToItem
1175 and A.BelongsToFile = B.BelongsToFile)""" % \
1176 (self
.TblDsc
.Table
, \
1177 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
, \
1179 self
.TblDsc
.Table
, \
1180 MODEL_META_DATA_DEFINE
)
1181 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1182 for Record
in RecordSet
:
1183 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[0], Record
[1])
1184 EdkLogger
.debug(4, "SqlCommand: %s" % SqlCommand
)
1185 self
.Cur
.execute(SqlCommand
)
1188 # Disabled !if, !elif and !else with un-match value
1190 SqlCommand
= """select A.Model, A.Value1, A.Value2, A.Value3, A.StartLine, A.EndLine, B.Value2 from %s as A join %s as B
1191 where A.Model in (%s, %s)
1193 and A.BelongsToFile = %s
1196 and A.Value1 = B.Value1
1197 and A.StartLine > B.StartLine
1198 and A.BelongsToItem = B.BelongsToItem
1199 and A.BelongsToFile = B.BelongsToFile""" % \
1200 (self
.TblDsc
.Table
, self
.TblDsc
.Table
, \
1201 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
, \
1202 self
.FileID
, MODEL_META_DATA_DEFINE
)
1203 RecordSet
= self
.TblDsc
.Exec(SqlCommand
)
1205 for Record
in RecordSet
:
1206 if Record
[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
:
1207 if not self
.Compare(Record
[6], Record
[2], Record
[3]):
1208 SqlCommand
= """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self
.TblDsc
.Table
, Record
[4], Record
[5])
1209 self
.TblDsc
.Exec(SqlCommand
)
1211 DisabledList
.append(Record
[1])
1213 if Record
[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
and Record
[1] in DisabledList
:
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
)
1219 # Compare two values
1221 # @param CompareType:
1224 def Compare(self
, Value1
, CompareType
, Value2
):
1225 Command
= """Value1 %s Value2""" % CompareType
1226 return eval(Command
)
1228 ## First time to insert records to database
1230 # Insert item data of a section to database
1231 # @param FileID: The ID of belonging file
1232 # @param Filename: The name of belonging file
1233 # @param CurrentSection: The name of currect section
1234 # @param SectionItemList: A list of items of the section
1235 # @param ArchList: A list of arches
1236 # @param ThirdList: A list of third parameters, ModuleType for LibraryClass and SkuId for Dynamic Pcds
1237 # @param IfDefList: A list of all conditional statements
1239 def InsertSectionItemsIntoDatabase(self
, FileID
, Filename
, CurrentSection
, SectionItemList
, ArchList
, ThirdList
, IfDefList
):
1241 # Insert each item data of a section
1243 for Index
in range(0, len(ArchList
)):
1244 Arch
= ArchList
[Index
]
1245 Third
= ThirdList
[Index
]
1247 Arch
= TAB_ARCH_COMMON
.upper()
1249 Model
= Section
[CurrentSection
.upper()]
1250 #Records = self.RecordSet[Model]
1252 for SectionItem
in SectionItemList
:
1253 BelongsToItem
, EndLine
, EndColumn
= -1, -1, -1
1254 LineValue
, StartLine
, EndLine
= SectionItem
[0], SectionItem
[1], SectionItem
[1]
1257 EdkLogger
.debug(4, "Parsing %s ..." % LineValue
)
1261 if LineValue
.upper().find(TAB_IF_DEF
.upper()) > -1:
1262 IfDefList
.append((LineValue
[len(TAB_IF_N_DEF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
))
1268 if LineValue
.upper().find(TAB_IF_N_DEF
.upper()) > -1:
1269 IfDefList
.append((LineValue
[len(TAB_IF_N_DEF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
))
1275 if LineValue
.upper().find(TAB_END_IF
.upper()) > -1:
1276 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
, Arch
)
1281 if LineValue
.upper().find(TAB_IF
.upper()) > -1:
1282 IfDefList
.append((LineValue
[len(TAB_IF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
))
1288 if LineValue
.upper().find(TAB_ELSE_IF
.upper()) > -1:
1289 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
- 1, Arch
)
1290 IfDefList
.append((LineValue
[len(TAB_ELSE_IF
):].strip(), StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
))
1296 if LineValue
.upper().find(TAB_ELSE
.upper()) > -1:
1297 Key
= IfDefList
[-1][0].split(' ' , 1)[0].strip()
1298 self
.InsertConditionalStatement(Filename
, FileID
, Model
, IfDefList
, StartLine
, Arch
)
1299 IfDefList
.append((Key
, StartLine
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
))
1303 # Parse !include statement first
1305 if LineValue
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') > -1:
1306 self
.ParseInclude(LineValue
, StartLine
, self
.TblDsc
, FileID
, Filename
, CurrentSection
, MODEL_META_DATA_INCLUDE
, Arch
)
1310 # And then parse DEFINE statement
1312 if LineValue
.upper().find(DataType
.TAB_DEFINE
.upper() + ' ') > -1:
1313 self
.ParseDefine(LineValue
, StartLine
, self
.TblDsc
, FileID
, Filename
, CurrentSection
, MODEL_META_DATA_DEFINE
, Arch
)
1317 # At last parse other sections
1319 if CurrentSection
== TAB_LIBRARY_CLASSES
or CurrentSection
in TAB_PCD_DYNAMIC_TYPE_LIST
or CurrentSection
in TAB_PCD_DYNAMIC_EX_TYPE_LIST
:
1320 ID
= self
.TblDsc
.Insert(Model
, LineValue
, Third
, '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1321 #Records.append([LineValue, Arch, StartLine, ID, Third])
1323 elif CurrentSection
!= TAB_COMPONENTS
:
1324 ID
= self
.TblDsc
.Insert(Model
, LineValue
, '', '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1325 #Records.append([LineValue, Arch, StartLine, ID, Third])
1329 # Parse COMPONENT section
1331 if CurrentSection
== TAB_COMPONENTS
:
1333 GetComponent(SectionItemList
, Components
)
1334 for Component
in Components
:
1335 EdkLogger
.debug(4, "Parsing component %s ..." % Component
)
1336 DscItmeID
= self
.TblDsc
.Insert(MODEL_META_DATA_COMPONENT
, Component
[0], '', '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
1337 for Item
in Component
[1]:
1338 List
= GetSplitValueList(Item
, MaxSplit
=2)
1339 LibName
, LibIns
= '', ''
1345 self
.TblDsc
.Insert(MODEL_EFI_LIBRARY_CLASS
, LibName
, LibIns
, '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1346 for Item
in Component
[2]:
1347 self
.TblDsc
.Insert(MODEL_META_DATA_BUILD_OPTION
, Item
, '', '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1348 for Item
in Component
[3]:
1349 Model
= Section
[Item
[0].upper()]
1350 self
.TblDsc
.Insert(Model
, Item
[1], '', '', Arch
, DscItmeID
, FileID
, StartLine
, -1, StartLine
, -1, 0)
1352 ## Show detailed information of Dsc
1354 # Print all members and their values of Dsc class
1357 print TAB_SECTION_START
+ TAB_INF_DEFINES
+ TAB_SECTION_END
1358 printDict(self
.Defines
.DefinesDictionary
)
1360 for Key
in self
.KeyList
:
1361 for Arch
in DataType
.ARCH_LIST_FULL
:
1362 Command
= "printList(TAB_SECTION_START + '" + \
1363 Key
+ DataType
.TAB_SPLIT
+ Arch
+ \
1364 "' + TAB_SECTION_END, self.Contents[arch]." + Key
+ ')'
1367 ## Show detailed information of Platform
1369 # Print all members and their values of Platform class
1371 def ShowPlatform(self
):
1373 for Arch
in M
.Header
.keys():
1374 print '\nArch =', Arch
1375 print 'Filename =', M
.Header
[Arch
].FileName
1376 print 'FullPath =', M
.Header
[Arch
].FullPath
1377 print 'BaseName =', M
.Header
[Arch
].Name
1378 print 'Guid =', M
.Header
[Arch
].Guid
1379 print 'Version =', M
.Header
[Arch
].Version
1380 print 'DscSpecification =', M
.Header
[Arch
].DscSpecification
1381 print 'SkuId =', M
.Header
[Arch
].SkuIdName
1382 print 'SupArchList =', M
.Header
[Arch
].SupArchList
1383 print 'BuildTargets =', M
.Header
[Arch
].BuildTargets
1384 print 'OutputDirectory =', M
.Header
[Arch
].OutputDirectory
1385 print 'BuildNumber =', M
.Header
[Arch
].BuildNumber
1386 print 'MakefileName =', M
.Header
[Arch
].MakefileName
1387 print 'BsBaseAddress =', M
.Header
[Arch
].BsBaseAddress
1388 print 'RtBaseAddress =', M
.Header
[Arch
].RtBaseAddress
1389 print 'Define =', M
.Header
[Arch
].Define
1390 print 'Fdf =', M
.FlashDefinitionFile
.FilePath
1391 print '\nBuildOptions =', M
.BuildOptions
, M
.BuildOptions
.IncludeFiles
1392 for Item
in M
.BuildOptions
.BuildOptionList
:
1393 print '\t', 'ToolChainFamily =', Item
.ToolChainFamily
, 'ToolChain =', Item
.ToolChain
, 'Option =', Item
.Option
, 'Arch =', Item
.SupArchList
1394 print '\nSkuIds =', M
.SkuInfos
.SkuInfoList
, M
.SkuInfos
.IncludeFiles
1395 print '\nLibraries =', M
.Libraries
, M
.Libraries
.IncludeFiles
1396 for Item
in M
.Libraries
.LibraryList
:
1397 print '\t', Item
.FilePath
, Item
.SupArchList
, Item
.Define
1398 print '\nLibraryClasses =', M
.LibraryClasses
, M
.LibraryClasses
.IncludeFiles
1399 for Item
in M
.LibraryClasses
.LibraryList
:
1400 print '\t', Item
.Name
, Item
.FilePath
, Item
.SupModuleList
, Item
.SupArchList
, Item
.Define
1401 print '\nPcds =', M
.DynamicPcdBuildDefinitions
1402 for Item
in M
.DynamicPcdBuildDefinitions
:
1403 print '\tCname=', Item
.CName
, 'TSG=', Item
.TokenSpaceGuidCName
, 'Value=', Item
.DefaultValue
, 'Token=', Item
.Token
, 'Type=', Item
.ItemType
, 'Datum=', Item
.DatumType
, 'Size=', Item
.MaxDatumSize
, 'Arch=', Item
.SupArchList
, Item
.SkuInfoList
1404 for Sku
in Item
.SkuInfoList
.values():
1405 print '\t\t', str(Sku
)
1406 print '\nComponents =', M
.Modules
.ModuleList
, M
.Modules
.IncludeFiles
1407 for Item
in M
.Modules
.ModuleList
:
1408 print '\t', Item
.FilePath
, Item
.ExecFilePath
, Item
.SupArchList
1409 for Lib
in Item
.LibraryClasses
.LibraryList
:
1410 print '\t\tLib:', Lib
.Name
, Lib
.FilePath
1411 for Bo
in Item
.ModuleSaBuildOption
.BuildOptionList
:
1412 print '\t\tBuildOption:', Bo
.ToolChainFamily
, Bo
.ToolChain
, Bo
.Option
1413 for Pcd
in Item
.PcdBuildDefinitions
:
1414 print '\t\tPcd:', Pcd
.CName
, Pcd
.TokenSpaceGuidCName
, Pcd
.MaxDatumSize
, Pcd
.DefaultValue
, Pcd
.ItemType
1418 # This acts like the main() function for the script, unless it is 'import'ed into another
1421 if __name__
== '__main__':
1422 EdkLogger
.Initialize()
1423 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
1425 W
= os
.getenv('WORKSPACE')
1426 F
= os
.path
.join(W
, 'Nt32Pkg/Nt32Pkg.dsc')
1428 Db
= Database
.Database('Dsc.db')
1431 P
= Dsc(os
.path
.normpath(F
), True, True, W
, Db
)