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