2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2018, 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.
15 from __future__
import absolute_import
16 from Common
.DataType
import *
17 from Common
.Misc
import *
18 from Common
.caching
import cached_property
, cached_class_function
20 from .MetaFileParser
import *
21 from collections
import OrderedDict
22 from Workspace
.BuildClassObject
import ModuleBuildClassObject
, LibraryClassObject
, PcdClassObject
24 ## Module build information from INF file
26 # This class is used to retrieve information stored in database and convert them
27 # into ModuleBuildClassObject form for easier use for AutoGen.
29 class InfBuildData(ModuleBuildClassObject
):
30 # dict used to convert PCD type in database to string used by build tool
32 MODEL_PCD_FIXED_AT_BUILD
: TAB_PCDS_FIXED_AT_BUILD
,
33 MODEL_PCD_PATCHABLE_IN_MODULE
: TAB_PCDS_PATCHABLE_IN_MODULE
,
34 MODEL_PCD_FEATURE_FLAG
: TAB_PCDS_FEATURE_FLAG
,
35 MODEL_PCD_DYNAMIC
: TAB_PCDS_DYNAMIC
,
36 MODEL_PCD_DYNAMIC_DEFAULT
: TAB_PCDS_DYNAMIC
,
37 MODEL_PCD_DYNAMIC_HII
: TAB_PCDS_DYNAMIC_HII
,
38 MODEL_PCD_DYNAMIC_VPD
: TAB_PCDS_DYNAMIC_VPD
,
39 MODEL_PCD_DYNAMIC_EX
: TAB_PCDS_DYNAMIC_EX
,
40 MODEL_PCD_DYNAMIC_EX_DEFAULT
: TAB_PCDS_DYNAMIC_EX
,
41 MODEL_PCD_DYNAMIC_EX_HII
: TAB_PCDS_DYNAMIC_EX_HII
,
42 MODEL_PCD_DYNAMIC_EX_VPD
: TAB_PCDS_DYNAMIC_EX_VPD
,
45 # dict used to convert part of [Defines] to members of InfBuildData directly
50 TAB_INF_DEFINES_BASE_NAME
: "_BaseName",
51 TAB_INF_DEFINES_FILE_GUID
: "_Guid",
52 TAB_INF_DEFINES_MODULE_TYPE
: "_ModuleType",
56 # TAB_INF_DEFINES_INF_VERSION : "_AutoGenVersion",
57 TAB_INF_DEFINES_COMPONENT_TYPE
: "_ComponentType",
58 TAB_INF_DEFINES_MAKEFILE_NAME
: "_MakefileName",
59 # TAB_INF_DEFINES_CUSTOM_MAKEFILE : "_CustomMakefile",
60 TAB_INF_DEFINES_DPX_SOURCE
:"_DxsFile",
61 TAB_INF_DEFINES_VERSION_NUMBER
: "_Version",
62 TAB_INF_DEFINES_VERSION_STRING
: "_Version",
63 TAB_INF_DEFINES_VERSION
: "_Version",
64 TAB_INF_DEFINES_PCD_IS_DRIVER
: "_PcdIsDriver",
65 TAB_INF_DEFINES_SHADOW
: "_Shadow",
67 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH
: "_SourceOverridePath",
70 # regular expression for converting XXX_FLAGS in [nmake] section to new type
71 _NMAKE_FLAG_PATTERN_
= re
.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re
.UNICODE
)
72 # dict used to convert old tool name used in [nmake] section to new ones
75 BINARY_FILE_TYPE_LIB
: "SLINK",
80 ## Constructor of InfBuildData
82 # Initialize object of InfBuildData
84 # @param FilePath The path of platform description file
85 # @param RawData The raw data of DSC file
86 # @param BuildDataBase Database used to retrieve module/package information
87 # @param Arch The target architecture
88 # @param Platform The name of platform employing this module
89 # @param Macros Macros used for replacement in DSC file
91 def __init__(self
, FilePath
, RawData
, BuildDatabase
, Arch
=TAB_ARCH_COMMON
, Target
=None, Toolchain
=None):
92 self
.MetaFile
= FilePath
93 self
._ModuleDir
= FilePath
.Dir
94 self
._RawData
= RawData
95 self
._Bdb
= BuildDatabase
98 self
._Toolchain
= Toolchain
99 self
._Platform
= TAB_COMMON
100 if FilePath
.Key
in GlobalData
.gOverrideDir
:
101 self
._SourceOverridePath
= GlobalData
.gOverrideDir
[FilePath
.Key
]
103 self
._SourceOverridePath
= None
104 self
._TailComments
= None
105 self
._BaseName
= None
107 self
._ModuleType
= None
108 self
._ComponentType
= None
109 self
._BuildType
= None
112 self
._PcdIsDriver
= None
113 self
._BinaryModule
= None
115 self
._MakefileName
= None
116 self
._CustomMakefile
= None
117 self
._Specification
= None
118 self
._LibraryClass
= None
119 self
._ModuleEntryPointList
= None
120 self
._ModuleUnloadImageList
= None
121 self
._ConstructorList
= None
122 self
._DestructorList
= None
123 self
._Defs
= OrderedDict()
124 self
._ProtocolComments
= None
125 self
._PpiComments
= None
126 self
._GuidsUsedByPcd
= OrderedDict()
127 self
._GuidComments
= None
128 self
._PcdComments
= None
129 self
._BuildOptions
= None
130 self
._DependencyFileList
= None
133 def __setitem__(self
, key
, value
):
134 self
.__dict
__[self
._PROPERTY
_[key
]] = value
137 def __getitem__(self
, key
):
138 return self
.__dict
__[self
._PROPERTY
_[key
]]
141 def __contains__(self
, key
):
142 return key
in self
._PROPERTY
_
144 ## Get current effective macros
148 # EDK_GLOBAL defined macros can be applied to EDK module
149 if self
.AutoGenVersion
< 0x00010005:
150 RetVal
.update(GlobalData
.gEdkGlobal
)
151 RetVal
.update(GlobalData
.gGlobalDefines
)
159 ## Return the name of platform employing this module
162 return self
._Platform
165 def HeaderComments(self
):
166 return [a
[0] for a
in self
._RawData
[MODEL_META_DATA_HEADER_COMMENT
]]
169 def TailComments(self
):
170 return [a
[0] for a
in self
._RawData
[MODEL_META_DATA_TAIL_COMMENT
]]
172 ## Retrieve all information in [Defines] section
174 # (Retriving all [Defines] information in one-shot is just to save time.)
176 @cached_class_function
177 def _GetHeaderInfo(self
):
178 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
179 for Record
in RecordList
:
180 Name
, Value
= Record
[1], ReplaceMacro(Record
[2], self
._Macros
, False)
181 # items defined _PROPERTY_ don't need additional processing
184 self
._Defs
[Name
] = Value
185 self
._Macros
[Name
] = Value
186 # some special items in [Defines] section need special treatment
187 elif Name
in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):
188 if Name
in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):
189 Name
= 'UEFI_SPECIFICATION_VERSION'
190 if self
._Specification
is None:
191 self
._Specification
= OrderedDict()
192 self
._Specification
[Name
] = GetHexVerValue(Value
)
193 if self
._Specification
[Name
] is None:
194 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
195 "'%s' format is not supported for %s" % (Value
, Name
),
196 File
=self
.MetaFile
, Line
=Record
[-1])
197 elif Name
== 'LIBRARY_CLASS':
198 if self
._LibraryClass
is None:
199 self
._LibraryClass
= []
200 ValueList
= GetSplitValueList(Value
)
201 LibraryClass
= ValueList
[0]
202 if len(ValueList
) > 1:
203 SupModuleList
= GetSplitValueList(ValueList
[1], ' ')
205 SupModuleList
= SUP_MODULE_LIST
206 self
._LibraryClass
.append(LibraryClassObject(LibraryClass
, SupModuleList
))
207 elif Name
== 'ENTRY_POINT':
208 if self
._ModuleEntryPointList
is None:
209 self
._ModuleEntryPointList
= []
210 self
._ModuleEntryPointList
.append(Value
)
211 elif Name
== 'UNLOAD_IMAGE':
212 if self
._ModuleUnloadImageList
is None:
213 self
._ModuleUnloadImageList
= []
216 self
._ModuleUnloadImageList
.append(Value
)
217 elif Name
== 'CONSTRUCTOR':
218 if self
._ConstructorList
is None:
219 self
._ConstructorList
= []
222 self
._ConstructorList
.append(Value
)
223 elif Name
== 'DESTRUCTOR':
224 if self
._DestructorList
is None:
225 self
._DestructorList
= []
228 self
._DestructorList
.append(Value
)
229 elif Name
== TAB_INF_DEFINES_CUSTOM_MAKEFILE
:
230 TokenList
= GetSplitValueList(Value
)
231 if self
._CustomMakefile
is None:
232 self
._CustomMakefile
= {}
233 if len(TokenList
) < 2:
234 self
._CustomMakefile
[TAB_COMPILER_MSFT
] = TokenList
[0]
235 self
._CustomMakefile
['GCC'] = TokenList
[0]
237 if TokenList
[0] not in [TAB_COMPILER_MSFT
, 'GCC']:
238 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
239 "No supported family [%s]" % TokenList
[0],
240 File
=self
.MetaFile
, Line
=Record
[-1])
241 self
._CustomMakefile
[TokenList
[0]] = TokenList
[1]
243 self
._Defs
[Name
] = Value
244 self
._Macros
[Name
] = Value
247 # Retrieve information in sections specific to Edk.x modules
249 if self
.AutoGenVersion
>= 0x00010005:
250 if not self
._ModuleType
:
251 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
252 "MODULE_TYPE is not given", File
=self
.MetaFile
)
253 if self
._ModuleType
not in SUP_MODULE_LIST
:
254 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
255 for Record
in RecordList
:
257 if Name
== "MODULE_TYPE":
260 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
261 "MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self
._ModuleType
, ' '.join(l
for l
in SUP_MODULE_LIST
)),
262 File
=self
.MetaFile
, Line
=LineNo
)
263 if (self
._Specification
is None) or (not 'PI_SPECIFICATION_VERSION' in self
._Specification
) or (int(self
._Specification
['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):
264 if self
._ModuleType
== SUP_MODULE_SMM_CORE
:
265 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
)
266 if (self
._Specification
is None) or (not 'PI_SPECIFICATION_VERSION' in self
._Specification
) or (int(self
._Specification
['PI_SPECIFICATION_VERSION'], 16) < 0x00010032):
267 if self
._ModuleType
== SUP_MODULE_MM_CORE_STANDALONE
:
268 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "MM_CORE_STANDALONE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x00010032", File
=self
.MetaFile
)
269 if self
._ModuleType
== SUP_MODULE_MM_STANDALONE
:
270 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "MM_STANDALONE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x00010032", File
=self
.MetaFile
)
271 if 'PCI_DEVICE_ID' in self
._Defs
and 'PCI_VENDOR_ID' in self
._Defs \
272 and 'PCI_CLASS_CODE' in self
._Defs
and 'PCI_REVISION' in self
._Defs
:
273 self
._BuildType
= 'UEFI_OPTIONROM'
274 if 'PCI_COMPRESS' in self
._Defs
:
275 if self
._Defs
['PCI_COMPRESS'] not in ('TRUE', 'FALSE'):
276 EdkLogger
.error("build", FORMAT_INVALID
, "Expected TRUE/FALSE for PCI_COMPRESS: %s" % self
.MetaFile
)
278 elif 'UEFI_HII_RESOURCE_SECTION' in self
._Defs \
279 and self
._Defs
['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':
280 self
._BuildType
= 'UEFI_HII'
282 self
._BuildType
= self
._ModuleType
.upper()
285 File
= PathClass(NormPath(self
._DxsFile
), self
._ModuleDir
, Arch
=self
._Arch
)
286 # check the file validation
287 ErrorCode
, ErrorInfo
= File
.Validate(".dxs", CaseSensitive
=False)
289 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
,
290 File
=self
.MetaFile
, Line
=LineNo
)
291 if not self
._DependencyFileList
:
292 self
._DependencyFileList
= []
293 self
._DependencyFileList
.append(File
)
295 if not self
._ComponentType
:
296 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
297 "COMPONENT_TYPE is not given", File
=self
.MetaFile
)
298 self
._BuildType
= self
._ComponentType
.upper()
299 if self
._ComponentType
in COMPONENT_TO_MODULE_MAP_DICT
:
300 self
._ModuleType
= COMPONENT_TO_MODULE_MAP_DICT
[self
._ComponentType
]
301 if self
._ComponentType
== EDK_COMPONENT_TYPE_LIBRARY
:
302 self
._LibraryClass
= [LibraryClassObject(self
._BaseName
, SUP_MODULE_LIST
)]
303 # make use some [nmake] section macros
304 Macros
= self
._Macros
305 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
306 Macros
['PROCESSOR'] = self
._Arch
307 RecordList
= self
._RawData
[MODEL_META_DATA_NMAKE
, self
._Arch
, self
._Platform
]
308 for Name
, Value
, Dummy
, Arch
, Platform
, ID
, LineNo
in RecordList
:
309 Value
= ReplaceMacro(Value
, Macros
, True)
310 if Name
== "IMAGE_ENTRY_POINT":
311 if self
._ModuleEntryPointList
is None:
312 self
._ModuleEntryPointList
= []
313 self
._ModuleEntryPointList
.append(Value
)
314 elif Name
== "DPX_SOURCE":
315 File
= PathClass(NormPath(Value
), self
._ModuleDir
, Arch
=self
._Arch
)
316 # check the file validation
317 ErrorCode
, ErrorInfo
= File
.Validate(".dxs", CaseSensitive
=False)
319 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
,
320 File
=self
.MetaFile
, Line
=LineNo
)
321 if not self
._DependencyFileList
:
322 self
._DependencyFileList
= []
323 self
._DependencyFileList
.append(File
)
325 ToolList
= self
._NMAKE
_FLAG
_PATTERN
_.findall(Name
)
326 if len(ToolList
) == 1:
327 if self
._BuildOptions
is None:
328 self
._BuildOptions
= OrderedDict()
330 if ToolList
[0] in self
._TOOL
_CODE
_:
331 Tool
= self
._TOOL
_CODE
_[ToolList
[0]]
334 ToolChain
= "*_*_*_%s_FLAGS" % Tool
335 # Edk.x only support MSFT tool chain
336 # ignore not replaced macros in value
337 ValueList
= GetSplitList(' ' + Value
, '/D')
339 for Index
in range(1, len(ValueList
)):
340 if ValueList
[Index
][-1] == '=' or ValueList
[Index
] == '':
342 Dummy
= Dummy
+ ' /D ' + ValueList
[Index
]
343 Value
= Dummy
.strip()
344 if (TAB_COMPILER_MSFT
, ToolChain
) not in self
._BuildOptions
:
345 self
._BuildOptions
[TAB_COMPILER_MSFT
, ToolChain
] = Value
347 OptionString
= self
._BuildOptions
[TAB_COMPILER_MSFT
, ToolChain
]
348 self
._BuildOptions
[TAB_COMPILER_MSFT
, ToolChain
] = OptionString
+ " " + Value
350 ## Retrieve file version
352 def AutoGenVersion(self
):
354 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
355 for Record
in RecordList
:
356 if Record
[1] == TAB_INF_DEFINES_INF_VERSION
:
358 ValueList
= Record
[2].split('.')
359 Major
= '%04o' % int(ValueList
[0], 0)
360 Minor
= '%04o' % int(ValueList
[1], 0)
361 RetVal
= int('0x' + Major
+ Minor
, 0)
363 RetVal
= int(Record
[2], 0)
367 ## Retrieve BASE_NAME
370 if self
._BaseName
is None:
371 self
._GetHeaderInfo
()
372 if self
._BaseName
is None:
373 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BASE_NAME name", File
=self
.MetaFile
)
374 return self
._BaseName
379 if self
._DxsFile
is None:
380 self
._GetHeaderInfo
()
381 if self
._DxsFile
is None:
385 ## Retrieve MODULE_TYPE
387 def ModuleType(self
):
388 if self
._ModuleType
is None:
389 self
._GetHeaderInfo
()
390 if self
._ModuleType
is None:
391 self
._ModuleType
= SUP_MODULE_BASE
392 if self
._ModuleType
not in SUP_MODULE_LIST
:
393 self
._ModuleType
= SUP_MODULE_USER_DEFINED
394 return self
._ModuleType
396 ## Retrieve COMPONENT_TYPE
398 def ComponentType(self
):
399 if self
._ComponentType
is None:
400 self
._GetHeaderInfo
()
401 if self
._ComponentType
is None:
402 self
._ComponentType
= SUP_MODULE_USER_DEFINED
403 return self
._ComponentType
405 ## Retrieve "BUILD_TYPE"
408 if self
._BuildType
is None:
409 self
._GetHeaderInfo
()
410 if not self
._BuildType
:
411 self
._BuildType
= SUP_MODULE_BASE
412 return self
._BuildType
414 ## Retrieve file guid
417 if self
._Guid
is None:
418 self
._GetHeaderInfo
()
419 if self
._Guid
is None:
420 self
._Guid
= '00000000-0000-0000-0000-000000000000'
423 ## Retrieve module version
426 if self
._Version
is None:
427 self
._GetHeaderInfo
()
428 if self
._Version
is None:
429 self
._Version
= '0.0'
432 ## Retrieve PCD_IS_DRIVER
434 def PcdIsDriver(self
):
435 if self
._PcdIsDriver
is None:
436 self
._GetHeaderInfo
()
437 if self
._PcdIsDriver
is None:
438 self
._PcdIsDriver
= ''
439 return self
._PcdIsDriver
444 if self
._Shadow
is None:
445 self
._GetHeaderInfo
()
446 if self
._Shadow
and self
._Shadow
.upper() == 'TRUE':
452 ## Retrieve CUSTOM_MAKEFILE
454 def CustomMakefile(self
):
455 if self
._CustomMakefile
is None:
456 self
._GetHeaderInfo
()
457 if self
._CustomMakefile
is None:
458 self
._CustomMakefile
= {}
459 return self
._CustomMakefile
461 ## Retrieve EFI_SPECIFICATION_VERSION
463 def Specification(self
):
464 if self
._Specification
is None:
465 self
._GetHeaderInfo
()
466 if self
._Specification
is None:
467 self
._Specification
= {}
468 return self
._Specification
470 ## Retrieve LIBRARY_CLASS
472 def LibraryClass(self
):
473 if self
._LibraryClass
is None:
474 self
._GetHeaderInfo
()
475 if self
._LibraryClass
is None:
476 self
._LibraryClass
= []
477 return self
._LibraryClass
479 ## Retrieve ENTRY_POINT
481 def ModuleEntryPointList(self
):
482 if self
._ModuleEntryPointList
is None:
483 self
._GetHeaderInfo
()
484 if self
._ModuleEntryPointList
is None:
485 self
._ModuleEntryPointList
= []
486 return self
._ModuleEntryPointList
488 ## Retrieve UNLOAD_IMAGE
490 def ModuleUnloadImageList(self
):
491 if self
._ModuleUnloadImageList
is None:
492 self
._GetHeaderInfo
()
493 if self
._ModuleUnloadImageList
is None:
494 self
._ModuleUnloadImageList
= []
495 return self
._ModuleUnloadImageList
497 ## Retrieve CONSTRUCTOR
499 def ConstructorList(self
):
500 if self
._ConstructorList
is None:
501 self
._GetHeaderInfo
()
502 if self
._ConstructorList
is None:
503 self
._ConstructorList
= []
504 return self
._ConstructorList
506 ## Retrieve DESTRUCTOR
508 def DestructorList(self
):
509 if self
._DestructorList
is None:
510 self
._GetHeaderInfo
()
511 if self
._DestructorList
is None:
512 self
._DestructorList
= []
513 return self
._DestructorList
515 ## Retrieve definies other than above ones
518 self
._GetHeaderInfo
()
521 ## Retrieve binary files
522 @cached_class_function
523 def _GetBinaries(self
):
525 RecordList
= self
._RawData
[MODEL_EFI_BINARY_FILE
, self
._Arch
, self
._Platform
]
526 Macros
= self
._Macros
527 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
528 Macros
['PROCESSOR'] = self
._Arch
529 for Record
in RecordList
:
535 TokenList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
537 Target
= TokenList
[0]
538 if len(TokenList
) > 1:
539 FeatureFlag
= Record
[1:]
541 File
= PathClass(NormPath(Record
[1], Macros
), self
._ModuleDir
, '', FileType
, True, self
._Arch
, '', Target
)
542 # check the file validation
543 ErrorCode
, ErrorInfo
= File
.Validate()
545 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
549 ## Retrieve binary files with error check.
552 RetVal
= self
._GetBinaries
()
553 if GlobalData
.gIgnoreSource
and not RetVal
:
554 ErrorInfo
= "The INF file does not contain any RetVal to use in creating the image\n"
555 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
)
559 ## Retrieve source files
562 self
._GetHeaderInfo
()
563 # Ignore all source files in a binary build mode
564 if GlobalData
.gIgnoreSource
:
568 RecordList
= self
._RawData
[MODEL_EFI_SOURCE_FILE
, self
._Arch
, self
._Platform
]
569 Macros
= self
._Macros
570 for Record
in RecordList
:
572 ToolChainFamily
= Record
[1]
575 if self
.AutoGenVersion
< 0x00010005:
576 Macros
["EDK_SOURCE"] = GlobalData
.gEcpSource
577 Macros
['PROCESSOR'] = self
._Arch
578 SourceFile
= NormPath(Record
[0], Macros
)
579 if SourceFile
[0] == os
.path
.sep
:
580 SourceFile
= mws
.join(GlobalData
.gWorkspace
, SourceFile
[1:])
581 # old module source files (Edk)
582 File
= PathClass(SourceFile
, self
._ModuleDir
, self
._SourceOverridePath
,
583 '', False, self
._Arch
, ToolChainFamily
, '', TagName
, ToolCode
)
584 # check the file validation
585 ErrorCode
, ErrorInfo
= File
.Validate(CaseSensitive
=False)
587 if File
.Ext
.lower() == '.h':
588 EdkLogger
.warn('build', 'Include file not found', ExtraData
=ErrorInfo
,
589 File
=self
.MetaFile
, Line
=LineNo
)
592 EdkLogger
.error('build', ErrorCode
, ExtraData
=File
, File
=self
.MetaFile
, Line
=LineNo
)
594 File
= PathClass(NormPath(Record
[0], Macros
), self
._ModuleDir
, '',
595 '', False, self
._Arch
, ToolChainFamily
, '', TagName
, ToolCode
)
596 # check the file validation
597 ErrorCode
, ErrorInfo
= File
.Validate()
599 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
602 # add any previously found dependency files to the source list
603 if self
._DependencyFileList
:
604 RetVal
.extend(self
._DependencyFileList
)
607 ## Retrieve library classes employed by this module
609 def LibraryClasses(self
):
610 RetVal
= OrderedDict()
611 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, self
._Platform
]
612 for Record
in RecordList
:
616 Instance
= NormPath(Instance
, self
._Macros
)
617 RetVal
[Lib
] = Instance
620 ## Retrieve library names (for Edk.x style of modules)
624 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
, self
._Platform
]
625 for Record
in RecordList
:
626 LibraryName
= ReplaceMacro(Record
[0], self
._Macros
, False)
627 # in case of name with '.lib' extension, which is unusual in Edk.x inf
628 LibraryName
= os
.path
.splitext(LibraryName
)[0]
629 if LibraryName
not in RetVal
:
630 RetVal
.append(LibraryName
)
634 def ProtocolComments(self
):
636 return self
._ProtocolComments
638 ## Retrieve protocols consumed/produced by this module
641 RetVal
= OrderedDict()
642 self
._ProtocolComments
= OrderedDict()
643 RecordList
= self
._RawData
[MODEL_EFI_PROTOCOL
, self
._Arch
, self
._Platform
]
644 for Record
in RecordList
:
646 Value
= ProtocolValue(CName
, self
.Packages
, self
.MetaFile
.Path
)
648 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
649 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
650 "Value of Protocol [%s] is not found under [Protocols] section in" % CName
,
651 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
652 RetVal
[CName
] = Value
653 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
654 self
._ProtocolComments
[CName
] = [a
[0] for a
in CommentRecords
]
658 def PpiComments(self
):
660 return self
._PpiComments
662 ## Retrieve PPIs consumed/produced by this module
665 RetVal
= OrderedDict()
666 self
._PpiComments
= OrderedDict()
667 RecordList
= self
._RawData
[MODEL_EFI_PPI
, self
._Arch
, self
._Platform
]
668 for Record
in RecordList
:
670 Value
= PpiValue(CName
, self
.Packages
, self
.MetaFile
.Path
)
672 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
673 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
674 "Value of PPI [%s] is not found under [Ppis] section in " % CName
,
675 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
676 RetVal
[CName
] = Value
677 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
678 self
._PpiComments
[CName
] = [a
[0] for a
in CommentRecords
]
682 def GuidComments(self
):
684 return self
._GuidComments
686 ## Retrieve GUIDs consumed/produced by this module
689 RetVal
= OrderedDict()
690 self
._GuidComments
= OrderedDict()
691 RecordList
= self
._RawData
[MODEL_EFI_GUID
, self
._Arch
, self
._Platform
]
692 for Record
in RecordList
:
694 Value
= GuidValue(CName
, self
.Packages
, self
.MetaFile
.Path
)
696 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
697 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
698 "Value of Guid [%s] is not found under [Guids] section in" % CName
,
699 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
700 RetVal
[CName
] = Value
701 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Record
[5]]
702 self
._GuidComments
[CName
] = [a
[0] for a
in CommentRecords
]
705 ## Retrieve include paths necessary for this module (for Edk.x style of modules)
709 if self
._SourceOverridePath
:
710 RetVal
.append(self
._SourceOverridePath
)
712 Macros
= self
._Macros
713 Macros
['PROCESSOR'] = GlobalData
.gEdkGlobal
.get('PROCESSOR', self
._Arch
)
714 RecordList
= self
._RawData
[MODEL_EFI_INCLUDE
, self
._Arch
, self
._Platform
]
715 for Record
in RecordList
:
716 if Record
[0].find('EDK_SOURCE') > -1:
717 Macros
['EDK_SOURCE'] = GlobalData
.gEcpSource
718 File
= NormPath(Record
[0], self
._Macros
)
720 File
= os
.path
.join(self
._ModuleDir
, File
)
722 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
723 File
= RealPath(os
.path
.normpath(File
))
727 # TRICK: let compiler to choose correct header file
728 Macros
['EDK_SOURCE'] = GlobalData
.gEdkSource
729 File
= NormPath(Record
[0], self
._Macros
)
731 File
= os
.path
.join(self
._ModuleDir
, File
)
733 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
734 File
= RealPath(os
.path
.normpath(File
))
738 File
= NormPath(Record
[0], Macros
)
740 File
= os
.path
.join(self
._ModuleDir
, File
)
742 File
= mws
.join(GlobalData
.gWorkspace
, File
)
743 File
= RealPath(os
.path
.normpath(File
))
746 if not File
and Record
[0].find('EFI_SOURCE') > -1:
747 # tricky to regard WorkSpace as EFI_SOURCE
748 Macros
['EFI_SOURCE'] = GlobalData
.gWorkspace
749 File
= NormPath(Record
[0], Macros
)
751 File
= os
.path
.join(self
._ModuleDir
, File
)
753 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
754 File
= RealPath(os
.path
.normpath(File
))
759 ## Retrieve packages this module depends on
763 RecordList
= self
._RawData
[MODEL_META_DATA_PACKAGE
, self
._Arch
, self
._Platform
]
764 Macros
= self
._Macros
765 Macros
['EDK_SOURCE'] = GlobalData
.gEcpSource
766 for Record
in RecordList
:
767 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
768 # check the file validation
769 ErrorCode
, ErrorInfo
= File
.Validate('.dec')
772 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
773 # parse this package now. we need it to get protocol/ppi/guid value
774 RetVal
.append(self
._Bdb
[File
, self
._Arch
, self
._Target
, self
._Toolchain
])
777 ## Retrieve PCD comments
779 def PcdComments(self
):
781 return self
._PcdComments
783 ## Retrieve PCDs used in this module
786 self
._PcdComments
= OrderedDict()
787 RetVal
= OrderedDict()
788 RetVal
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
789 RetVal
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
790 RetVal
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
791 RetVal
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC
))
792 RetVal
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC_EX
))
795 ## Retrieve build options specific to this module
797 def BuildOptions(self
):
798 if self
._BuildOptions
is None:
799 self
._BuildOptions
= OrderedDict()
800 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, self
._Platform
]
801 for Record
in RecordList
:
802 ToolChainFamily
= Record
[0]
803 ToolChain
= Record
[1]
805 if (ToolChainFamily
, ToolChain
) not in self
._BuildOptions
or Option
.startswith('='):
806 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = Option
808 # concatenate the option string if they're for the same tool
809 OptionString
= self
._BuildOptions
[ToolChainFamily
, ToolChain
]
810 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
811 return self
._BuildOptions
813 ## Retrieve dependency expression
816 RetVal
= tdict(False, 2)
818 # If the module has only Binaries and no Sources, then ignore [Depex]
819 if not self
.Sources
and self
.Binaries
:
822 RecordList
= self
._RawData
[MODEL_EFI_DEPEX
, self
._Arch
]
823 # PEIM and DXE drivers must have a valid [Depex] section
824 if len(self
.LibraryClass
) == 0 and len(RecordList
) == 0:
825 if self
.ModuleType
== SUP_MODULE_DXE_DRIVER
or self
.ModuleType
== SUP_MODULE_PEIM
or self
.ModuleType
== SUP_MODULE_DXE_SMM_DRIVER
or \
826 self
.ModuleType
== SUP_MODULE_DXE_SAL_DRIVER
or self
.ModuleType
== SUP_MODULE_DXE_RUNTIME_DRIVER
:
827 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
828 % self
.ModuleType
, File
=self
.MetaFile
)
830 if len(RecordList
) != 0 and self
.ModuleType
== SUP_MODULE_USER_DEFINED
:
831 for Record
in RecordList
:
832 if Record
[4] not in [SUP_MODULE_PEIM
, SUP_MODULE_DXE_DRIVER
, SUP_MODULE_DXE_SMM_DRIVER
]:
833 EdkLogger
.error('build', FORMAT_INVALID
,
834 "'%s' module must specify the type of [Depex] section" % self
.ModuleType
,
837 TemporaryDictionary
= OrderedDict()
838 for Record
in RecordList
:
839 DepexStr
= ReplaceMacro(Record
[0], self
._Macros
, False)
841 ModuleType
= Record
[4]
842 TokenList
= DepexStr
.split()
843 if (Arch
, ModuleType
) not in TemporaryDictionary
:
844 TemporaryDictionary
[Arch
, ModuleType
] = []
845 DepexList
= TemporaryDictionary
[Arch
, ModuleType
]
846 for Token
in TokenList
:
847 if Token
in DEPEX_SUPPORTED_OPCODE_SET
:
848 DepexList
.append(Token
)
849 elif Token
.endswith(".inf"): # module file name
850 ModuleFile
= os
.path
.normpath(Token
)
851 Module
= self
.BuildDatabase
[ModuleFile
]
853 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "Module is not found in active platform",
854 ExtraData
=Token
, File
=self
.MetaFile
, Line
=Record
[-1])
855 DepexList
.append(Module
.Guid
)
857 # it use the Fixed PCD format
859 if tuple(Token
.split('.')[::-1]) not in self
.Pcds
:
860 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "PCD [{}] used in [Depex] section should be listed in module PCD section".format(Token
), File
=self
.MetaFile
, Line
=Record
[-1])
862 if self
.Pcds
[tuple(Token
.split('.')[::-1])].DatumType
!= TAB_VOID
:
863 EdkLogger
.error('build', FORMAT_INVALID
, "PCD [{}] used in [Depex] section should be VOID* datum type".format(Token
), File
=self
.MetaFile
, Line
=Record
[-1])
866 # get the GUID value now
867 Value
= ProtocolValue(Token
, self
.Packages
, self
.MetaFile
.Path
)
869 Value
= PpiValue(Token
, self
.Packages
, self
.MetaFile
.Path
)
871 Value
= GuidValue(Token
, self
.Packages
, self
.MetaFile
.Path
)
874 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
875 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
876 "Value of [%s] is not found in" % Token
,
877 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
878 DepexList
.append(Value
)
879 for Arch
, ModuleType
in TemporaryDictionary
:
880 RetVal
[Arch
, ModuleType
] = TemporaryDictionary
[Arch
, ModuleType
]
883 ## Retrieve depedency expression
885 def DepexExpression(self
):
886 RetVal
= tdict(False, 2)
887 RecordList
= self
._RawData
[MODEL_EFI_DEPEX
, self
._Arch
]
888 TemporaryDictionary
= OrderedDict()
889 for Record
in RecordList
:
890 DepexStr
= ReplaceMacro(Record
[0], self
._Macros
, False)
892 ModuleType
= Record
[4]
893 TokenList
= DepexStr
.split()
894 if (Arch
, ModuleType
) not in TemporaryDictionary
:
895 TemporaryDictionary
[Arch
, ModuleType
] = ''
896 for Token
in TokenList
:
897 TemporaryDictionary
[Arch
, ModuleType
] = TemporaryDictionary
[Arch
, ModuleType
] + Token
.strip() + ' '
898 for Arch
, ModuleType
in TemporaryDictionary
:
899 RetVal
[Arch
, ModuleType
] = TemporaryDictionary
[Arch
, ModuleType
]
902 @cached_class_function
903 def GetGuidsUsedByPcd(self
):
905 return self
._GuidsUsedByPcd
907 ## Retrieve PCD for given type
908 def _GetPcd(self
, Type
):
910 PcdDict
= tdict(True, 4)
912 RecordList
= self
._RawData
[Type
, self
._Arch
, self
._Platform
]
913 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, Platform
, Id
, LineNo
in RecordList
:
914 PcdDict
[Arch
, Platform
, PcdCName
, TokenSpaceGuid
] = (Setting
, LineNo
)
915 PcdList
.append((PcdCName
, TokenSpaceGuid
))
917 if TokenSpaceGuid
not in self
.Guids
:
918 Value
= GuidValue(TokenSpaceGuid
, self
.Packages
, self
.MetaFile
.Path
)
920 PackageList
= "\n\t".join(str(P
) for P
in self
.Packages
)
921 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
922 "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid
,
923 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=LineNo
)
924 self
.Guids
[TokenSpaceGuid
] = Value
925 self
._GuidsUsedByPcd
[TokenSpaceGuid
] = Value
926 CommentRecords
= self
._RawData
[MODEL_META_DATA_COMMENT
, self
._Arch
, self
._Platform
, Id
]
928 for CmtRec
in CommentRecords
:
929 Comments
.append(CmtRec
[0])
930 self
._PcdComments
[TokenSpaceGuid
, PcdCName
] = Comments
932 # resolve PCD type, value, datum info, etc. by getting its definition from package
933 _GuidDict
= self
.Guids
.copy()
934 for PcdCName
, TokenSpaceGuid
in PcdList
:
935 PcdRealName
= PcdCName
936 Setting
, LineNo
= PcdDict
[self
._Arch
, self
.Platform
, PcdCName
, TokenSpaceGuid
]
939 ValueList
= AnalyzePcdData(Setting
)
940 DefaultValue
= ValueList
[0]
941 Pcd
= PcdClassObject(
951 self
.Guids
[TokenSpaceGuid
]
953 if Type
== MODEL_PCD_PATCHABLE_IN_MODULE
and ValueList
[1]:
954 # Patch PCD: TokenSpace.PcdCName|Value|Offset
955 Pcd
.Offset
= ValueList
[1]
957 if (PcdRealName
, TokenSpaceGuid
) in GlobalData
.MixedPcd
:
958 for Package
in self
.Packages
:
959 for key
in Package
.Pcds
:
960 if (Package
.Pcds
[key
].TokenCName
, Package
.Pcds
[key
].TokenSpaceGuidCName
) == (PcdRealName
, TokenSpaceGuid
):
961 for item
in GlobalData
.MixedPcd
[(PcdRealName
, TokenSpaceGuid
)]:
962 Pcd_Type
= item
[0].split('_')[-1]
963 if Pcd_Type
== Package
.Pcds
[key
].Type
:
964 Value
= Package
.Pcds
[key
]
965 Value
.TokenCName
= Package
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
967 newkey
= (Value
.TokenCName
, key
[1])
969 newkey
= (Value
.TokenCName
, key
[1], key
[2])
970 del Package
.Pcds
[key
]
971 Package
.Pcds
[newkey
] = Value
978 # get necessary info from package declaring this PCD
979 for Package
in self
.Packages
:
981 # 'dynamic' in INF means its type is determined by platform;
982 # if platform doesn't give its type, use 'lowest' one in the
983 # following order, if any
985 # TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_PATCHABLE_IN_MODULE, TAB_PCDS_FEATURE_FLAG, TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_EX
987 _GuidDict
.update(Package
.Guids
)
988 PcdType
= self
._PCD
_TYPE
_STRING
_[Type
]
989 if Type
== MODEL_PCD_DYNAMIC
:
991 for T
in PCD_TYPE_LIST
:
992 if (PcdRealName
, TokenSpaceGuid
) in GlobalData
.MixedPcd
:
993 for item
in GlobalData
.MixedPcd
[(PcdRealName
, TokenSpaceGuid
)]:
994 if str(item
[0]).endswith(T
) and (item
[0], item
[1], T
) in Package
.Pcds
:
1002 if (PcdRealName
, TokenSpaceGuid
, T
) in Package
.Pcds
:
1008 if (PcdRealName
, TokenSpaceGuid
) in GlobalData
.MixedPcd
:
1009 for item
in GlobalData
.MixedPcd
[(PcdRealName
, TokenSpaceGuid
)]:
1010 Pcd_Type
= item
[0].split('_')[-1]
1011 if Pcd_Type
== PcdType
:
1019 if (PcdCName
, TokenSpaceGuid
, PcdType
) in Package
.Pcds
:
1020 PcdInPackage
= Package
.Pcds
[PcdCName
, TokenSpaceGuid
, PcdType
]
1022 Pcd
.TokenValue
= PcdInPackage
.TokenValue
1025 # Check whether the token value exist or not.
1027 if Pcd
.TokenValue
is None or Pcd
.TokenValue
== "":
1031 "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid
, PcdRealName
, str(Package
)),
1032 File
=self
.MetaFile
, Line
=LineNo
,
1036 # Check hexadecimal token value length and format.
1038 ReIsValidPcdTokenValue
= re
.compile(r
"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re
.DOTALL
)
1039 if Pcd
.TokenValue
.startswith("0x") or Pcd
.TokenValue
.startswith("0X"):
1040 if ReIsValidPcdTokenValue
.match(Pcd
.TokenValue
) is None:
1044 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdRealName
, str(Package
)),
1045 File
=self
.MetaFile
, Line
=LineNo
,
1050 # Check decimal token value length and format.
1054 TokenValueInt
= int (Pcd
.TokenValue
, 10)
1055 if (TokenValueInt
< 0 or TokenValueInt
> 4294967295):
1059 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, as a decimal it should between: 0 - 4294967295!" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdRealName
, str(Package
)),
1060 File
=self
.MetaFile
, Line
=LineNo
,
1067 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, it should be hexadecimal or decimal!" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdRealName
, str(Package
)),
1068 File
=self
.MetaFile
, Line
=LineNo
,
1072 Pcd
.DatumType
= PcdInPackage
.DatumType
1073 Pcd
.MaxDatumSize
= PcdInPackage
.MaxDatumSize
1074 Pcd
.InfDefaultValue
= Pcd
.DefaultValue
1075 if not Pcd
.DefaultValue
:
1076 Pcd
.DefaultValue
= PcdInPackage
.DefaultValue
1079 Pcd
.DefaultValue
= ValueExpressionEx(Pcd
.DefaultValue
, Pcd
.DatumType
, _GuidDict
)(True)
1080 except BadExpression
as Value
:
1081 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %(TokenSpaceGuid
, PcdRealName
, Pcd
.DefaultValue
, Value
),
1082 File
=self
.MetaFile
, Line
=LineNo
)
1088 "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid
, PcdRealName
, self
.MetaFile
),
1089 File
=self
.MetaFile
, Line
=LineNo
,
1090 ExtraData
="\t%s" % '\n\t'.join(str(P
) for P
in self
.Packages
)
1092 Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
1096 ## check whether current module is binary module
1098 def IsBinaryModule(self
):
1099 if (self
.Binaries
and not self
.Sources
) or GlobalData
.gIgnoreSource
: