]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Workspace/InfBuildData.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / InfBuildData.py
1 ## @file
2 # This file is used to create a database used by build tool
3 #
4 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 from __future__ import absolute_import
16 from Common.DataType import *
17 from Common.Misc import *
18 from Common.caching import cached_property, cached_class_function
19 from types import *
20 from .MetaFileParser import *
21 from collections import OrderedDict
22 from Workspace.BuildClassObject import ModuleBuildClassObject, LibraryClassObject, PcdClassObject
23
24 ## Get Protocol value from given packages
25 #
26 # @param CName The CName of the GUID
27 # @param PackageList List of packages looking-up in
28 # @param Inffile The driver file
29 #
30 # @retval GuidValue if the CName is found in any given package
31 # @retval None if the CName is not found in all given packages
32 #
33 def _ProtocolValue(CName, PackageList, Inffile = None):
34 for P in PackageList:
35 ProtocolKeys = list(P.Protocols.keys())
36 if Inffile and P._PrivateProtocols:
37 if not Inffile.startswith(P.MetaFile.Dir):
38 ProtocolKeys = [x for x in P.Protocols if x not in P._PrivateProtocols]
39 if CName in ProtocolKeys:
40 return P.Protocols[CName]
41 return None
42
43 ## Get PPI value from given packages
44 #
45 # @param CName The CName of the GUID
46 # @param PackageList List of packages looking-up in
47 # @param Inffile The driver file
48 #
49 # @retval GuidValue if the CName is found in any given package
50 # @retval None if the CName is not found in all given packages
51 #
52 def _PpiValue(CName, PackageList, Inffile = None):
53 for P in PackageList:
54 PpiKeys = list(P.Ppis.keys())
55 if Inffile and P._PrivatePpis:
56 if not Inffile.startswith(P.MetaFile.Dir):
57 PpiKeys = [x for x in P.Ppis if x not in P._PrivatePpis]
58 if CName in PpiKeys:
59 return P.Ppis[CName]
60 return None
61
62 ## Module build information from INF file
63 #
64 # This class is used to retrieve information stored in database and convert them
65 # into ModuleBuildClassObject form for easier use for AutoGen.
66 #
67 class InfBuildData(ModuleBuildClassObject):
68 # dict used to convert PCD type in database to string used by build tool
69 _PCD_TYPE_STRING_ = {
70 MODEL_PCD_FIXED_AT_BUILD : TAB_PCDS_FIXED_AT_BUILD,
71 MODEL_PCD_PATCHABLE_IN_MODULE : TAB_PCDS_PATCHABLE_IN_MODULE,
72 MODEL_PCD_FEATURE_FLAG : TAB_PCDS_FEATURE_FLAG,
73 MODEL_PCD_DYNAMIC : TAB_PCDS_DYNAMIC,
74 MODEL_PCD_DYNAMIC_DEFAULT : TAB_PCDS_DYNAMIC,
75 MODEL_PCD_DYNAMIC_HII : TAB_PCDS_DYNAMIC_HII,
76 MODEL_PCD_DYNAMIC_VPD : TAB_PCDS_DYNAMIC_VPD,
77 MODEL_PCD_DYNAMIC_EX : TAB_PCDS_DYNAMIC_EX,
78 MODEL_PCD_DYNAMIC_EX_DEFAULT : TAB_PCDS_DYNAMIC_EX,
79 MODEL_PCD_DYNAMIC_EX_HII : TAB_PCDS_DYNAMIC_EX_HII,
80 MODEL_PCD_DYNAMIC_EX_VPD : TAB_PCDS_DYNAMIC_EX_VPD,
81 }
82
83 # dict used to convert part of [Defines] to members of InfBuildData directly
84 _PROPERTY_ = {
85 #
86 # Required Fields
87 #
88 TAB_INF_DEFINES_BASE_NAME : "_BaseName",
89 TAB_INF_DEFINES_FILE_GUID : "_Guid",
90 TAB_INF_DEFINES_MODULE_TYPE : "_ModuleType",
91 #
92 # Optional Fields
93 #
94 # TAB_INF_DEFINES_INF_VERSION : "_AutoGenVersion",
95 TAB_INF_DEFINES_COMPONENT_TYPE : "_ComponentType",
96 TAB_INF_DEFINES_MAKEFILE_NAME : "_MakefileName",
97 # TAB_INF_DEFINES_CUSTOM_MAKEFILE : "_CustomMakefile",
98 TAB_INF_DEFINES_DPX_SOURCE :"_DxsFile",
99 TAB_INF_DEFINES_VERSION_NUMBER : "_Version",
100 TAB_INF_DEFINES_VERSION_STRING : "_Version",
101 TAB_INF_DEFINES_VERSION : "_Version",
102 TAB_INF_DEFINES_PCD_IS_DRIVER : "_PcdIsDriver",
103 TAB_INF_DEFINES_SHADOW : "_Shadow",
104
105 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH : "_SourceOverridePath",
106 }
107
108 # regular expression for converting XXX_FLAGS in [nmake] section to new type
109 _NMAKE_FLAG_PATTERN_ = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)
110 # dict used to convert old tool name used in [nmake] section to new ones
111 _TOOL_CODE_ = {
112 "C" : "CC",
113 BINARY_FILE_TYPE_LIB : "SLINK",
114 "LINK" : "DLINK",
115 }
116
117
118 ## Constructor of InfBuildData
119 #
120 # Initialize object of InfBuildData
121 #
122 # @param FilePath The path of platform description file
123 # @param RawData The raw data of DSC file
124 # @param BuildDataBase Database used to retrieve module/package information
125 # @param Arch The target architecture
126 # @param Platform The name of platform employing this module
127 # @param Macros Macros used for replacement in DSC file
128 #
129 def __init__(self, FilePath, RawData, BuildDatabase, Arch=TAB_ARCH_COMMON, Target=None, Toolchain=None):
130 self.MetaFile = FilePath
131 self._ModuleDir = FilePath.Dir
132 self._RawData = RawData
133 self._Bdb = BuildDatabase
134 self._Arch = Arch
135 self._Target = Target
136 self._Toolchain = Toolchain
137 self._Platform = TAB_COMMON
138 if FilePath.Key in GlobalData.gOverrideDir:
139 self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key]
140 else:
141 self._SourceOverridePath = None
142 self._TailComments = None
143 self._BaseName = None
144 self._DxsFile = None
145 self._ModuleType = None
146 self._ComponentType = None
147 self._BuildType = None
148 self._Guid = None
149 self._Version = None
150 self._PcdIsDriver = None
151 self._BinaryModule = None
152 self._Shadow = None
153 self._MakefileName = None
154 self._CustomMakefile = None
155 self._Specification = None
156 self._LibraryClass = None
157 self._ModuleEntryPointList = None
158 self._ModuleUnloadImageList = None
159 self._ConstructorList = None
160 self._DestructorList = None
161 self._Defs = OrderedDict()
162 self._ProtocolComments = None
163 self._PpiComments = None
164 self._GuidsUsedByPcd = OrderedDict()
165 self._GuidComments = None
166 self._PcdComments = None
167 self._BuildOptions = None
168 self._DependencyFileList = None
169
170 ## XXX[key] = value
171 def __setitem__(self, key, value):
172 self.__dict__[self._PROPERTY_[key]] = value
173
174 ## value = XXX[key]
175 def __getitem__(self, key):
176 return self.__dict__[self._PROPERTY_[key]]
177
178 ## "in" test support
179 def __contains__(self, key):
180 return key in self._PROPERTY_
181
182 ## Get current effective macros
183 @cached_property
184 def _Macros(self):
185 RetVal = {}
186 return RetVal
187
188 ## Get architecture
189 @cached_property
190 def Arch(self):
191 return self._Arch
192
193 ## Return the name of platform employing this module
194 @cached_property
195 def Platform(self):
196 return self._Platform
197
198 @cached_property
199 def HeaderComments(self):
200 return [a[0] for a in self._RawData[MODEL_META_DATA_HEADER_COMMENT]]
201
202 @cached_property
203 def TailComments(self):
204 return [a[0] for a in self._RawData[MODEL_META_DATA_TAIL_COMMENT]]
205
206 ## Retrieve all information in [Defines] section
207 #
208 # (Retrieving all [Defines] information in one-shot is just to save time.)
209 #
210 @cached_class_function
211 def _GetHeaderInfo(self):
212 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
213 for Record in RecordList:
214 Name, Value = Record[1], ReplaceMacro(Record[2], self._Macros, False)
215 # items defined _PROPERTY_ don't need additional processing
216 if Name in self:
217 self[Name] = Value
218 self._Defs[Name] = Value
219 self._Macros[Name] = Value
220 # some special items in [Defines] section need special treatment
221 elif Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):
222 if Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):
223 Name = 'UEFI_SPECIFICATION_VERSION'
224 if self._Specification is None:
225 self._Specification = OrderedDict()
226 self._Specification[Name] = GetHexVerValue(Value)
227 if self._Specification[Name] is None:
228 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
229 "'%s' format is not supported for %s" % (Value, Name),
230 File=self.MetaFile, Line=Record[-1])
231 elif Name == 'LIBRARY_CLASS':
232 if self._LibraryClass is None:
233 self._LibraryClass = []
234 ValueList = GetSplitValueList(Value)
235 LibraryClass = ValueList[0]
236 if len(ValueList) > 1:
237 SupModuleList = GetSplitValueList(ValueList[1], ' ')
238 else:
239 SupModuleList = SUP_MODULE_LIST
240 self._LibraryClass.append(LibraryClassObject(LibraryClass, SupModuleList))
241 elif Name == 'ENTRY_POINT':
242 if self._ModuleEntryPointList is None:
243 self._ModuleEntryPointList = []
244 self._ModuleEntryPointList.append(Value)
245 elif Name == 'UNLOAD_IMAGE':
246 if self._ModuleUnloadImageList is None:
247 self._ModuleUnloadImageList = []
248 if not Value:
249 continue
250 self._ModuleUnloadImageList.append(Value)
251 elif Name == 'CONSTRUCTOR':
252 if self._ConstructorList is None:
253 self._ConstructorList = []
254 if not Value:
255 continue
256 self._ConstructorList.append(Value)
257 elif Name == 'DESTRUCTOR':
258 if self._DestructorList is None:
259 self._DestructorList = []
260 if not Value:
261 continue
262 self._DestructorList.append(Value)
263 elif Name == TAB_INF_DEFINES_CUSTOM_MAKEFILE:
264 TokenList = GetSplitValueList(Value)
265 if self._CustomMakefile is None:
266 self._CustomMakefile = {}
267 if len(TokenList) < 2:
268 self._CustomMakefile[TAB_COMPILER_MSFT] = TokenList[0]
269 self._CustomMakefile['GCC'] = TokenList[0]
270 else:
271 if TokenList[0] not in [TAB_COMPILER_MSFT, 'GCC']:
272 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
273 "No supported family [%s]" % TokenList[0],
274 File=self.MetaFile, Line=Record[-1])
275 self._CustomMakefile[TokenList[0]] = TokenList[1]
276 else:
277 self._Defs[Name] = Value
278 self._Macros[Name] = Value
279
280 #
281 # Retrieve information in sections specific to Edk.x modules
282 #
283 if not self._ModuleType:
284 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
285 "MODULE_TYPE is not given", File=self.MetaFile)
286 if self._ModuleType not in SUP_MODULE_LIST:
287 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
288 for Record in RecordList:
289 Name = Record[1]
290 if Name == "MODULE_TYPE":
291 LineNo = Record[6]
292 break
293 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
294 "MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self._ModuleType, ' '.join(l for l in SUP_MODULE_LIST)),
295 File=self.MetaFile, Line=LineNo)
296 if (self._Specification is None) or (not 'PI_SPECIFICATION_VERSION' in self._Specification) or (int(self._Specification['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):
297 if self._ModuleType == SUP_MODULE_SMM_CORE:
298 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)
299 if (self._Specification is None) or (not 'PI_SPECIFICATION_VERSION' in self._Specification) or (int(self._Specification['PI_SPECIFICATION_VERSION'], 16) < 0x00010032):
300 if self._ModuleType == SUP_MODULE_MM_CORE_STANDALONE:
301 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)
302 if self._ModuleType == SUP_MODULE_MM_STANDALONE:
303 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)
304 if 'PCI_DEVICE_ID' in self._Defs and 'PCI_VENDOR_ID' in self._Defs \
305 and 'PCI_CLASS_CODE' in self._Defs and 'PCI_REVISION' in self._Defs:
306 self._BuildType = 'UEFI_OPTIONROM'
307 if 'PCI_COMPRESS' in self._Defs:
308 if self._Defs['PCI_COMPRESS'] not in ('TRUE', 'FALSE'):
309 EdkLogger.error("build", FORMAT_INVALID, "Expected TRUE/FALSE for PCI_COMPRESS: %s" % self.MetaFile)
310
311 elif 'UEFI_HII_RESOURCE_SECTION' in self._Defs \
312 and self._Defs['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':
313 self._BuildType = 'UEFI_HII'
314 else:
315 self._BuildType = self._ModuleType.upper()
316
317 if self._DxsFile:
318 File = PathClass(NormPath(self._DxsFile), self._ModuleDir, Arch=self._Arch)
319 # check the file validation
320 ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)
321 if ErrorCode != 0:
322 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo,
323 File=self.MetaFile, Line=LineNo)
324 if not self._DependencyFileList:
325 self._DependencyFileList = []
326 self._DependencyFileList.append(File)
327
328 ## Retrieve file version
329 @cached_property
330 def AutoGenVersion(self):
331 RetVal = 0x00010000
332 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
333 for Record in RecordList:
334 if Record[1] == TAB_INF_DEFINES_INF_VERSION:
335 if '.' in Record[2]:
336 ValueList = Record[2].split('.')
337 Major = '%04o' % int(ValueList[0], 0)
338 Minor = '%04o' % int(ValueList[1], 0)
339 RetVal = int('0x' + Major + Minor, 0)
340 else:
341 RetVal = int(Record[2], 0)
342 break
343 return RetVal
344
345 ## Retrieve BASE_NAME
346 @cached_property
347 def BaseName(self):
348 if self._BaseName is None:
349 self._GetHeaderInfo()
350 if self._BaseName is None:
351 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BASE_NAME name", File=self.MetaFile)
352 return self._BaseName
353
354 ## Retrieve DxsFile
355 @cached_property
356 def DxsFile(self):
357 if self._DxsFile is None:
358 self._GetHeaderInfo()
359 if self._DxsFile is None:
360 self._DxsFile = ''
361 return self._DxsFile
362
363 ## Retrieve MODULE_TYPE
364 @cached_property
365 def ModuleType(self):
366 if self._ModuleType is None:
367 self._GetHeaderInfo()
368 if self._ModuleType is None:
369 self._ModuleType = SUP_MODULE_BASE
370 if self._ModuleType not in SUP_MODULE_LIST:
371 self._ModuleType = SUP_MODULE_USER_DEFINED
372 return self._ModuleType
373
374 ## Retrieve COMPONENT_TYPE
375 @cached_property
376 def ComponentType(self):
377 if self._ComponentType is None:
378 self._GetHeaderInfo()
379 if self._ComponentType is None:
380 self._ComponentType = SUP_MODULE_USER_DEFINED
381 return self._ComponentType
382
383 ## Retrieve "BUILD_TYPE"
384 @cached_property
385 def BuildType(self):
386 if self._BuildType is None:
387 self._GetHeaderInfo()
388 if not self._BuildType:
389 self._BuildType = SUP_MODULE_BASE
390 return self._BuildType
391
392 ## Retrieve file guid
393 @cached_property
394 def Guid(self):
395 if self._Guid is None:
396 self._GetHeaderInfo()
397 if self._Guid is None:
398 self._Guid = '00000000-0000-0000-0000-000000000000'
399 return self._Guid
400
401 ## Retrieve module version
402 @cached_property
403 def Version(self):
404 if self._Version is None:
405 self._GetHeaderInfo()
406 if self._Version is None:
407 self._Version = '0.0'
408 return self._Version
409
410 ## Retrieve PCD_IS_DRIVER
411 @cached_property
412 def PcdIsDriver(self):
413 if self._PcdIsDriver is None:
414 self._GetHeaderInfo()
415 if self._PcdIsDriver is None:
416 self._PcdIsDriver = ''
417 return self._PcdIsDriver
418
419 ## Retrieve SHADOW
420 @cached_property
421 def Shadow(self):
422 if self._Shadow is None:
423 self._GetHeaderInfo()
424 if self._Shadow and self._Shadow.upper() == 'TRUE':
425 self._Shadow = True
426 else:
427 self._Shadow = False
428 return self._Shadow
429
430 ## Retrieve CUSTOM_MAKEFILE
431 @cached_property
432 def CustomMakefile(self):
433 if self._CustomMakefile is None:
434 self._GetHeaderInfo()
435 if self._CustomMakefile is None:
436 self._CustomMakefile = {}
437 return self._CustomMakefile
438
439 ## Retrieve EFI_SPECIFICATION_VERSION
440 @cached_property
441 def Specification(self):
442 if self._Specification is None:
443 self._GetHeaderInfo()
444 if self._Specification is None:
445 self._Specification = {}
446 return self._Specification
447
448 ## Retrieve LIBRARY_CLASS
449 @cached_property
450 def LibraryClass(self):
451 if self._LibraryClass is None:
452 self._GetHeaderInfo()
453 if self._LibraryClass is None:
454 self._LibraryClass = []
455 return self._LibraryClass
456
457 ## Retrieve ENTRY_POINT
458 @cached_property
459 def ModuleEntryPointList(self):
460 if self._ModuleEntryPointList is None:
461 self._GetHeaderInfo()
462 if self._ModuleEntryPointList is None:
463 self._ModuleEntryPointList = []
464 return self._ModuleEntryPointList
465
466 ## Retrieve UNLOAD_IMAGE
467 @cached_property
468 def ModuleUnloadImageList(self):
469 if self._ModuleUnloadImageList is None:
470 self._GetHeaderInfo()
471 if self._ModuleUnloadImageList is None:
472 self._ModuleUnloadImageList = []
473 return self._ModuleUnloadImageList
474
475 ## Retrieve CONSTRUCTOR
476 @cached_property
477 def ConstructorList(self):
478 if self._ConstructorList is None:
479 self._GetHeaderInfo()
480 if self._ConstructorList is None:
481 self._ConstructorList = []
482 return self._ConstructorList
483
484 ## Retrieve DESTRUCTOR
485 @cached_property
486 def DestructorList(self):
487 if self._DestructorList is None:
488 self._GetHeaderInfo()
489 if self._DestructorList is None:
490 self._DestructorList = []
491 return self._DestructorList
492
493 ## Retrieve definies other than above ones
494 @cached_property
495 def Defines(self):
496 self._GetHeaderInfo()
497 return self._Defs
498
499 ## Retrieve binary files
500 @cached_class_function
501 def _GetBinaries(self):
502 RetVal = []
503 RecordList = self._RawData[MODEL_EFI_BINARY_FILE, self._Arch, self._Platform]
504 Macros = self._Macros
505 Macros['PROCESSOR'] = self._Arch
506 for Record in RecordList:
507 FileType = Record[0]
508 LineNo = Record[-1]
509 Target = TAB_COMMON
510 FeatureFlag = []
511 if Record[2]:
512 TokenList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)
513 if TokenList:
514 Target = TokenList[0]
515 if len(TokenList) > 1:
516 FeatureFlag = Record[1:]
517
518 File = PathClass(NormPath(Record[1], Macros), self._ModuleDir, '', FileType, True, self._Arch, '', Target)
519 # check the file validation
520 ErrorCode, ErrorInfo = File.Validate()
521 if ErrorCode != 0:
522 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
523 RetVal.append(File)
524 return RetVal
525
526 ## Retrieve binary files with error check.
527 @cached_property
528 def Binaries(self):
529 RetVal = self._GetBinaries()
530 if GlobalData.gIgnoreSource and not RetVal:
531 ErrorInfo = "The INF file does not contain any RetVal to use in creating the image\n"
532 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, ExtraData=ErrorInfo, File=self.MetaFile)
533
534 return RetVal
535
536 ## Retrieve source files
537 @cached_property
538 def Sources(self):
539 self._GetHeaderInfo()
540 # Ignore all source files in a binary build mode
541 if GlobalData.gIgnoreSource:
542 return []
543
544 RetVal = []
545 RecordList = self._RawData[MODEL_EFI_SOURCE_FILE, self._Arch, self._Platform]
546 Macros = self._Macros
547 for Record in RecordList:
548 LineNo = Record[-1]
549 ToolChainFamily = Record[1]
550 TagName = Record[2]
551 ToolCode = Record[3]
552
553 File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, '',
554 '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)
555 # check the file validation
556 ErrorCode, ErrorInfo = File.Validate()
557 if ErrorCode != 0:
558 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
559
560 RetVal.append(File)
561 # add any previously found dependency files to the source list
562 if self._DependencyFileList:
563 RetVal.extend(self._DependencyFileList)
564 return RetVal
565
566 ## Retrieve library classes employed by this module
567 @cached_property
568 def LibraryClasses(self):
569 RetVal = OrderedDict()
570 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform]
571 for Record in RecordList:
572 Lib = Record[0]
573 Instance = Record[1]
574 if Instance:
575 Instance = NormPath(Instance, self._Macros)
576 RetVal[Lib] = Instance
577 else:
578 RetVal[Lib] = None
579 return RetVal
580
581 ## Retrieve library names (for Edk.x style of modules)
582 @cached_property
583 def Libraries(self):
584 RetVal = []
585 RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch, self._Platform]
586 for Record in RecordList:
587 LibraryName = ReplaceMacro(Record[0], self._Macros, False)
588 # in case of name with '.lib' extension, which is unusual in Edk.x inf
589 LibraryName = os.path.splitext(LibraryName)[0]
590 if LibraryName not in RetVal:
591 RetVal.append(LibraryName)
592 return RetVal
593
594 @cached_property
595 def ProtocolComments(self):
596 self.Protocols
597 return self._ProtocolComments
598
599 ## Retrieve protocols consumed/produced by this module
600 @cached_property
601 def Protocols(self):
602 RetVal = OrderedDict()
603 self._ProtocolComments = OrderedDict()
604 RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self._Platform]
605 for Record in RecordList:
606 CName = Record[0]
607 Value = _ProtocolValue(CName, self.Packages, self.MetaFile.Path)
608 if Value is None:
609 PackageList = "\n\t".join(str(P) for P in self.Packages)
610 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
611 "Value of Protocol [%s] is not found under [Protocols] section in" % CName,
612 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
613 RetVal[CName] = Value
614 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
615 self._ProtocolComments[CName] = [a[0] for a in CommentRecords]
616 return RetVal
617
618 @cached_property
619 def PpiComments(self):
620 self.Ppis
621 return self._PpiComments
622
623 ## Retrieve PPIs consumed/produced by this module
624 @cached_property
625 def Ppis(self):
626 RetVal = OrderedDict()
627 self._PpiComments = OrderedDict()
628 RecordList = self._RawData[MODEL_EFI_PPI, self._Arch, self._Platform]
629 for Record in RecordList:
630 CName = Record[0]
631 Value = _PpiValue(CName, self.Packages, self.MetaFile.Path)
632 if Value is None:
633 PackageList = "\n\t".join(str(P) for P in self.Packages)
634 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
635 "Value of PPI [%s] is not found under [Ppis] section in " % CName,
636 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
637 RetVal[CName] = Value
638 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
639 self._PpiComments[CName] = [a[0] for a in CommentRecords]
640 return RetVal
641
642 @cached_property
643 def GuidComments(self):
644 self.Guids
645 return self._GuidComments
646
647 ## Retrieve GUIDs consumed/produced by this module
648 @cached_property
649 def Guids(self):
650 RetVal = OrderedDict()
651 self._GuidComments = OrderedDict()
652 RecordList = self._RawData[MODEL_EFI_GUID, self._Arch, self._Platform]
653 for Record in RecordList:
654 CName = Record[0]
655 Value = GuidValue(CName, self.Packages, self.MetaFile.Path)
656 if Value is None:
657 PackageList = "\n\t".join(str(P) for P in self.Packages)
658 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
659 "Value of Guid [%s] is not found under [Guids] section in" % CName,
660 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
661 RetVal[CName] = Value
662 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
663 self._GuidComments[CName] = [a[0] for a in CommentRecords]
664 return RetVal
665
666 ## Retrieve include paths necessary for this module (for Edk.x style of modules)
667 @cached_property
668 def Includes(self):
669 RetVal = []
670 if self._SourceOverridePath:
671 RetVal.append(self._SourceOverridePath)
672
673 Macros = self._Macros
674 Macros['PROCESSOR'] = GlobalData.gEdkGlobal.get('PROCESSOR', self._Arch)
675 RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform]
676 for Record in RecordList:
677 File = NormPath(Record[0], Macros)
678 if File[0] == '.':
679 File = os.path.join(self._ModuleDir, File)
680 else:
681 File = mws.join(GlobalData.gWorkspace, File)
682 File = RealPath(os.path.normpath(File))
683 if File:
684 RetVal.append(File)
685 return RetVal
686
687 ## Retrieve packages this module depends on
688 @cached_property
689 def Packages(self):
690 RetVal = []
691 RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch, self._Platform]
692 Macros = self._Macros
693 for Record in RecordList:
694 File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
695 # check the file validation
696 ErrorCode, ErrorInfo = File.Validate('.dec')
697 if ErrorCode != 0:
698 LineNo = Record[-1]
699 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
700 # parse this package now. we need it to get protocol/ppi/guid value
701 RetVal.append(self._Bdb[File, self._Arch, self._Target, self._Toolchain])
702 return RetVal
703
704 ## Retrieve PCD comments
705 @cached_property
706 def PcdComments(self):
707 self.Pcds
708 return self._PcdComments
709
710 ## Retrieve PCDs used in this module
711 @cached_property
712 def Pcds(self):
713 self._PcdComments = OrderedDict()
714 RetVal = OrderedDict()
715 RetVal.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
716 RetVal.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
717 RetVal.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
718 RetVal.update(self._GetPcd(MODEL_PCD_DYNAMIC))
719 RetVal.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
720 return RetVal
721
722 @cached_property
723 def PcdsName(self):
724 PcdsName = set()
725 for Type in (MODEL_PCD_FIXED_AT_BUILD,MODEL_PCD_PATCHABLE_IN_MODULE,MODEL_PCD_FEATURE_FLAG,MODEL_PCD_DYNAMIC,MODEL_PCD_DYNAMIC_EX):
726 RecordList = self._RawData[Type, self._Arch, self._Platform]
727 for TokenSpaceGuid, PcdCName, _, _, _, _, _ in RecordList:
728 PcdsName.add((PcdCName, TokenSpaceGuid))
729 return PcdsName
730
731 ## Retrieve build options specific to this module
732 @cached_property
733 def BuildOptions(self):
734 if self._BuildOptions is None:
735 self._BuildOptions = OrderedDict()
736 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, self._Platform]
737 for Record in RecordList:
738 ToolChainFamily = Record[0]
739 ToolChain = Record[1]
740 Option = Record[2]
741 if (ToolChainFamily, ToolChain) not in self._BuildOptions or Option.startswith('='):
742 self._BuildOptions[ToolChainFamily, ToolChain] = Option
743 else:
744 # concatenate the option string if they're for the same tool
745 OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
746 self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
747 return self._BuildOptions
748
749 ## Retrieve dependency expression
750 @cached_property
751 def Depex(self):
752 RetVal = tdict(False, 2)
753
754 # If the module has only Binaries and no Sources, then ignore [Depex]
755 if not self.Sources and self.Binaries:
756 return RetVal
757
758 RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
759 # PEIM and DXE drivers must have a valid [Depex] section
760 if len(self.LibraryClass) == 0 and len(RecordList) == 0:
761 if self.ModuleType == SUP_MODULE_DXE_DRIVER or self.ModuleType == SUP_MODULE_PEIM or self.ModuleType == SUP_MODULE_DXE_SMM_DRIVER or \
762 self.ModuleType == SUP_MODULE_DXE_SAL_DRIVER or self.ModuleType == SUP_MODULE_DXE_RUNTIME_DRIVER:
763 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
764 % self.ModuleType, File=self.MetaFile)
765
766 if len(RecordList) != 0 and self.ModuleType == SUP_MODULE_USER_DEFINED:
767 for Record in RecordList:
768 if Record[4] not in [SUP_MODULE_PEIM, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_SMM_DRIVER]:
769 EdkLogger.error('build', FORMAT_INVALID,
770 "'%s' module must specify the type of [Depex] section" % self.ModuleType,
771 File=self.MetaFile)
772
773 TemporaryDictionary = OrderedDict()
774 for Record in RecordList:
775 DepexStr = ReplaceMacro(Record[0], self._Macros, False)
776 Arch = Record[3]
777 ModuleType = Record[4]
778 TokenList = DepexStr.split()
779 if (Arch, ModuleType) not in TemporaryDictionary:
780 TemporaryDictionary[Arch, ModuleType] = []
781 DepexList = TemporaryDictionary[Arch, ModuleType]
782 for Token in TokenList:
783 if Token in DEPEX_SUPPORTED_OPCODE_SET:
784 DepexList.append(Token)
785 elif Token.endswith(".inf"): # module file name
786 ModuleFile = os.path.normpath(Token)
787 Module = self.BuildDatabase[ModuleFile]
788 if Module is None:
789 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Module is not found in active platform",
790 ExtraData=Token, File=self.MetaFile, Line=Record[-1])
791 DepexList.append(Module.Guid)
792 else:
793 # it use the Fixed PCD format
794 if '.' in Token:
795 if tuple(Token.split('.')[::-1]) not in self.Pcds:
796 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])
797 else:
798 if self.Pcds[tuple(Token.split('.')[::-1])].DatumType != TAB_VOID:
799 EdkLogger.error('build', FORMAT_INVALID, "PCD [{}] used in [Depex] section should be VOID* datum type".format(Token), File=self.MetaFile, Line=Record[-1])
800 Value = Token
801 else:
802 # get the GUID value now
803 Value = _ProtocolValue(Token, self.Packages, self.MetaFile.Path)
804 if Value is None:
805 Value = _PpiValue(Token, self.Packages, self.MetaFile.Path)
806 if Value is None:
807 Value = GuidValue(Token, self.Packages, self.MetaFile.Path)
808
809 if Value is None:
810 PackageList = "\n\t".join(str(P) for P in self.Packages)
811 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
812 "Value of [%s] is not found in" % Token,
813 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
814 DepexList.append(Value)
815 for Arch, ModuleType in TemporaryDictionary:
816 RetVal[Arch, ModuleType] = TemporaryDictionary[Arch, ModuleType]
817 return RetVal
818
819 ## Retrieve dependency expression
820 @cached_property
821 def DepexExpression(self):
822 RetVal = tdict(False, 2)
823 RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
824 TemporaryDictionary = OrderedDict()
825 for Record in RecordList:
826 DepexStr = ReplaceMacro(Record[0], self._Macros, False)
827 Arch = Record[3]
828 ModuleType = Record[4]
829 TokenList = DepexStr.split()
830 if (Arch, ModuleType) not in TemporaryDictionary:
831 TemporaryDictionary[Arch, ModuleType] = ''
832 for Token in TokenList:
833 TemporaryDictionary[Arch, ModuleType] = TemporaryDictionary[Arch, ModuleType] + Token.strip() + ' '
834 for Arch, ModuleType in TemporaryDictionary:
835 RetVal[Arch, ModuleType] = TemporaryDictionary[Arch, ModuleType]
836 return RetVal
837
838 @cached_class_function
839 def GetGuidsUsedByPcd(self):
840 self.Pcds
841 return self._GuidsUsedByPcd
842
843 ## Retrieve PCD for given type
844 def _GetPcd(self, Type):
845 Pcds = OrderedDict()
846 PcdDict = tdict(True, 4)
847 PcdList = []
848 RecordList = self._RawData[Type, self._Arch, self._Platform]
849 for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Id, LineNo in RecordList:
850 PcdDict[Arch, Platform, PcdCName, TokenSpaceGuid] = (Setting, LineNo)
851 PcdList.append((PcdCName, TokenSpaceGuid))
852 # get the guid value
853 if TokenSpaceGuid not in self.Guids:
854 Value = GuidValue(TokenSpaceGuid, self.Packages, self.MetaFile.Path)
855 if Value is None:
856 PackageList = "\n\t".join(str(P) for P in self.Packages)
857 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
858 "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid,
859 ExtraData=PackageList, File=self.MetaFile, Line=LineNo)
860 self.Guids[TokenSpaceGuid] = Value
861 self._GuidsUsedByPcd[TokenSpaceGuid] = Value
862 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Id]
863 Comments = []
864 for CmtRec in CommentRecords:
865 Comments.append(CmtRec[0])
866 self._PcdComments[TokenSpaceGuid, PcdCName] = Comments
867
868 # resolve PCD type, value, datum info, etc. by getting its definition from package
869 _GuidDict = self.Guids.copy()
870 for PcdCName, TokenSpaceGuid in PcdList:
871 PcdRealName = PcdCName
872 Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid]
873 if Setting is None:
874 continue
875 ValueList = AnalyzePcdData(Setting)
876 DefaultValue = ValueList[0]
877 Pcd = PcdClassObject(
878 PcdCName,
879 TokenSpaceGuid,
880 '',
881 '',
882 DefaultValue,
883 '',
884 '',
885 {},
886 False,
887 self.Guids[TokenSpaceGuid]
888 )
889 if Type == MODEL_PCD_PATCHABLE_IN_MODULE and ValueList[1]:
890 # Patch PCD: TokenSpace.PcdCName|Value|Offset
891 Pcd.Offset = ValueList[1]
892
893 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
894 for Package in self.Packages:
895 for key in Package.Pcds:
896 if (Package.Pcds[key].TokenCName, Package.Pcds[key].TokenSpaceGuidCName) == (PcdRealName, TokenSpaceGuid):
897 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
898 Pcd_Type = item[0].split('_')[-1]
899 if Pcd_Type == Package.Pcds[key].Type:
900 Value = Package.Pcds[key]
901 Value.TokenCName = Package.Pcds[key].TokenCName + '_' + Pcd_Type
902 if len(key) == 2:
903 newkey = (Value.TokenCName, key[1])
904 elif len(key) == 3:
905 newkey = (Value.TokenCName, key[1], key[2])
906 del Package.Pcds[key]
907 Package.Pcds[newkey] = Value
908 break
909 else:
910 pass
911 else:
912 pass
913
914 # get necessary info from package declaring this PCD
915 for Package in self.Packages:
916 #
917 # 'dynamic' in INF means its type is determined by platform;
918 # if platform doesn't give its type, use 'lowest' one in the
919 # following order, if any
920 #
921 # TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_PATCHABLE_IN_MODULE, TAB_PCDS_FEATURE_FLAG, TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_EX
922 #
923 _GuidDict.update(Package.Guids)
924 PcdType = self._PCD_TYPE_STRING_[Type]
925 if Type == MODEL_PCD_DYNAMIC:
926 Pcd.Pending = True
927 for T in PCD_TYPE_LIST:
928 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
929 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
930 if str(item[0]).endswith(T) and (item[0], item[1], T) in Package.Pcds:
931 PcdType = T
932 PcdCName = item[0]
933 break
934 else:
935 pass
936 break
937 else:
938 if (PcdRealName, TokenSpaceGuid, T) in Package.Pcds:
939 PcdType = T
940 break
941
942 else:
943 Pcd.Pending = False
944 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
945 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
946 Pcd_Type = item[0].split('_')[-1]
947 if Pcd_Type == PcdType:
948 PcdCName = item[0]
949 break
950 else:
951 pass
952 else:
953 pass
954
955 if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:
956 PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType]
957 Pcd.Type = PcdType
958 Pcd.TokenValue = PcdInPackage.TokenValue
959
960 #
961 # Check whether the token value exist or not.
962 #
963 if Pcd.TokenValue is None or Pcd.TokenValue == "":
964 EdkLogger.error(
965 'build',
966 FORMAT_INVALID,
967 "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid, PcdRealName, str(Package)),
968 File=self.MetaFile, Line=LineNo,
969 ExtraData=None
970 )
971 #
972 # Check hexadecimal token value length and format.
973 #
974 ReIsValidPcdTokenValue = re.compile(r"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re.DOTALL)
975 if Pcd.TokenValue.startswith("0x") or Pcd.TokenValue.startswith("0X"):
976 if ReIsValidPcdTokenValue.match(Pcd.TokenValue) is None:
977 EdkLogger.error(
978 'build',
979 FORMAT_INVALID,
980 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName, str(Package)),
981 File=self.MetaFile, Line=LineNo,
982 ExtraData=None
983 )
984
985 #
986 # Check decimal token value length and format.
987 #
988 else:
989 try:
990 TokenValueInt = int (Pcd.TokenValue, 10)
991 if (TokenValueInt < 0 or TokenValueInt > 4294967295):
992 EdkLogger.error(
993 'build',
994 FORMAT_INVALID,
995 "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)),
996 File=self.MetaFile, Line=LineNo,
997 ExtraData=None
998 )
999 except:
1000 EdkLogger.error(
1001 'build',
1002 FORMAT_INVALID,
1003 "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)),
1004 File=self.MetaFile, Line=LineNo,
1005 ExtraData=None
1006 )
1007
1008 Pcd.DatumType = PcdInPackage.DatumType
1009 Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize
1010 Pcd.InfDefaultValue = Pcd.DefaultValue
1011 if not Pcd.DefaultValue:
1012 Pcd.DefaultValue = PcdInPackage.DefaultValue
1013 else:
1014 try:
1015 Pcd.DefaultValue = ValueExpressionEx(Pcd.DefaultValue, Pcd.DatumType, _GuidDict)(True)
1016 except BadExpression as Value:
1017 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(TokenSpaceGuid, PcdRealName, Pcd.DefaultValue, Value),
1018 File=self.MetaFile, Line=LineNo)
1019 break
1020 else:
1021 EdkLogger.error(
1022 'build',
1023 FORMAT_INVALID,
1024 "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdRealName, self.MetaFile),
1025 File=self.MetaFile, Line=LineNo,
1026 ExtraData="\t%s" % '\n\t'.join(str(P) for P in self.Packages)
1027 )
1028 Pcds[PcdCName, TokenSpaceGuid] = Pcd
1029
1030 return Pcds
1031
1032 ## check whether current module is binary module
1033 @property
1034 def IsBinaryModule(self):
1035 if (self.Binaries and not self.Sources) or GlobalData.gIgnoreSource:
1036 return True
1037 return False