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