2 # This file is used to define each component of DSC file
4 # Copyright (c) 2007 ~ 2008, Intel Corporation
5 # All rights reserved. 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 for NewItem
in open(Filename
, 'r').readlines():
389 if CleanString(NewItem
) == '':
391 MergeArches(Libraries
, NewItem
, Arch
)
393 for Record
in RecordSet
:
394 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
395 MergeArches(Libraries
, Record
[0], Arch
)
397 for Key
in Libraries
.keys():
398 Library
= PlatformLibraryClass()
399 Library
.FilePath
= NormPath(Key
)
400 Library
.SupArchList
= Libraries
[Key
]
401 self
.Platform
.Libraries
.LibraryList
.append(Library
)
405 # Get LibraryClasses of Dsc
406 # <LibraryClassKeyWord>|<LibraryInstance>
408 # @param ContainerFile: The Dsc file full path
410 def GenLibraryClasses(self
, ContainerFile
):
411 EdkLogger
.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
414 # Get all include files
416 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_EFI_LIBRARY_CLASS
, self
.FileID
)
419 # Get all LibraryClasses
421 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, -1, self
.FileID
)
424 # Go through each arch
426 for Arch
in DataType
.ARCH_LIST
:
427 for IncludeFile
in IncludeFiles
:
428 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
429 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_LIBRARY_CLASSES
, '', IncludeFile
[2])
430 for NewItem
in open(Filename
, 'r').readlines():
431 if CleanString(NewItem
) == '':
433 MergeArches(LibraryClasses
, GetLibraryClass([NewItem
, IncludeFile
[4]], Filename
, self
.WorkspaceDir
, -1), Arch
)
435 for Record
in RecordSet
:
436 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
437 (LibClassName
, LibClassIns
, SupModelList
) = GetLibraryClass([Record
[0], Record
[4]], ContainerFile
, self
.WorkspaceDir
, Record
[2])
438 MergeArches(LibraryClasses
, (LibClassName
, LibClassIns
, SupModelList
), Arch
)
442 if self
.IsToDatabase
:
443 SqlCommand
= """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
444 where ID = %s""" % (self
.TblDsc
.Table
, ConvertToSqlString2(LibClassName
), ConvertToSqlString2(LibClassIns
), ConvertToSqlString2(SupModelList
), Record
[3])
445 self
.TblDsc
.Exec(SqlCommand
)
447 for Key
in LibraryClasses
.keys():
448 Library
= PlatformLibraryClass()
449 Library
.Name
= Key
[0]
450 Library
.FilePath
= NormPath(Key
[1])
451 Library
.SupModuleList
= GetSplitValueList(Key
[2])
452 Library
.SupArchList
= LibraryClasses
[Key
]
453 self
.Platform
.LibraryClasses
.LibraryList
.append(Library
)
457 # Gen Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]
459 # @param Type: The type of Pcd
460 # @param ContainerFile: The file which describes the pcd, used for error report
462 def GenPcds(self
, Type
= '', ContainerFile
= ''):
464 if Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
465 Model
= MODEL_PCD_PATCHABLE_IN_MODULE
466 elif Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
:
467 Model
= MODEL_PCD_FIXED_AT_BUILD
470 EdkLogger
.debug(2, "Generate %s ..." % Type
)
473 # Get all include files
475 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
480 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
483 # Go through each arch
485 for Arch
in DataType
.ARCH_LIST
:
486 for IncludeFile
in IncludeFiles
:
487 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
488 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
489 for NewItem
in open(Filename
, 'r').readlines():
490 if CleanString(NewItem
) == '':
492 (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
) = GetPcd(NewItem
, Type
, Filename
, -1)
493 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
), Arch
)
494 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
496 for Record
in RecordSet
:
497 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
498 (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
) = GetPcd(Record
[0], Type
, ContainerFile
, Record
[2])
499 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, DatumType
, MaxDatumSize
, Type
), Arch
)
500 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
503 Pcd
= PcdClass(Key
[0], '', Key
[1], Key
[3], Key
[4], Key
[2], Key
[5], [], {}, [])
504 Pcd
.SupArchList
= Pcds
[Key
]
505 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
507 ## Gen FeatureFlagPcds
509 # Gen FeatureFlagPcds of Dsc file as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE
511 # @param Type: The type of Pcd
512 # @param ContainerFile: The file which describes the pcd, used for error report
514 def GenFeatureFlagPcds(self
, Type
= '', ContainerFile
= ''):
516 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
517 Model
= MODEL_PCD_FEATURE_FLAG
520 EdkLogger
.debug(2, "Generate %s ..." % Type
)
523 # Get all include files
525 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
528 # Get all FeatureFlagPcds
530 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
533 # Go through each arch
535 for Arch
in DataType
.ARCH_LIST
:
536 for IncludeFile
in IncludeFiles
:
537 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
538 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
539 for NewItem
in open(Filename
, 'r').readlines():
540 if CleanString(NewItem
) == '':
542 (TokenName
, TokenGuidCName
, Value
, Type
) = GetFeatureFlagPcd(NewItem
, Type
, Filename
, -1)
543 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, Type
), Arch
)
544 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
546 for Record
in RecordSet
:
547 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
548 (TokenName
, TokenGuidCName
, Value
, Type
) = GetFeatureFlagPcd(Record
[0], Type
, ContainerFile
, Record
[2])
549 MergeArches(Pcds
, (TokenName
, TokenGuidCName
, Value
, Type
), Arch
)
550 self
.PcdToken
[Record
[3]] = (TokenGuidCName
, TokenName
)
553 Pcd
= PcdClass(Key
[0], '', Key
[1], '', '', Key
[2], Key
[3], [], {}, [])
554 Pcd
.SupArchList
= Pcds
[Key
]
555 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
557 ## Gen DynamicDefaultPcds
559 # Gen DynamicDefaultPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]
561 # @param Type: The type of Pcd
562 # @param ContainerFile: The file which describes the pcd, used for error report
564 def GenDynamicDefaultPcds(self
, Type
= '', ContainerFile
= ''):
567 if Type
== DataType
.TAB_PCDS_DYNAMIC_DEFAULT
:
568 Model
= MODEL_PCD_DYNAMIC_DEFAULT
569 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_DEFAULT
:
570 Model
= MODEL_PCD_DYNAMIC_EX_DEFAULT
573 EdkLogger
.debug(2, "Generate %s ..." % Type
)
576 # Get all include files
578 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
581 # Get all DynamicDefaultPcds
583 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
586 # Go through each arch
588 for Arch
in DataType
.ARCH_LIST
:
589 for IncludeFile
in IncludeFiles
:
590 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
591 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
592 for NewItem
in open(Filename
, 'r').readlines():
593 if CleanString(NewItem
) == '':
595 (K1
, K2
, K3
, K4
, K5
, K6
) = GetDynamicDefaultPcd(NewItem
, Type
, Filename
, -1)
596 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, IncludeFile
[4]), Arch
)
597 self
.PcdToken
[Record
[3]] = (K2
, K1
)
599 for Record
in RecordSet
:
600 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
601 (K1
, K2
, K3
, K4
, K5
, K6
) = GetDynamicDefaultPcd(Record
[0], Type
, ContainerFile
, Record
[2])
602 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, Record
[4]), Arch
)
603 self
.PcdToken
[Record
[3]] = (K2
, K1
)
606 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[6], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', '', Key
[2])
608 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
609 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
= EdkLogger
.IsRaiseError
)
610 Pcd
= PcdClass(Key
[0], '', Key
[1], Key
[3], Key
[4], Key
[2], Key
[5], [], SkuInfoList
, [])
611 Pcd
.SupArchList
= Pcds
[Key
]
612 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
614 ## Gen DynamicHiiPcds
616 # Gen DynamicHiiPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]
618 # @param Type: The type of Pcd
619 # @param ContainerFile: The file which describes the pcd, used for error report
621 def GenDynamicHiiPcds(self
, Type
= '', ContainerFile
= ''):
624 if Type
== DataType
.TAB_PCDS_DYNAMIC_HII
:
625 Model
= MODEL_PCD_DYNAMIC_HII
626 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_HII
:
627 Model
= MODEL_PCD_DYNAMIC_EX_HII
630 EdkLogger
.debug(2, "Generate %s ..." % Type
)
633 # Get all include files
635 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
638 # Get all DynamicHiiPcds
640 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
643 # Go through each arch
645 for Arch
in DataType
.ARCH_LIST
:
646 for IncludeFile
in IncludeFiles
:
647 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
648 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
649 for NewItem
in open(Filename
, 'r').readlines():
650 if CleanString(NewItem
) == '':
652 (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
) = GetDynamicHiiPcd(NewItem
, Type
, Filename
, -1)
653 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
, IncludeFile
[4]), Arch
)
654 self
.PcdToken
[Record
[3]] = (K2
, K1
)
656 for Record
in RecordSet
:
657 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
658 (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
) = GetDynamicHiiPcd(Record
[0], Type
, ContainerFile
, Record
[2])
659 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, K6
, K7
, K8
, Record
[4]), Arch
)
660 self
.PcdToken
[Record
[3]] = (K2
, K1
)
663 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[8], self
.Platform
.SkuInfos
.SkuInfoList
, Key
[2], Key
[3], Key
[4], Key
[5], '', '')
665 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
666 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
= EdkLogger
.IsRaiseError
)
667 Pcd
= PcdClass(Key
[0], '', Key
[1], '', Key
[6], Key
[5], Key
[7], [], SkuInfoList
, [])
668 Pcd
.SupArchList
= Pcds
[Key
]
669 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
671 ## Gen DynamicVpdPcds
673 # Gen DynamicVpdPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]
675 # @param Type: The type of Pcd
676 # @param ContainerFile: The file which describes the pcd, used for error report
678 def GenDynamicVpdPcds(self
, Type
= '', ContainerFile
= ''):
681 if Type
== DataType
.TAB_PCDS_DYNAMIC_VPD
:
682 Model
= MODEL_PCD_DYNAMIC_VPD
683 elif Type
== DataType
.TAB_PCDS_DYNAMIC_EX_VPD
:
684 Model
= MODEL_PCD_DYNAMIC_EX_VPD
687 EdkLogger
.debug(2, "Generate %s ..." % Type
)
690 # Get all include files
692 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, Model
, self
.FileID
)
695 # Get all DynamicVpdPcds
697 RecordSet
= QueryDscItem(self
.TblDsc
, Model
, -1, self
.FileID
)
700 # Go through each arch
702 for Arch
in DataType
.ARCH_LIST
:
703 for IncludeFile
in IncludeFiles
:
704 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
705 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, Type
, '', IncludeFile
[2])
706 for NewItem
in open(Filename
, 'r').readlines():
707 if CleanString(NewItem
) == '':
709 (K1
, K2
, K3
, K4
, K5
) = GetDynamicVpdPcd(NewItem
, Type
, Filename
, -1)
710 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, IncludeFile
[4]), Arch
)
711 self
.PcdToken
[Record
[3]] = (K2
, K1
)
713 for Record
in RecordSet
:
714 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
715 (K1
, K2
, K3
, K4
, K5
) = GetDynamicVpdPcd(Record
[0], Type
, ContainerFile
, Record
[2])
716 MergeArches(Pcds
, (K1
, K2
, K3
, K4
, K5
, Record
[4]), Arch
)
717 self
.PcdToken
[Record
[3]] = (K2
, K1
)
720 (Status
, SkuInfoList
) = self
.GenSkuInfoList(Key
[5], self
.Platform
.SkuInfos
.SkuInfoList
, '', '', '', '', Key
[2], '')
722 ErrorMsg
= "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList
, Type
)
723 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, ContainerFile
, RaiseError
= EdkLogger
.IsRaiseError
)
724 Pcd
= PcdClass(Key
[0], '', Key
[1], '', Key
[3], '', Key
[4], [], SkuInfoList
, [])
725 Pcd
.SupArchList
= Pcds
[Key
]
726 self
.Platform
.DynamicPcdBuildDefinitions
.append(Pcd
)
731 # Get Component section defined in Dsc file
733 # @param ContainerFile: The file which describes the Components, used for error report
735 # @retval PlatformModuleClass() A instance for PlatformModuleClass
737 def GenComponents(self
, ContainerFile
):
738 EdkLogger
.debug(2, "Generate %s ..." % TAB_COMPONENTS
)
741 # Get all include files
743 IncludeFiles
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_COMPONENT
, self
.FileID
)
748 RecordSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_COMPONENT
, -1, self
.FileID
)
751 # Go through each arch
753 for Arch
in DataType
.ARCH_LIST
:
754 for IncludeFile
in IncludeFiles
:
755 if IncludeFile
[1] == Arch
or IncludeFile
[1] == TAB_ARCH_COMMON
.upper():
756 Filename
= CheckFileExist(self
.WorkspaceDir
, IncludeFile
[0], ContainerFile
, TAB_COMPONENTS
, '', IncludeFile
[2])
757 for NewItem
in open(Filename
, 'r').readlines():
758 if CleanString(NewItem
) == '':
761 GetComponents(open(Filename
, 'r').read(), TAB_COMPONENTS
, NewItems
, TAB_COMMENT_SPLIT
)
762 for NewComponent
in NewItems
:
763 MergeArches(Components
, self
.GenComponent(NewComponent
, Filename
), Arch
)
765 for Record
in RecordSet
:
766 if Record
[1] == Arch
or Record
[1] == TAB_ARCH_COMMON
.upper():
767 Lib
, Bo
, Pcd
= [], [], []
769 SubLibSet
= QueryDscItem(self
.TblDsc
, MODEL_EFI_LIBRARY_CLASS
, Record
[3], self
.FileID
)
770 for SubLib
in SubLibSet
:
771 Lib
.append(TAB_VALUE_SPLIT
.join([SubLib
[0],SubLib
[4]]))
773 SubBoSet
= QueryDscItem(self
.TblDsc
, MODEL_META_DATA_BUILD_OPTION
, Record
[3], self
.FileID
)
774 for SubBo
in SubBoSet
:
777 SubPcdSet1
= QueryDscItem(self
.TblDsc
, MODEL_PCD_FIXED_AT_BUILD
, Record
[3], self
.FileID
)
778 SubPcdSet2
= QueryDscItem(self
.TblDsc
, MODEL_PCD_PATCHABLE_IN_MODULE
, Record
[3], self
.FileID
)
779 SubPcdSet3
= QueryDscItem(self
.TblDsc
, MODEL_PCD_FEATURE_FLAG
, Record
[3], self
.FileID
)
780 SubPcdSet4
= QueryDscItem(self
.TblDsc
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, Record
[3], self
.FileID
)
781 SubPcdSet5
= QueryDscItem(self
.TblDsc
, MODEL_PCD_DYNAMIC_DEFAULT
, Record
[3], self
.FileID
)
782 for SubPcd
in SubPcdSet1
:
783 Pcd
.append([DataType
.TAB_PCDS_FIXED_AT_BUILD
, SubPcd
[0], SubPcd
[3]])
784 for SubPcd
in SubPcdSet2
:
785 Pcd
.append([DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
, SubPcd
[0], SubPcd
[3]])
786 for SubPcd
in SubPcdSet3
:
787 Pcd
.append([DataType
.TAB_PCDS_FEATURE_FLAG
, SubPcd
[0], SubPcd
[3]])
788 for SubPcd
in SubPcdSet4
:
789 Pcd
.append([DataType
.TAB_PCDS_DYNAMIC_EX
, SubPcd
[0], SubPcd
[3]])
790 for SubPcd
in SubPcdSet5
:
791 Pcd
.append([DataType
.TAB_PCDS_DYNAMIC
, SubPcd
[0], SubPcd
[3]])
792 Item
= [Record
[0], Lib
, Bo
, Pcd
]
793 MergeArches(Components
, self
.GenComponent(Item
, ContainerFile
), Arch
)
795 for Key
in Components
.keys():
796 Key
.SupArchList
= Components
[Key
]
797 self
.Platform
.Modules
.ModuleList
.append(Key
)
801 # Get Component section defined in Dsc file
803 # @param Item: Contents includes a component block
804 # @param ContainerFile: The file which describes the library class, used for error report
806 # @retval PlatformModuleClass() A instance for PlatformModuleClass
808 def GenComponent(self
, Item
, ContainerFile
, LineNo
= -1):
809 (InfFilename
, ExecFilename
) = GetExec(Item
[0])
810 LibraryClasses
= Item
[1]
811 BuildOptions
= Item
[2]
813 Component
= PlatformModuleClass()
814 Component
.FilePath
= NormPath(InfFilename
)
815 Component
.ExecFilePath
= NormPath(ExecFilename
)
816 CheckFileType(Component
.FilePath
, '.Inf', ContainerFile
, 'component name', Item
[0], LineNo
)
817 CheckFileExist(self
.WorkspaceDir
, Component
.FilePath
, ContainerFile
, 'component', Item
[0], LineNo
)
818 for Lib
in LibraryClasses
:
819 List
= GetSplitValueList(Lib
)
821 RaiseParserError(Lib
, 'LibraryClasses', ContainerFile
, '<ClassName>|<InfFilename>')
823 LibFile
= NormPath(List
[1])
824 if LibName
== "" or LibName
== "NULL":
825 LibName
= "NULL%d" % self
._NullClassIndex
826 self
._NullClassIndex
+= 1
827 CheckFileType(List
[1], '.Inf', ContainerFile
, 'library instance of component ', Lib
, LineNo
)
828 CheckFileExist(self
.WorkspaceDir
, LibFile
, ContainerFile
, 'library instance of component', Lib
, LineNo
)
829 Component
.LibraryClasses
.LibraryList
.append(PlatformLibraryClass(LibName
, LibFile
))
830 for BuildOption
in BuildOptions
:
831 Key
= GetBuildOption(BuildOption
, ContainerFile
)
832 Component
.ModuleSaBuildOption
.BuildOptionList
.append(BuildOptionClass(Key
[0], Key
[1], Key
[2]))
835 List
= GetSplitValueList(Pcd
[1])
842 if Type
== DataType
.TAB_PCDS_FEATURE_FLAG
:
844 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|TRUE/FALSE')
846 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
847 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
848 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', List
[1], Type
, [], {}, []))
850 # For FixedAtBuild or PatchableInModule
852 if Type
== DataType
.TAB_PCDS_FIXED_AT_BUILD
or Type
== DataType
.TAB_PCDS_PATCHABLE_IN_MODULE
:
854 if len(List
) != 3 and len(List
) != 4:
855 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>|<Value>[|<MaxDatumSize>]')
857 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
858 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
859 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', List
[2], List
[1], Type
, [], {}, []))
862 # For Dynamic or DynamicEx
864 if Type
== DataType
.TAB_PCDS_DYNAMIC
or Type
== DataType
.TAB_PCDS_DYNAMIC_EX
:
866 RaiseParserError(Pcd
[1], 'Components', ContainerFile
, '<PcdTokenSpaceGuidCName>.<PcdTokenName>')
868 CheckPcdTokenInfo(List
[0], 'Components', ContainerFile
)
869 TokenInfo
= GetSplitValueList(List
[0], DataType
.TAB_SPLIT
)
870 Component
.PcdBuildDefinitions
.append(PcdClass(TokenInfo
[1], '', TokenInfo
[0], '', '', '', Type
, [], {}, []))
875 self
.PcdToken
[PcdId
] = (TokenInfo
[0], TokenInfo
[1])
882 # Gen SkuInfoList section defined in Dsc file
884 # @param SkuNameList: Input value for SkuNameList
885 # @param SkuInfo: Input value for SkuInfo
886 # @param VariableName: Input value for VariableName
887 # @param VariableGuid: Input value for VariableGuid
888 # @param VariableOffset: Input value for VariableOffset
889 # @param HiiDefaultValue: Input value for HiiDefaultValue
890 # @param VpdOffset: Input value for VpdOffset
891 # @param DefaultValue: Input value for DefaultValue
893 # @retval (False, SkuName) Not found in section SkuId Dsc file
894 # @retval (True, SkuInfoList) Found in section SkuId of Dsc file
896 def GenSkuInfoList(self
, SkuNameList
, SkuInfo
, VariableName
= '', VariableGuid
= '', VariableOffset
= '', HiiDefaultValue
= '', VpdOffset
= '', DefaultValue
= ''):
897 SkuNameList
= GetSplitValueList(SkuNameList
)
898 if SkuNameList
== None or SkuNameList
== [] or SkuNameList
== ['']:
899 SkuNameList
= ['DEFAULT']
901 for Item
in SkuNameList
:
902 if Item
not in SkuInfo
:
904 Sku
= SkuInfoClass(Item
, SkuInfo
[Item
], VariableName
, VariableGuid
, VariableOffset
, HiiDefaultValue
, VpdOffset
, DefaultValue
)
905 SkuInfoList
[Item
] = Sku
907 return True, SkuInfoList
909 ## Parse Include statement
911 # Get include file path
913 # 1. Insert a record into TblFile ???
914 # 2. Insert a record into TblDsc
915 # Value1: IncludeFilePath
917 # @param LineValue: The line of incude statement
918 def ParseInclude(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
919 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "!include statement '%s' found in section %s" % (LineValue
, SectionName
))
920 SectionModel
= Section
[SectionName
.upper()]
921 IncludeFile
= CleanString(LineValue
[LineValue
.upper().find(DataType
.TAB_INCLUDE
.upper() + ' ') + len(DataType
.TAB_INCLUDE
+ ' ') : ])
922 Table
.Insert(Model
, IncludeFile
, '', '', Arch
, SectionModel
, FileID
, StartLine
, -1, StartLine
, -1, 0)
924 ## Parse DEFINE statement
928 # 1. Insert a record into TblDsc
930 # Value2: Macro Value
932 def ParseDefine(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
933 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "DEFINE statement '%s' found in section %s" % (LineValue
, SectionName
))
934 SectionModel
= Section
[SectionName
.upper()]
935 Define
= GetSplitValueList(CleanString(LineValue
[LineValue
.upper().find(DataType
.TAB_DEFINE
.upper() + ' ') + len(DataType
.TAB_DEFINE
+ ' ') : ]), TAB_EQUAL_SPLIT
, 1)
936 Table
.Insert(Model
, Define
[0], Define
[1], '', Arch
, SectionModel
, FileID
, StartLine
, -1, StartLine
, -1, 0)
938 ## Parse Defines section
940 # Get one item in defines section
945 def ParseDefinesSection(self
, LineValue
, StartLine
, Table
, FileID
, Filename
, SectionName
, Model
, Arch
):
946 EdkLogger
.debug(EdkLogger
.DEBUG_2
, "Parse '%s' found in section %s" % (LineValue
, SectionName
))
947 Defines
= GetSplitValueList(LineValue
, TAB_EQUAL_SPLIT
, 1)
948 if len(Defines
) != 2:
949 RaiseParserError(LineValue
, SectionName
, Filename
, '', StartLine
)
950 self
.TblDsc
.Insert(Model
, Defines
[0], Defines
[1], '', Arch
, -1, FileID
, StartLine
, -1, StartLine
, -1, 0)
952 ## Insert conditional statements
954 # Pop an item from IfDefList
955 # Insert conditional statements to database
957 # @param Filename: Path of parsing file
958 # @param IfDefList: A list stored current conditional statements
959 # @param EndLine: The end line no
960 # @param ArchList: Support arch list
962 def InsertConditionalStatement(self
, Filename
, FileID
, BelongsToItem
, IfDefList
, EndLine
, ArchList
):
963 (Value1
, Value2
, Value3
, Model
, StartColumn
, EndColumn
, Enabled
) = ('', '', '', -1, -1, -1, 0)
965 ErrorMsg
= 'Not suited conditional statement in file %s' % Filename
966 EdkLogger
.error("DSC File Parser", PARSER_ERROR
, ErrorMsg
, Filename
, RaiseError
= EdkLogger
.IsRaiseError
)
969 # Get New Dsc item ID
971 DscID
= self
.TblDsc
.GetCount() + 1
974 # Pop the conditional statements which is closed
976 PreviousIf
= IfDefList
.pop()
977 EdkLogger
.debug(EdkLogger
.DEBUG_5
, 'Previous IfDef: ' + str(PreviousIf
))
982 if PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
):
983 Value1
= PreviousIf
[0]
984 Model
= PreviousIf
[2]
985 self
.TblDsc
.Insert(Model
, Value1
, Value2
, Value3
, ArchList
, BelongsToItem
, self
.FileID
, PreviousIf
[1], StartColumn
, EndLine
, EndColumn
, Enabled
)
989 elif PreviousIf
[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
, Model
):
990 List
= PreviousIf
[0].split(' ')
994 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_R8_START
) > -1:
1044 ReservedLine
= GetSplitValueList(Line
, TAB_COMMENT_R8_START
, 1)[0]
1045 IsFindBlockComment
= True
1046 if Line
.find(TAB_COMMENT_R8_END
) > -1:
1047 Line
= ReservedLine
+ GetSplitValueList(Line
, TAB_COMMENT_R8_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
)