]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Workspace/InfBuildData.py
BaseTools: Workspace classes refactor properties
[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.StringUtils import *
17 from Common.DataType import *
18 from Common.Misc import *
19 from types import *
20 from .MetaFileParser import *
21 from collections import OrderedDict
22
23 from Workspace.BuildClassObject import ModuleBuildClassObject, LibraryClassObject, PcdClassObject
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 DscBuildData
81 #
82 # Initialize object of DscBuildData
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 self._SourceOverridePath = None
101 if FilePath.Key in GlobalData.gOverrideDir:
102 self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key]
103 self._Clear()
104
105 ## XXX[key] = value
106 def __setitem__(self, key, value):
107 self.__dict__[self._PROPERTY_[key]] = value
108
109 ## value = XXX[key]
110 def __getitem__(self, key):
111 return self.__dict__[self._PROPERTY_[key]]
112
113 ## "in" test support
114 def __contains__(self, key):
115 return key in self._PROPERTY_
116
117 ## Set all internal used members of InfBuildData to None
118 def _Clear(self):
119 self._HeaderComments = None
120 self._TailComments = None
121 self._Header_ = None
122 self._AutoGenVersion = None
123 self._BaseName = None
124 self._DxsFile = None
125 self._ModuleType = None
126 self._ComponentType = None
127 self._BuildType = None
128 self._Guid = None
129 self._Version = None
130 self._PcdIsDriver = None
131 self._BinaryModule = None
132 self._Shadow = None
133 self._MakefileName = None
134 self._CustomMakefile = None
135 self._Specification = None
136 self._LibraryClass = None
137 self._ModuleEntryPointList = None
138 self._ModuleUnloadImageList = None
139 self._ConstructorList = None
140 self._DestructorList = None
141 self._Defs = OrderedDict()
142 self._Binaries = None
143 self._Sources = None
144 self._LibraryClasses = None
145 self._Libraries = None
146 self._Protocols = None
147 self._ProtocolComments = None
148 self._Ppis = None
149 self._PpiComments = None
150 self._Guids = None
151 self._GuidsUsedByPcd = OrderedDict()
152 self._GuidComments = None
153 self._Includes = None
154 self._Packages = None
155 self._Pcds = None
156 self._PcdComments = None
157 self._BuildOptions = None
158 self._Depex = None
159 self._DepexExpression = None
160 self._MacroDict = None
161
162 ## Get current effective macros
163 @property
164 def _Macros(self):
165 if self._MacroDict is None:
166 self._MacroDict = {}
167 # EDK_GLOBAL defined macros can be applied to EDK module
168 if self.AutoGenVersion < 0x00010005:
169 self._MacroDict.update(GlobalData.gEdkGlobal)
170 self._MacroDict.update(GlobalData.gGlobalDefines)
171 return self._MacroDict
172
173 ## Get architecture
174 @property
175 def Arch(self):
176 return self._Arch
177
178 ## Return the name of platform employing this module
179 @property
180 def Platform(self):
181 return self._Platform
182
183
184 @property
185 def HeaderComments(self):
186 if not self._HeaderComments:
187 self._HeaderComments = [a[0] for a in self._RawData[MODEL_META_DATA_HEADER_COMMENT]]
188 return self._HeaderComments
189
190 @property
191 def TailComments(self):
192 if not self._TailComments:
193 self._TailComments = [a[0] for a in self._RawData[MODEL_META_DATA_TAIL_COMMENT]]
194 return self._TailComments
195
196 ## Retrieve all information in [Defines] section
197 #
198 # (Retriving all [Defines] information in one-shot is just to save time.)
199 #
200 def _GetHeaderInfo(self):
201 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
202 for Record in RecordList:
203 Name, Value = Record[1], ReplaceMacro(Record[2], self._Macros, False)
204 # items defined _PROPERTY_ don't need additional processing
205 if Name in self:
206 self[Name] = Value
207 self._Defs[Name] = Value
208 self._Macros[Name] = Value
209 # some special items in [Defines] section need special treatment
210 elif Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):
211 if Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):
212 Name = 'UEFI_SPECIFICATION_VERSION'
213 if self._Specification is None:
214 self._Specification = OrderedDict()
215 self._Specification[Name] = GetHexVerValue(Value)
216 if self._Specification[Name] is None:
217 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
218 "'%s' format is not supported for %s" % (Value, Name),
219 File=self.MetaFile, Line=Record[-1])
220 elif Name == 'LIBRARY_CLASS':
221 if self._LibraryClass is None:
222 self._LibraryClass = []
223 ValueList = GetSplitValueList(Value)
224 LibraryClass = ValueList[0]
225 if len(ValueList) > 1:
226 SupModuleList = GetSplitValueList(ValueList[1], ' ')
227 else:
228 SupModuleList = SUP_MODULE_LIST
229 self._LibraryClass.append(LibraryClassObject(LibraryClass, SupModuleList))
230 elif Name == 'ENTRY_POINT':
231 if self._ModuleEntryPointList is None:
232 self._ModuleEntryPointList = []
233 self._ModuleEntryPointList.append(Value)
234 elif Name == 'UNLOAD_IMAGE':
235 if self._ModuleUnloadImageList is None:
236 self._ModuleUnloadImageList = []
237 if not Value:
238 continue
239 self._ModuleUnloadImageList.append(Value)
240 elif Name == 'CONSTRUCTOR':
241 if self._ConstructorList is None:
242 self._ConstructorList = []
243 if not Value:
244 continue
245 self._ConstructorList.append(Value)
246 elif Name == 'DESTRUCTOR':
247 if self._DestructorList is None:
248 self._DestructorList = []
249 if not Value:
250 continue
251 self._DestructorList.append(Value)
252 elif Name == TAB_INF_DEFINES_CUSTOM_MAKEFILE:
253 TokenList = GetSplitValueList(Value)
254 if self._CustomMakefile is None:
255 self._CustomMakefile = {}
256 if len(TokenList) < 2:
257 self._CustomMakefile[TAB_COMPILER_MSFT] = TokenList[0]
258 self._CustomMakefile['GCC'] = TokenList[0]
259 else:
260 if TokenList[0] not in [TAB_COMPILER_MSFT, 'GCC']:
261 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
262 "No supported family [%s]" % TokenList[0],
263 File=self.MetaFile, Line=Record[-1])
264 self._CustomMakefile[TokenList[0]] = TokenList[1]
265 else:
266 self._Defs[Name] = Value
267 self._Macros[Name] = Value
268
269 #
270 # Retrieve information in sections specific to Edk.x modules
271 #
272 if self.AutoGenVersion >= 0x00010005:
273 if not self._ModuleType:
274 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
275 "MODULE_TYPE is not given", File=self.MetaFile)
276 if self._ModuleType not in SUP_MODULE_LIST:
277 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
278 for Record in RecordList:
279 Name = Record[1]
280 if Name == "MODULE_TYPE":
281 LineNo = Record[6]
282 break
283 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
284 "MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self._ModuleType, ' '.join(l for l in SUP_MODULE_LIST)),
285 File=self.MetaFile, Line=LineNo)
286 if (self._Specification is None) or (not 'PI_SPECIFICATION_VERSION' in self._Specification) or (int(self._Specification['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):
287 if self._ModuleType == SUP_MODULE_SMM_CORE:
288 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)
289 if (self._Specification is None) or (not 'PI_SPECIFICATION_VERSION' in self._Specification) or (int(self._Specification['PI_SPECIFICATION_VERSION'], 16) < 0x00010032):
290 if self._ModuleType == SUP_MODULE_MM_CORE_STANDALONE:
291 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)
292 if self._ModuleType == SUP_MODULE_MM_STANDALONE:
293 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)
294 if 'PCI_DEVICE_ID' in self._Defs and 'PCI_VENDOR_ID' in self._Defs \
295 and 'PCI_CLASS_CODE' in self._Defs and 'PCI_REVISION' in self._Defs:
296 self._BuildType = 'UEFI_OPTIONROM'
297 if 'PCI_COMPRESS' in self._Defs:
298 if self._Defs['PCI_COMPRESS'] not in ('TRUE', 'FALSE'):
299 EdkLogger.error("build", FORMAT_INVALID, "Expected TRUE/FALSE for PCI_COMPRESS: %s" % self.MetaFile)
300
301 elif 'UEFI_HII_RESOURCE_SECTION' in self._Defs \
302 and self._Defs['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':
303 self._BuildType = 'UEFI_HII'
304 else:
305 self._BuildType = self._ModuleType.upper()
306
307 if self._DxsFile:
308 File = PathClass(NormPath(self._DxsFile), self._ModuleDir, Arch=self._Arch)
309 # check the file validation
310 ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)
311 if ErrorCode != 0:
312 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo,
313 File=self.MetaFile, Line=LineNo)
314 if self.Sources is None:
315 self._Sources = []
316 self._Sources.append(File)
317 else:
318 if not self._ComponentType:
319 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
320 "COMPONENT_TYPE is not given", File=self.MetaFile)
321 self._BuildType = self._ComponentType.upper()
322 if self._ComponentType in COMPONENT_TO_MODULE_MAP_DICT:
323 self._ModuleType = COMPONENT_TO_MODULE_MAP_DICT[self._ComponentType]
324 if self._ComponentType == EDK_COMPONENT_TYPE_LIBRARY:
325 self._LibraryClass = [LibraryClassObject(self._BaseName, SUP_MODULE_LIST)]
326 # make use some [nmake] section macros
327 Macros = self._Macros
328 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
329 Macros['PROCESSOR'] = self._Arch
330 RecordList = self._RawData[MODEL_META_DATA_NMAKE, self._Arch, self._Platform]
331 for Name, Value, Dummy, Arch, Platform, ID, LineNo in RecordList:
332 Value = ReplaceMacro(Value, Macros, True)
333 if Name == "IMAGE_ENTRY_POINT":
334 if self._ModuleEntryPointList is None:
335 self._ModuleEntryPointList = []
336 self._ModuleEntryPointList.append(Value)
337 elif Name == "DPX_SOURCE":
338 File = PathClass(NormPath(Value), self._ModuleDir, Arch=self._Arch)
339 # check the file validation
340 ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)
341 if ErrorCode != 0:
342 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo,
343 File=self.MetaFile, Line=LineNo)
344 if self.Sources is None:
345 self._Sources = []
346 self._Sources.append(File)
347 else:
348 ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name)
349 if len(ToolList) == 1:
350 if self._BuildOptions is None:
351 self._BuildOptions = OrderedDict()
352
353 if ToolList[0] in self._TOOL_CODE_:
354 Tool = self._TOOL_CODE_[ToolList[0]]
355 else:
356 Tool = ToolList[0]
357 ToolChain = "*_*_*_%s_FLAGS" % Tool
358 # Edk.x only support MSFT tool chain
359 # ignore not replaced macros in value
360 ValueList = GetSplitList(' ' + Value, '/D')
361 Dummy = ValueList[0]
362 for Index in range(1, len(ValueList)):
363 if ValueList[Index][-1] == '=' or ValueList[Index] == '':
364 continue
365 Dummy = Dummy + ' /D ' + ValueList[Index]
366 Value = Dummy.strip()
367 if (TAB_COMPILER_MSFT, ToolChain) not in self._BuildOptions:
368 self._BuildOptions[TAB_COMPILER_MSFT, ToolChain] = Value
369 else:
370 OptionString = self._BuildOptions[TAB_COMPILER_MSFT, ToolChain]
371 self._BuildOptions[TAB_COMPILER_MSFT, ToolChain] = OptionString + " " + Value
372 # set _Header to non-None in order to avoid database re-querying
373 self._Header_ = 'DUMMY'
374
375 ## Retrieve file version
376 @property
377 def AutoGenVersion(self):
378 if self._AutoGenVersion is None:
379 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
380 for Record in RecordList:
381 if Record[1] == TAB_INF_DEFINES_INF_VERSION:
382 if '.' in Record[2]:
383 ValueList = Record[2].split('.')
384 Major = '%04o' % int(ValueList[0], 0)
385 Minor = '%04o' % int(ValueList[1], 0)
386 self._AutoGenVersion = int('0x' + Major + Minor, 0)
387 else:
388 self._AutoGenVersion = int(Record[2], 0)
389 break
390 if self._AutoGenVersion is None:
391 self._AutoGenVersion = 0x00010000
392 return self._AutoGenVersion
393
394 ## Retrieve BASE_NAME
395 @property
396 def BaseName(self):
397 if self._BaseName is None:
398 if self._Header_ is None:
399 self._GetHeaderInfo()
400 if self._BaseName is None:
401 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BASE_NAME name", File=self.MetaFile)
402 return self._BaseName
403
404 ## Retrieve DxsFile
405 @property
406 def DxsFile(self):
407 if self._DxsFile is None:
408 if self._Header_ is None:
409 self._GetHeaderInfo()
410 if self._DxsFile is None:
411 self._DxsFile = ''
412 return self._DxsFile
413
414 ## Retrieve MODULE_TYPE
415 @property
416 def ModuleType(self):
417 if self._ModuleType is None:
418 if self._Header_ is None:
419 self._GetHeaderInfo()
420 if self._ModuleType is None:
421 self._ModuleType = SUP_MODULE_BASE
422 if self._ModuleType not in SUP_MODULE_LIST:
423 self._ModuleType = SUP_MODULE_USER_DEFINED
424 return self._ModuleType
425
426 ## Retrieve COMPONENT_TYPE
427 @property
428 def ComponentType(self):
429 if self._ComponentType is None:
430 if self._Header_ is None:
431 self._GetHeaderInfo()
432 if self._ComponentType is None:
433 self._ComponentType = SUP_MODULE_USER_DEFINED
434 return self._ComponentType
435
436 ## Retrieve "BUILD_TYPE"
437 @property
438 def BuildType(self):
439 if self._BuildType is None:
440 if self._Header_ is None:
441 self._GetHeaderInfo()
442 if not self._BuildType:
443 self._BuildType = SUP_MODULE_BASE
444 return self._BuildType
445
446 ## Retrieve file guid
447 @property
448 def Guid(self):
449 if self._Guid is None:
450 if self._Header_ is None:
451 self._GetHeaderInfo()
452 if self._Guid is None:
453 self._Guid = '00000000-0000-0000-0000-000000000000'
454 return self._Guid
455
456 ## Retrieve module version
457 @property
458 def Version(self):
459 if self._Version is None:
460 if self._Header_ is None:
461 self._GetHeaderInfo()
462 if self._Version is None:
463 self._Version = '0.0'
464 return self._Version
465
466 ## Retrieve PCD_IS_DRIVER
467 @property
468 def PcdIsDriver(self):
469 if self._PcdIsDriver is None:
470 if self._Header_ is None:
471 self._GetHeaderInfo()
472 if self._PcdIsDriver is None:
473 self._PcdIsDriver = ''
474 return self._PcdIsDriver
475
476 ## Retrieve SHADOW
477 @property
478 def Shadow(self):
479 if self._Shadow is None:
480 if self._Header_ is None:
481 self._GetHeaderInfo()
482 if self._Shadow is not None and self._Shadow.upper() == 'TRUE':
483 self._Shadow = True
484 else:
485 self._Shadow = False
486 return self._Shadow
487
488 ## Retrieve CUSTOM_MAKEFILE
489 @property
490 def CustomMakefile(self):
491 if self._CustomMakefile is None:
492 if self._Header_ is None:
493 self._GetHeaderInfo()
494 if self._CustomMakefile is None:
495 self._CustomMakefile = {}
496 return self._CustomMakefile
497
498 ## Retrieve EFI_SPECIFICATION_VERSION
499 @property
500 def Specification(self):
501 if self._Specification is None:
502 if self._Header_ is None:
503 self._GetHeaderInfo()
504 if self._Specification is None:
505 self._Specification = {}
506 return self._Specification
507
508 ## Retrieve LIBRARY_CLASS
509 @property
510 def LibraryClass(self):
511 if self._LibraryClass is None:
512 if self._Header_ is None:
513 self._GetHeaderInfo()
514 if self._LibraryClass is None:
515 self._LibraryClass = []
516 return self._LibraryClass
517
518 ## Retrieve ENTRY_POINT
519 @property
520 def ModuleEntryPointList(self):
521 if self._ModuleEntryPointList is None:
522 if self._Header_ is None:
523 self._GetHeaderInfo()
524 if self._ModuleEntryPointList is None:
525 self._ModuleEntryPointList = []
526 return self._ModuleEntryPointList
527
528 ## Retrieve UNLOAD_IMAGE
529 @property
530 def ModuleUnloadImageList(self):
531 if self._ModuleUnloadImageList is None:
532 if self._Header_ is None:
533 self._GetHeaderInfo()
534 if self._ModuleUnloadImageList is None:
535 self._ModuleUnloadImageList = []
536 return self._ModuleUnloadImageList
537
538 ## Retrieve CONSTRUCTOR
539 @property
540 def ConstructorList(self):
541 if self._ConstructorList is None:
542 if self._Header_ is None:
543 self._GetHeaderInfo()
544 if self._ConstructorList is None:
545 self._ConstructorList = []
546 return self._ConstructorList
547
548 ## Retrieve DESTRUCTOR
549 @property
550 def DestructorList(self):
551 if self._DestructorList is None:
552 if self._Header_ is None:
553 self._GetHeaderInfo()
554 if self._DestructorList is None:
555 self._DestructorList = []
556 return self._DestructorList
557
558 ## Retrieve definies other than above ones
559 @property
560 def Defines(self):
561 if len(self._Defs) == 0 and self._Header_ is None:
562 self._GetHeaderInfo()
563 return self._Defs
564
565 ## Retrieve binary files
566 def _GetBinaries(self):
567 if self._Binaries is None:
568 self._Binaries = []
569 RecordList = self._RawData[MODEL_EFI_BINARY_FILE, self._Arch, self._Platform]
570 Macros = self._Macros
571 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
572 Macros['PROCESSOR'] = self._Arch
573 for Record in RecordList:
574 FileType = Record[0]
575 LineNo = Record[-1]
576 Target = TAB_COMMON
577 FeatureFlag = []
578 if Record[2]:
579 TokenList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)
580 if TokenList:
581 Target = TokenList[0]
582 if len(TokenList) > 1:
583 FeatureFlag = Record[1:]
584
585 File = PathClass(NormPath(Record[1], Macros), self._ModuleDir, '', FileType, True, self._Arch, '', Target)
586 # check the file validation
587 ErrorCode, ErrorInfo = File.Validate()
588 if ErrorCode != 0:
589 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
590 self._Binaries.append(File)
591 return self._Binaries
592
593 ## Retrieve binary files with error check.
594 @property
595 def Binaries(self):
596 Binaries = self._GetBinaries()
597 if GlobalData.gIgnoreSource and Binaries == []:
598 ErrorInfo = "The INF file does not contain any Binaries to use in creating the image\n"
599 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, ExtraData=ErrorInfo, File=self.MetaFile)
600
601 return Binaries
602
603 ## Retrieve source files
604 @property
605 def Sources(self):
606 # Ignore all source files in a binary build mode
607 if GlobalData.gIgnoreSource:
608 self._Sources = []
609 return self._Sources
610
611 if self._Sources is None:
612 self._Sources = []
613 RecordList = self._RawData[MODEL_EFI_SOURCE_FILE, self._Arch, self._Platform]
614 Macros = self._Macros
615 for Record in RecordList:
616 LineNo = Record[-1]
617 ToolChainFamily = Record[1]
618 TagName = Record[2]
619 ToolCode = Record[3]
620 FeatureFlag = Record[4]
621 if self.AutoGenVersion < 0x00010005:
622 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
623 Macros['PROCESSOR'] = self._Arch
624 SourceFile = NormPath(Record[0], Macros)
625 if SourceFile[0] == os.path.sep:
626 SourceFile = mws.join(GlobalData.gWorkspace, SourceFile[1:])
627 # old module source files (Edk)
628 File = PathClass(SourceFile, self._ModuleDir, self._SourceOverridePath,
629 '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)
630 # check the file validation
631 ErrorCode, ErrorInfo = File.Validate(CaseSensitive=False)
632 if ErrorCode != 0:
633 if File.Ext.lower() == '.h':
634 EdkLogger.warn('build', 'Include file not found', ExtraData=ErrorInfo,
635 File=self.MetaFile, Line=LineNo)
636 continue
637 else:
638 EdkLogger.error('build', ErrorCode, ExtraData=File, File=self.MetaFile, Line=LineNo)
639 else:
640 File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, '',
641 '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)
642 # check the file validation
643 ErrorCode, ErrorInfo = File.Validate()
644 if ErrorCode != 0:
645 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
646
647 self._Sources.append(File)
648 return self._Sources
649
650 ## Retrieve library classes employed by this module
651 @property
652 def LibraryClasses(self):
653 if self._LibraryClasses is None:
654 self._LibraryClasses = OrderedDict()
655 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform]
656 for Record in RecordList:
657 Lib = Record[0]
658 Instance = Record[1]
659 if Instance:
660 Instance = NormPath(Instance, self._Macros)
661 self._LibraryClasses[Lib] = Instance
662 return self._LibraryClasses
663
664 ## Retrieve library names (for Edk.x style of modules)
665 @property
666 def Libraries(self):
667 if self._Libraries is None:
668 self._Libraries = []
669 RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch, self._Platform]
670 for Record in RecordList:
671 LibraryName = ReplaceMacro(Record[0], self._Macros, False)
672 # in case of name with '.lib' extension, which is unusual in Edk.x inf
673 LibraryName = os.path.splitext(LibraryName)[0]
674 if LibraryName not in self._Libraries:
675 self._Libraries.append(LibraryName)
676 return self._Libraries
677
678 @property
679 def ProtocolComments(self):
680 self.Protocols
681 return self._ProtocolComments
682
683 ## Retrieve protocols consumed/produced by this module
684 @property
685 def Protocols(self):
686 if self._Protocols is None:
687 self._Protocols = OrderedDict()
688 self._ProtocolComments = OrderedDict()
689 RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self._Platform]
690 for Record in RecordList:
691 CName = Record[0]
692 Value = ProtocolValue(CName, self.Packages, self.MetaFile.Path)
693 if Value is None:
694 PackageList = "\n\t".join(str(P) for P in self.Packages)
695 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
696 "Value of Protocol [%s] is not found under [Protocols] section in" % CName,
697 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
698 self._Protocols[CName] = Value
699 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
700 Comments = []
701 for CmtRec in CommentRecords:
702 Comments.append(CmtRec[0])
703 self._ProtocolComments[CName] = Comments
704 return self._Protocols
705
706 @property
707 def PpiComments(self):
708 self.Ppis
709 return self._PpiComments
710
711 ## Retrieve PPIs consumed/produced by this module
712 @property
713 def Ppis(self):
714 if self._Ppis is None:
715 self._Ppis = OrderedDict()
716 self._PpiComments = OrderedDict()
717 RecordList = self._RawData[MODEL_EFI_PPI, self._Arch, self._Platform]
718 for Record in RecordList:
719 CName = Record[0]
720 Value = PpiValue(CName, self.Packages, self.MetaFile.Path)
721 if Value is None:
722 PackageList = "\n\t".join(str(P) for P in self.Packages)
723 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
724 "Value of PPI [%s] is not found under [Ppis] section in " % CName,
725 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
726 self._Ppis[CName] = Value
727 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
728 Comments = []
729 for CmtRec in CommentRecords:
730 Comments.append(CmtRec[0])
731 self._PpiComments[CName] = Comments
732 return self._Ppis
733
734 @property
735 def GuidComments(self):
736 self.Guids
737 return self._GuidComments
738
739 ## Retrieve GUIDs consumed/produced by this module
740 @property
741 def Guids(self):
742 if self._Guids is None:
743 self._Guids = OrderedDict()
744 self._GuidComments = OrderedDict()
745 RecordList = self._RawData[MODEL_EFI_GUID, self._Arch, self._Platform]
746 for Record in RecordList:
747 CName = Record[0]
748 Value = GuidValue(CName, self.Packages, self.MetaFile.Path)
749 if Value is None:
750 PackageList = "\n\t".join(str(P) for P in self.Packages)
751 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
752 "Value of Guid [%s] is not found under [Guids] section in" % CName,
753 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
754 self._Guids[CName] = Value
755 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
756 Comments = []
757 for CmtRec in CommentRecords:
758 Comments.append(CmtRec[0])
759 self._GuidComments[CName] = Comments
760 return self._Guids
761
762 ## Retrieve include paths necessary for this module (for Edk.x style of modules)
763 @property
764 def Includes(self):
765 if self._Includes is None:
766 self._Includes = []
767 if self._SourceOverridePath:
768 self._Includes.append(self._SourceOverridePath)
769
770 Macros = self._Macros
771 Macros['PROCESSOR'] = GlobalData.gEdkGlobal.get('PROCESSOR', self._Arch)
772 RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform]
773 for Record in RecordList:
774 if Record[0].find('EDK_SOURCE') > -1:
775 Macros['EDK_SOURCE'] = GlobalData.gEcpSource
776 File = NormPath(Record[0], self._Macros)
777 if File[0] == '.':
778 File = os.path.join(self._ModuleDir, File)
779 else:
780 File = os.path.join(GlobalData.gWorkspace, File)
781 File = RealPath(os.path.normpath(File))
782 if File:
783 self._Includes.append(File)
784
785 # TRICK: let compiler to choose correct header file
786 Macros['EDK_SOURCE'] = GlobalData.gEdkSource
787 File = NormPath(Record[0], self._Macros)
788 if File[0] == '.':
789 File = os.path.join(self._ModuleDir, File)
790 else:
791 File = os.path.join(GlobalData.gWorkspace, File)
792 File = RealPath(os.path.normpath(File))
793 if File:
794 self._Includes.append(File)
795 else:
796 File = NormPath(Record[0], Macros)
797 if File[0] == '.':
798 File = os.path.join(self._ModuleDir, File)
799 else:
800 File = mws.join(GlobalData.gWorkspace, File)
801 File = RealPath(os.path.normpath(File))
802 if File:
803 self._Includes.append(File)
804 if not File and Record[0].find('EFI_SOURCE') > -1:
805 # tricky to regard WorkSpace as EFI_SOURCE
806 Macros['EFI_SOURCE'] = GlobalData.gWorkspace
807 File = NormPath(Record[0], Macros)
808 if File[0] == '.':
809 File = os.path.join(self._ModuleDir, File)
810 else:
811 File = os.path.join(GlobalData.gWorkspace, File)
812 File = RealPath(os.path.normpath(File))
813 if File:
814 self._Includes.append(File)
815 return self._Includes
816
817 ## Retrieve packages this module depends on
818 @property
819 def Packages(self):
820 if self._Packages is None:
821 self._Packages = []
822 RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch, self._Platform]
823 Macros = self._Macros
824 Macros['EDK_SOURCE'] = GlobalData.gEcpSource
825 for Record in RecordList:
826 File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
827 LineNo = Record[-1]
828 # check the file validation
829 ErrorCode, ErrorInfo = File.Validate('.dec')
830 if ErrorCode != 0:
831 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
832 # parse this package now. we need it to get protocol/ppi/guid value
833 Package = self._Bdb[File, self._Arch, self._Target, self._Toolchain]
834 self._Packages.append(Package)
835 return self._Packages
836
837 ## Retrieve PCD comments
838 @property
839 def PcdComments(self):
840 self.Pcds
841 return self._PcdComments
842
843 ## Retrieve PCDs used in this module
844 @property
845 def Pcds(self):
846 if self._Pcds is None:
847 self._Pcds = OrderedDict()
848 self._PcdComments = OrderedDict()
849 self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
850 self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
851 self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
852 self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))
853 self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
854 return self._Pcds
855
856 ## Retrieve build options specific to this module
857 @property
858 def BuildOptions(self):
859 if self._BuildOptions is None:
860 self._BuildOptions = OrderedDict()
861 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, self._Platform]
862 for Record in RecordList:
863 ToolChainFamily = Record[0]
864 ToolChain = Record[1]
865 Option = Record[2]
866 if (ToolChainFamily, ToolChain) not in self._BuildOptions or Option.startswith('='):
867 self._BuildOptions[ToolChainFamily, ToolChain] = Option
868 else:
869 # concatenate the option string if they're for the same tool
870 OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
871 self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
872 return self._BuildOptions
873
874 ## Retrieve dependency expression
875 @property
876 def Depex(self):
877 if self._Depex is None:
878 self._Depex = tdict(False, 2)
879 RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
880
881 # If the module has only Binaries and no Sources, then ignore [Depex]
882 if self.Sources is None or self.Sources == []:
883 if self.Binaries is not None and self.Binaries != []:
884 return self._Depex
885
886 # PEIM and DXE drivers must have a valid [Depex] section
887 if len(self.LibraryClass) == 0 and len(RecordList) == 0:
888 if self.ModuleType == SUP_MODULE_DXE_DRIVER or self.ModuleType == SUP_MODULE_PEIM or self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER or \
889 self.ModuleType == SUP_MODULE_DXE_SAL_DRIVER or self.ModuleType == SUP_MODULE_DXE_RUNTIME_DRIVER:
890 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
891 % self.ModuleType, File=self.MetaFile)
892
893 if len(RecordList) != 0 and self.ModuleType == SUP_MODULE_USER_DEFINED:
894 for Record in RecordList:
895 if Record[4] not in [SUP_MODULE_PEIM, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER]:
896 EdkLogger.error('build', FORMAT_INVALID,
897 "'%s' module must specify the type of [Depex] section" % self.ModuleType,
898 File=self.MetaFile)
899
900 Depex = OrderedDict()
901 for Record in RecordList:
902 DepexStr = ReplaceMacro(Record[0], self._Macros, False)
903 Arch = Record[3]
904 ModuleType = Record[4]
905 TokenList = DepexStr.split()
906 if (Arch, ModuleType) not in Depex:
907 Depex[Arch, ModuleType] = []
908 DepexList = Depex[Arch, ModuleType]
909 for Token in TokenList:
910 if Token in DEPEX_SUPPORTED_OPCODE_SET:
911 DepexList.append(Token)
912 elif Token.endswith(".inf"): # module file name
913 ModuleFile = os.path.normpath(Token)
914 Module = self.BuildDatabase[ModuleFile]
915 if Module is None:
916 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Module is not found in active platform",
917 ExtraData=Token, File=self.MetaFile, Line=Record[-1])
918 DepexList.append(Module.Guid)
919 else:
920 # it use the Fixed PCD format
921 if '.' in Token:
922 if tuple(Token.split('.')[::-1]) not in self.Pcds:
923 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])
924 else:
925 if self.Pcds[tuple(Token.split('.')[::-1])].DatumType != TAB_VOID:
926 EdkLogger.error('build', FORMAT_INVALID, "PCD [{}] used in [Depex] section should be VOID* datum type".format(Token), File=self.MetaFile, Line=Record[-1])
927 Value = Token
928 else:
929 # get the GUID value now
930 Value = ProtocolValue(Token, self.Packages, self.MetaFile.Path)
931 if Value is None:
932 Value = PpiValue(Token, self.Packages, self.MetaFile.Path)
933 if Value is None:
934 Value = GuidValue(Token, self.Packages, self.MetaFile.Path)
935
936 if Value is None:
937 PackageList = "\n\t".join(str(P) for P in self.Packages)
938 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
939 "Value of [%s] is not found in" % Token,
940 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
941 DepexList.append(Value)
942 for Arch, ModuleType in Depex:
943 self._Depex[Arch, ModuleType] = Depex[Arch, ModuleType]
944 return self._Depex
945
946 ## Retrieve depedency expression
947 @property
948 def DepexExpression(self):
949 if self._DepexExpression is None:
950 self._DepexExpression = tdict(False, 2)
951 RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
952 DepexExpression = OrderedDict()
953 for Record in RecordList:
954 DepexStr = ReplaceMacro(Record[0], self._Macros, False)
955 Arch = Record[3]
956 ModuleType = Record[4]
957 TokenList = DepexStr.split()
958 if (Arch, ModuleType) not in DepexExpression:
959 DepexExpression[Arch, ModuleType] = ''
960 for Token in TokenList:
961 DepexExpression[Arch, ModuleType] = DepexExpression[Arch, ModuleType] + Token.strip() + ' '
962 for Arch, ModuleType in DepexExpression:
963 self._DepexExpression[Arch, ModuleType] = DepexExpression[Arch, ModuleType]
964 return self._DepexExpression
965
966 def GetGuidsUsedByPcd(self):
967 return self._GuidsUsedByPcd
968
969 ## Retrieve PCD for given type
970 def _GetPcd(self, Type):
971 Pcds = OrderedDict()
972 PcdDict = tdict(True, 4)
973 PcdList = []
974 RecordList = self._RawData[Type, self._Arch, self._Platform]
975 for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Id, LineNo in RecordList:
976 PcdDict[Arch, Platform, PcdCName, TokenSpaceGuid] = (Setting, LineNo)
977 PcdList.append((PcdCName, TokenSpaceGuid))
978 # get the guid value
979 if TokenSpaceGuid not in self.Guids:
980 Value = GuidValue(TokenSpaceGuid, self.Packages, self.MetaFile.Path)
981 if Value is None:
982 PackageList = "\n\t".join(str(P) for P in self.Packages)
983 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
984 "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid,
985 ExtraData=PackageList, File=self.MetaFile, Line=LineNo)
986 self.Guids[TokenSpaceGuid] = Value
987 self._GuidsUsedByPcd[TokenSpaceGuid] = Value
988 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Id]
989 Comments = []
990 for CmtRec in CommentRecords:
991 Comments.append(CmtRec[0])
992 self._PcdComments[TokenSpaceGuid, PcdCName] = Comments
993
994 # resolve PCD type, value, datum info, etc. by getting its definition from package
995 _GuidDict = self.Guids.copy()
996 for PcdCName, TokenSpaceGuid in PcdList:
997 PcdRealName = PcdCName
998 Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid]
999 if Setting is None:
1000 continue
1001 ValueList = AnalyzePcdData(Setting)
1002 DefaultValue = ValueList[0]
1003 Pcd = PcdClassObject(
1004 PcdCName,
1005 TokenSpaceGuid,
1006 '',
1007 '',
1008 DefaultValue,
1009 '',
1010 '',
1011 {},
1012 False,
1013 self.Guids[TokenSpaceGuid]
1014 )
1015 if Type == MODEL_PCD_PATCHABLE_IN_MODULE and ValueList[1]:
1016 # Patch PCD: TokenSpace.PcdCName|Value|Offset
1017 Pcd.Offset = ValueList[1]
1018
1019 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
1020 for Package in self.Packages:
1021 for key in Package.Pcds:
1022 if (Package.Pcds[key].TokenCName, Package.Pcds[key].TokenSpaceGuidCName) == (PcdRealName, TokenSpaceGuid):
1023 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
1024 Pcd_Type = item[0].split('_')[-1]
1025 if Pcd_Type == Package.Pcds[key].Type:
1026 Value = Package.Pcds[key]
1027 Value.TokenCName = Package.Pcds[key].TokenCName + '_' + Pcd_Type
1028 if len(key) == 2:
1029 newkey = (Value.TokenCName, key[1])
1030 elif len(key) == 3:
1031 newkey = (Value.TokenCName, key[1], key[2])
1032 del Package.Pcds[key]
1033 Package.Pcds[newkey] = Value
1034 break
1035 else:
1036 pass
1037 else:
1038 pass
1039
1040 # get necessary info from package declaring this PCD
1041 for Package in self.Packages:
1042 #
1043 # 'dynamic' in INF means its type is determined by platform;
1044 # if platform doesn't give its type, use 'lowest' one in the
1045 # following order, if any
1046 #
1047 # TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_PATCHABLE_IN_MODULE, TAB_PCDS_FEATURE_FLAG, TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_EX
1048 #
1049 _GuidDict.update(Package.Guids)
1050 PcdType = self._PCD_TYPE_STRING_[Type]
1051 if Type == MODEL_PCD_DYNAMIC:
1052 Pcd.Pending = True
1053 for T in PCD_TYPE_LIST:
1054 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
1055 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
1056 if str(item[0]).endswith(T) and (item[0], item[1], T) in Package.Pcds:
1057 PcdType = T
1058 PcdCName = item[0]
1059 break
1060 else:
1061 pass
1062 break
1063 else:
1064 if (PcdRealName, TokenSpaceGuid, T) in Package.Pcds:
1065 PcdType = T
1066 break
1067
1068 else:
1069 Pcd.Pending = False
1070 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
1071 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
1072 Pcd_Type = item[0].split('_')[-1]
1073 if Pcd_Type == PcdType:
1074 PcdCName = item[0]
1075 break
1076 else:
1077 pass
1078 else:
1079 pass
1080
1081 if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:
1082 PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType]
1083 Pcd.Type = PcdType
1084 Pcd.TokenValue = PcdInPackage.TokenValue
1085
1086 #
1087 # Check whether the token value exist or not.
1088 #
1089 if Pcd.TokenValue is None or Pcd.TokenValue == "":
1090 EdkLogger.error(
1091 'build',
1092 FORMAT_INVALID,
1093 "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid, PcdRealName, str(Package)),
1094 File=self.MetaFile, Line=LineNo,
1095 ExtraData=None
1096 )
1097 #
1098 # Check hexadecimal token value length and format.
1099 #
1100 ReIsValidPcdTokenValue = re.compile(r"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re.DOTALL)
1101 if Pcd.TokenValue.startswith("0x") or Pcd.TokenValue.startswith("0X"):
1102 if ReIsValidPcdTokenValue.match(Pcd.TokenValue) is None:
1103 EdkLogger.error(
1104 'build',
1105 FORMAT_INVALID,
1106 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName, str(Package)),
1107 File=self.MetaFile, Line=LineNo,
1108 ExtraData=None
1109 )
1110
1111 #
1112 # Check decimal token value length and format.
1113 #
1114 else:
1115 try:
1116 TokenValueInt = int (Pcd.TokenValue, 10)
1117 if (TokenValueInt < 0 or TokenValueInt > 4294967295):
1118 EdkLogger.error(
1119 'build',
1120 FORMAT_INVALID,
1121 "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)),
1122 File=self.MetaFile, Line=LineNo,
1123 ExtraData=None
1124 )
1125 except:
1126 EdkLogger.error(
1127 'build',
1128 FORMAT_INVALID,
1129 "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)),
1130 File=self.MetaFile, Line=LineNo,
1131 ExtraData=None
1132 )
1133
1134 Pcd.DatumType = PcdInPackage.DatumType
1135 Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize
1136 Pcd.InfDefaultValue = Pcd.DefaultValue
1137 if not Pcd.DefaultValue:
1138 Pcd.DefaultValue = PcdInPackage.DefaultValue
1139 else:
1140 try:
1141 Pcd.DefaultValue = ValueExpressionEx(Pcd.DefaultValue, Pcd.DatumType, _GuidDict)(True)
1142 except BadExpression as Value:
1143 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(TokenSpaceGuid, PcdRealName, Pcd.DefaultValue, Value),
1144 File=self.MetaFile, Line=LineNo)
1145 break
1146 else:
1147 EdkLogger.error(
1148 'build',
1149 FORMAT_INVALID,
1150 "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdRealName, self.MetaFile),
1151 File=self.MetaFile, Line=LineNo,
1152 ExtraData="\t%s" % '\n\t'.join(str(P) for P in self.Packages)
1153 )
1154 Pcds[PcdCName, TokenSpaceGuid] = Pcd
1155
1156 return Pcds
1157
1158 ## check whether current module is binary module
1159 @property
1160 def IsBinaryModule(self):
1161 if (self.Binaries and not self.Sources) or GlobalData.gIgnoreSource:
1162 return True
1163 return False