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