]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Workspace/InfBuildData.py
BaseTools: Optimize string concatenation
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / InfBuildData.py
1 ## @file
2 # This file is used to create a database used by build tool
3 #
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
10 #
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.
13 #
14
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
19 from types import *
20 from .MetaFileParser import *
21 from collections import OrderedDict
22 from Workspace.BuildClassObject import ModuleBuildClassObject, LibraryClassObject, PcdClassObject
23
24 ## Module build information from INF file
25 #
26 # This class is used to retrieve information stored in database and convert them
27 # into ModuleBuildClassObject form for easier use for AutoGen.
28 #
29 class InfBuildData(ModuleBuildClassObject):
30 # dict used to convert PCD type in database to string used by build tool
31 _PCD_TYPE_STRING_ = {
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,
43 }
44
45 # dict used to convert part of [Defines] to members of InfBuildData directly
46 _PROPERTY_ = {
47 #
48 # Required Fields
49 #
50 TAB_INF_DEFINES_BASE_NAME : "_BaseName",
51 TAB_INF_DEFINES_FILE_GUID : "_Guid",
52 TAB_INF_DEFINES_MODULE_TYPE : "_ModuleType",
53 #
54 # Optional Fields
55 #
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",
66
67 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH : "_SourceOverridePath",
68 }
69
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
73 _TOOL_CODE_ = {
74 "C" : "CC",
75 BINARY_FILE_TYPE_LIB : "SLINK",
76 "LINK" : "DLINK",
77 }
78
79
80 ## Constructor of InfBuildData
81 #
82 # Initialize object of InfBuildData
83 #
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
90 #
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
96 self._Arch = Arch
97 self._Target = Target
98 self._Toolchain = Toolchain
99 self._Platform = TAB_COMMON
100 if FilePath.Key in GlobalData.gOverrideDir:
101 self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key]
102 else:
103 self._SourceOverridePath = None
104 self._TailComments = None
105 self._BaseName = None
106 self._DxsFile = None
107 self._ModuleType = None
108 self._ComponentType = None
109 self._BuildType = None
110 self._Guid = None
111 self._Version = None
112 self._PcdIsDriver = None
113 self._BinaryModule = None
114 self._Shadow = 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
131
132 ## XXX[key] = value
133 def __setitem__(self, key, value):
134 self.__dict__[self._PROPERTY_[key]] = value
135
136 ## value = XXX[key]
137 def __getitem__(self, key):
138 return self.__dict__[self._PROPERTY_[key]]
139
140 ## "in" test support
141 def __contains__(self, key):
142 return key in self._PROPERTY_
143
144 ## Get current effective macros
145 @cached_property
146 def _Macros(self):
147 RetVal = {}
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)
152 return RetVal
153
154 ## Get architecture
155 @cached_property
156 def Arch(self):
157 return self._Arch
158
159 ## Return the name of platform employing this module
160 @cached_property
161 def Platform(self):
162 return self._Platform
163
164 @cached_property
165 def HeaderComments(self):
166 return [a[0] for a in self._RawData[MODEL_META_DATA_HEADER_COMMENT]]
167
168 @cached_property
169 def TailComments(self):
170 return [a[0] for a in self._RawData[MODEL_META_DATA_TAIL_COMMENT]]
171
172 ## Retrieve all information in [Defines] section
173 #
174 # (Retriving all [Defines] information in one-shot is just to save time.)
175 #
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
182 if Name in self:
183 self[Name] = Value
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], ' ')
204 else:
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 = []
214 if not Value:
215 continue
216 self._ModuleUnloadImageList.append(Value)
217 elif Name == 'CONSTRUCTOR':
218 if self._ConstructorList is None:
219 self._ConstructorList = []
220 if not Value:
221 continue
222 self._ConstructorList.append(Value)
223 elif Name == 'DESTRUCTOR':
224 if self._DestructorList is None:
225 self._DestructorList = []
226 if not Value:
227 continue
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]
236 else:
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]
242 else:
243 self._Defs[Name] = Value
244 self._Macros[Name] = Value
245
246 #
247 # Retrieve information in sections specific to Edk.x modules
248 #
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:
256 Name = Record[1]
257 if Name == "MODULE_TYPE":
258 LineNo = Record[6]
259 break
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)
277
278 elif 'UEFI_HII_RESOURCE_SECTION' in self._Defs \
279 and self._Defs['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':
280 self._BuildType = 'UEFI_HII'
281 else:
282 self._BuildType = self._ModuleType.upper()
283
284 if self._DxsFile:
285 File = PathClass(NormPath(self._DxsFile), self._ModuleDir, Arch=self._Arch)
286 # check the file validation
287 ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)
288 if ErrorCode != 0:
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)
294 else:
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)
318 if ErrorCode != 0:
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)
324 else:
325 ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name)
326 if len(ToolList) == 1:
327 if self._BuildOptions is None:
328 self._BuildOptions = OrderedDict()
329
330 if ToolList[0] in self._TOOL_CODE_:
331 Tool = self._TOOL_CODE_[ToolList[0]]
332 else:
333 Tool = 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')
338 Dummy = ValueList[0]
339 for Index in range(1, len(ValueList)):
340 if ValueList[Index][-1] == '=' or ValueList[Index] == '':
341 continue
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
346 else:
347 OptionString = self._BuildOptions[TAB_COMPILER_MSFT, ToolChain]
348 self._BuildOptions[TAB_COMPILER_MSFT, ToolChain] = OptionString + " " + Value
349
350 ## Retrieve file version
351 @cached_property
352 def AutoGenVersion(self):
353 RetVal = 0x00010000
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:
357 if '.' in Record[2]:
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)
362 else:
363 RetVal = int(Record[2], 0)
364 break
365 return RetVal
366
367 ## Retrieve BASE_NAME
368 @cached_property
369 def BaseName(self):
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
375
376 ## Retrieve DxsFile
377 @cached_property
378 def DxsFile(self):
379 if self._DxsFile is None:
380 self._GetHeaderInfo()
381 if self._DxsFile is None:
382 self._DxsFile = ''
383 return self._DxsFile
384
385 ## Retrieve MODULE_TYPE
386 @cached_property
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
395
396 ## Retrieve COMPONENT_TYPE
397 @cached_property
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
404
405 ## Retrieve "BUILD_TYPE"
406 @cached_property
407 def BuildType(self):
408 if self._BuildType is None:
409 self._GetHeaderInfo()
410 if not self._BuildType:
411 self._BuildType = SUP_MODULE_BASE
412 return self._BuildType
413
414 ## Retrieve file guid
415 @cached_property
416 def Guid(self):
417 if self._Guid is None:
418 self._GetHeaderInfo()
419 if self._Guid is None:
420 self._Guid = '00000000-0000-0000-0000-000000000000'
421 return self._Guid
422
423 ## Retrieve module version
424 @cached_property
425 def Version(self):
426 if self._Version is None:
427 self._GetHeaderInfo()
428 if self._Version is None:
429 self._Version = '0.0'
430 return self._Version
431
432 ## Retrieve PCD_IS_DRIVER
433 @cached_property
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
440
441 ## Retrieve SHADOW
442 @cached_property
443 def Shadow(self):
444 if self._Shadow is None:
445 self._GetHeaderInfo()
446 if self._Shadow and self._Shadow.upper() == 'TRUE':
447 self._Shadow = True
448 else:
449 self._Shadow = False
450 return self._Shadow
451
452 ## Retrieve CUSTOM_MAKEFILE
453 @cached_property
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
460
461 ## Retrieve EFI_SPECIFICATION_VERSION
462 @cached_property
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
469
470 ## Retrieve LIBRARY_CLASS
471 @cached_property
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
478
479 ## Retrieve ENTRY_POINT
480 @cached_property
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
487
488 ## Retrieve UNLOAD_IMAGE
489 @cached_property
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
496
497 ## Retrieve CONSTRUCTOR
498 @cached_property
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
505
506 ## Retrieve DESTRUCTOR
507 @cached_property
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
514
515 ## Retrieve definies other than above ones
516 @cached_property
517 def Defines(self):
518 self._GetHeaderInfo()
519 return self._Defs
520
521 ## Retrieve binary files
522 @cached_class_function
523 def _GetBinaries(self):
524 RetVal = []
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:
530 FileType = Record[0]
531 LineNo = Record[-1]
532 Target = TAB_COMMON
533 FeatureFlag = []
534 if Record[2]:
535 TokenList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)
536 if TokenList:
537 Target = TokenList[0]
538 if len(TokenList) > 1:
539 FeatureFlag = Record[1:]
540
541 File = PathClass(NormPath(Record[1], Macros), self._ModuleDir, '', FileType, True, self._Arch, '', Target)
542 # check the file validation
543 ErrorCode, ErrorInfo = File.Validate()
544 if ErrorCode != 0:
545 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
546 RetVal.append(File)
547 return RetVal
548
549 ## Retrieve binary files with error check.
550 @cached_property
551 def Binaries(self):
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)
556
557 return RetVal
558
559 ## Retrieve source files
560 @cached_property
561 def Sources(self):
562 self._GetHeaderInfo()
563 # Ignore all source files in a binary build mode
564 if GlobalData.gIgnoreSource:
565 return []
566
567 RetVal = []
568 RecordList = self._RawData[MODEL_EFI_SOURCE_FILE, self._Arch, self._Platform]
569 Macros = self._Macros
570 for Record in RecordList:
571 LineNo = Record[-1]
572 ToolChainFamily = Record[1]
573 TagName = Record[2]
574 ToolCode = Record[3]
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)
586 if ErrorCode != 0:
587 if File.Ext.lower() == '.h':
588 EdkLogger.warn('build', 'Include file not found', ExtraData=ErrorInfo,
589 File=self.MetaFile, Line=LineNo)
590 continue
591 else:
592 EdkLogger.error('build', ErrorCode, ExtraData=File, File=self.MetaFile, Line=LineNo)
593 else:
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()
598 if ErrorCode != 0:
599 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
600
601 RetVal.append(File)
602 # add any previously found dependency files to the source list
603 if self._DependencyFileList:
604 RetVal.extend(self._DependencyFileList)
605 return RetVal
606
607 ## Retrieve library classes employed by this module
608 @cached_property
609 def LibraryClasses(self):
610 RetVal = OrderedDict()
611 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform]
612 for Record in RecordList:
613 Lib = Record[0]
614 Instance = Record[1]
615 if Instance:
616 Instance = NormPath(Instance, self._Macros)
617 RetVal[Lib] = Instance
618 else:
619 RetVal[Lib] = None
620 return RetVal
621
622 ## Retrieve library names (for Edk.x style of modules)
623 @cached_property
624 def Libraries(self):
625 RetVal = []
626 RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch, self._Platform]
627 for Record in RecordList:
628 LibraryName = ReplaceMacro(Record[0], self._Macros, False)
629 # in case of name with '.lib' extension, which is unusual in Edk.x inf
630 LibraryName = os.path.splitext(LibraryName)[0]
631 if LibraryName not in RetVal:
632 RetVal.append(LibraryName)
633 return RetVal
634
635 @cached_property
636 def ProtocolComments(self):
637 self.Protocols
638 return self._ProtocolComments
639
640 ## Retrieve protocols consumed/produced by this module
641 @cached_property
642 def Protocols(self):
643 RetVal = OrderedDict()
644 self._ProtocolComments = OrderedDict()
645 RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self._Platform]
646 for Record in RecordList:
647 CName = Record[0]
648 Value = ProtocolValue(CName, self.Packages, self.MetaFile.Path)
649 if Value is None:
650 PackageList = "\n\t".join(str(P) for P in self.Packages)
651 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
652 "Value of Protocol [%s] is not found under [Protocols] section in" % CName,
653 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
654 RetVal[CName] = Value
655 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
656 self._ProtocolComments[CName] = [a[0] for a in CommentRecords]
657 return RetVal
658
659 @cached_property
660 def PpiComments(self):
661 self.Ppis
662 return self._PpiComments
663
664 ## Retrieve PPIs consumed/produced by this module
665 @cached_property
666 def Ppis(self):
667 RetVal = OrderedDict()
668 self._PpiComments = OrderedDict()
669 RecordList = self._RawData[MODEL_EFI_PPI, self._Arch, self._Platform]
670 for Record in RecordList:
671 CName = Record[0]
672 Value = PpiValue(CName, self.Packages, self.MetaFile.Path)
673 if Value is None:
674 PackageList = "\n\t".join(str(P) for P in self.Packages)
675 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
676 "Value of PPI [%s] is not found under [Ppis] section in " % CName,
677 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
678 RetVal[CName] = Value
679 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
680 self._PpiComments[CName] = [a[0] for a in CommentRecords]
681 return RetVal
682
683 @cached_property
684 def GuidComments(self):
685 self.Guids
686 return self._GuidComments
687
688 ## Retrieve GUIDs consumed/produced by this module
689 @cached_property
690 def Guids(self):
691 RetVal = OrderedDict()
692 self._GuidComments = OrderedDict()
693 RecordList = self._RawData[MODEL_EFI_GUID, self._Arch, self._Platform]
694 for Record in RecordList:
695 CName = Record[0]
696 Value = GuidValue(CName, self.Packages, self.MetaFile.Path)
697 if Value is None:
698 PackageList = "\n\t".join(str(P) for P in self.Packages)
699 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
700 "Value of Guid [%s] is not found under [Guids] section in" % CName,
701 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
702 RetVal[CName] = Value
703 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
704 self._GuidComments[CName] = [a[0] for a in CommentRecords]
705 return RetVal
706
707 ## Retrieve include paths necessary for this module (for Edk.x style of modules)
708 @cached_property
709 def Includes(self):
710 RetVal = []
711 if self._SourceOverridePath:
712 RetVal.append(self._SourceOverridePath)
713
714 Macros = self._Macros
715 Macros['PROCESSOR'] = GlobalData.gEdkGlobal.get('PROCESSOR', self._Arch)
716 RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform]
717 for Record in RecordList:
718 if Record[0].find('EDK_SOURCE') > -1:
719 Macros['EDK_SOURCE'] = GlobalData.gEcpSource
720 File = NormPath(Record[0], self._Macros)
721 if File[0] == '.':
722 File = os.path.join(self._ModuleDir, File)
723 else:
724 File = os.path.join(GlobalData.gWorkspace, File)
725 File = RealPath(os.path.normpath(File))
726 if File:
727 RetVal.append(File)
728
729 # TRICK: let compiler to choose correct header file
730 Macros['EDK_SOURCE'] = GlobalData.gEdkSource
731 File = NormPath(Record[0], self._Macros)
732 if File[0] == '.':
733 File = os.path.join(self._ModuleDir, File)
734 else:
735 File = os.path.join(GlobalData.gWorkspace, File)
736 File = RealPath(os.path.normpath(File))
737 if File:
738 RetVal.append(File)
739 else:
740 File = NormPath(Record[0], Macros)
741 if File[0] == '.':
742 File = os.path.join(self._ModuleDir, File)
743 else:
744 File = mws.join(GlobalData.gWorkspace, File)
745 File = RealPath(os.path.normpath(File))
746 if File:
747 RetVal.append(File)
748 if not File and Record[0].find('EFI_SOURCE') > -1:
749 # tricky to regard WorkSpace as EFI_SOURCE
750 Macros['EFI_SOURCE'] = GlobalData.gWorkspace
751 File = NormPath(Record[0], Macros)
752 if File[0] == '.':
753 File = os.path.join(self._ModuleDir, File)
754 else:
755 File = os.path.join(GlobalData.gWorkspace, File)
756 File = RealPath(os.path.normpath(File))
757 if File:
758 RetVal.append(File)
759 return RetVal
760
761 ## Retrieve packages this module depends on
762 @cached_property
763 def Packages(self):
764 RetVal = []
765 RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch, self._Platform]
766 Macros = self._Macros
767 Macros['EDK_SOURCE'] = GlobalData.gEcpSource
768 for Record in RecordList:
769 File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
770 # check the file validation
771 ErrorCode, ErrorInfo = File.Validate('.dec')
772 if ErrorCode != 0:
773 LineNo = Record[-1]
774 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
775 # parse this package now. we need it to get protocol/ppi/guid value
776 RetVal.append(self._Bdb[File, self._Arch, self._Target, self._Toolchain])
777 return RetVal
778
779 ## Retrieve PCD comments
780 @cached_property
781 def PcdComments(self):
782 self.Pcds
783 return self._PcdComments
784
785 ## Retrieve PCDs used in this module
786 @cached_property
787 def Pcds(self):
788 self._PcdComments = OrderedDict()
789 RetVal = OrderedDict()
790 RetVal.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
791 RetVal.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
792 RetVal.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
793 RetVal.update(self._GetPcd(MODEL_PCD_DYNAMIC))
794 RetVal.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
795 return RetVal
796
797 @cached_property
798 def PcdsName(self):
799 PcdsName = set()
800 for Type in (MODEL_PCD_FIXED_AT_BUILD,MODEL_PCD_PATCHABLE_IN_MODULE,MODEL_PCD_FEATURE_FLAG,MODEL_PCD_DYNAMIC,MODEL_PCD_DYNAMIC_EX):
801 RecordList = self._RawData[Type, self._Arch, self._Platform]
802 for TokenSpaceGuid, PcdCName, _, _, _, _, _ in RecordList:
803 PcdsName.add((PcdCName, TokenSpaceGuid))
804 return PcdsName
805
806 ## Retrieve build options specific to this module
807 @cached_property
808 def BuildOptions(self):
809 if self._BuildOptions is None:
810 self._BuildOptions = OrderedDict()
811 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, self._Platform]
812 for Record in RecordList:
813 ToolChainFamily = Record[0]
814 ToolChain = Record[1]
815 Option = Record[2]
816 if (ToolChainFamily, ToolChain) not in self._BuildOptions or Option.startswith('='):
817 self._BuildOptions[ToolChainFamily, ToolChain] = Option
818 else:
819 # concatenate the option string if they're for the same tool
820 OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
821 self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
822 return self._BuildOptions
823
824 ## Retrieve dependency expression
825 @cached_property
826 def Depex(self):
827 RetVal = tdict(False, 2)
828
829 # If the module has only Binaries and no Sources, then ignore [Depex]
830 if not self.Sources and self.Binaries:
831 return RetVal
832
833 RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
834 # PEIM and DXE drivers must have a valid [Depex] section
835 if len(self.LibraryClass) == 0 and len(RecordList) == 0:
836 if self.ModuleType == SUP_MODULE_DXE_DRIVER or self.ModuleType == SUP_MODULE_PEIM or self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER or \
837 self.ModuleType == SUP_MODULE_DXE_SAL_DRIVER or self.ModuleType == SUP_MODULE_DXE_RUNTIME_DRIVER:
838 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
839 % self.ModuleType, File=self.MetaFile)
840
841 if len(RecordList) != 0 and self.ModuleType == SUP_MODULE_USER_DEFINED:
842 for Record in RecordList:
843 if Record[4] not in [SUP_MODULE_PEIM, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER]:
844 EdkLogger.error('build', FORMAT_INVALID,
845 "'%s' module must specify the type of [Depex] section" % self.ModuleType,
846 File=self.MetaFile)
847
848 TemporaryDictionary = OrderedDict()
849 for Record in RecordList:
850 DepexStr = ReplaceMacro(Record[0], self._Macros, False)
851 Arch = Record[3]
852 ModuleType = Record[4]
853 TokenList = DepexStr.split()
854 if (Arch, ModuleType) not in TemporaryDictionary:
855 TemporaryDictionary[Arch, ModuleType] = []
856 DepexList = TemporaryDictionary[Arch, ModuleType]
857 for Token in TokenList:
858 if Token in DEPEX_SUPPORTED_OPCODE_SET:
859 DepexList.append(Token)
860 elif Token.endswith(".inf"): # module file name
861 ModuleFile = os.path.normpath(Token)
862 Module = self.BuildDatabase[ModuleFile]
863 if Module is None:
864 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Module is not found in active platform",
865 ExtraData=Token, File=self.MetaFile, Line=Record[-1])
866 DepexList.append(Module.Guid)
867 else:
868 # it use the Fixed PCD format
869 if '.' in Token:
870 if tuple(Token.split('.')[::-1]) not in self.Pcds:
871 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])
872 else:
873 if self.Pcds[tuple(Token.split('.')[::-1])].DatumType != TAB_VOID:
874 EdkLogger.error('build', FORMAT_INVALID, "PCD [{}] used in [Depex] section should be VOID* datum type".format(Token), File=self.MetaFile, Line=Record[-1])
875 Value = Token
876 else:
877 # get the GUID value now
878 Value = ProtocolValue(Token, self.Packages, self.MetaFile.Path)
879 if Value is None:
880 Value = PpiValue(Token, self.Packages, self.MetaFile.Path)
881 if Value is None:
882 Value = GuidValue(Token, self.Packages, self.MetaFile.Path)
883
884 if Value is None:
885 PackageList = "\n\t".join(str(P) for P in self.Packages)
886 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
887 "Value of [%s] is not found in" % Token,
888 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
889 DepexList.append(Value)
890 for Arch, ModuleType in TemporaryDictionary:
891 RetVal[Arch, ModuleType] = TemporaryDictionary[Arch, ModuleType]
892 return RetVal
893
894 ## Retrieve depedency expression
895 @cached_property
896 def DepexExpression(self):
897 RetVal = tdict(False, 2)
898 RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
899 TemporaryDictionary = OrderedDict()
900 for Record in RecordList:
901 DepexStr = ReplaceMacro(Record[0], self._Macros, False)
902 Arch = Record[3]
903 ModuleType = Record[4]
904 TokenList = DepexStr.split()
905 if (Arch, ModuleType) not in TemporaryDictionary:
906 TemporaryDictionary[Arch, ModuleType] = ''
907 for Token in TokenList:
908 TemporaryDictionary[Arch, ModuleType] = TemporaryDictionary[Arch, ModuleType] + Token.strip() + ' '
909 for Arch, ModuleType in TemporaryDictionary:
910 RetVal[Arch, ModuleType] = TemporaryDictionary[Arch, ModuleType]
911 return RetVal
912
913 @cached_class_function
914 def GetGuidsUsedByPcd(self):
915 self.Pcds
916 return self._GuidsUsedByPcd
917
918 ## Retrieve PCD for given type
919 def _GetPcd(self, Type):
920 Pcds = OrderedDict()
921 PcdDict = tdict(True, 4)
922 PcdList = []
923 RecordList = self._RawData[Type, self._Arch, self._Platform]
924 for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Id, LineNo in RecordList:
925 PcdDict[Arch, Platform, PcdCName, TokenSpaceGuid] = (Setting, LineNo)
926 PcdList.append((PcdCName, TokenSpaceGuid))
927 # get the guid value
928 if TokenSpaceGuid not in self.Guids:
929 Value = GuidValue(TokenSpaceGuid, self.Packages, self.MetaFile.Path)
930 if Value is None:
931 PackageList = "\n\t".join(str(P) for P in self.Packages)
932 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
933 "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid,
934 ExtraData=PackageList, File=self.MetaFile, Line=LineNo)
935 self.Guids[TokenSpaceGuid] = Value
936 self._GuidsUsedByPcd[TokenSpaceGuid] = Value
937 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Id]
938 Comments = []
939 for CmtRec in CommentRecords:
940 Comments.append(CmtRec[0])
941 self._PcdComments[TokenSpaceGuid, PcdCName] = Comments
942
943 # resolve PCD type, value, datum info, etc. by getting its definition from package
944 _GuidDict = self.Guids.copy()
945 for PcdCName, TokenSpaceGuid in PcdList:
946 PcdRealName = PcdCName
947 Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid]
948 if Setting is None:
949 continue
950 ValueList = AnalyzePcdData(Setting)
951 DefaultValue = ValueList[0]
952 Pcd = PcdClassObject(
953 PcdCName,
954 TokenSpaceGuid,
955 '',
956 '',
957 DefaultValue,
958 '',
959 '',
960 {},
961 False,
962 self.Guids[TokenSpaceGuid]
963 )
964 if Type == MODEL_PCD_PATCHABLE_IN_MODULE and ValueList[1]:
965 # Patch PCD: TokenSpace.PcdCName|Value|Offset
966 Pcd.Offset = ValueList[1]
967
968 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
969 for Package in self.Packages:
970 for key in Package.Pcds:
971 if (Package.Pcds[key].TokenCName, Package.Pcds[key].TokenSpaceGuidCName) == (PcdRealName, TokenSpaceGuid):
972 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
973 Pcd_Type = item[0].split('_')[-1]
974 if Pcd_Type == Package.Pcds[key].Type:
975 Value = Package.Pcds[key]
976 Value.TokenCName = Package.Pcds[key].TokenCName + '_' + Pcd_Type
977 if len(key) == 2:
978 newkey = (Value.TokenCName, key[1])
979 elif len(key) == 3:
980 newkey = (Value.TokenCName, key[1], key[2])
981 del Package.Pcds[key]
982 Package.Pcds[newkey] = Value
983 break
984 else:
985 pass
986 else:
987 pass
988
989 # get necessary info from package declaring this PCD
990 for Package in self.Packages:
991 #
992 # 'dynamic' in INF means its type is determined by platform;
993 # if platform doesn't give its type, use 'lowest' one in the
994 # following order, if any
995 #
996 # TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_PATCHABLE_IN_MODULE, TAB_PCDS_FEATURE_FLAG, TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_EX
997 #
998 _GuidDict.update(Package.Guids)
999 PcdType = self._PCD_TYPE_STRING_[Type]
1000 if Type == MODEL_PCD_DYNAMIC:
1001 Pcd.Pending = True
1002 for T in PCD_TYPE_LIST:
1003 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
1004 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
1005 if str(item[0]).endswith(T) and (item[0], item[1], T) in Package.Pcds:
1006 PcdType = T
1007 PcdCName = item[0]
1008 break
1009 else:
1010 pass
1011 break
1012 else:
1013 if (PcdRealName, TokenSpaceGuid, T) in Package.Pcds:
1014 PcdType = T
1015 break
1016
1017 else:
1018 Pcd.Pending = False
1019 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
1020 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
1021 Pcd_Type = item[0].split('_')[-1]
1022 if Pcd_Type == PcdType:
1023 PcdCName = item[0]
1024 break
1025 else:
1026 pass
1027 else:
1028 pass
1029
1030 if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:
1031 PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType]
1032 Pcd.Type = PcdType
1033 Pcd.TokenValue = PcdInPackage.TokenValue
1034
1035 #
1036 # Check whether the token value exist or not.
1037 #
1038 if Pcd.TokenValue is None or Pcd.TokenValue == "":
1039 EdkLogger.error(
1040 'build',
1041 FORMAT_INVALID,
1042 "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid, PcdRealName, str(Package)),
1043 File=self.MetaFile, Line=LineNo,
1044 ExtraData=None
1045 )
1046 #
1047 # Check hexadecimal token value length and format.
1048 #
1049 ReIsValidPcdTokenValue = re.compile(r"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re.DOTALL)
1050 if Pcd.TokenValue.startswith("0x") or Pcd.TokenValue.startswith("0X"):
1051 if ReIsValidPcdTokenValue.match(Pcd.TokenValue) is None:
1052 EdkLogger.error(
1053 'build',
1054 FORMAT_INVALID,
1055 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName, str(Package)),
1056 File=self.MetaFile, Line=LineNo,
1057 ExtraData=None
1058 )
1059
1060 #
1061 # Check decimal token value length and format.
1062 #
1063 else:
1064 try:
1065 TokenValueInt = int (Pcd.TokenValue, 10)
1066 if (TokenValueInt < 0 or TokenValueInt > 4294967295):
1067 EdkLogger.error(
1068 'build',
1069 FORMAT_INVALID,
1070 "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)),
1071 File=self.MetaFile, Line=LineNo,
1072 ExtraData=None
1073 )
1074 except:
1075 EdkLogger.error(
1076 'build',
1077 FORMAT_INVALID,
1078 "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)),
1079 File=self.MetaFile, Line=LineNo,
1080 ExtraData=None
1081 )
1082
1083 Pcd.DatumType = PcdInPackage.DatumType
1084 Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize
1085 Pcd.InfDefaultValue = Pcd.DefaultValue
1086 if not Pcd.DefaultValue:
1087 Pcd.DefaultValue = PcdInPackage.DefaultValue
1088 else:
1089 try:
1090 Pcd.DefaultValue = ValueExpressionEx(Pcd.DefaultValue, Pcd.DatumType, _GuidDict)(True)
1091 except BadExpression as Value:
1092 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(TokenSpaceGuid, PcdRealName, Pcd.DefaultValue, Value),
1093 File=self.MetaFile, Line=LineNo)
1094 break
1095 else:
1096 EdkLogger.error(
1097 'build',
1098 FORMAT_INVALID,
1099 "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdRealName, self.MetaFile),
1100 File=self.MetaFile, Line=LineNo,
1101 ExtraData="\t%s" % '\n\t'.join(str(P) for P in self.Packages)
1102 )
1103 Pcds[PcdCName, TokenSpaceGuid] = Pcd
1104
1105 return Pcds
1106
1107 ## check whether current module is binary module
1108 @property
1109 def IsBinaryModule(self):
1110 if (self.Binaries and not self.Sources) or GlobalData.gIgnoreSource:
1111 return True
1112 return False