2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>
5 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 import Common
.LongFilePathOs
as os
23 import Common
.EdkLogger
as EdkLogger
24 import Common
.GlobalData
as GlobalData
25 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
27 from Common
.String
import *
28 from Common
.DataType
import *
29 from Common
.Misc
import *
32 from CommonDataClass
.CommonClass
import SkuInfoClass
34 from MetaDataTable
import *
35 from MetaFileTable
import *
36 from MetaFileParser
import *
37 from BuildClassObject
import *
38 from WorkspaceCommon
import GetDeclaredPcd
39 from Common
.Misc
import AnalyzeDscPcd
40 from Common
.Misc
import ProcessDuplicatedInf
42 from Common
.Parsing
import IsValidWord
43 from Common
.VariableAttributes
import VariableAttributes
44 import Common
.GlobalData
as GlobalData
46 ## Platform build information from DSC file
48 # This class is used to retrieve information stored in database and convert them
49 # into PlatformBuildClassObject form for easier use for AutoGen.
51 class DscBuildData(PlatformBuildClassObject
):
52 # dict used to convert PCD type in database to string used by build tool
54 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
55 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
56 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
57 MODEL_PCD_DYNAMIC
: "Dynamic",
58 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
59 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
60 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
61 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
62 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
63 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
64 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
67 # dict used to convert part of [Defines] to members of DscBuildData directly
72 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
73 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
74 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
75 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
76 #TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
77 #TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
78 #TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
79 TAB_DSC_DEFINES_SKUID_IDENTIFIER
: "_SkuName",
80 #TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
81 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
82 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
83 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
84 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
85 #TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
86 #TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
89 # used to compose dummy library class name for those forced library instances
90 _NullLibraryNumber
= 0
92 ## Constructor of DscBuildData
94 # Initialize object of DscBuildData
96 # @param FilePath The path of platform description file
97 # @param RawData The raw data of DSC file
98 # @param BuildDataBase Database used to retrieve module/package information
99 # @param Arch The target architecture
100 # @param Platform (not used for DscBuildData)
101 # @param Macros Macros used for replacement in DSC file
103 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
='COMMON', Target
=None, Toolchain
=None):
104 self
.MetaFile
= FilePath
105 self
._RawData
= RawData
106 self
._Bdb
= BuildDataBase
108 self
._Target
= Target
109 self
._Toolchain
= Toolchain
111 self
._HandleOverridePath
()
114 def __setitem__(self
, key
, value
):
115 self
.__dict
__[self
._PROPERTY
_[key
]] = value
118 def __getitem__(self
, key
):
119 return self
.__dict
__[self
._PROPERTY
_[key
]]
122 def __contains__(self
, key
):
123 return key
in self
._PROPERTY
_
125 ## Set all internal used members of DscBuildData to None
128 self
._PlatformName
= None
131 self
._DscSpecification
= None
132 self
._OutputDirectory
= None
133 self
._SupArchList
= None
134 self
._BuildTargets
= None
136 self
._SkuIdentifier
= None
137 self
._AvilableSkuIds
= None
138 self
._PcdInfoFlag
= None
139 self
._VarCheckFlag
= None
140 self
._FlashDefinition
= None
141 self
._Prebuild
= None
142 self
._Postbuild
= None
143 self
._BuildNumber
= None
144 self
._MakefileName
= None
145 self
._BsBaseAddress
= None
146 self
._RtBaseAddress
= None
149 self
._LibraryInstances
= None
150 self
._LibraryClasses
= None
153 self
._BuildOptions
= None
154 self
._ModuleTypeOptions
= None
155 self
._LoadFixAddress
= None
156 self
._RFCLanguages
= None
157 self
._ISOLanguages
= None
158 self
._VpdToolGuid
= None
162 ## handle Override Path of Module
163 def _HandleOverridePath(self
):
164 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
165 Macros
= self
._Macros
166 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
167 for Record
in RecordList
:
170 ModuleFile
= PathClass(NormPath(Record
[0]), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
171 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
173 SourceOverridePath
= mws
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0]))
175 # Check if the source override path exists
176 if not os
.path
.isdir(SourceOverridePath
):
177 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
='Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=SourceOverridePath
, Line
=LineNo
)
179 #Add to GlobalData Variables
180 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = SourceOverridePath
182 ## Get current effective macros
183 def _GetMacros(self
):
184 if self
.__Macros
== None:
186 self
.__Macros
.update(GlobalData
.gPlatformDefines
)
187 self
.__Macros
.update(GlobalData
.gGlobalDefines
)
188 self
.__Macros
.update(GlobalData
.gCommandLineDefines
)
197 # Changing the default ARCH to another may affect all other information
198 # because all information in a platform may be ARCH-related. That's
199 # why we need to clear all internal used members, in order to cause all
200 # information to be re-retrieved.
202 # @param Value The value of ARCH
204 def _SetArch(self
, Value
):
205 if self
._Arch
== Value
:
210 ## Retrieve all information in [Defines] section
212 # (Retriving all [Defines] information in one-shot is just to save time.)
214 def _GetHeaderInfo(self
):
215 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
216 for Record
in RecordList
:
218 # items defined _PROPERTY_ don't need additional processing
220 # some special items in [Defines] section need special treatment
221 if Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
222 self
._OutputDirectory
= NormPath(Record
[2], self
._Macros
)
223 if ' ' in self
._OutputDirectory
:
224 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
225 File
=self
.MetaFile
, Line
=Record
[-1],
226 ExtraData
=self
._OutputDirectory
)
227 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
228 self
._FlashDefinition
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
229 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
231 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
233 elif Name
== TAB_DSC_PREBUILD
:
234 self
._Prebuild
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
235 elif Name
== TAB_DSC_POSTBUILD
:
236 self
._Postbuild
= PathClass(NormPath(Record
[2], self
._Macros
), GlobalData
.gWorkspace
)
237 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
238 self
._SupArchList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
239 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
240 self
._BuildTargets
= GetSplitValueList(Record
[2])
241 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
242 if self
._SkuName
== None:
243 self
._SkuName
= Record
[2]
244 self
._SkuIdentifier
= Record
[2]
245 self
._AvilableSkuIds
= Record
[2]
246 elif Name
== TAB_DSC_DEFINES_PCD_INFO_GENERATION
:
247 self
._PcdInfoFlag
= Record
[2]
248 elif Name
== TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION
:
249 self
._VarCheckFlag
= Record
[2]
250 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
252 self
._LoadFixAddress
= int (Record
[2], 0)
254 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record
[2]))
255 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
256 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
257 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for RFC_LANGUAGES must have double quotes around it, for example: RFC_LANGUAGES = "en-us;zh-hans"',
258 File
=self
.MetaFile
, Line
=Record
[-1])
259 LanguageCodes
= Record
[2][1:-1]
260 if not LanguageCodes
:
261 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
262 File
=self
.MetaFile
, Line
=Record
[-1])
263 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
264 # check whether there is empty entries in the list
265 if None in LanguageList
:
266 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
267 File
=self
.MetaFile
, Line
=Record
[-1])
268 self
._RFCLanguages
= LanguageList
269 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
270 if not Record
[2] or Record
[2][0] != '"' or Record
[2][-1] != '"' or len(Record
[2]) == 1:
271 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
272 File
=self
.MetaFile
, Line
=Record
[-1])
273 LanguageCodes
= Record
[2][1:-1]
274 if not LanguageCodes
:
275 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
276 File
=self
.MetaFile
, Line
=Record
[-1])
277 if len(LanguageCodes
)%3:
278 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
279 File
=self
.MetaFile
, Line
=Record
[-1])
281 for i
in range(0, len(LanguageCodes
), 3):
282 LanguageList
.append(LanguageCodes
[i
:i
+3])
283 self
._ISOLanguages
= LanguageList
284 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
286 # try to convert GUID to a real UUID value to see whether the GUID is format
287 # for VPD_TOOL_GUID is correct.
292 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
293 self
._VpdToolGuid
= Record
[2]
295 self
[Name
] = Record
[2]
296 # set _Header to non-None in order to avoid database re-querying
297 self
._Header
= 'DUMMY'
299 ## Retrieve platform name
300 def _GetPlatformName(self
):
301 if self
._PlatformName
== None:
302 if self
._Header
== None:
303 self
._GetHeaderInfo
()
304 if self
._PlatformName
== None:
305 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
306 return self
._PlatformName
308 ## Retrieve file guid
309 def _GetFileGuid(self
):
310 if self
._Guid
== None:
311 if self
._Header
== None:
312 self
._GetHeaderInfo
()
313 if self
._Guid
== None:
314 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_GUID", File
=self
.MetaFile
)
317 ## Retrieve platform version
318 def _GetVersion(self
):
319 if self
._Version
== None:
320 if self
._Header
== None:
321 self
._GetHeaderInfo
()
322 if self
._Version
== None:
323 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_VERSION", File
=self
.MetaFile
)
326 ## Retrieve platform description file version
327 def _GetDscSpec(self
):
328 if self
._DscSpecification
== None:
329 if self
._Header
== None:
330 self
._GetHeaderInfo
()
331 if self
._DscSpecification
== None:
332 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No DSC_SPECIFICATION", File
=self
.MetaFile
)
333 return self
._DscSpecification
335 ## Retrieve OUTPUT_DIRECTORY
336 def _GetOutpuDir(self
):
337 if self
._OutputDirectory
== None:
338 if self
._Header
== None:
339 self
._GetHeaderInfo
()
340 if self
._OutputDirectory
== None:
341 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
342 return self
._OutputDirectory
344 ## Retrieve SUPPORTED_ARCHITECTURES
345 def _GetSupArch(self
):
346 if self
._SupArchList
== None:
347 if self
._Header
== None:
348 self
._GetHeaderInfo
()
349 if self
._SupArchList
== None:
350 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No SUPPORTED_ARCHITECTURES", File
=self
.MetaFile
)
351 return self
._SupArchList
353 ## Retrieve BUILD_TARGETS
354 def _GetBuildTarget(self
):
355 if self
._BuildTargets
== None:
356 if self
._Header
== None:
357 self
._GetHeaderInfo
()
358 if self
._BuildTargets
== None:
359 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BUILD_TARGETS", File
=self
.MetaFile
)
360 return self
._BuildTargets
362 def _GetPcdInfoFlag(self
):
363 if self
._PcdInfoFlag
== None or self
._PcdInfoFlag
.upper() == 'FALSE':
365 elif self
._PcdInfoFlag
.upper() == 'TRUE':
369 def _GetVarCheckFlag(self
):
370 if self
._VarCheckFlag
== None or self
._VarCheckFlag
.upper() == 'FALSE':
372 elif self
._VarCheckFlag
.upper() == 'TRUE':
376 def _GetAviableSkuIds(self
):
377 if self
._AvilableSkuIds
:
378 return self
._AvilableSkuIds
379 return self
.SkuIdentifier
380 def _GetSkuIdentifier(self
):
383 if self
._SkuIdentifier
== None:
384 if self
._Header
== None:
385 self
._GetHeaderInfo
()
386 return self
._SkuIdentifier
387 ## Retrieve SKUID_IDENTIFIER
388 def _GetSkuName(self
):
389 if self
._SkuName
== None:
390 if self
._Header
== None:
391 self
._GetHeaderInfo
()
392 if (self
._SkuName
== None or self
._SkuName
not in self
.SkuIds
):
393 self
._SkuName
= 'DEFAULT'
396 ## Override SKUID_IDENTIFIER
397 def _SetSkuName(self
, Value
):
398 self
._SkuName
= Value
401 def _GetFdfFile(self
):
402 if self
._FlashDefinition
== None:
403 if self
._Header
== None:
404 self
._GetHeaderInfo
()
405 if self
._FlashDefinition
== None:
406 self
._FlashDefinition
= ''
407 return self
._FlashDefinition
409 def _GetPrebuild(self
):
410 if self
._Prebuild
== None:
411 if self
._Header
== None:
412 self
._GetHeaderInfo
()
413 if self
._Prebuild
== None:
415 return self
._Prebuild
417 def _GetPostbuild(self
):
418 if self
._Postbuild
== None:
419 if self
._Header
== None:
420 self
._GetHeaderInfo
()
421 if self
._Postbuild
== None:
423 return self
._Postbuild
425 ## Retrieve FLASH_DEFINITION
426 def _GetBuildNumber(self
):
427 if self
._BuildNumber
== None:
428 if self
._Header
== None:
429 self
._GetHeaderInfo
()
430 if self
._BuildNumber
== None:
431 self
._BuildNumber
= ''
432 return self
._BuildNumber
434 ## Retrieve MAKEFILE_NAME
435 def _GetMakefileName(self
):
436 if self
._MakefileName
== None:
437 if self
._Header
== None:
438 self
._GetHeaderInfo
()
439 if self
._MakefileName
== None:
440 self
._MakefileName
= ''
441 return self
._MakefileName
443 ## Retrieve BsBaseAddress
444 def _GetBsBaseAddress(self
):
445 if self
._BsBaseAddress
== None:
446 if self
._Header
== None:
447 self
._GetHeaderInfo
()
448 if self
._BsBaseAddress
== None:
449 self
._BsBaseAddress
= ''
450 return self
._BsBaseAddress
452 ## Retrieve RtBaseAddress
453 def _GetRtBaseAddress(self
):
454 if self
._RtBaseAddress
== None:
455 if self
._Header
== None:
456 self
._GetHeaderInfo
()
457 if self
._RtBaseAddress
== None:
458 self
._RtBaseAddress
= ''
459 return self
._RtBaseAddress
461 ## Retrieve the top address for the load fix address
462 def _GetLoadFixAddress(self
):
463 if self
._LoadFixAddress
== None:
464 if self
._Header
== None:
465 self
._GetHeaderInfo
()
467 if self
._LoadFixAddress
== None:
468 self
._LoadFixAddress
= self
._Macros
.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
, '0')
471 self
._LoadFixAddress
= int (self
._LoadFixAddress
, 0)
473 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self
._LoadFixAddress
))
476 # If command line defined, should override the value in DSC file.
478 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData
.gCommandLineDefines
.keys():
480 self
._LoadFixAddress
= int(GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
482 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (GlobalData
.gCommandLineDefines
['FIX_LOAD_TOP_MEMORY_ADDRESS']))
484 if self
._LoadFixAddress
< 0:
485 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self
._LoadFixAddress
))
486 if self
._LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
._LoadFixAddress
% 0x1000 != 0:
487 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self
._LoadFixAddress
))
489 return self
._LoadFixAddress
491 ## Retrieve RFCLanguage filter
492 def _GetRFCLanguages(self
):
493 if self
._RFCLanguages
== None:
494 if self
._Header
== None:
495 self
._GetHeaderInfo
()
496 if self
._RFCLanguages
== None:
497 self
._RFCLanguages
= []
498 return self
._RFCLanguages
500 ## Retrieve ISOLanguage filter
501 def _GetISOLanguages(self
):
502 if self
._ISOLanguages
== None:
503 if self
._Header
== None:
504 self
._GetHeaderInfo
()
505 if self
._ISOLanguages
== None:
506 self
._ISOLanguages
= []
507 return self
._ISOLanguages
508 ## Retrieve the GUID string for VPD tool
509 def _GetVpdToolGuid(self
):
510 if self
._VpdToolGuid
== None:
511 if self
._Header
== None:
512 self
._GetHeaderInfo
()
513 if self
._VpdToolGuid
== None:
514 self
._VpdToolGuid
= ''
515 return self
._VpdToolGuid
517 ## Retrieve [SkuIds] section information
518 def _GetSkuIds(self
):
519 if self
._SkuIds
== None:
520 self
._SkuIds
= sdict()
521 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
, self
._Arch
]
522 for Record
in RecordList
:
523 if Record
[0] in [None, '']:
524 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
525 File
=self
.MetaFile
, Line
=Record
[-1])
526 if Record
[1] in [None, '']:
527 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
528 File
=self
.MetaFile
, Line
=Record
[-1])
529 self
._SkuIds
[Record
[1]] = Record
[0]
530 if 'DEFAULT' not in self
._SkuIds
:
531 self
._SkuIds
['DEFAULT'] = '0'
532 if 'COMMON' not in self
._SkuIds
:
533 self
._SkuIds
['COMMON'] = '0'
536 ## Retrieve [Components] section information
537 def _GetModules(self
):
538 if self
._Modules
!= None:
541 self
._Modules
= sdict()
542 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
543 Macros
= self
._Macros
544 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
545 for Record
in RecordList
:
546 DuplicatedFile
= False
548 # process only records COMMON and self.Arch
549 SectionArch
= Record
[3].upper()
550 if SectionArch
!= 'COMMON':
551 if SectionArch
!= self
.Arch
:
554 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
558 # check the file validation
559 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
561 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
564 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
565 if self
._Arch
!= 'COMMON' and ModuleFile
in self
._Modules
:
566 DuplicatedFile
= True
568 Module
= ModuleBuildClassObject()
569 Module
.MetaFile
= ModuleFile
571 # get module private library instance
572 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
573 for Record
in RecordList
:
574 LibraryClass
= Record
[0]
575 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
578 # check the file validation
579 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
581 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
584 if LibraryClass
== '' or LibraryClass
== 'NULL':
585 self
._NullLibraryNumber
+= 1
586 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
587 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
588 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
589 if LibraryPath
not in self
.LibraryInstances
:
590 self
.LibraryInstances
.append(LibraryPath
)
592 # get module private PCD setting
593 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
594 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
595 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
596 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
in RecordList
:
597 TokenList
= GetSplitValueList(Setting
)
598 DefaultValue
= TokenList
[0]
599 if len(TokenList
) > 1:
600 MaxDatumSize
= TokenList
[1]
603 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
604 Pcd
= PcdClassObject(
616 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
618 # get module private build options
619 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
620 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
in RecordList
:
621 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
622 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
624 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
625 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
627 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, None, ModuleId
]
628 if DuplicatedFile
and not RecordList
:
629 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
631 if len(RecordList
) != 1:
632 EdkLogger
.error('build', OPTION_UNKNOWN
, 'Only FILE_GUID can be listed in <Defines> section.',
633 File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
634 ModuleFile
= ProcessDuplicatedInf(ModuleFile
, RecordList
[0][2], GlobalData
.gWorkspace
)
635 ModuleFile
.Arch
= self
._Arch
637 self
._Modules
[ModuleFile
] = Module
640 ## Retrieve all possible library instances used in this platform
641 def _GetLibraryInstances(self
):
642 if self
._LibraryInstances
== None:
643 self
._GetLibraryClasses
()
644 return self
._LibraryInstances
646 ## Retrieve [LibraryClasses] information
647 def _GetLibraryClasses(self
):
648 if self
._LibraryClasses
== None:
649 self
._LibraryInstances
= []
651 # tdict is a special dict kind of type, used for selecting correct
652 # library instance for given library class and module type
654 LibraryClassDict
= tdict(True, 3)
655 # track all library class names
656 LibraryClassSet
= set()
657 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, -1]
658 Macros
= self
._Macros
659 for Record
in RecordList
:
660 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, LineNo
= Record
661 if LibraryClass
== '' or LibraryClass
== 'NULL':
662 self
._NullLibraryNumber
+= 1
663 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
664 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
665 LibraryClassSet
.add(LibraryClass
)
666 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
667 # check the file validation
668 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
670 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
673 if ModuleType
!= 'COMMON' and ModuleType
not in SUP_MODULE_LIST
:
674 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
675 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
676 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
677 if LibraryInstance
not in self
._LibraryInstances
:
678 self
._LibraryInstances
.append(LibraryInstance
)
680 # resolve the specific library instance for each class and each module type
681 self
._LibraryClasses
= tdict(True)
682 for LibraryClass
in LibraryClassSet
:
683 # try all possible module types
684 for ModuleType
in SUP_MODULE_LIST
:
685 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
686 if LibraryInstance
== None:
688 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
690 # for Edk style library instances, which are listed in different section
691 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
692 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
693 for Record
in RecordList
:
694 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
696 # check the file validation
697 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
699 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
701 if File
not in self
._LibraryInstances
:
702 self
._LibraryInstances
.append(File
)
704 # we need the module name as the library class name, so we have
705 # to parse it here. (self._Bdb[] will trigger a file parse if it
706 # hasn't been parsed)
708 Library
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
709 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
710 return self
._LibraryClasses
712 def _ValidatePcd(self
, PcdCName
, TokenSpaceGuid
, Setting
, PcdType
, LineNo
):
713 if self
._DecPcds
== None:
714 self
._DecPcds
= GetDeclaredPcd(self
, self
._Bdb
, self
._Arch
, self
._Target
, self
._Toolchain
)
716 if GlobalData
.gFdfParser
:
717 FdfInfList
= GlobalData
.gFdfParser
.Profile
.InfList
720 for Inf
in FdfInfList
:
721 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
722 if ModuleFile
in self
._Modules
:
724 ModuleData
= self
._Bdb
[ModuleFile
, self
._Arch
, self
._Target
, self
._Toolchain
]
725 PkgSet
.update(ModuleData
.Packages
)
729 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
730 self
._DecPcds
.update(DecPcds
)
732 if (PcdCName
, TokenSpaceGuid
) not in self
._DecPcds
:
733 EdkLogger
.error('build', PARSER_ERROR
,
734 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid
, PcdCName
, self
._Arch
),
735 File
=self
.MetaFile
, Line
=LineNo
)
736 ValueList
, IsValid
, Index
= AnalyzeDscPcd(Setting
, PcdType
, self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
)
737 if not IsValid
and PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
738 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
.MetaFile
, Line
=LineNo
,
739 ExtraData
="%s.%s|%s" % (TokenSpaceGuid
, PcdCName
, Setting
))
740 if ValueList
[Index
] and PcdType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
742 ValueList
[Index
] = ValueExpression(ValueList
[Index
], GlobalData
.gPlatformPcds
)(True)
743 except WrnExpression
, Value
:
744 ValueList
[Index
] = Value
.result
745 except EvaluationException
, Excpt
:
746 if hasattr(Excpt
, 'Pcd'):
747 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
748 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
749 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
750 " of the DSC file" % Excpt
.Pcd
,
751 File
=self
.MetaFile
, Line
=LineNo
)
753 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
754 File
=self
.MetaFile
, Line
=LineNo
)
756 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
757 File
=self
.MetaFile
, Line
=LineNo
)
758 if ValueList
[Index
] == 'True':
759 ValueList
[Index
] = '1'
760 elif ValueList
[Index
] == 'False':
761 ValueList
[Index
] = '0'
763 Valid
, ErrStr
= CheckPcdDatum(self
._DecPcds
[PcdCName
, TokenSpaceGuid
].DatumType
, ValueList
[Index
])
765 EdkLogger
.error('build', FORMAT_INVALID
, ErrStr
, File
=self
.MetaFile
, Line
=LineNo
,
766 ExtraData
="%s.%s" % (TokenSpaceGuid
, PcdCName
))
769 ## Retrieve all PCD settings in platform
771 if self
._Pcds
== None:
773 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
774 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
775 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
776 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
777 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
778 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
779 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
780 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
781 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
784 ## Retrieve [BuildOptions]
785 def _GetBuildOptions(self
):
786 if self
._BuildOptions
== None:
787 self
._BuildOptions
= sdict()
789 # Retrieve build option for EDKII and EDK style module
791 for CodeBase
in (EDKII_NAME
, EDK_NAME
):
792 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, CodeBase
]
793 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
in RecordList
:
794 CurKey
= (ToolChainFamily
, ToolChain
, CodeBase
)
796 # Only flags can be appended
798 if CurKey
not in self
._BuildOptions
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
799 self
._BuildOptions
[CurKey
] = Option
801 self
._BuildOptions
[CurKey
] += ' ' + Option
802 return self
._BuildOptions
804 def GetBuildOptionsByModuleType(self
, Edk
, ModuleType
):
805 if self
._ModuleTypeOptions
== None:
806 self
._ModuleTypeOptions
= sdict()
807 if (Edk
, ModuleType
) not in self
._ModuleTypeOptions
:
809 self
._ModuleTypeOptions
[Edk
, ModuleType
] = options
810 DriverType
= '%s.%s' % (Edk
, ModuleType
)
811 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, DriverType
]
812 for ToolChainFamily
, ToolChain
, Option
, Arch
, Type
, Dummy3
, Dummy4
in RecordList
:
813 if Type
== DriverType
:
814 Key
= (ToolChainFamily
, ToolChain
, Edk
)
815 if Key
not in options
or not ToolChain
.endswith('_FLAGS') or Option
.startswith('='):
816 options
[Key
] = Option
818 options
[Key
] += ' ' + Option
819 return self
._ModuleTypeOptions
[Edk
, ModuleType
]
821 ## Retrieve non-dynamic PCD settings
823 # @param Type PCD type
825 # @retval a dict object contains settings of given PCD type
827 def _GetPcd(self
, Type
):
830 # tdict is a special dict kind of type, used for selecting correct
831 # PCD settings for certain ARCH
834 SkuObj
= SkuClass(self
.SkuIdentifier
,self
.SkuIds
)
836 PcdDict
= tdict(True, 3)
838 # Find out all possible PCD candidates for self._Arch
839 RecordList
= self
._RawData
[Type
, self
._Arch
]
840 PcdValueDict
= sdict()
841 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
in RecordList
:
842 if SkuName
in (SkuObj
.SystemSkuId
,'DEFAULT','COMMON'):
843 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
,Dummy4
))
844 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
,SkuName
] = Setting
846 #handle pcd value override
847 for PcdCName
, TokenSpaceGuid
, SkuName
,Dummy4
in PcdSet
:
848 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
,SkuName
]
851 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
852 if (PcdCName
, TokenSpaceGuid
) in PcdValueDict
:
853 PcdValueDict
[PcdCName
, TokenSpaceGuid
][SkuName
] = (PcdValue
,DatumType
,MaxDatumSize
)
855 PcdValueDict
[PcdCName
, TokenSpaceGuid
] = {SkuName
:(PcdValue
,DatumType
,MaxDatumSize
)}
857 PcdsKeys
= PcdValueDict
.keys()
858 for PcdCName
,TokenSpaceGuid
in PcdsKeys
:
860 PcdSetting
= PcdValueDict
[PcdCName
, TokenSpaceGuid
]
864 if 'COMMON' in PcdSetting
:
865 PcdValue
,DatumType
,MaxDatumSize
= PcdSetting
['COMMON']
866 if 'DEFAULT' in PcdSetting
:
867 PcdValue
,DatumType
,MaxDatumSize
= PcdSetting
['DEFAULT']
868 if SkuObj
.SystemSkuId
in PcdSetting
:
869 PcdValue
,DatumType
,MaxDatumSize
= PcdSetting
[SkuObj
.SystemSkuId
]
871 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
874 self
._PCD
_TYPE
_STRING
_[Type
],
885 ## Retrieve dynamic PCD settings
887 # @param Type PCD type
889 # @retval a dict object contains settings of given PCD type
891 def _GetDynamicPcd(self
, Type
):
893 SkuObj
= SkuClass(self
.SkuIdentifier
,self
.SkuIds
)
897 # tdict is a special dict kind of type, used for selecting correct
898 # PCD settings for certain ARCH and SKU
900 PcdDict
= tdict(True, 4)
902 # Find out all possible PCD candidates for self._Arch
903 RecordList
= self
._RawData
[Type
, self
._Arch
]
904 AvailableSkuIdSet
= SkuObj
.AvailableSkuIdSet
.copy()
906 AvailableSkuIdSet
.update({'DEFAULT':0,'COMMON':0})
907 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
in RecordList
:
908 if SkuName
not in AvailableSkuIdSet
:
911 PcdList
.append((PcdCName
, TokenSpaceGuid
, SkuName
,Dummy4
))
912 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
913 # Remove redundant PCD candidates, per the ARCH and SKU
914 for PcdCName
, TokenSpaceGuid
, SkuName
, Dummy4
in PcdList
:
916 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
920 PcdValue
, DatumType
, MaxDatumSize
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
921 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
], '', '', '', '', '', PcdValue
)
922 if (PcdCName
,TokenSpaceGuid
) in Pcds
.keys():
923 pcdObject
= Pcds
[PcdCName
,TokenSpaceGuid
]
924 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
925 if MaxDatumSize
.strip():
926 CurrentMaxSize
= int(MaxDatumSize
.strip(),0)
929 if pcdObject
.MaxDatumSize
:
930 PcdMaxSize
= int(pcdObject
.MaxDatumSize
,0)
933 if CurrentMaxSize
> PcdMaxSize
:
934 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
936 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
939 self
._PCD
_TYPE
_STRING
_[Type
],
949 for pcd
in Pcds
.values():
950 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
,pcd
.TokenSpaceGuidCName
]
951 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
952 valuefromDec
= pcdDecObject
.DefaultValue
953 SkuInfo
= SkuInfoClass('DEFAULT', '0', '', '', '', '', '', valuefromDec
)
954 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
955 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
956 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
957 del(pcd
.SkuInfoList
['COMMON'])
958 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
959 del(pcd
.SkuInfoList
['COMMON'])
960 if SkuObj
.SkuUsageType
== SkuObj
.SINGLE
:
961 if 'DEFAULT' in pcd
.SkuInfoList
.keys() and SkuObj
.SystemSkuId
not in pcd
.SkuInfoList
.keys():
962 pcd
.SkuInfoList
[SkuObj
.SystemSkuId
] = pcd
.SkuInfoList
['DEFAULT']
963 del(pcd
.SkuInfoList
['DEFAULT'])
967 def CompareVarAttr(self
, Attr1
, Attr2
):
968 if not Attr1
or not Attr2
: # for empty string
970 Attr1s
= [attr
.strip() for attr
in Attr1
.split(",")]
971 Attr1Set
= set(Attr1s
)
972 Attr2s
= [attr
.strip() for attr
in Attr2
.split(",")]
973 Attr2Set
= set(Attr2s
)
974 if Attr2Set
== Attr1Set
:
978 ## Retrieve dynamic HII PCD settings
980 # @param Type PCD type
982 # @retval a dict object contains settings of given PCD type
984 def _GetDynamicHiiPcd(self
, Type
):
986 SkuObj
= SkuClass(self
.SkuIdentifier
,self
.SkuIds
)
991 # tdict is a special dict kind of type, used for selecting correct
992 # PCD settings for certain ARCH and SKU
994 PcdDict
= tdict(True, 4)
996 RecordList
= self
._RawData
[Type
, self
._Arch
]
997 # Find out all possible PCD candidates for self._Arch
998 AvailableSkuIdSet
= SkuObj
.AvailableSkuIdSet
.copy()
1000 AvailableSkuIdSet
.update({'DEFAULT':0,'COMMON':0})
1001 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
in RecordList
:
1002 if SkuName
not in AvailableSkuIdSet
:
1004 PcdSet
.add((PcdCName
, TokenSpaceGuid
, SkuName
,Dummy4
))
1005 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
1006 # Remove redundant PCD candidates, per the ARCH and SKU
1007 for PcdCName
, TokenSpaceGuid
,SkuName
, Dummy4
in PcdSet
:
1009 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
1012 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VarAttribute
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1014 rt
, Msg
= VariableAttributes
.ValidateVarAttributes(VarAttribute
)
1016 EdkLogger
.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR
, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid
, PcdCName
)), Msg
),
1017 ExtraData
= "[%s]" % VarAttribute
)
1019 FormatCorrect
= True
1020 if VariableOffset
.isdigit():
1021 if int(VariableOffset
,10) > 0xFFFF:
1023 elif re
.match(r
'[\t\s]*0[xX][a-fA-F0-9]+$',VariableOffset
):
1024 if int(VariableOffset
,16) > 0xFFFF:
1026 # For Offset written in "A.B"
1027 elif VariableOffset
.find('.') > -1:
1028 VariableOffsetList
= VariableOffset
.split(".")
1029 if not (len(VariableOffsetList
) == 2
1030 and IsValidWord(VariableOffsetList
[0])
1031 and IsValidWord(VariableOffsetList
[1])):
1032 FormatCorrect
= False
1034 FormatCorrect
= False
1035 if not FormatCorrect
:
1036 EdkLogger
.error('Build', FORMAT_INVALID
, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid
,PcdCName
)))
1039 EdkLogger
.error('Build', OPTION_VALUE_INVALID
, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid
,PcdCName
)))
1040 if (VariableName
, VariableGuid
) not in VariableAttrs
:
1041 VariableAttrs
[(VariableName
, VariableGuid
)] = VarAttribute
1043 if not self
.CompareVarAttr(VariableAttrs
[(VariableName
, VariableGuid
)], VarAttribute
):
1044 EdkLogger
.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR
, "The variable %s.%s for DynamicHii PCDs has conflicting attributes [%s] and [%s] " % (VariableGuid
, VariableName
, VarAttribute
, VariableAttrs
[(VariableName
, VariableGuid
)]))
1046 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
, VariableAttribute
= VarAttribute
)
1047 pcdDecObject
= self
._DecPcds
[PcdCName
, TokenSpaceGuid
]
1048 if (PcdCName
,TokenSpaceGuid
) in Pcds
.keys():
1049 pcdObject
= Pcds
[PcdCName
,TokenSpaceGuid
]
1050 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
1052 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1055 self
._PCD
_TYPE
_STRING
_[Type
],
1060 {SkuName
: SkuInfo
},
1063 pcdDecObject
.validateranges
,
1064 pcdDecObject
.validlists
,
1065 pcdDecObject
.expressions
1069 for pcd
in Pcds
.values():
1070 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
1071 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
,pcd
.TokenSpaceGuidCName
]
1072 # Only fix the value while no value provided in DSC file.
1073 for sku
in pcd
.SkuInfoList
.values():
1074 if (sku
.HiiDefaultValue
== "" or sku
.HiiDefaultValue
==None):
1075 sku
.HiiDefaultValue
= pcdDecObject
.DefaultValue
1076 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
1077 valuefromDec
= pcdDecObject
.DefaultValue
1078 SkuInfo
= SkuInfoClass('DEFAULT', '0', SkuInfoObj
.VariableName
, SkuInfoObj
.VariableGuid
, SkuInfoObj
.VariableOffset
, valuefromDec
)
1079 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
1080 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
1081 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
1082 del(pcd
.SkuInfoList
['COMMON'])
1083 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
1084 del(pcd
.SkuInfoList
['COMMON'])
1086 if SkuObj
.SkuUsageType
== SkuObj
.SINGLE
:
1087 if 'DEFAULT' in pcd
.SkuInfoList
.keys() and SkuObj
.SystemSkuId
not in pcd
.SkuInfoList
.keys():
1088 pcd
.SkuInfoList
[SkuObj
.SystemSkuId
] = pcd
.SkuInfoList
['DEFAULT']
1089 del(pcd
.SkuInfoList
['DEFAULT'])
1092 if pcd
.MaxDatumSize
.strip():
1093 MaxSize
= int(pcd
.MaxDatumSize
,0)
1096 if pcdDecObject
.DatumType
== 'VOID*':
1097 for (skuname
,skuobj
) in pcd
.SkuInfoList
.items():
1099 if skuobj
.HiiDefaultValue
.startswith("L"):
1100 datalen
= (len(skuobj
.HiiDefaultValue
)- 3 + 1) * 2
1101 elif skuobj
.HiiDefaultValue
.startswith("{"):
1102 datalen
= len(skuobj
.HiiDefaultValue
.split(","))
1104 datalen
= len(skuobj
.HiiDefaultValue
) -2 + 1
1107 pcd
.MaxDatumSize
= str(MaxSize
)
1110 ## Retrieve dynamic VPD PCD settings
1112 # @param Type PCD type
1114 # @retval a dict object contains settings of given PCD type
1116 def _GetDynamicVpdPcd(self
, Type
):
1118 SkuObj
= SkuClass(self
.SkuIdentifier
,self
.SkuIds
)
1122 # tdict is a special dict kind of type, used for selecting correct
1123 # PCD settings for certain ARCH and SKU
1125 PcdDict
= tdict(True, 4)
1127 # Find out all possible PCD candidates for self._Arch
1128 RecordList
= self
._RawData
[Type
, self
._Arch
]
1129 AvailableSkuIdSet
= SkuObj
.AvailableSkuIdSet
.copy()
1131 AvailableSkuIdSet
.update({'DEFAULT':0,'COMMON':0})
1132 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
in RecordList
:
1133 if SkuName
not in AvailableSkuIdSet
:
1136 PcdList
.append((PcdCName
, TokenSpaceGuid
,SkuName
, Dummy4
))
1137 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
1138 # Remove redundant PCD candidates, per the ARCH and SKU
1139 for PcdCName
, TokenSpaceGuid
, SkuName
,Dummy4
in PcdList
:
1140 Setting
= PcdDict
[self
._Arch
, SkuName
, PcdCName
, TokenSpaceGuid
]
1144 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
1145 # For the Integer & Boolean type, the optional data can only be InitialValue.
1146 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
1147 # until the DEC parser has been called.
1149 VpdOffset
, MaxDatumSize
, InitialValue
= self
._ValidatePcd
(PcdCName
, TokenSpaceGuid
, Setting
, Type
, Dummy4
)
1150 SkuInfo
= SkuInfoClass(SkuName
, self
.SkuIds
[SkuName
], '', '', '', '', VpdOffset
, InitialValue
)
1151 if (PcdCName
,TokenSpaceGuid
) in Pcds
.keys():
1152 pcdObject
= Pcds
[PcdCName
,TokenSpaceGuid
]
1153 pcdObject
.SkuInfoList
[SkuName
] = SkuInfo
1154 if MaxDatumSize
.strip():
1155 CurrentMaxSize
= int(MaxDatumSize
.strip(),0)
1158 if pcdObject
.MaxDatumSize
:
1159 PcdMaxSize
= int(pcdObject
.MaxDatumSize
,0)
1162 if CurrentMaxSize
> PcdMaxSize
:
1163 pcdObject
.MaxDatumSize
= str(CurrentMaxSize
)
1165 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
1168 self
._PCD
_TYPE
_STRING
_[Type
],
1173 {SkuName
: SkuInfo
},
1177 for pcd
in Pcds
.values():
1178 SkuInfoObj
= pcd
.SkuInfoList
.values()[0]
1179 pcdDecObject
= self
._DecPcds
[pcd
.TokenCName
,pcd
.TokenSpaceGuidCName
]
1180 if 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' not in pcd
.SkuInfoList
.keys():
1181 valuefromDec
= pcdDecObject
.DefaultValue
1182 SkuInfo
= SkuInfoClass('DEFAULT', '0', '', '', '','',SkuInfoObj
.VpdOffset
, valuefromDec
)
1183 pcd
.SkuInfoList
['DEFAULT'] = SkuInfo
1184 elif 'DEFAULT' not in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
1185 pcd
.SkuInfoList
['DEFAULT'] = pcd
.SkuInfoList
['COMMON']
1186 del(pcd
.SkuInfoList
['COMMON'])
1187 elif 'DEFAULT' in pcd
.SkuInfoList
.keys() and 'COMMON' in pcd
.SkuInfoList
.keys():
1188 del(pcd
.SkuInfoList
['COMMON'])
1189 if SkuObj
.SkuUsageType
== SkuObj
.SINGLE
:
1190 if 'DEFAULT' in pcd
.SkuInfoList
.keys() and SkuObj
.SystemSkuId
not in pcd
.SkuInfoList
.keys():
1191 pcd
.SkuInfoList
[SkuObj
.SystemSkuId
] = pcd
.SkuInfoList
['DEFAULT']
1192 del(pcd
.SkuInfoList
['DEFAULT'])
1196 ## Add external modules
1198 # The external modules are mostly those listed in FDF file, which don't
1201 # @param FilePath The path of module description file
1203 def AddModule(self
, FilePath
):
1204 FilePath
= NormPath(FilePath
)
1205 if FilePath
not in self
.Modules
:
1206 Module
= ModuleBuildClassObject()
1207 Module
.MetaFile
= FilePath
1208 self
.Modules
.append(Module
)
1210 ## Add external PCDs
1212 # The external PCDs are mostly those listed in FDF file to specify address
1213 # or offset information.
1215 # @param Name Name of the PCD
1216 # @param Guid Token space guid of the PCD
1217 # @param Value Value of the PCD
1219 def AddPcd(self
, Name
, Guid
, Value
):
1220 if (Name
, Guid
) not in self
.Pcds
:
1221 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
1222 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
1224 _Macros
= property(_GetMacros
)
1225 Arch
= property(_GetArch
, _SetArch
)
1226 Platform
= property(_GetPlatformName
)
1227 PlatformName
= property(_GetPlatformName
)
1228 Guid
= property(_GetFileGuid
)
1229 Version
= property(_GetVersion
)
1230 DscSpecification
= property(_GetDscSpec
)
1231 OutputDirectory
= property(_GetOutpuDir
)
1232 SupArchList
= property(_GetSupArch
)
1233 BuildTargets
= property(_GetBuildTarget
)
1234 SkuName
= property(_GetSkuName
, _SetSkuName
)
1235 SkuIdentifier
= property(_GetSkuIdentifier
)
1236 AvilableSkuIds
= property(_GetAviableSkuIds
)
1237 PcdInfoFlag
= property(_GetPcdInfoFlag
)
1238 VarCheckFlag
= property(_GetVarCheckFlag
)
1239 FlashDefinition
= property(_GetFdfFile
)
1240 Prebuild
= property(_GetPrebuild
)
1241 Postbuild
= property(_GetPostbuild
)
1242 BuildNumber
= property(_GetBuildNumber
)
1243 MakefileName
= property(_GetMakefileName
)
1244 BsBaseAddress
= property(_GetBsBaseAddress
)
1245 RtBaseAddress
= property(_GetRtBaseAddress
)
1246 LoadFixAddress
= property(_GetLoadFixAddress
)
1247 RFCLanguages
= property(_GetRFCLanguages
)
1248 ISOLanguages
= property(_GetISOLanguages
)
1249 VpdToolGuid
= property(_GetVpdToolGuid
)
1250 SkuIds
= property(_GetSkuIds
)
1251 Modules
= property(_GetModules
)
1252 LibraryInstances
= property(_GetLibraryInstances
)
1253 LibraryClasses
= property(_GetLibraryClasses
)
1254 Pcds
= property(_GetPcds
)
1255 BuildOptions
= property(_GetBuildOptions
)
1257 ## Platform build information from DEC file
1259 # This class is used to retrieve information stored in database and convert them
1260 # into PackageBuildClassObject form for easier use for AutoGen.
1262 class DecBuildData(PackageBuildClassObject
):
1263 # dict used to convert PCD type in database to string used by build tool
1264 _PCD_TYPE_STRING_
= {
1265 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
1266 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
1267 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
1268 MODEL_PCD_DYNAMIC
: "Dynamic",
1269 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
1270 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
1271 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
1272 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
1273 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
1274 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
1275 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
1278 # dict used to convert part of [Defines] to members of DecBuildData directly
1283 TAB_DEC_DEFINES_PACKAGE_NAME
: "_PackageName",
1284 TAB_DEC_DEFINES_PACKAGE_GUID
: "_Guid",
1285 TAB_DEC_DEFINES_PACKAGE_VERSION
: "_Version",
1286 TAB_DEC_DEFINES_PKG_UNI_FILE
: "_PkgUniFile",
1290 ## Constructor of DecBuildData
1292 # Initialize object of DecBuildData
1294 # @param FilePath The path of package description file
1295 # @param RawData The raw data of DEC file
1296 # @param BuildDataBase Database used to retrieve module information
1297 # @param Arch The target architecture
1298 # @param Platform (not used for DecBuildData)
1299 # @param Macros Macros used for replacement in DSC file
1301 def __init__(self
, File
, RawData
, BuildDataBase
, Arch
='COMMON', Target
=None, Toolchain
=None):
1302 self
.MetaFile
= File
1303 self
._PackageDir
= File
.Dir
1304 self
._RawData
= RawData
1305 self
._Bdb
= BuildDataBase
1307 self
._Target
= Target
1308 self
._Toolchain
= Toolchain
1312 def __setitem__(self
, key
, value
):
1313 self
.__dict
__[self
._PROPERTY
_[key
]] = value
1316 def __getitem__(self
, key
):
1317 return self
.__dict
__[self
._PROPERTY
_[key
]]
1319 ## "in" test support
1320 def __contains__(self
, key
):
1321 return key
in self
._PROPERTY
_
1323 ## Set all internal used members of DecBuildData to None
1326 self
._PackageName
= None
1328 self
._Version
= None
1329 self
._PkgUniFile
= None
1330 self
._Protocols
= None
1333 self
._Includes
= None
1334 self
._LibraryClasses
= None
1336 self
.__Macros
= None
1338 ## Get current effective macros
1339 def _GetMacros(self
):
1340 if self
.__Macros
== None:
1342 self
.__Macros
.update(GlobalData
.gGlobalDefines
)
1343 return self
.__Macros
1351 # Changing the default ARCH to another may affect all other information
1352 # because all information in a platform may be ARCH-related. That's
1353 # why we need to clear all internal used members, in order to cause all
1354 # information to be re-retrieved.
1356 # @param Value The value of ARCH
1358 def _SetArch(self
, Value
):
1359 if self
._Arch
== Value
:
1364 ## Retrieve all information in [Defines] section
1366 # (Retriving all [Defines] information in one-shot is just to save time.)
1368 def _GetHeaderInfo(self
):
1369 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
1370 for Record
in RecordList
:
1373 self
[Name
] = Record
[2]
1374 self
._Header
= 'DUMMY'
1376 ## Retrieve package name
1377 def _GetPackageName(self
):
1378 if self
._PackageName
== None:
1379 if self
._Header
== None:
1380 self
._GetHeaderInfo
()
1381 if self
._PackageName
== None:
1382 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "No PACKAGE_NAME", File
=self
.MetaFile
)
1383 return self
._PackageName
1385 ## Retrieve file guid
1386 def _GetFileGuid(self
):
1387 if self
._Guid
== None:
1388 if self
._Header
== None:
1389 self
._GetHeaderInfo
()
1390 if self
._Guid
== None:
1391 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "No PACKAGE_GUID", File
=self
.MetaFile
)
1394 ## Retrieve package version
1395 def _GetVersion(self
):
1396 if self
._Version
== None:
1397 if self
._Header
== None:
1398 self
._GetHeaderInfo
()
1399 if self
._Version
== None:
1401 return self
._Version
1403 ## Retrieve protocol definitions (name/value pairs)
1404 def _GetProtocol(self
):
1405 if self
._Protocols
== None:
1407 # tdict is a special kind of dict, used for selecting correct
1408 # protocol defition for given ARCH
1410 ProtocolDict
= tdict(True)
1412 # find out all protocol definitions for specific and 'common' arch
1413 RecordList
= self
._RawData
[MODEL_EFI_PROTOCOL
, self
._Arch
]
1414 for Name
, Guid
, Dummy
, Arch
, ID
, LineNo
in RecordList
:
1415 if Name
not in NameList
:
1416 NameList
.append(Name
)
1417 ProtocolDict
[Arch
, Name
] = Guid
1418 # use sdict to keep the order
1419 self
._Protocols
= sdict()
1420 for Name
in NameList
:
1422 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1423 # will automatically turn to 'common' ARCH for trying
1425 self
._Protocols
[Name
] = ProtocolDict
[self
._Arch
, Name
]
1426 return self
._Protocols
1428 ## Retrieve PPI definitions (name/value pairs)
1430 if self
._Ppis
== None:
1432 # tdict is a special kind of dict, used for selecting correct
1433 # PPI defition for given ARCH
1435 PpiDict
= tdict(True)
1437 # find out all PPI definitions for specific arch and 'common' arch
1438 RecordList
= self
._RawData
[MODEL_EFI_PPI
, self
._Arch
]
1439 for Name
, Guid
, Dummy
, Arch
, ID
, LineNo
in RecordList
:
1440 if Name
not in NameList
:
1441 NameList
.append(Name
)
1442 PpiDict
[Arch
, Name
] = Guid
1443 # use sdict to keep the order
1444 self
._Ppis
= sdict()
1445 for Name
in NameList
:
1447 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1448 # will automatically turn to 'common' ARCH for trying
1450 self
._Ppis
[Name
] = PpiDict
[self
._Arch
, Name
]
1453 ## Retrieve GUID definitions (name/value pairs)
1455 if self
._Guids
== None:
1457 # tdict is a special kind of dict, used for selecting correct
1458 # GUID defition for given ARCH
1460 GuidDict
= tdict(True)
1462 # find out all protocol definitions for specific and 'common' arch
1463 RecordList
= self
._RawData
[MODEL_EFI_GUID
, self
._Arch
]
1464 for Name
, Guid
, Dummy
, Arch
, ID
, LineNo
in RecordList
:
1465 if Name
not in NameList
:
1466 NameList
.append(Name
)
1467 GuidDict
[Arch
, Name
] = Guid
1468 # use sdict to keep the order
1469 self
._Guids
= sdict()
1470 for Name
in NameList
:
1472 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1473 # will automatically turn to 'common' ARCH for trying
1475 self
._Guids
[Name
] = GuidDict
[self
._Arch
, Name
]
1478 ## Retrieve public include paths declared in this package
1479 def _GetInclude(self
):
1480 if self
._Includes
== None:
1482 RecordList
= self
._RawData
[MODEL_EFI_INCLUDE
, self
._Arch
]
1483 Macros
= self
._Macros
1484 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
1485 for Record
in RecordList
:
1486 File
= PathClass(NormPath(Record
[0], Macros
), self
._PackageDir
, Arch
=self
._Arch
)
1489 ErrorCode
, ErrorInfo
= File
.Validate()
1491 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
1493 # avoid duplicate include path
1494 if File
not in self
._Includes
:
1495 self
._Includes
.append(File
)
1496 return self
._Includes
1498 ## Retrieve library class declarations (not used in build at present)
1499 def _GetLibraryClass(self
):
1500 if self
._LibraryClasses
== None:
1502 # tdict is a special kind of dict, used for selecting correct
1503 # library class declaration for given ARCH
1505 LibraryClassDict
= tdict(True)
1506 LibraryClassSet
= set()
1507 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
]
1508 Macros
= self
._Macros
1509 for LibraryClass
, File
, Dummy
, Arch
, ID
, LineNo
in RecordList
:
1510 File
= PathClass(NormPath(File
, Macros
), self
._PackageDir
, Arch
=self
._Arch
)
1511 # check the file validation
1512 ErrorCode
, ErrorInfo
= File
.Validate()
1514 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
1515 LibraryClassSet
.add(LibraryClass
)
1516 LibraryClassDict
[Arch
, LibraryClass
] = File
1517 self
._LibraryClasses
= sdict()
1518 for LibraryClass
in LibraryClassSet
:
1519 self
._LibraryClasses
[LibraryClass
] = LibraryClassDict
[self
._Arch
, LibraryClass
]
1520 return self
._LibraryClasses
1522 ## Retrieve PCD declarations
1524 if self
._Pcds
== None:
1525 self
._Pcds
= sdict()
1526 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1527 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1528 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1529 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC
))
1530 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC_EX
))
1533 ## Retrieve PCD declarations for given type
1534 def _GetPcd(self
, Type
):
1537 # tdict is a special kind of dict, used for selecting correct
1538 # PCD declaration for given ARCH
1540 PcdDict
= tdict(True, 3)
1541 # for summarizing PCD
1543 # find out all PCDs of the 'type'
1544 RecordList
= self
._RawData
[Type
, self
._Arch
]
1545 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, Dummy1
, Dummy2
in RecordList
:
1546 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
] = Setting
1547 PcdSet
.add((PcdCName
, TokenSpaceGuid
))
1549 for PcdCName
, TokenSpaceGuid
in PcdSet
:
1551 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1552 # will automatically turn to 'common' ARCH and try again
1554 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
]
1558 DefaultValue
, DatumType
, TokenNumber
= AnalyzePcdData(Setting
)
1560 validateranges
, validlists
, expressions
= self
._RawData
.GetValidExpression(TokenSpaceGuid
, PcdCName
)
1561 Pcds
[PcdCName
, TokenSpaceGuid
, self
._PCD
_TYPE
_STRING
_[Type
]] = PcdClassObject(
1564 self
._PCD
_TYPE
_STRING
_[Type
],
1572 list(validateranges
),
1579 _Macros
= property(_GetMacros
)
1580 Arch
= property(_GetArch
, _SetArch
)
1581 PackageName
= property(_GetPackageName
)
1582 Guid
= property(_GetFileGuid
)
1583 Version
= property(_GetVersion
)
1585 Protocols
= property(_GetProtocol
)
1586 Ppis
= property(_GetPpi
)
1587 Guids
= property(_GetGuid
)
1588 Includes
= property(_GetInclude
)
1589 LibraryClasses
= property(_GetLibraryClass
)
1590 Pcds
= property(_GetPcds
)
1592 ## Module build information from INF file
1594 # This class is used to retrieve information stored in database and convert them
1595 # into ModuleBuildClassObject form for easier use for AutoGen.
1597 class InfBuildData(ModuleBuildClassObject
):
1598 # dict used to convert PCD type in database to string used by build tool
1599 _PCD_TYPE_STRING_
= {
1600 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
1601 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
1602 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
1603 MODEL_PCD_DYNAMIC
: "Dynamic",
1604 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
1605 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
1606 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
1607 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
1608 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
1609 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
1610 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
1613 # dict used to convert part of [Defines] to members of InfBuildData directly
1618 TAB_INF_DEFINES_BASE_NAME
: "_BaseName",
1619 TAB_INF_DEFINES_FILE_GUID
: "_Guid",
1620 TAB_INF_DEFINES_MODULE_TYPE
: "_ModuleType",
1624 #TAB_INF_DEFINES_INF_VERSION : "_AutoGenVersion",
1625 TAB_INF_DEFINES_COMPONENT_TYPE
: "_ComponentType",
1626 TAB_INF_DEFINES_MAKEFILE_NAME
: "_MakefileName",
1627 #TAB_INF_DEFINES_CUSTOM_MAKEFILE : "_CustomMakefile",
1628 TAB_INF_DEFINES_DPX_SOURCE
:"_DxsFile",
1629 TAB_INF_DEFINES_VERSION_NUMBER
: "_Version",
1630 TAB_INF_DEFINES_VERSION_STRING
: "_Version",
1631 TAB_INF_DEFINES_VERSION
: "_Version",
1632 TAB_INF_DEFINES_PCD_IS_DRIVER
: "_PcdIsDriver",
1633 TAB_INF_DEFINES_SHADOW
: "_Shadow",
1635 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH
: "_SourceOverridePath",
1638 # dict used to convert Component type to Module type
1641 "SECURITY_CORE" : "SEC",
1642 "PEI_CORE" : "PEI_CORE",
1643 "COMBINED_PEIM_DRIVER" : "PEIM",
1644 "PIC_PEIM" : "PEIM",
1645 "RELOCATABLE_PEIM" : "PEIM",
1646 "PE32_PEIM" : "PEIM",
1647 "BS_DRIVER" : "DXE_DRIVER",
1648 "RT_DRIVER" : "DXE_RUNTIME_DRIVER",
1649 "SAL_RT_DRIVER" : "DXE_SAL_DRIVER",
1650 "DXE_SMM_DRIVER" : "DXE_SMM_DRIVER",
1651 # "SMM_DRIVER" : "DXE_SMM_DRIVER",
1652 # "BS_DRIVER" : "DXE_SMM_DRIVER",
1653 # "BS_DRIVER" : "UEFI_DRIVER",
1654 "APPLICATION" : "UEFI_APPLICATION",
1658 # regular expression for converting XXX_FLAGS in [nmake] section to new type
1659 _NMAKE_FLAG_PATTERN_
= re
.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re
.UNICODE
)
1660 # dict used to convert old tool name used in [nmake] section to new ones
1668 ## Constructor of DscBuildData
1670 # Initialize object of DscBuildData
1672 # @param FilePath The path of platform description file
1673 # @param RawData The raw data of DSC file
1674 # @param BuildDataBase Database used to retrieve module/package information
1675 # @param Arch The target architecture
1676 # @param Platform The name of platform employing this module
1677 # @param Macros Macros used for replacement in DSC file
1679 def __init__(self
, FilePath
, RawData
, BuildDatabase
, Arch
='COMMON', Target
=None, Toolchain
=None):
1680 self
.MetaFile
= FilePath
1681 self
._ModuleDir
= FilePath
.Dir
1682 self
._RawData
= RawData
1683 self
._Bdb
= BuildDatabase
1685 self
._Target
= Target
1686 self
._Toolchain
= Toolchain
1687 self
._Platform
= 'COMMON'
1688 self
._SourceOverridePath
= None
1689 if FilePath
.Key
in GlobalData
.gOverrideDir
:
1690 self
._SourceOverridePath
= GlobalData
.gOverrideDir
[FilePath
.Key
]
1694 def __setitem__(self
, key
, value
):
1695 self
.__dict
__[self
._PROPERTY
_[key
]] = value
1698 def __getitem__(self
, key
):
1699 return self
.__dict
__[self
._PROPERTY
_[key
]]
1701 ## "in" test support
1702 def __contains__(self
, key
):
1703 return key
in self
._PROPERTY
_
1705 ## Set all internal used members of InfBuildData to None
1707 self
._HeaderComments
= None
1708 self
._TailComments
= None
1709 self
._Header
_ = None
1710 self
._AutoGenVersion
= None
1711 self
._BaseName
= None
1712 self
._DxsFile
= None
1713 self
._ModuleType
= None
1714 self
._ComponentType
= None
1715 self
._BuildType
= None
1717 self
._Version
= None
1718 self
._PcdIsDriver
= None
1719 self
._BinaryModule
= None
1721 self
._MakefileName
= None
1722 self
._CustomMakefile
= None
1723 self
._Specification
= None
1724 self
._LibraryClass
= None
1725 self
._ModuleEntryPointList
= None
1726 self
._ModuleUnloadImageList
= None
1727 self
._ConstructorList
= None
1728 self
._DestructorList
= None
1730 self
._Binaries
= None
1731 self
._Sources
= None
1732 self
._LibraryClasses
= None
1733 self
._Libraries
= None
1734 self
._Protocols
= None
1735 self
._ProtocolComments
= None
1737 self
._PpiComments
= None
1739 self
._GuidsUsedByPcd
= sdict()
1740 self
._GuidComments
= None
1741 self
._Includes
= None
1742 self
._Packages
= None
1744 self
._PcdComments
= None
1745 self
._BuildOptions
= None
1747 self
._DepexExpression
= None
1748 self
.__Macros
= None
1750 ## Get current effective macros
1751 def _GetMacros(self
):
1752 if self
.__Macros
== None:
1754 # EDK_GLOBAL defined macros can be applied to EDK module
1755 if self
.AutoGenVersion
< 0x00010005:
1756 self
.__Macros
.update(GlobalData
.gEdkGlobal
)
1757 self
.__Macros
.update(GlobalData
.gGlobalDefines
)
1758 return self
.__Macros
1766 # Changing the default ARCH to another may affect all other information
1767 # because all information in a platform may be ARCH-related. That's
1768 # why we need to clear all internal used members, in order to cause all
1769 # information to be re-retrieved.
1771 # @param Value The value of ARCH
1773 def _SetArch(self
, Value
):
1774 if self
._Arch
== Value
:
1779 ## Return the name of platform employing this module
1780 def _GetPlatform(self
):
1781 return self
._Platform
1783 ## Change the name of platform employing this module
1785 # Changing the default name of platform to another may affect some information
1786 # because they may be PLATFORM-related. That's why we need to clear all internal
1787 # used members, in order to cause all information to be re-retrieved.
1789 def _SetPlatform(self
, Value
):
1790 if self
._Platform
== Value
:
1792 self
._Platform
= Value
1794 def _GetHeaderComments(self
):
1795 if not self
._HeaderComments
:
1796 self
._HeaderComments
= []
1797 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER_COMMENT
]
1798 for Record
in RecordList
:
1799 self
._HeaderComments
.append(Record
[0])
1800 return self
._HeaderComments
1801 def _GetTailComments(self
):
1802 if not self
._TailComments
:
1803 self
._TailComments
= []
1804 RecordList
= self
._RawData
[MODEL_META_DATA_TAIL_COMMENT
]
1805 for Record
in RecordList
:
1806 self
._TailComments
.append(Record
[0])
1807 return self
._TailComments
1808 ## Retrieve all information in [Defines] section
1810 # (Retriving all [Defines] information in one-shot is just to save time.)
1812 def _GetHeaderInfo(self
):
1813 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
1814 for Record
in RecordList
:
1815 Name
, Value
= Record
[1], ReplaceMacro(Record
[2], self
._Macros
, False)
1816 # items defined _PROPERTY_ don't need additional processing
1819 if self
._Defs
== None:
1820 self
._Defs
= sdict()
1821 self
._Defs
[Name
] = Value
1822 # some special items in [Defines] section need special treatment
1823 elif Name
in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):
1824 if Name
in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):
1825 Name
= 'UEFI_SPECIFICATION_VERSION'
1826 if self
._Specification
== None:
1827 self
._Specification
= sdict()
1828 self
._Specification
[Name
] = GetHexVerValue(Value
)
1829 if self
._Specification
[Name
] == None:
1830 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
1831 "'%s' format is not supported for %s" % (Value
, Name
),
1832 File
=self
.MetaFile
, Line
=Record
[-1])
1833 elif Name
== 'LIBRARY_CLASS':
1834 if self
._LibraryClass
== None:
1835 self
._LibraryClass
= []
1836 ValueList
= GetSplitValueList(Value
)
1837 LibraryClass
= ValueList
[0]
1838 if len(ValueList
) > 1:
1839 SupModuleList
= GetSplitValueList(ValueList
[1], ' ')
1841 SupModuleList
= SUP_MODULE_LIST
1842 self
._LibraryClass
.append(LibraryClassObject(LibraryClass
, SupModuleList
))
1843 elif Name
== 'ENTRY_POINT':
1844 if self
._ModuleEntryPointList
== None:
1845 self
._ModuleEntryPointList
= []
1846 self
._ModuleEntryPointList
.append(Value
)
1847 elif Name
== 'UNLOAD_IMAGE':
1848 if self
._ModuleUnloadImageList
== None:
1849 self
._ModuleUnloadImageList
= []
1852 self
._ModuleUnloadImageList
.append(Value
)
1853 elif Name
== 'CONSTRUCTOR':
1854 if self
._ConstructorList
== None:
1855 self
._ConstructorList
= []
1858 self
._ConstructorList
.append(Value
)
1859 elif Name
== 'DESTRUCTOR':
1860 if self
._DestructorList
== None:
1861 self
._DestructorList
= []
1864 self
._DestructorList
.append(Value
)
1865 elif Name
== TAB_INF_DEFINES_CUSTOM_MAKEFILE
:
1866 TokenList
= GetSplitValueList(Value
)
1867 if self
._CustomMakefile
== None:
1868 self
._CustomMakefile
= {}
1869 if len(TokenList
) < 2:
1870 self
._CustomMakefile
['MSFT'] = TokenList
[0]
1871 self
._CustomMakefile
['GCC'] = TokenList
[0]
1873 if TokenList
[0] not in ['MSFT', 'GCC']:
1874 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
1875 "No supported family [%s]" % TokenList
[0],
1876 File
=self
.MetaFile
, Line
=Record
[-1])
1877 self
._CustomMakefile
[TokenList
[0]] = TokenList
[1]
1879 if self
._Defs
== None:
1880 self
._Defs
= sdict()
1881 self
._Defs
[Name
] = Value
1884 # Retrieve information in sections specific to Edk.x modules
1886 if self
.AutoGenVersion
>= 0x00010005:
1887 if not self
._ModuleType
:
1888 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1889 "MODULE_TYPE is not given", File
=self
.MetaFile
)
1890 if self
._ModuleType
not in SUP_MODULE_LIST
:
1891 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
1892 for Record
in RecordList
:
1894 if Name
== "MODULE_TYPE":
1897 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
1898 "MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self
._ModuleType
, ' '.join(l
for l
in SUP_MODULE_LIST
)),
1899 File
=self
.MetaFile
, Line
=LineNo
)
1900 if (self
._Specification
== None) or (not 'PI_SPECIFICATION_VERSION' in self
._Specification
) or (int(self
._Specification
['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):
1901 if self
._ModuleType
== SUP_MODULE_SMM_CORE
:
1902 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File
=self
.MetaFile
)
1903 if self
._Defs
and 'PCI_DEVICE_ID' in self
._Defs
and 'PCI_VENDOR_ID' in self
._Defs \
1904 and 'PCI_CLASS_CODE' in self
._Defs
:
1905 self
._BuildType
= 'UEFI_OPTIONROM'
1906 elif self
._Defs
and 'UEFI_HII_RESOURCE_SECTION' in self
._Defs \
1907 and self
._Defs
['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':
1908 self
._BuildType
= 'UEFI_HII'
1910 self
._BuildType
= self
._ModuleType
.upper()
1913 File
= PathClass(NormPath(self
._DxsFile
), self
._ModuleDir
, Arch
=self
._Arch
)
1914 # check the file validation
1915 ErrorCode
, ErrorInfo
= File
.Validate(".dxs", CaseSensitive
=False)
1917 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
,
1918 File
=self
.MetaFile
, Line
=LineNo
)
1919 if self
.Sources
== None:
1921 self
._Sources
.append(File
)
1923 if not self
._ComponentType
:
1924 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1925 "COMPONENT_TYPE is not given", File
=self
.MetaFile
)
1926 self
._BuildType
= self
._ComponentType
.upper()
1927 if self
._ComponentType
in self
._MODULE
_TYPE
_:
1928 self
._ModuleType
= self
._MODULE
_TYPE
_[self
._ComponentType
]
1929 if self
._ComponentType
== 'LIBRARY':
1930 self
._LibraryClass
= [LibraryClassObject(self
._BaseName
, SUP_MODULE_LIST
)]
1931 # make use some [nmake] section macros
1932 Macros
= self
._Macros
1933 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
1934 Macros
['PROCESSOR'] = self
._Arch
1935 RecordList
= self
._RawData
[MODEL_META_DATA_NMAKE
, self
._Arch
, self
._Platform
]
1936 for Name
, Value
, Dummy
, Arch
, Platform
, ID
, LineNo
in RecordList
:
1937 Value
= ReplaceMacro(Value
, Macros
, True)
1938 if Name
== "IMAGE_ENTRY_POINT":
1939 if self
._ModuleEntryPointList
== None:
1940 self
._ModuleEntryPointList
= []
1941 self
._ModuleEntryPointList
.append(Value
)
1942 elif Name
== "DPX_SOURCE":
1943 File
= PathClass(NormPath(Value
), self
._ModuleDir
, Arch
=self
._Arch
)
1944 # check the file validation
1945 ErrorCode
, ErrorInfo
= File
.Validate(".dxs", CaseSensitive
=False)
1947 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
,
1948 File
=self
.MetaFile
, Line
=LineNo
)
1949 if self
.Sources
== None:
1951 self
._Sources
.append(File
)
1953 ToolList
= self
._NMAKE
_FLAG
_PATTERN
_.findall(Name
)
1954 if len(ToolList
) == 0 or len(ToolList
) != 1:
1956 # EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name,
1957 # File=self.MetaFile, Line=LineNo)
1959 if self
._BuildOptions
== None:
1960 self
._BuildOptions
= sdict()
1962 if ToolList
[0] in self
._TOOL
_CODE
_:
1963 Tool
= self
._TOOL
_CODE
_[ToolList
[0]]
1966 ToolChain
= "*_*_*_%s_FLAGS" % Tool
1967 ToolChainFamily
= 'MSFT' # Edk.x only support MSFT tool chain
1968 #ignore not replaced macros in value
1969 ValueList
= GetSplitList(' ' + Value
, '/D')
1970 Dummy
= ValueList
[0]
1971 for Index
in range(1, len(ValueList
)):
1972 if ValueList
[Index
][-1] == '=' or ValueList
[Index
] == '':
1974 Dummy
= Dummy
+ ' /D ' + ValueList
[Index
]
1975 Value
= Dummy
.strip()
1976 if (ToolChainFamily
, ToolChain
) not in self
._BuildOptions
:
1977 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = Value
1979 OptionString
= self
._BuildOptions
[ToolChainFamily
, ToolChain
]
1980 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Value
1981 # set _Header to non-None in order to avoid database re-querying
1982 self
._Header
_ = 'DUMMY'
1984 ## Retrieve file version
1985 def _GetInfVersion(self
):
1986 if self
._AutoGenVersion
== None:
1987 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
1988 for Record
in RecordList
:
1989 if Record
[1] == TAB_INF_DEFINES_INF_VERSION
:
1990 if '.' in Record
[2]:
1991 ValueList
= Record
[2].split('.')
1992 Major
= '%04o' % int(ValueList
[0], 0)
1993 Minor
= '%04o' % int(ValueList
[1], 0)
1994 self
._AutoGenVersion
= int('0x' + Major
+ Minor
, 0)
1996 self
._AutoGenVersion
= int(Record
[2], 0)
1998 if self
._AutoGenVersion
== None:
1999 self
._AutoGenVersion
= 0x00010000
2000 return self
._AutoGenVersion
2002 ## Retrieve BASE_NAME
2003 def _GetBaseName(self
):
2004 if self
._BaseName
== None:
2005 if self
._Header
_ == None:
2006 self
._GetHeaderInfo
()
2007 if self
._BaseName
== None:
2008 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BASE_NAME name", File
=self
.MetaFile
)
2009 return self
._BaseName
2012 def _GetDxsFile(self
):
2013 if self
._DxsFile
== None:
2014 if self
._Header
_ == None:
2015 self
._GetHeaderInfo
()
2016 if self
._DxsFile
== None:
2018 return self
._DxsFile
2020 ## Retrieve MODULE_TYPE
2021 def _GetModuleType(self
):
2022 if self
._ModuleType
== None:
2023 if self
._Header
_ == None:
2024 self
._GetHeaderInfo
()
2025 if self
._ModuleType
== None:
2026 self
._ModuleType
= 'BASE'
2027 if self
._ModuleType
not in SUP_MODULE_LIST
:
2028 self
._ModuleType
= "USER_DEFINED"
2029 return self
._ModuleType
2031 ## Retrieve COMPONENT_TYPE
2032 def _GetComponentType(self
):
2033 if self
._ComponentType
== None:
2034 if self
._Header
_ == None:
2035 self
._GetHeaderInfo
()
2036 if self
._ComponentType
== None:
2037 self
._ComponentType
= 'USER_DEFINED'
2038 return self
._ComponentType
2040 ## Retrieve "BUILD_TYPE"
2041 def _GetBuildType(self
):
2042 if self
._BuildType
== None:
2043 if self
._Header
_ == None:
2044 self
._GetHeaderInfo
()
2045 if not self
._BuildType
:
2046 self
._BuildType
= "BASE"
2047 return self
._BuildType
2049 ## Retrieve file guid
2050 def _GetFileGuid(self
):
2051 if self
._Guid
== None:
2052 if self
._Header
_ == None:
2053 self
._GetHeaderInfo
()
2054 if self
._Guid
== None:
2055 self
._Guid
= '00000000-0000-0000-0000-000000000000'
2058 ## Retrieve module version
2059 def _GetVersion(self
):
2060 if self
._Version
== None:
2061 if self
._Header
_ == None:
2062 self
._GetHeaderInfo
()
2063 if self
._Version
== None:
2064 self
._Version
= '0.0'
2065 return self
._Version
2067 ## Retrieve PCD_IS_DRIVER
2068 def _GetPcdIsDriver(self
):
2069 if self
._PcdIsDriver
== None:
2070 if self
._Header
_ == None:
2071 self
._GetHeaderInfo
()
2072 if self
._PcdIsDriver
== None:
2073 self
._PcdIsDriver
= ''
2074 return self
._PcdIsDriver
2077 def _GetShadow(self
):
2078 if self
._Shadow
== None:
2079 if self
._Header
_ == None:
2080 self
._GetHeaderInfo
()
2081 if self
._Shadow
!= None and self
._Shadow
.upper() == 'TRUE':
2084 self
._Shadow
= False
2087 ## Retrieve CUSTOM_MAKEFILE
2088 def _GetMakefile(self
):
2089 if self
._CustomMakefile
== None:
2090 if self
._Header
_ == None:
2091 self
._GetHeaderInfo
()
2092 if self
._CustomMakefile
== None:
2093 self
._CustomMakefile
= {}
2094 return self
._CustomMakefile
2096 ## Retrieve EFI_SPECIFICATION_VERSION
2098 if self
._Specification
== None:
2099 if self
._Header
_ == None:
2100 self
._GetHeaderInfo
()
2101 if self
._Specification
== None:
2102 self
._Specification
= {}
2103 return self
._Specification
2105 ## Retrieve LIBRARY_CLASS
2106 def _GetLibraryClass(self
):
2107 if self
._LibraryClass
== None:
2108 if self
._Header
_ == None:
2109 self
._GetHeaderInfo
()
2110 if self
._LibraryClass
== None:
2111 self
._LibraryClass
= []
2112 return self
._LibraryClass
2114 ## Retrieve ENTRY_POINT
2115 def _GetEntryPoint(self
):
2116 if self
._ModuleEntryPointList
== None:
2117 if self
._Header
_ == None:
2118 self
._GetHeaderInfo
()
2119 if self
._ModuleEntryPointList
== None:
2120 self
._ModuleEntryPointList
= []
2121 return self
._ModuleEntryPointList
2123 ## Retrieve UNLOAD_IMAGE
2124 def _GetUnloadImage(self
):
2125 if self
._ModuleUnloadImageList
== None:
2126 if self
._Header
_ == None:
2127 self
._GetHeaderInfo
()
2128 if self
._ModuleUnloadImageList
== None:
2129 self
._ModuleUnloadImageList
= []
2130 return self
._ModuleUnloadImageList
2132 ## Retrieve CONSTRUCTOR
2133 def _GetConstructor(self
):
2134 if self
._ConstructorList
== None:
2135 if self
._Header
_ == None:
2136 self
._GetHeaderInfo
()
2137 if self
._ConstructorList
== None:
2138 self
._ConstructorList
= []
2139 return self
._ConstructorList
2141 ## Retrieve DESTRUCTOR
2142 def _GetDestructor(self
):
2143 if self
._DestructorList
== None:
2144 if self
._Header
_ == None:
2145 self
._GetHeaderInfo
()
2146 if self
._DestructorList
== None:
2147 self
._DestructorList
= []
2148 return self
._DestructorList
2150 ## Retrieve definies other than above ones
2151 def _GetDefines(self
):
2152 if self
._Defs
== None:
2153 if self
._Header
_ == None:
2154 self
._GetHeaderInfo
()
2155 if self
._Defs
== None:
2156 self
._Defs
= sdict()
2159 ## Retrieve binary files
2160 def _GetBinaries(self
):
2161 if self
._Binaries
== None:
2163 RecordList
= self
._RawData
[MODEL_EFI_BINARY_FILE
, self
._Arch
, self
._Platform
]
2164 Macros
= self
._Macros
2165 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
2166 Macros
['PROCESSOR'] = self
._Arch
2167 for Record
in RecordList
:
2168 FileType
= Record
[0]
2173 TokenList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
2175 Target
= TokenList
[0]
2176 if len(TokenList
) > 1:
2177 FeatureFlag
= Record
[1:]
2179 File
= PathClass(NormPath(Record
[1], Macros
), self
._ModuleDir
, '', FileType
, True, self
._Arch
, '', Target
)
2180 # check the file validation
2181 ErrorCode
, ErrorInfo
= File
.Validate()
2183 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
2184 self
._Binaries
.append(File
)
2185 return self
._Binaries
2187 ## Retrieve binary files with error check.
2188 def _GetBinaryFiles(self
):
2189 Binaries
= self
._GetBinaries
()
2190 if GlobalData
.gIgnoreSource
and Binaries
== []:
2191 ErrorInfo
= "The INF file does not contain any Binaries to use in creating the image\n"
2192 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
)
2195 ## Check whether it exists the binaries with current ARCH in AsBuild INF
2196 def _IsSupportedArch(self
):
2197 if self
._GetBinaries
() and not self
._GetSourceFiles
():
2201 ## Retrieve source files
2202 def _GetSourceFiles(self
):
2203 #Ignore all source files in a binary build mode
2204 if GlobalData
.gIgnoreSource
:
2206 return self
._Sources
2208 if self
._Sources
== None:
2210 RecordList
= self
._RawData
[MODEL_EFI_SOURCE_FILE
, self
._Arch
, self
._Platform
]
2211 Macros
= self
._Macros
2212 for Record
in RecordList
:
2214 ToolChainFamily
= Record
[1]
2216 ToolCode
= Record
[3]
2217 FeatureFlag
= Record
[4]
2218 if self
.AutoGenVersion
< 0x00010005:
2219 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
2220 Macros
['PROCESSOR'] = self
._Arch
2221 SourceFile
= NormPath(Record
[0], Macros
)
2222 if SourceFile
[0] == os
.path
.sep
:
2223 SourceFile
= mws
.join(GlobalData
.gWorkspace
, SourceFile
[1:])
2224 # old module source files (Edk)
2225 File
= PathClass(SourceFile
, self
._ModuleDir
, self
._SourceOverridePath
,
2226 '', False, self
._Arch
, ToolChainFamily
, '', TagName
, ToolCode
)
2227 # check the file validation
2228 ErrorCode
, ErrorInfo
= File
.Validate(CaseSensitive
=False)
2230 if File
.Ext
.lower() == '.h':
2231 EdkLogger
.warn('build', 'Include file not found', ExtraData
=ErrorInfo
,
2232 File
=self
.MetaFile
, Line
=LineNo
)
2235 EdkLogger
.error('build', ErrorCode
, ExtraData
=File
, File
=self
.MetaFile
, Line
=LineNo
)
2237 File
= PathClass(NormPath(Record
[0], Macros
), self
._ModuleDir
, '',
2238 '', False, self
._Arch
, ToolChainFamily
, '', TagName
, ToolCode
)
2239 # check the file validation
2240 ErrorCode
, ErrorInfo
= File
.Validate()
2242 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
2244 self
._Sources
.append(File
)
2245 return self
._Sources
2247 ## Retrieve library classes employed by this module
2248 def _GetLibraryClassUses(self
):
2249 if self
._LibraryClasses
== None:
2250 self
._LibraryClasses
= sdict()
2251 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, self
._Platform
]
2252 for Record
in RecordList
:
2254 Instance
= Record
[1]
2256 Instance
= NormPath(Instance
, self
._Macros
)
2257 self
._LibraryClasses
[Lib
] = Instance
2258 return self
._LibraryClasses
2260 ## Retrieve library names (for Edk.x style of modules)
2261 def _GetLibraryNames(self
):
2262 if self
._Libraries
== None:
2263 self
._Libraries
= []
2264 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
, self
._Platform
]
2265 for Record
in RecordList
:
2266 LibraryName
= ReplaceMacro(Record
[0], self
._Macros
, False)
2267 # in case of name with '.lib' extension, which is unusual in Edk.x inf
2268 LibraryName
= os
.path
.splitext(LibraryName
)[0]
2269 if LibraryName
not in self
._Libraries
:
2270 self
._Libraries
.append(LibraryName
)
2271 return self
._Libraries
2273 def _GetProtocolComments(self
):
2274 self
._GetProtocols
()
2275 return self
._ProtocolComments
2276 ## Retrieve protocols consumed/produced by this module
2277 def _GetProtocols(self
):
2278 if self
._Protocols
== None:
2279 self
._Protocols
= sdict()
2280 self
._ProtocolComments
= sdict()
2281 RecordList
= self
._RawData
[MODEL_EFI_PROTOCOL
, self
._Arch
, self
._Platform
]
2282 for Record
in RecordList
:
2284 Value
= ProtocolValue(CName
, self
.Packages
)
2286 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
2287 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
2288 "Value of Protocol [%s] is not found under [Protocols] section in" % CName
,
2289 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
2290 self
._Protocols
[CName
] = Value
2291 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
2293 for CmtRec
in CommentRecords
:
2294 Comments
.append(CmtRec
[0])
2295 self
._ProtocolComments
[CName
] = Comments
2296 return self
._Protocols
2298 def _GetPpiComments(self
):
2300 return self
._PpiComments
2301 ## Retrieve PPIs consumed/produced by this module
2303 if self
._Ppis
== None:
2304 self
._Ppis
= sdict()
2305 self
._PpiComments
= sdict()
2306 RecordList
= self
._RawData
[MODEL_EFI_PPI
, self
._Arch
, self
._Platform
]
2307 for Record
in RecordList
:
2309 Value
= PpiValue(CName
, self
.Packages
)
2311 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
2312 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
2313 "Value of PPI [%s] is not found under [Ppis] section in " % CName
,
2314 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
2315 self
._Ppis
[CName
] = Value
2316 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
2318 for CmtRec
in CommentRecords
:
2319 Comments
.append(CmtRec
[0])
2320 self
._PpiComments
[CName
] = Comments
2323 def _GetGuidComments(self
):
2325 return self
._GuidComments
2326 ## Retrieve GUIDs consumed/produced by this module
2327 def _GetGuids(self
):
2328 if self
._Guids
== None:
2329 self
._Guids
= sdict()
2330 self
._GuidComments
= sdict()
2331 RecordList
= self
._RawData
[MODEL_EFI_GUID
, self
._Arch
, self
._Platform
]
2332 for Record
in RecordList
:
2334 Value
= GuidValue(CName
, self
.Packages
)
2336 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
2337 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
2338 "Value of Guid [%s] is not found under [Guids] section in" % CName
,
2339 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
2340 self
._Guids
[CName
] = Value
2341 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
2343 for CmtRec
in CommentRecords
:
2344 Comments
.append(CmtRec
[0])
2345 self
._GuidComments
[CName
] = Comments
2348 ## Retrieve include paths necessary for this module (for Edk.x style of modules)
2349 def _GetIncludes(self
):
2350 if self
._Includes
== None:
2352 if self
._SourceOverridePath
:
2353 self
._Includes
.append(self
._SourceOverridePath
)
2355 Macros
= self
._Macros
2356 if 'PROCESSOR' in GlobalData
.gEdkGlobal
.keys():
2357 Macros
['PROCESSOR'] = GlobalData
.gEdkGlobal
['PROCESSOR']
2359 Macros
['PROCESSOR'] = self
._Arch
2360 RecordList
= self
._RawData
[MODEL_EFI_INCLUDE
, self
._Arch
, self
._Platform
]
2361 for Record
in RecordList
:
2362 if Record
[0].find('EDK_SOURCE') > -1:
2363 Macros
['EDK_SOURCE'] = GlobalData
.gEcpSource
2364 File
= NormPath(Record
[0], self
._Macros
)
2366 File
= os
.path
.join(self
._ModuleDir
, File
)
2368 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
2369 File
= RealPath(os
.path
.normpath(File
))
2371 self
._Includes
.append(File
)
2373 #TRICK: let compiler to choose correct header file
2374 Macros
['EDK_SOURCE'] = GlobalData
.gEdkSource
2375 File
= NormPath(Record
[0], self
._Macros
)
2377 File
= os
.path
.join(self
._ModuleDir
, File
)
2379 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
2380 File
= RealPath(os
.path
.normpath(File
))
2382 self
._Includes
.append(File
)
2384 File
= NormPath(Record
[0], Macros
)
2386 File
= os
.path
.join(self
._ModuleDir
, File
)
2388 File
= mws
.join(GlobalData
.gWorkspace
, File
)
2389 File
= RealPath(os
.path
.normpath(File
))
2391 self
._Includes
.append(File
)
2392 if not File
and Record
[0].find('EFI_SOURCE') > -1:
2393 # tricky to regard WorkSpace as EFI_SOURCE
2394 Macros
['EFI_SOURCE'] = GlobalData
.gWorkspace
2395 File
= NormPath(Record
[0], Macros
)
2397 File
= os
.path
.join(self
._ModuleDir
, File
)
2399 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
2400 File
= RealPath(os
.path
.normpath(File
))
2402 self
._Includes
.append(File
)
2403 return self
._Includes
2405 ## Retrieve packages this module depends on
2406 def _GetPackages(self
):
2407 if self
._Packages
== None:
2409 RecordList
= self
._RawData
[MODEL_META_DATA_PACKAGE
, self
._Arch
, self
._Platform
]
2410 Macros
= self
._Macros
2411 Macros
['EDK_SOURCE'] = GlobalData
.gEcpSource
2412 for Record
in RecordList
:
2413 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
2415 # check the file validation
2416 ErrorCode
, ErrorInfo
= File
.Validate('.dec')
2418 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
2419 # parse this package now. we need it to get protocol/ppi/guid value
2420 Package
= self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
]
2421 self
._Packages
.append(Package
)
2422 return self
._Packages
2424 ## Retrieve PCD comments
2425 def _GetPcdComments(self
):
2427 return self
._PcdComments
2428 ## Retrieve PCDs used in this module
2430 if self
._Pcds
== None:
2431 self
._Pcds
= sdict()
2432 self
._PcdComments
= sdict()
2433 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
2434 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
2435 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
2436 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC
))
2437 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC_EX
))
2440 ## Retrieve build options specific to this module
2441 def _GetBuildOptions(self
):
2442 if self
._BuildOptions
== None:
2443 self
._BuildOptions
= sdict()
2444 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, self
._Platform
]
2445 for Record
in RecordList
:
2446 ToolChainFamily
= Record
[0]
2447 ToolChain
= Record
[1]
2449 if (ToolChainFamily
, ToolChain
) not in self
._BuildOptions
or Option
.startswith('='):
2450 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = Option
2452 # concatenate the option string if they're for the same tool
2453 OptionString
= self
._BuildOptions
[ToolChainFamily
, ToolChain
]
2454 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
2455 return self
._BuildOptions
2457 ## Retrieve dependency expression
2458 def _GetDepex(self
):
2459 if self
._Depex
== None:
2460 self
._Depex
= tdict(False, 2)
2461 RecordList
= self
._RawData
[MODEL_EFI_DEPEX
, self
._Arch
]
2463 # If the module has only Binaries and no Sources, then ignore [Depex]
2464 if self
.Sources
== None or self
.Sources
== []:
2465 if self
.Binaries
!= None and self
.Binaries
!= []:
2468 # PEIM and DXE drivers must have a valid [Depex] section
2469 if len(self
.LibraryClass
) == 0 and len(RecordList
) == 0:
2470 if self
.ModuleType
== 'DXE_DRIVER' or self
.ModuleType
== 'PEIM' or self
.ModuleType
== 'DXE_SMM_DRIVER' or \
2471 self
.ModuleType
== 'DXE_SAL_DRIVER' or self
.ModuleType
== 'DXE_RUNTIME_DRIVER':
2472 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
2473 % self
.ModuleType
, File
=self
.MetaFile
)
2475 if len(RecordList
) != 0 and self
.ModuleType
== 'USER_DEFINED':
2476 for Record
in RecordList
:
2477 if Record
[4] not in ['PEIM', 'DXE_DRIVER', 'DXE_SMM_DRIVER']:
2478 EdkLogger
.error('build', FORMAT_INVALID
,
2479 "'%s' module must specify the type of [Depex] section" % self
.ModuleType
,
2483 for Record
in RecordList
:
2484 DepexStr
= ReplaceMacro(Record
[0], self
._Macros
, False)
2486 ModuleType
= Record
[4]
2487 TokenList
= DepexStr
.split()
2488 if (Arch
, ModuleType
) not in Depex
:
2489 Depex
[Arch
, ModuleType
] = []
2490 DepexList
= Depex
[Arch
, ModuleType
]
2491 for Token
in TokenList
:
2492 if Token
in DEPEX_SUPPORTED_OPCODE
:
2493 DepexList
.append(Token
)
2494 elif Token
.endswith(".inf"): # module file name
2495 ModuleFile
= os
.path
.normpath(Token
)
2496 Module
= self
.BuildDatabase
[ModuleFile
]
2498 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "Module is not found in active platform",
2499 ExtraData
=Token
, File
=self
.MetaFile
, Line
=Record
[-1])
2500 DepexList
.append(Module
.Guid
)
2502 # get the GUID value now
2503 Value
= ProtocolValue(Token
, self
.Packages
)
2505 Value
= PpiValue(Token
, self
.Packages
)
2507 Value
= GuidValue(Token
, self
.Packages
)
2509 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
2510 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
2511 "Value of [%s] is not found in" % Token
,
2512 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
2513 DepexList
.append(Value
)
2514 for Arch
, ModuleType
in Depex
:
2515 self
._Depex
[Arch
, ModuleType
] = Depex
[Arch
, ModuleType
]
2518 ## Retrieve depedency expression
2519 def _GetDepexExpression(self
):
2520 if self
._DepexExpression
== None:
2521 self
._DepexExpression
= tdict(False, 2)
2522 RecordList
= self
._RawData
[MODEL_EFI_DEPEX
, self
._Arch
]
2523 DepexExpression
= sdict()
2524 for Record
in RecordList
:
2525 DepexStr
= ReplaceMacro(Record
[0], self
._Macros
, False)
2527 ModuleType
= Record
[4]
2528 TokenList
= DepexStr
.split()
2529 if (Arch
, ModuleType
) not in DepexExpression
:
2530 DepexExpression
[Arch
, ModuleType
] = ''
2531 for Token
in TokenList
:
2532 DepexExpression
[Arch
, ModuleType
] = DepexExpression
[Arch
, ModuleType
] + Token
.strip() + ' '
2533 for Arch
, ModuleType
in DepexExpression
:
2534 self
._DepexExpression
[Arch
, ModuleType
] = DepexExpression
[Arch
, ModuleType
]
2535 return self
._DepexExpression
2537 def GetGuidsUsedByPcd(self
):
2538 return self
._GuidsUsedByPcd
2539 ## Retrieve PCD for given type
2540 def _GetPcd(self
, Type
):
2542 PcdDict
= tdict(True, 4)
2544 RecordList
= self
._RawData
[Type
, self
._Arch
, self
._Platform
]
2545 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, Platform
, Id
, LineNo
in RecordList
:
2546 PcdDict
[Arch
, Platform
, PcdCName
, TokenSpaceGuid
] = (Setting
, LineNo
)
2547 PcdList
.append((PcdCName
, TokenSpaceGuid
))
2548 # get the guid value
2549 if TokenSpaceGuid
not in self
.Guids
:
2550 Value
= GuidValue(TokenSpaceGuid
, self
.Packages
)
2552 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
2553 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
2554 "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid
,
2555 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=LineNo
)
2556 self
.Guids
[TokenSpaceGuid
] = Value
2557 self
._GuidsUsedByPcd
[TokenSpaceGuid
] = Value
2558 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Id
]
2560 for CmtRec
in CommentRecords
:
2561 Comments
.append(CmtRec
[0])
2562 self
._PcdComments
[TokenSpaceGuid
, PcdCName
] = Comments
2564 # resolve PCD type, value, datum info, etc. by getting its definition from package
2565 for PcdCName
, TokenSpaceGuid
in PcdList
:
2566 Setting
, LineNo
= PcdDict
[self
._Arch
, self
.Platform
, PcdCName
, TokenSpaceGuid
]
2569 ValueList
= AnalyzePcdData(Setting
)
2570 DefaultValue
= ValueList
[0]
2571 Pcd
= PcdClassObject(
2581 self
.Guids
[TokenSpaceGuid
]
2583 if Type
== MODEL_PCD_PATCHABLE_IN_MODULE
and ValueList
[1]:
2584 # Patch PCD: TokenSpace.PcdCName|Value|Offset
2585 Pcd
.Offset
= ValueList
[1]
2587 # get necessary info from package declaring this PCD
2588 for Package
in self
.Packages
:
2590 # 'dynamic' in INF means its type is determined by platform;
2591 # if platform doesn't give its type, use 'lowest' one in the
2592 # following order, if any
2594 # "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"
2596 PcdType
= self
._PCD
_TYPE
_STRING
_[Type
]
2597 if Type
== MODEL_PCD_DYNAMIC
:
2599 for T
in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:
2600 if (PcdCName
, TokenSpaceGuid
, T
) in Package
.Pcds
:
2606 if (PcdCName
, TokenSpaceGuid
, PcdType
) in Package
.Pcds
:
2607 PcdInPackage
= Package
.Pcds
[PcdCName
, TokenSpaceGuid
, PcdType
]
2609 Pcd
.TokenValue
= PcdInPackage
.TokenValue
2612 # Check whether the token value exist or not.
2614 if Pcd
.TokenValue
== None or Pcd
.TokenValue
== "":
2618 "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid
, PcdCName
, str(Package
)),
2619 File
=self
.MetaFile
, Line
=LineNo
,
2623 # Check hexadecimal token value length and format.
2625 ReIsValidPcdTokenValue
= re
.compile(r
"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re
.DOTALL
)
2626 if Pcd
.TokenValue
.startswith("0x") or Pcd
.TokenValue
.startswith("0X"):
2627 if ReIsValidPcdTokenValue
.match(Pcd
.TokenValue
) == None:
2631 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdCName
, str(Package
)),
2632 File
=self
.MetaFile
, Line
=LineNo
,
2637 # Check decimal token value length and format.
2641 TokenValueInt
= int (Pcd
.TokenValue
, 10)
2642 if (TokenValueInt
< 0 or TokenValueInt
> 4294967295):
2646 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, as a decimal it should between: 0 - 4294967295!" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdCName
, str(Package
)),
2647 File
=self
.MetaFile
, Line
=LineNo
,
2654 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, it should be hexadecimal or decimal!" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdCName
, str(Package
)),
2655 File
=self
.MetaFile
, Line
=LineNo
,
2659 Pcd
.DatumType
= PcdInPackage
.DatumType
2660 Pcd
.MaxDatumSize
= PcdInPackage
.MaxDatumSize
2661 Pcd
.InfDefaultValue
= Pcd
.DefaultValue
2662 if Pcd
.DefaultValue
in [None, '']:
2663 Pcd
.DefaultValue
= PcdInPackage
.DefaultValue
2669 "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid
, PcdCName
, self
.MetaFile
),
2670 File
=self
.MetaFile
, Line
=LineNo
,
2671 ExtraData
="\t%s" % '\n\t'.join([str(P
) for P
in self
.Packages
])
2673 Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
2677 ## check whether current module is binary module
2678 def _IsBinaryModule(self
):
2679 if self
.Binaries
and not self
.Sources
:
2681 elif GlobalData
.gIgnoreSource
:
2686 _Macros
= property(_GetMacros
)
2687 Arch
= property(_GetArch
, _SetArch
)
2688 Platform
= property(_GetPlatform
, _SetPlatform
)
2690 HeaderComments
= property(_GetHeaderComments
)
2691 TailComments
= property(_GetTailComments
)
2692 AutoGenVersion
= property(_GetInfVersion
)
2693 BaseName
= property(_GetBaseName
)
2694 ModuleType
= property(_GetModuleType
)
2695 ComponentType
= property(_GetComponentType
)
2696 BuildType
= property(_GetBuildType
)
2697 Guid
= property(_GetFileGuid
)
2698 Version
= property(_GetVersion
)
2699 PcdIsDriver
= property(_GetPcdIsDriver
)
2700 Shadow
= property(_GetShadow
)
2701 CustomMakefile
= property(_GetMakefile
)
2702 Specification
= property(_GetSpec
)
2703 LibraryClass
= property(_GetLibraryClass
)
2704 ModuleEntryPointList
= property(_GetEntryPoint
)
2705 ModuleUnloadImageList
= property(_GetUnloadImage
)
2706 ConstructorList
= property(_GetConstructor
)
2707 DestructorList
= property(_GetDestructor
)
2708 Defines
= property(_GetDefines
)
2709 DxsFile
= property(_GetDxsFile
)
2711 Binaries
= property(_GetBinaryFiles
)
2712 Sources
= property(_GetSourceFiles
)
2713 LibraryClasses
= property(_GetLibraryClassUses
)
2714 Libraries
= property(_GetLibraryNames
)
2715 Protocols
= property(_GetProtocols
)
2716 ProtocolComments
= property(_GetProtocolComments
)
2717 Ppis
= property(_GetPpis
)
2718 PpiComments
= property(_GetPpiComments
)
2719 Guids
= property(_GetGuids
)
2720 GuidComments
= property(_GetGuidComments
)
2721 Includes
= property(_GetIncludes
)
2722 Packages
= property(_GetPackages
)
2723 Pcds
= property(_GetPcds
)
2724 PcdComments
= property(_GetPcdComments
)
2725 BuildOptions
= property(_GetBuildOptions
)
2726 Depex
= property(_GetDepex
)
2727 DepexExpression
= property(_GetDepexExpression
)
2728 IsBinaryModule
= property(_IsBinaryModule
)
2729 IsSupportedArch
= property(_IsSupportedArch
)
2733 # This class defined the build database for all modules, packages and platform.
2734 # It will call corresponding parser for the given file if it cannot find it in
2737 # @param DbPath Path of database file
2738 # @param GlobalMacros Global macros used for replacement during file parsing
2739 # @prarm RenewDb=False Create new database file if it's already there
2741 class WorkspaceDatabase(object):
2745 # internal class used for call corresponding file parser and caching the result
2746 # to avoid unnecessary re-parsing
2748 class BuildObjectFactory(object):
2751 ".inf" : MODEL_FILE_INF
,
2752 ".dec" : MODEL_FILE_DEC
,
2753 ".dsc" : MODEL_FILE_DSC
,
2758 MODEL_FILE_INF
: InfParser
,
2759 MODEL_FILE_DEC
: DecParser
,
2760 MODEL_FILE_DSC
: DscParser
,
2763 # convert to xxxBuildData object
2765 MODEL_FILE_INF
: InfBuildData
,
2766 MODEL_FILE_DEC
: DecBuildData
,
2767 MODEL_FILE_DSC
: DscBuildData
,
2770 _CACHE_
= {} # (FilePath, Arch) : <object>
2773 def __init__(self
, WorkspaceDb
):
2774 self
.WorkspaceDb
= WorkspaceDb
2776 # key = (FilePath, Arch=None)
2777 def __contains__(self
, Key
):
2783 return (FilePath
, Arch
) in self
._CACHE
_
2785 # key = (FilePath, Arch=None, Target=None, Toochain=None)
2786 def __getitem__(self
, Key
):
2788 KeyLength
= len(Key
)
2802 # if it's generated before, just return the cached one
2803 Key
= (FilePath
, Arch
, Target
, Toolchain
)
2804 if Key
in self
._CACHE
_:
2805 return self
._CACHE
_[Key
]
2809 if Ext
not in self
._FILE
_TYPE
_:
2811 FileType
= self
._FILE
_TYPE
_[Ext
]
2812 if FileType
not in self
._GENERATOR
_:
2815 # get the parser ready for this file
2816 MetaFile
= self
._FILE
_PARSER
_[FileType
](
2819 MetaFileStorage(self
.WorkspaceDb
.Cur
, FilePath
, FileType
)
2821 # alwasy do post-process, in case of macros change
2822 MetaFile
.DoPostProcess()
2823 # object the build is based on
2824 BuildObject
= self
._GENERATOR
_[FileType
](
2832 self
._CACHE
_[Key
] = BuildObject
2835 # placeholder for file format conversion
2836 class TransformObjectFactory
:
2837 def __init__(self
, WorkspaceDb
):
2838 self
.WorkspaceDb
= WorkspaceDb
2840 # key = FilePath, Arch
2841 def __getitem__(self
, Key
):
2844 ## Constructor of WorkspaceDatabase
2846 # @param DbPath Path of database file
2847 # @param GlobalMacros Global macros used for replacement during file parsing
2848 # @prarm RenewDb=False Create new database file if it's already there
2850 def __init__(self
, DbPath
, RenewDb
=False):
2851 self
._DbClosedFlag
= False
2853 DbPath
= os
.path
.normpath(mws
.join(GlobalData
.gWorkspace
, 'Conf', GlobalData
.gDatabasePath
))
2855 # don't create necessary path for db in memory
2856 if DbPath
!= ':memory:':
2857 DbDir
= os
.path
.split(DbPath
)[0]
2858 if not os
.path
.exists(DbDir
):
2861 # remove db file in case inconsistency between db and file in file system
2862 if self
._CheckWhetherDbNeedRenew
(RenewDb
, DbPath
):
2865 # create db with optimized parameters
2866 self
.Conn
= sqlite3
.connect(DbPath
, isolation_level
='DEFERRED')
2867 self
.Conn
.execute("PRAGMA synchronous=OFF")
2868 self
.Conn
.execute("PRAGMA temp_store=MEMORY")
2869 self
.Conn
.execute("PRAGMA count_changes=OFF")
2870 self
.Conn
.execute("PRAGMA cache_size=8192")
2871 #self.Conn.execute("PRAGMA page_size=8192")
2873 # to avoid non-ascii character conversion issue
2874 self
.Conn
.text_factory
= str
2875 self
.Cur
= self
.Conn
.cursor()
2877 # create table for internal uses
2878 self
.TblDataModel
= TableDataModel(self
.Cur
)
2879 self
.TblFile
= TableFile(self
.Cur
)
2880 self
.Platform
= None
2882 # conversion object for build or file format conversion purpose
2883 self
.BuildObject
= WorkspaceDatabase
.BuildObjectFactory(self
)
2884 self
.TransformObject
= WorkspaceDatabase
.TransformObjectFactory(self
)
2886 ## Check whether workspace database need to be renew.
2887 # The renew reason maybe:
2888 # 1) If user force to renew;
2889 # 2) If user do not force renew, and
2890 # a) If the time of last modified python source is newer than database file;
2891 # b) If the time of last modified frozen executable file is newer than database file;
2893 # @param force User force renew database
2894 # @param DbPath The absolute path of workspace database file
2896 # @return Bool value for whether need renew workspace databse
2898 def _CheckWhetherDbNeedRenew (self
, force
, DbPath
):
2899 # if database does not exist, we need do nothing
2900 if not os
.path
.exists(DbPath
): return False
2902 # if user force to renew database, then not check whether database is out of date
2903 if force
: return True
2906 # Check the time of last modified source file or build.exe
2907 # if is newer than time of database, then database need to be re-created.
2909 timeOfToolModified
= 0
2910 if hasattr(sys
, "frozen"):
2911 exePath
= os
.path
.abspath(sys
.executable
)
2912 timeOfToolModified
= os
.stat(exePath
).st_mtime
2914 curPath
= os
.path
.dirname(__file__
) # curPath is the path of WorkspaceDatabase.py
2915 rootPath
= os
.path
.split(curPath
)[0] # rootPath is root path of python source, such as /BaseTools/Source/Python
2916 if rootPath
== "" or rootPath
== None:
2917 EdkLogger
.verbose("\nFail to find the root path of build.exe or python sources, so can not \
2918 determine whether database file is out of date!\n")
2920 # walk the root path of source or build's binary to get the time last modified.
2922 for root
, dirs
, files
in os
.walk (rootPath
):
2924 # bypass source control folder
2925 if dir.lower() in [".svn", "_svn", "cvs"]:
2929 ext
= os
.path
.splitext(file)[1]
2930 if ext
.lower() == ".py": # only check .py files
2931 fd
= os
.stat(os
.path
.join(root
, file))
2932 if timeOfToolModified
< fd
.st_mtime
:
2933 timeOfToolModified
= fd
.st_mtime
2934 if timeOfToolModified
> os
.stat(DbPath
).st_mtime
:
2935 EdkLogger
.verbose("\nWorkspace database is out of data!")
2940 ## Initialize build database
2941 def InitDatabase(self
):
2942 EdkLogger
.verbose("\nInitialize build database started ...")
2947 self
.TblDataModel
.Create(False)
2948 self
.TblFile
.Create(False)
2951 # Initialize table DataModel
2953 self
.TblDataModel
.InitTable()
2954 EdkLogger
.verbose("Initialize build database ... DONE!")
2958 # @param Table: The instance of the table to be queried
2960 def QueryTable(self
, Table
):
2966 ## Close entire database
2969 # Close the connection and cursor
2972 if not self
._DbClosedFlag
:
2976 self
._DbClosedFlag
= True
2978 ## Summarize all packages in the database
2979 def GetPackageList(self
, Platform
, Arch
, TargetName
, ToolChainTag
):
2980 self
.Platform
= Platform
2982 Pa
= self
.BuildObject
[self
.Platform
, 'COMMON']
2984 # Get Package related to Modules
2986 for Module
in Pa
.Modules
:
2987 ModuleObj
= self
.BuildObject
[Module
, Arch
, TargetName
, ToolChainTag
]
2988 for Package
in ModuleObj
.Packages
:
2989 if Package
not in PackageList
:
2990 PackageList
.append(Package
)
2992 # Get Packages related to Libraries
2994 for Lib
in Pa
.LibraryInstances
:
2995 LibObj
= self
.BuildObject
[Lib
, Arch
, TargetName
, ToolChainTag
]
2996 for Package
in LibObj
.Packages
:
2997 if Package
not in PackageList
:
2998 PackageList
.append(Package
)
3002 ## Summarize all platforms in the database
3003 def _GetPlatformList(self
):
3005 for PlatformFile
in self
.TblFile
.GetFileList(MODEL_FILE_DSC
):
3007 Platform
= self
.BuildObject
[PathClass(PlatformFile
), 'COMMON']
3010 if Platform
!= None:
3011 PlatformList
.append(Platform
)
3014 def _MapPlatform(self
, Dscfile
):
3016 Platform
= self
.BuildObject
[PathClass(Dscfile
), 'COMMON']
3021 PlatformList
= property(_GetPlatformList
)
3025 # This acts like the main() function for the script, unless it is 'import'ed into another
3028 if __name__
== '__main__':