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