]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
BaseTools/build: Expand PREBUILD/POSTBUILD DSC actions
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / WorkspaceDatabase.py
1 ## @file
2 # This file is used to create a database used by build tool
3 #
4 # Copyright (c) 2008 - 2017, 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 ##
16 # Import Modules
17 #
18 import sqlite3
19 import Common.LongFilePathOs as os
20 import pickle
21 import uuid
22
23 import Common.EdkLogger as EdkLogger
24 import Common.GlobalData as GlobalData
25 from Common.MultipleWorkspace import MultipleWorkspace as mws
26
27 from Common.String import *
28 from Common.DataType import *
29 from Common.Misc import *
30 from types import *
31
32 from CommonDataClass.CommonClass import SkuInfoClass
33
34 from MetaDataTable import *
35 from MetaFileTable import *
36 from MetaFileParser import *
37 from BuildClassObject import *
38 from WorkspaceCommon import GetDeclaredPcd
39 from Common.Misc import AnalyzeDscPcd
40 from Common.Misc import ProcessDuplicatedInf
41 import re
42 from Common.Parsing import IsValidWord
43 from Common.VariableAttributes import VariableAttributes
44 import Common.GlobalData as GlobalData
45
46 ## Platform build information from DSC file
47 #
48 # This class is used to retrieve information stored in database and convert them
49 # into PlatformBuildClassObject form for easier use for AutoGen.
50 #
51 class DscBuildData(PlatformBuildClassObject):
52 # dict used to convert PCD type in database to string used by build tool
53 _PCD_TYPE_STRING_ = {
54 MODEL_PCD_FIXED_AT_BUILD : "FixedAtBuild",
55 MODEL_PCD_PATCHABLE_IN_MODULE : "PatchableInModule",
56 MODEL_PCD_FEATURE_FLAG : "FeatureFlag",
57 MODEL_PCD_DYNAMIC : "Dynamic",
58 MODEL_PCD_DYNAMIC_DEFAULT : "Dynamic",
59 MODEL_PCD_DYNAMIC_HII : "DynamicHii",
60 MODEL_PCD_DYNAMIC_VPD : "DynamicVpd",
61 MODEL_PCD_DYNAMIC_EX : "DynamicEx",
62 MODEL_PCD_DYNAMIC_EX_DEFAULT : "DynamicEx",
63 MODEL_PCD_DYNAMIC_EX_HII : "DynamicExHii",
64 MODEL_PCD_DYNAMIC_EX_VPD : "DynamicExVpd",
65 }
66
67 # dict used to convert part of [Defines] to members of DscBuildData directly
68 _PROPERTY_ = {
69 #
70 # Required Fields
71 #
72 TAB_DSC_DEFINES_PLATFORM_NAME : "_PlatformName",
73 TAB_DSC_DEFINES_PLATFORM_GUID : "_Guid",
74 TAB_DSC_DEFINES_PLATFORM_VERSION : "_Version",
75 TAB_DSC_DEFINES_DSC_SPECIFICATION : "_DscSpecification",
76 #TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
77 #TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
78 #TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
79 TAB_DSC_DEFINES_SKUID_IDENTIFIER : "_SkuName",
80 #TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
81 TAB_DSC_DEFINES_BUILD_NUMBER : "_BuildNumber",
82 TAB_DSC_DEFINES_MAKEFILE_NAME : "_MakefileName",
83 TAB_DSC_DEFINES_BS_BASE_ADDRESS : "_BsBaseAddress",
84 TAB_DSC_DEFINES_RT_BASE_ADDRESS : "_RtBaseAddress",
85 #TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
86 #TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
87 }
88
89 # used to compose dummy library class name for those forced library instances
90 _NullLibraryNumber = 0
91
92 ## Constructor of DscBuildData
93 #
94 # Initialize object of DscBuildData
95 #
96 # @param FilePath The path of platform description file
97 # @param RawData The raw data of DSC file
98 # @param BuildDataBase Database used to retrieve module/package information
99 # @param Arch The target architecture
100 # @param Platform (not used for DscBuildData)
101 # @param Macros Macros used for replacement in DSC file
102 #
103 def __init__(self, FilePath, RawData, BuildDataBase, Arch='COMMON', Target=None, Toolchain=None):
104 self.MetaFile = FilePath
105 self._RawData = RawData
106 self._Bdb = BuildDataBase
107 self._Arch = Arch
108 self._Target = Target
109 self._Toolchain = Toolchain
110 self._Clear()
111 self._HandleOverridePath()
112
113 ## XXX[key] = value
114 def __setitem__(self, key, value):
115 self.__dict__[self._PROPERTY_[key]] = value
116
117 ## value = XXX[key]
118 def __getitem__(self, key):
119 return self.__dict__[self._PROPERTY_[key]]
120
121 ## "in" test support
122 def __contains__(self, key):
123 return key in self._PROPERTY_
124
125 ## Set all internal used members of DscBuildData to None
126 def _Clear(self):
127 self._Header = None
128 self._PlatformName = None
129 self._Guid = None
130 self._Version = None
131 self._DscSpecification = None
132 self._OutputDirectory = None
133 self._SupArchList = None
134 self._BuildTargets = None
135 self._SkuName = None
136 self._SkuIdentifier = None
137 self._AvilableSkuIds = None
138 self._PcdInfoFlag = None
139 self._VarCheckFlag = None
140 self._FlashDefinition = None
141 self._Prebuild = None
142 self._Postbuild = None
143 self._BuildNumber = None
144 self._MakefileName = None
145 self._BsBaseAddress = None
146 self._RtBaseAddress = None
147 self._SkuIds = None
148 self._Modules = None
149 self._LibraryInstances = None
150 self._LibraryClasses = None
151 self._Pcds = None
152 self._DecPcds = None
153 self._BuildOptions = None
154 self._ModuleTypeOptions = None
155 self._LoadFixAddress = None
156 self._RFCLanguages = None
157 self._ISOLanguages = None
158 self._VpdToolGuid = None
159 self.__Macros = None
160
161
162 ## handle Override Path of Module
163 def _HandleOverridePath(self):
164 RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]
165 Macros = self._Macros
166 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
167 for Record in RecordList:
168 ModuleId = Record[5]
169 LineNo = Record[6]
170 ModuleFile = PathClass(NormPath(Record[0]), GlobalData.gWorkspace, Arch=self._Arch)
171 RecordList = self._RawData[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH, self._Arch, None, ModuleId]
172 if RecordList != []:
173 SourceOverridePath = mws.join(GlobalData.gWorkspace, NormPath(RecordList[0][0]))
174
175 # Check if the source override path exists
176 if not os.path.isdir(SourceOverridePath):
177 EdkLogger.error('build', FILE_NOT_FOUND, Message='Source override path does not exist:', File=self.MetaFile, ExtraData=SourceOverridePath, Line=LineNo)
178
179 #Add to GlobalData Variables
180 GlobalData.gOverrideDir[ModuleFile.Key] = SourceOverridePath
181
182 ## Get current effective macros
183 def _GetMacros(self):
184 if self.__Macros == None:
185 self.__Macros = {}
186 self.__Macros.update(GlobalData.gPlatformDefines)
187 self.__Macros.update(GlobalData.gGlobalDefines)
188 self.__Macros.update(GlobalData.gCommandLineDefines)
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 ## Retrieve all information in [Defines] section
211 #
212 # (Retriving all [Defines] information in one-shot is just to save time.)
213 #
214 def _GetHeaderInfo(self):
215 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]
216 for Record in RecordList:
217 Name = Record[1]
218 # items defined _PROPERTY_ don't need additional processing
219
220 # some special items in [Defines] section need special treatment
221 if Name == TAB_DSC_DEFINES_OUTPUT_DIRECTORY:
222 self._OutputDirectory = NormPath(Record[2], self._Macros)
223 if ' ' in self._OutputDirectory:
224 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in OUTPUT_DIRECTORY",
225 File=self.MetaFile, Line=Record[-1],
226 ExtraData=self._OutputDirectory)
227 elif Name == TAB_DSC_DEFINES_FLASH_DEFINITION:
228 self._FlashDefinition = PathClass(NormPath(Record[2], self._Macros), GlobalData.gWorkspace)
229 ErrorCode, ErrorInfo = self._FlashDefinition.Validate('.fdf')
230 if ErrorCode != 0:
231 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=Record[-1],
232 ExtraData=ErrorInfo)
233 elif Name == TAB_DSC_PREBUILD:
234 PrebuildValue = Record[2]
235 if Record[2][0] == '"':
236 if Record[2][-1] != '"':
237 EdkLogger.error('build', FORMAT_INVALID, 'Missing double quotes in the end of %s statement.' % TAB_DSC_PREBUILD,
238 File=self.MetaFile, Line=Record[-1])
239 PrebuildValue = Record[2][1:-1]
240 self._Prebuild = PrebuildValue
241 elif Name == TAB_DSC_POSTBUILD:
242 PostbuildValue = Record[2]
243 if Record[2][0] == '"':
244 if Record[2][-1] != '"':
245 EdkLogger.error('build', FORMAT_INVALID, 'Missing double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD,
246 File=self.MetaFile, Line=Record[-1])
247 PostbuildValue = Record[2][1:-1]
248 self._Postbuild = PostbuildValue
249 elif Name == TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES:
250 self._SupArchList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)
251 elif Name == TAB_DSC_DEFINES_BUILD_TARGETS:
252 self._BuildTargets = GetSplitValueList(Record[2])
253 elif Name == TAB_DSC_DEFINES_SKUID_IDENTIFIER:
254 if self._SkuName == None:
255 self._SkuName = Record[2]
256 self._SkuIdentifier = Record[2]
257 self._AvilableSkuIds = Record[2]
258 elif Name == TAB_DSC_DEFINES_PCD_INFO_GENERATION:
259 self._PcdInfoFlag = Record[2]
260 elif Name == TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION:
261 self._VarCheckFlag = Record[2]
262 elif Name == TAB_FIX_LOAD_TOP_MEMORY_ADDRESS:
263 try:
264 self._LoadFixAddress = int (Record[2], 0)
265 except:
266 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record[2]))
267 elif Name == TAB_DSC_DEFINES_RFC_LANGUAGES:
268 if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:
269 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for RFC_LANGUAGES must have double quotes around it, for example: RFC_LANGUAGES = "en-us;zh-hans"',
270 File=self.MetaFile, Line=Record[-1])
271 LanguageCodes = Record[2][1:-1]
272 if not LanguageCodes:
273 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
274 File=self.MetaFile, Line=Record[-1])
275 LanguageList = GetSplitValueList(LanguageCodes, TAB_SEMI_COLON_SPLIT)
276 # check whether there is empty entries in the list
277 if None in LanguageList:
278 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more empty language code is in RFC_LANGUAGES statement',
279 File=self.MetaFile, Line=Record[-1])
280 self._RFCLanguages = LanguageList
281 elif Name == TAB_DSC_DEFINES_ISO_LANGUAGES:
282 if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:
283 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
284 File=self.MetaFile, Line=Record[-1])
285 LanguageCodes = Record[2][1:-1]
286 if not LanguageCodes:
287 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
288 File=self.MetaFile, Line=Record[-1])
289 if len(LanguageCodes)%3:
290 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'bad ISO639-2 format for ISO_LANGUAGES',
291 File=self.MetaFile, Line=Record[-1])
292 LanguageList = []
293 for i in range(0, len(LanguageCodes), 3):
294 LanguageList.append(LanguageCodes[i:i+3])
295 self._ISOLanguages = LanguageList
296 elif Name == TAB_DSC_DEFINES_VPD_TOOL_GUID:
297 #
298 # try to convert GUID to a real UUID value to see whether the GUID is format
299 # for VPD_TOOL_GUID is correct.
300 #
301 try:
302 uuid.UUID(Record[2])
303 except:
304 EdkLogger.error("build", FORMAT_INVALID, "Invalid GUID format for VPD_TOOL_GUID", File=self.MetaFile)
305 self._VpdToolGuid = Record[2]
306 elif Name in self:
307 self[Name] = Record[2]
308 # set _Header to non-None in order to avoid database re-querying
309 self._Header = 'DUMMY'
310
311 ## Retrieve platform name
312 def _GetPlatformName(self):
313 if self._PlatformName == None:
314 if self._Header == None:
315 self._GetHeaderInfo()
316 if self._PlatformName == None:
317 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_NAME", File=self.MetaFile)
318 return self._PlatformName
319
320 ## Retrieve file guid
321 def _GetFileGuid(self):
322 if self._Guid == None:
323 if self._Header == None:
324 self._GetHeaderInfo()
325 if self._Guid == None:
326 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_GUID", File=self.MetaFile)
327 return self._Guid
328
329 ## Retrieve platform version
330 def _GetVersion(self):
331 if self._Version == None:
332 if self._Header == None:
333 self._GetHeaderInfo()
334 if self._Version == None:
335 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_VERSION", File=self.MetaFile)
336 return self._Version
337
338 ## Retrieve platform description file version
339 def _GetDscSpec(self):
340 if self._DscSpecification == None:
341 if self._Header == None:
342 self._GetHeaderInfo()
343 if self._DscSpecification == None:
344 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No DSC_SPECIFICATION", File=self.MetaFile)
345 return self._DscSpecification
346
347 ## Retrieve OUTPUT_DIRECTORY
348 def _GetOutpuDir(self):
349 if self._OutputDirectory == None:
350 if self._Header == None:
351 self._GetHeaderInfo()
352 if self._OutputDirectory == None:
353 self._OutputDirectory = os.path.join("Build", self._PlatformName)
354 return self._OutputDirectory
355
356 ## Retrieve SUPPORTED_ARCHITECTURES
357 def _GetSupArch(self):
358 if self._SupArchList == None:
359 if self._Header == None:
360 self._GetHeaderInfo()
361 if self._SupArchList == None:
362 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No SUPPORTED_ARCHITECTURES", File=self.MetaFile)
363 return self._SupArchList
364
365 ## Retrieve BUILD_TARGETS
366 def _GetBuildTarget(self):
367 if self._BuildTargets == None:
368 if self._Header == None:
369 self._GetHeaderInfo()
370 if self._BuildTargets == None:
371 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BUILD_TARGETS", File=self.MetaFile)
372 return self._BuildTargets
373
374 def _GetPcdInfoFlag(self):
375 if self._PcdInfoFlag == None or self._PcdInfoFlag.upper() == 'FALSE':
376 return False
377 elif self._PcdInfoFlag.upper() == 'TRUE':
378 return True
379 else:
380 return False
381 def _GetVarCheckFlag(self):
382 if self._VarCheckFlag == None or self._VarCheckFlag.upper() == 'FALSE':
383 return False
384 elif self._VarCheckFlag.upper() == 'TRUE':
385 return True
386 else:
387 return False
388 def _GetAviableSkuIds(self):
389 if self._AvilableSkuIds:
390 return self._AvilableSkuIds
391 return self.SkuIdentifier
392 def _GetSkuIdentifier(self):
393 if self._SkuName:
394 return self._SkuName
395 if self._SkuIdentifier == None:
396 if self._Header == None:
397 self._GetHeaderInfo()
398 return self._SkuIdentifier
399 ## Retrieve SKUID_IDENTIFIER
400 def _GetSkuName(self):
401 if self._SkuName == None:
402 if self._Header == None:
403 self._GetHeaderInfo()
404 if (self._SkuName == None or self._SkuName not in self.SkuIds):
405 self._SkuName = 'DEFAULT'
406 return self._SkuName
407
408 ## Override SKUID_IDENTIFIER
409 def _SetSkuName(self, Value):
410 self._SkuName = Value
411 self._Pcds = None
412
413 def _GetFdfFile(self):
414 if self._FlashDefinition == None:
415 if self._Header == None:
416 self._GetHeaderInfo()
417 if self._FlashDefinition == None:
418 self._FlashDefinition = ''
419 return self._FlashDefinition
420
421 def _GetPrebuild(self):
422 if self._Prebuild == None:
423 if self._Header == None:
424 self._GetHeaderInfo()
425 if self._Prebuild == None:
426 self._Prebuild = ''
427 return self._Prebuild
428
429 def _GetPostbuild(self):
430 if self._Postbuild == None:
431 if self._Header == None:
432 self._GetHeaderInfo()
433 if self._Postbuild == None:
434 self._Postbuild = ''
435 return self._Postbuild
436
437 ## Retrieve FLASH_DEFINITION
438 def _GetBuildNumber(self):
439 if self._BuildNumber == None:
440 if self._Header == None:
441 self._GetHeaderInfo()
442 if self._BuildNumber == None:
443 self._BuildNumber = ''
444 return self._BuildNumber
445
446 ## Retrieve MAKEFILE_NAME
447 def _GetMakefileName(self):
448 if self._MakefileName == None:
449 if self._Header == None:
450 self._GetHeaderInfo()
451 if self._MakefileName == None:
452 self._MakefileName = ''
453 return self._MakefileName
454
455 ## Retrieve BsBaseAddress
456 def _GetBsBaseAddress(self):
457 if self._BsBaseAddress == None:
458 if self._Header == None:
459 self._GetHeaderInfo()
460 if self._BsBaseAddress == None:
461 self._BsBaseAddress = ''
462 return self._BsBaseAddress
463
464 ## Retrieve RtBaseAddress
465 def _GetRtBaseAddress(self):
466 if self._RtBaseAddress == None:
467 if self._Header == None:
468 self._GetHeaderInfo()
469 if self._RtBaseAddress == None:
470 self._RtBaseAddress = ''
471 return self._RtBaseAddress
472
473 ## Retrieve the top address for the load fix address
474 def _GetLoadFixAddress(self):
475 if self._LoadFixAddress == None:
476 if self._Header == None:
477 self._GetHeaderInfo()
478
479 if self._LoadFixAddress == None:
480 self._LoadFixAddress = self._Macros.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS, '0')
481
482 try:
483 self._LoadFixAddress = int (self._LoadFixAddress, 0)
484 except:
485 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self._LoadFixAddress))
486
487 #
488 # If command line defined, should override the value in DSC file.
489 #
490 if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines.keys():
491 try:
492 self._LoadFixAddress = int(GlobalData.gCommandLineDefines['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
493 except:
494 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (GlobalData.gCommandLineDefines['FIX_LOAD_TOP_MEMORY_ADDRESS']))
495
496 if self._LoadFixAddress < 0:
497 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self._LoadFixAddress))
498 if self._LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self._LoadFixAddress % 0x1000 != 0:
499 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self._LoadFixAddress))
500
501 return self._LoadFixAddress
502
503 ## Retrieve RFCLanguage filter
504 def _GetRFCLanguages(self):
505 if self._RFCLanguages == None:
506 if self._Header == None:
507 self._GetHeaderInfo()
508 if self._RFCLanguages == None:
509 self._RFCLanguages = []
510 return self._RFCLanguages
511
512 ## Retrieve ISOLanguage filter
513 def _GetISOLanguages(self):
514 if self._ISOLanguages == None:
515 if self._Header == None:
516 self._GetHeaderInfo()
517 if self._ISOLanguages == None:
518 self._ISOLanguages = []
519 return self._ISOLanguages
520 ## Retrieve the GUID string for VPD tool
521 def _GetVpdToolGuid(self):
522 if self._VpdToolGuid == None:
523 if self._Header == None:
524 self._GetHeaderInfo()
525 if self._VpdToolGuid == None:
526 self._VpdToolGuid = ''
527 return self._VpdToolGuid
528
529 ## Retrieve [SkuIds] section information
530 def _GetSkuIds(self):
531 if self._SkuIds == None:
532 self._SkuIds = sdict()
533 RecordList = self._RawData[MODEL_EFI_SKU_ID, self._Arch]
534 for Record in RecordList:
535 if Record[0] in [None, '']:
536 EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number',
537 File=self.MetaFile, Line=Record[-1])
538 if Record[1] in [None, '']:
539 EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name',
540 File=self.MetaFile, Line=Record[-1])
541 self._SkuIds[Record[1]] = Record[0]
542 if 'DEFAULT' not in self._SkuIds:
543 self._SkuIds['DEFAULT'] = '0'
544 if 'COMMON' not in self._SkuIds:
545 self._SkuIds['COMMON'] = '0'
546 return self._SkuIds
547
548 ## Retrieve [Components] section information
549 def _GetModules(self):
550 if self._Modules != None:
551 return self._Modules
552
553 self._Modules = sdict()
554 RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]
555 Macros = self._Macros
556 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
557 for Record in RecordList:
558 DuplicatedFile = False
559
560 ModuleFile = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
561 ModuleId = Record[5]
562 LineNo = Record[6]
563
564 # check the file validation
565 ErrorCode, ErrorInfo = ModuleFile.Validate('.inf')
566 if ErrorCode != 0:
567 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,
568 ExtraData=ErrorInfo)
569 # Check duplication
570 # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected
571 if self._Arch != 'COMMON' and ModuleFile in self._Modules:
572 DuplicatedFile = True
573
574 Module = ModuleBuildClassObject()
575 Module.MetaFile = ModuleFile
576
577 # get module private library instance
578 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, ModuleId]
579 for Record in RecordList:
580 LibraryClass = Record[0]
581 LibraryPath = PathClass(NormPath(Record[1], Macros), GlobalData.gWorkspace, Arch=self._Arch)
582 LineNo = Record[-1]
583
584 # check the file validation
585 ErrorCode, ErrorInfo = LibraryPath.Validate('.inf')
586 if ErrorCode != 0:
587 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,
588 ExtraData=ErrorInfo)
589
590 if LibraryClass == '' or LibraryClass == 'NULL':
591 self._NullLibraryNumber += 1
592 LibraryClass = 'NULL%d' % self._NullLibraryNumber
593 EdkLogger.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile, LibraryPath, LibraryClass))
594 Module.LibraryClasses[LibraryClass] = LibraryPath
595 if LibraryPath not in self.LibraryInstances:
596 self.LibraryInstances.append(LibraryPath)
597
598 # get module private PCD setting
599 for Type in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, \
600 MODEL_PCD_FEATURE_FLAG, MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]:
601 RecordList = self._RawData[Type, self._Arch, None, ModuleId]
602 for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:
603 TokenList = GetSplitValueList(Setting)
604 DefaultValue = TokenList[0]
605 if len(TokenList) > 1:
606 MaxDatumSize = TokenList[1]
607 else:
608 MaxDatumSize = ''
609 TypeString = self._PCD_TYPE_STRING_[Type]
610 Pcd = PcdClassObject(
611 PcdCName,
612 TokenSpaceGuid,
613 TypeString,
614 '',
615 DefaultValue,
616 '',
617 MaxDatumSize,
618 {},
619 False,
620 None
621 )
622 Module.Pcds[PcdCName, TokenSpaceGuid] = Pcd
623
624 # get module private build options
625 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, None, ModuleId]
626 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:
627 if (ToolChainFamily, ToolChain) not in Module.BuildOptions:
628 Module.BuildOptions[ToolChainFamily, ToolChain] = Option
629 else:
630 OptionString = Module.BuildOptions[ToolChainFamily, ToolChain]
631 Module.BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
632
633 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, None, ModuleId]
634 if DuplicatedFile and not RecordList:
635 EdkLogger.error('build', FILE_DUPLICATED, File=self.MetaFile, ExtraData=str(ModuleFile), Line=LineNo)
636 if RecordList:
637 if len(RecordList) != 1:
638 EdkLogger.error('build', OPTION_UNKNOWN, 'Only FILE_GUID can be listed in <Defines> section.',
639 File=self.MetaFile, ExtraData=str(ModuleFile), Line=LineNo)
640 ModuleFile = ProcessDuplicatedInf(ModuleFile, RecordList[0][2], GlobalData.gWorkspace)
641 ModuleFile.Arch = self._Arch
642
643 self._Modules[ModuleFile] = Module
644 return self._Modules
645
646 ## Retrieve all possible library instances used in this platform
647 def _GetLibraryInstances(self):
648 if self._LibraryInstances == None:
649 self._GetLibraryClasses()
650 return self._LibraryInstances
651
652 ## Retrieve [LibraryClasses] information
653 def _GetLibraryClasses(self):
654 if self._LibraryClasses == None:
655 self._LibraryInstances = []
656 #
657 # tdict is a special dict kind of type, used for selecting correct
658 # library instance for given library class and module type
659 #
660 LibraryClassDict = tdict(True, 3)
661 # track all library class names
662 LibraryClassSet = set()
663 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, -1]
664 Macros = self._Macros
665 for Record in RecordList:
666 LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, LineNo = Record
667 if LibraryClass == '' or LibraryClass == 'NULL':
668 self._NullLibraryNumber += 1
669 LibraryClass = 'NULL%d' % self._NullLibraryNumber
670 EdkLogger.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch, LibraryInstance, LibraryClass))
671 LibraryClassSet.add(LibraryClass)
672 LibraryInstance = PathClass(NormPath(LibraryInstance, Macros), GlobalData.gWorkspace, Arch=self._Arch)
673 # check the file validation
674 ErrorCode, ErrorInfo = LibraryInstance.Validate('.inf')
675 if ErrorCode != 0:
676 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,
677 ExtraData=ErrorInfo)
678
679 if ModuleType != 'COMMON' and ModuleType not in SUP_MODULE_LIST:
680 EdkLogger.error('build', OPTION_UNKNOWN, "Unknown module type [%s]" % ModuleType,
681 File=self.MetaFile, ExtraData=LibraryInstance, Line=LineNo)
682 LibraryClassDict[Arch, ModuleType, LibraryClass] = LibraryInstance
683 if LibraryInstance not in self._LibraryInstances:
684 self._LibraryInstances.append(LibraryInstance)
685
686 # resolve the specific library instance for each class and each module type
687 self._LibraryClasses = tdict(True)
688 for LibraryClass in LibraryClassSet:
689 # try all possible module types
690 for ModuleType in SUP_MODULE_LIST:
691 LibraryInstance = LibraryClassDict[self._Arch, ModuleType, LibraryClass]
692 if LibraryInstance == None:
693 continue
694 self._LibraryClasses[LibraryClass, ModuleType] = LibraryInstance
695
696 # for Edk style library instances, which are listed in different section
697 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
698 RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch]
699 for Record in RecordList:
700 File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
701 LineNo = Record[-1]
702 # check the file validation
703 ErrorCode, ErrorInfo = File.Validate('.inf')
704 if ErrorCode != 0:
705 EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,
706 ExtraData=ErrorInfo)
707 if File not in self._LibraryInstances:
708 self._LibraryInstances.append(File)
709 #
710 # we need the module name as the library class name, so we have
711 # to parse it here. (self._Bdb[] will trigger a file parse if it
712 # hasn't been parsed)
713 #
714 Library = self._Bdb[File, self._Arch, self._Target, self._Toolchain]
715 self._LibraryClasses[Library.BaseName, ':dummy:'] = Library
716 return self._LibraryClasses
717
718 def _ValidatePcd(self, PcdCName, TokenSpaceGuid, Setting, PcdType, LineNo):
719 if self._DecPcds == None:
720 self._DecPcds = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain)
721 FdfInfList = []
722 if GlobalData.gFdfParser:
723 FdfInfList = GlobalData.gFdfParser.Profile.InfList
724
725 PkgSet = set()
726 for Inf in FdfInfList:
727 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch=self._Arch)
728 if ModuleFile in self._Modules:
729 continue
730 ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]
731 PkgSet.update(ModuleData.Packages)
732 DecPcds = {}
733 for Pkg in PkgSet:
734 for Pcd in Pkg.Pcds:
735 DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]
736 self._DecPcds.update(DecPcds)
737
738 if (PcdCName, TokenSpaceGuid) not in self._DecPcds:
739 EdkLogger.error('build', PARSER_ERROR,
740 "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid, PcdCName, self._Arch),
741 File=self.MetaFile, Line=LineNo)
742 ValueList, IsValid, Index = AnalyzeDscPcd(Setting, PcdType, self._DecPcds[PcdCName, TokenSpaceGuid].DatumType)
743 if not IsValid and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
744 EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,
745 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
746 if ValueList[Index] and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
747 try:
748 ValueList[Index] = ValueExpression(ValueList[Index], GlobalData.gPlatformPcds)(True)
749 except WrnExpression, Value:
750 ValueList[Index] = Value.result
751 except EvaluationException, Excpt:
752 if hasattr(Excpt, 'Pcd'):
753 if Excpt.Pcd in GlobalData.gPlatformOtherPcds:
754 EdkLogger.error('Parser', FORMAT_INVALID, "Cannot use this PCD (%s) in an expression as"
755 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
756 " of the DSC file" % Excpt.Pcd,
757 File=self.MetaFile, Line=LineNo)
758 else:
759 EdkLogger.error('Parser', FORMAT_INVALID, "PCD (%s) is not defined in DSC file" % Excpt.Pcd,
760 File=self.MetaFile, Line=LineNo)
761 else:
762 EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),
763 File=self.MetaFile, Line=LineNo)
764 if ValueList[Index] == 'True':
765 ValueList[Index] = '1'
766 elif ValueList[Index] == 'False':
767 ValueList[Index] = '0'
768 if ValueList[Index]:
769 Valid, ErrStr = CheckPcdDatum(self._DecPcds[PcdCName, TokenSpaceGuid].DatumType, ValueList[Index])
770 if not Valid:
771 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,
772 ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
773 return ValueList
774
775 ## Retrieve all PCD settings in platform
776 def _GetPcds(self):
777 if self._Pcds == None:
778 self._Pcds = sdict()
779 self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
780 self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
781 self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
782 self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_DEFAULT))
783 self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_HII))
784 self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_VPD))
785 self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_EX_DEFAULT))
786 self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_EX_HII))
787 self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD))
788 return self._Pcds
789
790 ## Retrieve [BuildOptions]
791 def _GetBuildOptions(self):
792 if self._BuildOptions == None:
793 self._BuildOptions = sdict()
794 #
795 # Retrieve build option for EDKII and EDK style module
796 #
797 for CodeBase in (EDKII_NAME, EDK_NAME):
798 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, CodeBase]
799 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:
800 CurKey = (ToolChainFamily, ToolChain, CodeBase)
801 #
802 # Only flags can be appended
803 #
804 if CurKey not in self._BuildOptions or not ToolChain.endswith('_FLAGS') or Option.startswith('='):
805 self._BuildOptions[CurKey] = Option
806 else:
807 self._BuildOptions[CurKey] += ' ' + Option
808 return self._BuildOptions
809
810 def GetBuildOptionsByModuleType(self, Edk, ModuleType):
811 if self._ModuleTypeOptions == None:
812 self._ModuleTypeOptions = sdict()
813 if (Edk, ModuleType) not in self._ModuleTypeOptions:
814 options = sdict()
815 self._ModuleTypeOptions[Edk, ModuleType] = options
816 DriverType = '%s.%s' % (Edk, ModuleType)
817 CommonDriverType = '%s.%s' % ('COMMON', ModuleType)
818 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, DriverType]
819 for ToolChainFamily, ToolChain, Option, Arch, Type, Dummy3, Dummy4 in RecordList:
820 if Type == DriverType or Type == CommonDriverType:
821 Key = (ToolChainFamily, ToolChain, Edk)
822 if Key not in options or not ToolChain.endswith('_FLAGS') or Option.startswith('='):
823 options[Key] = Option
824 else:
825 options[Key] += ' ' + Option
826 return self._ModuleTypeOptions[Edk, ModuleType]
827
828 ## Retrieve non-dynamic PCD settings
829 #
830 # @param Type PCD type
831 #
832 # @retval a dict object contains settings of given PCD type
833 #
834 def _GetPcd(self, Type):
835 Pcds = sdict()
836 #
837 # tdict is a special dict kind of type, used for selecting correct
838 # PCD settings for certain ARCH
839 #
840
841 SkuObj = SkuClass(self.SkuIdentifier,self.SkuIds)
842
843 PcdDict = tdict(True, 3)
844 PcdSet = set()
845 # Find out all possible PCD candidates for self._Arch
846 RecordList = self._RawData[Type, self._Arch]
847 PcdValueDict = sdict()
848 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
849 if SkuName in (SkuObj.SystemSkuId,'DEFAULT','COMMON'):
850 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,Dummy4))
851 PcdDict[Arch, PcdCName, TokenSpaceGuid,SkuName] = Setting
852
853 #handle pcd value override
854 for PcdCName, TokenSpaceGuid, SkuName,Dummy4 in PcdSet:
855 Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid,SkuName]
856 if Setting == None:
857 continue
858 PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
859 if (PcdCName, TokenSpaceGuid) in PcdValueDict:
860 PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue,DatumType,MaxDatumSize)
861 else:
862 PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue,DatumType,MaxDatumSize)}
863
864 PcdsKeys = PcdValueDict.keys()
865 for PcdCName,TokenSpaceGuid in PcdsKeys:
866
867 PcdSetting = PcdValueDict[PcdCName, TokenSpaceGuid]
868 PcdValue = None
869 DatumType = None
870 MaxDatumSize = None
871 if 'COMMON' in PcdSetting:
872 PcdValue,DatumType,MaxDatumSize = PcdSetting['COMMON']
873 if 'DEFAULT' in PcdSetting:
874 PcdValue,DatumType,MaxDatumSize = PcdSetting['DEFAULT']
875 if SkuObj.SystemSkuId in PcdSetting:
876 PcdValue,DatumType,MaxDatumSize = PcdSetting[SkuObj.SystemSkuId]
877
878 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
879 PcdCName,
880 TokenSpaceGuid,
881 self._PCD_TYPE_STRING_[Type],
882 DatumType,
883 PcdValue,
884 '',
885 MaxDatumSize,
886 {},
887 False,
888 None
889 )
890 return Pcds
891
892 ## Retrieve dynamic PCD settings
893 #
894 # @param Type PCD type
895 #
896 # @retval a dict object contains settings of given PCD type
897 #
898 def _GetDynamicPcd(self, Type):
899
900 SkuObj = SkuClass(self.SkuIdentifier,self.SkuIds)
901
902 Pcds = sdict()
903 #
904 # tdict is a special dict kind of type, used for selecting correct
905 # PCD settings for certain ARCH and SKU
906 #
907 PcdDict = tdict(True, 4)
908 PcdList = []
909 # Find out all possible PCD candidates for self._Arch
910 RecordList = self._RawData[Type, self._Arch]
911 AvailableSkuIdSet = SkuObj.AvailableSkuIdSet.copy()
912
913 AvailableSkuIdSet.update({'DEFAULT':0,'COMMON':0})
914 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
915 if SkuName not in AvailableSkuIdSet:
916 continue
917
918 PcdList.append((PcdCName, TokenSpaceGuid, SkuName,Dummy4))
919 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
920 # Remove redundant PCD candidates, per the ARCH and SKU
921 for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:
922
923 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
924 if Setting == None:
925 continue
926
927 PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
928 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName], '', '', '', '', '', PcdValue)
929 if (PcdCName,TokenSpaceGuid) in Pcds.keys():
930 pcdObject = Pcds[PcdCName,TokenSpaceGuid]
931 pcdObject.SkuInfoList[SkuName] = SkuInfo
932 if MaxDatumSize.strip():
933 CurrentMaxSize = int(MaxDatumSize.strip(),0)
934 else:
935 CurrentMaxSize = 0
936 if pcdObject.MaxDatumSize:
937 PcdMaxSize = int(pcdObject.MaxDatumSize,0)
938 else:
939 PcdMaxSize = 0
940 if CurrentMaxSize > PcdMaxSize:
941 pcdObject.MaxDatumSize = str(CurrentMaxSize)
942 else:
943 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
944 PcdCName,
945 TokenSpaceGuid,
946 self._PCD_TYPE_STRING_[Type],
947 DatumType,
948 PcdValue,
949 '',
950 MaxDatumSize,
951 {SkuName : SkuInfo},
952 False,
953 None
954 )
955
956 for pcd in Pcds.values():
957 pcdDecObject = self._DecPcds[pcd.TokenCName,pcd.TokenSpaceGuidCName]
958 if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
959 valuefromDec = pcdDecObject.DefaultValue
960 SkuInfo = SkuInfoClass('DEFAULT', '0', '', '', '', '', '', valuefromDec)
961 pcd.SkuInfoList['DEFAULT'] = SkuInfo
962 elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
963 pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
964 del(pcd.SkuInfoList['COMMON'])
965 elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
966 del(pcd.SkuInfoList['COMMON'])
967 if SkuObj.SkuUsageType == SkuObj.SINGLE:
968 if 'DEFAULT' in pcd.SkuInfoList.keys() and SkuObj.SystemSkuId not in pcd.SkuInfoList.keys():
969 pcd.SkuInfoList[SkuObj.SystemSkuId] = pcd.SkuInfoList['DEFAULT']
970 del(pcd.SkuInfoList['DEFAULT'])
971
972 return Pcds
973
974 def CompareVarAttr(self, Attr1, Attr2):
975 if not Attr1 or not Attr2: # for empty string
976 return True
977 Attr1s = [attr.strip() for attr in Attr1.split(",")]
978 Attr1Set = set(Attr1s)
979 Attr2s = [attr.strip() for attr in Attr2.split(",")]
980 Attr2Set = set(Attr2s)
981 if Attr2Set == Attr1Set:
982 return True
983 else:
984 return False
985 ## Retrieve dynamic HII PCD settings
986 #
987 # @param Type PCD type
988 #
989 # @retval a dict object contains settings of given PCD type
990 #
991 def _GetDynamicHiiPcd(self, Type):
992
993 SkuObj = SkuClass(self.SkuIdentifier,self.SkuIds)
994 VariableAttrs = {}
995
996 Pcds = sdict()
997 #
998 # tdict is a special dict kind of type, used for selecting correct
999 # PCD settings for certain ARCH and SKU
1000 #
1001 PcdDict = tdict(True, 4)
1002 PcdSet = set()
1003 RecordList = self._RawData[Type, self._Arch]
1004 # Find out all possible PCD candidates for self._Arch
1005 AvailableSkuIdSet = SkuObj.AvailableSkuIdSet.copy()
1006
1007 AvailableSkuIdSet.update({'DEFAULT':0,'COMMON':0})
1008 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
1009 if SkuName not in AvailableSkuIdSet:
1010 continue
1011 PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,Dummy4))
1012 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
1013 # Remove redundant PCD candidates, per the ARCH and SKU
1014 for PcdCName, TokenSpaceGuid,SkuName, Dummy4 in PcdSet:
1015
1016 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
1017 if Setting == None:
1018 continue
1019 VariableName, VariableGuid, VariableOffset, DefaultValue, VarAttribute = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
1020
1021 rt, Msg = VariableAttributes.ValidateVarAttributes(VarAttribute)
1022 if not rt:
1023 EdkLogger.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid, PcdCName)), Msg),
1024 ExtraData = "[%s]" % VarAttribute)
1025 ExceedMax = False
1026 FormatCorrect = True
1027 if VariableOffset.isdigit():
1028 if int(VariableOffset,10) > 0xFFFF:
1029 ExceedMax = True
1030 elif re.match(r'[\t\s]*0[xX][a-fA-F0-9]+$',VariableOffset):
1031 if int(VariableOffset,16) > 0xFFFF:
1032 ExceedMax = True
1033 # For Offset written in "A.B"
1034 elif VariableOffset.find('.') > -1:
1035 VariableOffsetList = VariableOffset.split(".")
1036 if not (len(VariableOffsetList) == 2
1037 and IsValidWord(VariableOffsetList[0])
1038 and IsValidWord(VariableOffsetList[1])):
1039 FormatCorrect = False
1040 else:
1041 FormatCorrect = False
1042 if not FormatCorrect:
1043 EdkLogger.error('Build', FORMAT_INVALID, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid,PcdCName)))
1044
1045 if ExceedMax:
1046 EdkLogger.error('Build', OPTION_VALUE_INVALID, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid,PcdCName)))
1047 if (VariableName, VariableGuid) not in VariableAttrs:
1048 VariableAttrs[(VariableName, VariableGuid)] = VarAttribute
1049 else:
1050 if not self.CompareVarAttr(VariableAttrs[(VariableName, VariableGuid)], VarAttribute):
1051 EdkLogger.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR, "The variable %s.%s for DynamicHii PCDs has conflicting attributes [%s] and [%s] " % (VariableGuid, VariableName, VarAttribute, VariableAttrs[(VariableName, VariableGuid)]))
1052
1053 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName], VariableName, VariableGuid, VariableOffset, DefaultValue, VariableAttribute = VarAttribute)
1054 pcdDecObject = self._DecPcds[PcdCName, TokenSpaceGuid]
1055 if (PcdCName,TokenSpaceGuid) in Pcds.keys():
1056 pcdObject = Pcds[PcdCName,TokenSpaceGuid]
1057 pcdObject.SkuInfoList[SkuName] = SkuInfo
1058 else:
1059 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
1060 PcdCName,
1061 TokenSpaceGuid,
1062 self._PCD_TYPE_STRING_[Type],
1063 '',
1064 DefaultValue,
1065 '',
1066 '',
1067 {SkuName : SkuInfo},
1068 False,
1069 None,
1070 pcdDecObject.validateranges,
1071 pcdDecObject.validlists,
1072 pcdDecObject.expressions
1073 )
1074
1075
1076 for pcd in Pcds.values():
1077 SkuInfoObj = pcd.SkuInfoList.values()[0]
1078 pcdDecObject = self._DecPcds[pcd.TokenCName,pcd.TokenSpaceGuidCName]
1079 # Only fix the value while no value provided in DSC file.
1080 for sku in pcd.SkuInfoList.values():
1081 if (sku.HiiDefaultValue == "" or sku.HiiDefaultValue==None):
1082 sku.HiiDefaultValue = pcdDecObject.DefaultValue
1083 if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
1084 valuefromDec = pcdDecObject.DefaultValue
1085 SkuInfo = SkuInfoClass('DEFAULT', '0', SkuInfoObj.VariableName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec)
1086 pcd.SkuInfoList['DEFAULT'] = SkuInfo
1087 elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
1088 pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
1089 del(pcd.SkuInfoList['COMMON'])
1090 elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
1091 del(pcd.SkuInfoList['COMMON'])
1092
1093 if SkuObj.SkuUsageType == SkuObj.SINGLE:
1094 if 'DEFAULT' in pcd.SkuInfoList.keys() and SkuObj.SystemSkuId not in pcd.SkuInfoList.keys():
1095 pcd.SkuInfoList[SkuObj.SystemSkuId] = pcd.SkuInfoList['DEFAULT']
1096 del(pcd.SkuInfoList['DEFAULT'])
1097
1098
1099 if pcd.MaxDatumSize.strip():
1100 MaxSize = int(pcd.MaxDatumSize,0)
1101 else:
1102 MaxSize = 0
1103 if pcdDecObject.DatumType == 'VOID*':
1104 for (skuname,skuobj) in pcd.SkuInfoList.items():
1105 datalen = 0
1106 if skuobj.HiiDefaultValue.startswith("L"):
1107 datalen = (len(skuobj.HiiDefaultValue)- 3 + 1) * 2
1108 elif skuobj.HiiDefaultValue.startswith("{"):
1109 datalen = len(skuobj.HiiDefaultValue.split(","))
1110 else:
1111 datalen = len(skuobj.HiiDefaultValue) -2 + 1
1112 if datalen>MaxSize:
1113 MaxSize = datalen
1114 pcd.MaxDatumSize = str(MaxSize)
1115 return Pcds
1116
1117 ## Retrieve dynamic VPD PCD settings
1118 #
1119 # @param Type PCD type
1120 #
1121 # @retval a dict object contains settings of given PCD type
1122 #
1123 def _GetDynamicVpdPcd(self, Type):
1124
1125 SkuObj = SkuClass(self.SkuIdentifier,self.SkuIds)
1126
1127 Pcds = sdict()
1128 #
1129 # tdict is a special dict kind of type, used for selecting correct
1130 # PCD settings for certain ARCH and SKU
1131 #
1132 PcdDict = tdict(True, 4)
1133 PcdList = []
1134 # Find out all possible PCD candidates for self._Arch
1135 RecordList = self._RawData[Type, self._Arch]
1136 AvailableSkuIdSet = SkuObj.AvailableSkuIdSet.copy()
1137
1138 AvailableSkuIdSet.update({'DEFAULT':0,'COMMON':0})
1139 for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
1140 if SkuName not in AvailableSkuIdSet:
1141 continue
1142
1143 PcdList.append((PcdCName, TokenSpaceGuid,SkuName, Dummy4))
1144 PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
1145 # Remove redundant PCD candidates, per the ARCH and SKU
1146 for PcdCName, TokenSpaceGuid, SkuName,Dummy4 in PcdList:
1147 Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]
1148 if Setting == None:
1149 continue
1150 #
1151 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
1152 # For the Integer & Boolean type, the optional data can only be InitialValue.
1153 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
1154 # until the DEC parser has been called.
1155 #
1156 VpdOffset, MaxDatumSize, InitialValue = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
1157 SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName], '', '', '', '', VpdOffset, InitialValue)
1158 if (PcdCName,TokenSpaceGuid) in Pcds.keys():
1159 pcdObject = Pcds[PcdCName,TokenSpaceGuid]
1160 pcdObject.SkuInfoList[SkuName] = SkuInfo
1161 if MaxDatumSize.strip():
1162 CurrentMaxSize = int(MaxDatumSize.strip(),0)
1163 else:
1164 CurrentMaxSize = 0
1165 if pcdObject.MaxDatumSize:
1166 PcdMaxSize = int(pcdObject.MaxDatumSize,0)
1167 else:
1168 PcdMaxSize = 0
1169 if CurrentMaxSize > PcdMaxSize:
1170 pcdObject.MaxDatumSize = str(CurrentMaxSize)
1171 else:
1172 Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
1173 PcdCName,
1174 TokenSpaceGuid,
1175 self._PCD_TYPE_STRING_[Type],
1176 '',
1177 InitialValue,
1178 '',
1179 MaxDatumSize,
1180 {SkuName : SkuInfo},
1181 False,
1182 None
1183 )
1184 for pcd in Pcds.values():
1185 SkuInfoObj = pcd.SkuInfoList.values()[0]
1186 pcdDecObject = self._DecPcds[pcd.TokenCName,pcd.TokenSpaceGuidCName]
1187 if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
1188 valuefromDec = pcdDecObject.DefaultValue
1189 SkuInfo = SkuInfoClass('DEFAULT', '0', '', '', '','',SkuInfoObj.VpdOffset, valuefromDec)
1190 pcd.SkuInfoList['DEFAULT'] = SkuInfo
1191 elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
1192 pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
1193 del(pcd.SkuInfoList['COMMON'])
1194 elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
1195 del(pcd.SkuInfoList['COMMON'])
1196 if SkuObj.SkuUsageType == SkuObj.SINGLE:
1197 if 'DEFAULT' in pcd.SkuInfoList.keys() and SkuObj.SystemSkuId not in pcd.SkuInfoList.keys():
1198 pcd.SkuInfoList[SkuObj.SystemSkuId] = pcd.SkuInfoList['DEFAULT']
1199 del(pcd.SkuInfoList['DEFAULT'])
1200
1201 return Pcds
1202
1203 ## Add external modules
1204 #
1205 # The external modules are mostly those listed in FDF file, which don't
1206 # need "build".
1207 #
1208 # @param FilePath The path of module description file
1209 #
1210 def AddModule(self, FilePath):
1211 FilePath = NormPath(FilePath)
1212 if FilePath not in self.Modules:
1213 Module = ModuleBuildClassObject()
1214 Module.MetaFile = FilePath
1215 self.Modules.append(Module)
1216
1217 ## Add external PCDs
1218 #
1219 # The external PCDs are mostly those listed in FDF file to specify address
1220 # or offset information.
1221 #
1222 # @param Name Name of the PCD
1223 # @param Guid Token space guid of the PCD
1224 # @param Value Value of the PCD
1225 #
1226 def AddPcd(self, Name, Guid, Value):
1227 if (Name, Guid) not in self.Pcds:
1228 self.Pcds[Name, Guid] = PcdClassObject(Name, Guid, '', '', '', '', '', {}, False, None)
1229 self.Pcds[Name, Guid].DefaultValue = Value
1230
1231 _Macros = property(_GetMacros)
1232 Arch = property(_GetArch, _SetArch)
1233 Platform = property(_GetPlatformName)
1234 PlatformName = property(_GetPlatformName)
1235 Guid = property(_GetFileGuid)
1236 Version = property(_GetVersion)
1237 DscSpecification = property(_GetDscSpec)
1238 OutputDirectory = property(_GetOutpuDir)
1239 SupArchList = property(_GetSupArch)
1240 BuildTargets = property(_GetBuildTarget)
1241 SkuName = property(_GetSkuName, _SetSkuName)
1242 SkuIdentifier = property(_GetSkuIdentifier)
1243 AvilableSkuIds = property(_GetAviableSkuIds)
1244 PcdInfoFlag = property(_GetPcdInfoFlag)
1245 VarCheckFlag = property(_GetVarCheckFlag)
1246 FlashDefinition = property(_GetFdfFile)
1247 Prebuild = property(_GetPrebuild)
1248 Postbuild = property(_GetPostbuild)
1249 BuildNumber = property(_GetBuildNumber)
1250 MakefileName = property(_GetMakefileName)
1251 BsBaseAddress = property(_GetBsBaseAddress)
1252 RtBaseAddress = property(_GetRtBaseAddress)
1253 LoadFixAddress = property(_GetLoadFixAddress)
1254 RFCLanguages = property(_GetRFCLanguages)
1255 ISOLanguages = property(_GetISOLanguages)
1256 VpdToolGuid = property(_GetVpdToolGuid)
1257 SkuIds = property(_GetSkuIds)
1258 Modules = property(_GetModules)
1259 LibraryInstances = property(_GetLibraryInstances)
1260 LibraryClasses = property(_GetLibraryClasses)
1261 Pcds = property(_GetPcds)
1262 BuildOptions = property(_GetBuildOptions)
1263
1264 ## Platform build information from DEC file
1265 #
1266 # This class is used to retrieve information stored in database and convert them
1267 # into PackageBuildClassObject form for easier use for AutoGen.
1268 #
1269 class DecBuildData(PackageBuildClassObject):
1270 # dict used to convert PCD type in database to string used by build tool
1271 _PCD_TYPE_STRING_ = {
1272 MODEL_PCD_FIXED_AT_BUILD : "FixedAtBuild",
1273 MODEL_PCD_PATCHABLE_IN_MODULE : "PatchableInModule",
1274 MODEL_PCD_FEATURE_FLAG : "FeatureFlag",
1275 MODEL_PCD_DYNAMIC : "Dynamic",
1276 MODEL_PCD_DYNAMIC_DEFAULT : "Dynamic",
1277 MODEL_PCD_DYNAMIC_HII : "DynamicHii",
1278 MODEL_PCD_DYNAMIC_VPD : "DynamicVpd",
1279 MODEL_PCD_DYNAMIC_EX : "DynamicEx",
1280 MODEL_PCD_DYNAMIC_EX_DEFAULT : "DynamicEx",
1281 MODEL_PCD_DYNAMIC_EX_HII : "DynamicExHii",
1282 MODEL_PCD_DYNAMIC_EX_VPD : "DynamicExVpd",
1283 }
1284
1285 # dict used to convert part of [Defines] to members of DecBuildData directly
1286 _PROPERTY_ = {
1287 #
1288 # Required Fields
1289 #
1290 TAB_DEC_DEFINES_PACKAGE_NAME : "_PackageName",
1291 TAB_DEC_DEFINES_PACKAGE_GUID : "_Guid",
1292 TAB_DEC_DEFINES_PACKAGE_VERSION : "_Version",
1293 TAB_DEC_DEFINES_PKG_UNI_FILE : "_PkgUniFile",
1294 }
1295
1296
1297 ## Constructor of DecBuildData
1298 #
1299 # Initialize object of DecBuildData
1300 #
1301 # @param FilePath The path of package description file
1302 # @param RawData The raw data of DEC file
1303 # @param BuildDataBase Database used to retrieve module information
1304 # @param Arch The target architecture
1305 # @param Platform (not used for DecBuildData)
1306 # @param Macros Macros used for replacement in DSC file
1307 #
1308 def __init__(self, File, RawData, BuildDataBase, Arch='COMMON', Target=None, Toolchain=None):
1309 self.MetaFile = File
1310 self._PackageDir = File.Dir
1311 self._RawData = RawData
1312 self._Bdb = BuildDataBase
1313 self._Arch = Arch
1314 self._Target = Target
1315 self._Toolchain = Toolchain
1316 self._Clear()
1317
1318 ## XXX[key] = value
1319 def __setitem__(self, key, value):
1320 self.__dict__[self._PROPERTY_[key]] = value
1321
1322 ## value = XXX[key]
1323 def __getitem__(self, key):
1324 return self.__dict__[self._PROPERTY_[key]]
1325
1326 ## "in" test support
1327 def __contains__(self, key):
1328 return key in self._PROPERTY_
1329
1330 ## Set all internal used members of DecBuildData to None
1331 def _Clear(self):
1332 self._Header = None
1333 self._PackageName = None
1334 self._Guid = None
1335 self._Version = None
1336 self._PkgUniFile = None
1337 self._Protocols = None
1338 self._Ppis = None
1339 self._Guids = None
1340 self._Includes = None
1341 self._LibraryClasses = None
1342 self._Pcds = None
1343 self.__Macros = None
1344 self._PrivateProtocols = None
1345 self._PrivatePpis = None
1346 self._PrivateGuids = None
1347 self._PrivateIncludes = None
1348
1349 ## Get current effective macros
1350 def _GetMacros(self):
1351 if self.__Macros == None:
1352 self.__Macros = {}
1353 self.__Macros.update(GlobalData.gGlobalDefines)
1354 return self.__Macros
1355
1356 ## Get architecture
1357 def _GetArch(self):
1358 return self._Arch
1359
1360 ## Set architecture
1361 #
1362 # Changing the default ARCH to another may affect all other information
1363 # because all information in a platform may be ARCH-related. That's
1364 # why we need to clear all internal used members, in order to cause all
1365 # information to be re-retrieved.
1366 #
1367 # @param Value The value of ARCH
1368 #
1369 def _SetArch(self, Value):
1370 if self._Arch == Value:
1371 return
1372 self._Arch = Value
1373 self._Clear()
1374
1375 ## Retrieve all information in [Defines] section
1376 #
1377 # (Retriving all [Defines] information in one-shot is just to save time.)
1378 #
1379 def _GetHeaderInfo(self):
1380 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]
1381 for Record in RecordList:
1382 Name = Record[1]
1383 if Name in self:
1384 self[Name] = Record[2]
1385 self._Header = 'DUMMY'
1386
1387 ## Retrieve package name
1388 def _GetPackageName(self):
1389 if self._PackageName == None:
1390 if self._Header == None:
1391 self._GetHeaderInfo()
1392 if self._PackageName == None:
1393 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_NAME", File=self.MetaFile)
1394 return self._PackageName
1395
1396 ## Retrieve file guid
1397 def _GetFileGuid(self):
1398 if self._Guid == None:
1399 if self._Header == None:
1400 self._GetHeaderInfo()
1401 if self._Guid == None:
1402 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_GUID", File=self.MetaFile)
1403 return self._Guid
1404
1405 ## Retrieve package version
1406 def _GetVersion(self):
1407 if self._Version == None:
1408 if self._Header == None:
1409 self._GetHeaderInfo()
1410 if self._Version == None:
1411 self._Version = ''
1412 return self._Version
1413
1414 ## Retrieve protocol definitions (name/value pairs)
1415 def _GetProtocol(self):
1416 if self._Protocols == None:
1417 #
1418 # tdict is a special kind of dict, used for selecting correct
1419 # protocol defition for given ARCH
1420 #
1421 ProtocolDict = tdict(True)
1422 PrivateProtocolDict = tdict(True)
1423 NameList = []
1424 PrivateNameList = []
1425 PublicNameList = []
1426 # find out all protocol definitions for specific and 'common' arch
1427 RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch]
1428 for Name, Guid, Dummy, Arch, PrivateFlag, ID, LineNo in RecordList:
1429 if PrivateFlag == 'PRIVATE':
1430 if Name not in PrivateNameList:
1431 PrivateNameList.append(Name)
1432 PrivateProtocolDict[Arch, Name] = Guid
1433 if Name in PublicNameList:
1434 EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % Name, File=self.MetaFile, Line=LineNo)
1435 else:
1436 if Name not in PublicNameList:
1437 PublicNameList.append(Name)
1438 if Name in PrivateNameList:
1439 EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % Name, File=self.MetaFile, Line=LineNo)
1440 if Name not in NameList:
1441 NameList.append(Name)
1442 ProtocolDict[Arch, Name] = Guid
1443 # use sdict to keep the order
1444 self._Protocols = sdict()
1445 self._PrivateProtocols = sdict()
1446 for Name in NameList:
1447 #
1448 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1449 # will automatically turn to 'common' ARCH for trying
1450 #
1451 self._Protocols[Name] = ProtocolDict[self._Arch, Name]
1452 for Name in PrivateNameList:
1453 self._PrivateProtocols[Name] = PrivateProtocolDict[self._Arch, Name]
1454 return self._Protocols
1455
1456 ## Retrieve PPI definitions (name/value pairs)
1457 def _GetPpi(self):
1458 if self._Ppis == None:
1459 #
1460 # tdict is a special kind of dict, used for selecting correct
1461 # PPI defition for given ARCH
1462 #
1463 PpiDict = tdict(True)
1464 PrivatePpiDict = tdict(True)
1465 NameList = []
1466 PrivateNameList = []
1467 PublicNameList = []
1468 # find out all PPI definitions for specific arch and 'common' arch
1469 RecordList = self._RawData[MODEL_EFI_PPI, self._Arch]
1470 for Name, Guid, Dummy, Arch, PrivateFlag, ID, LineNo in RecordList:
1471 if PrivateFlag == 'PRIVATE':
1472 if Name not in PrivateNameList:
1473 PrivateNameList.append(Name)
1474 PrivatePpiDict[Arch, Name] = Guid
1475 if Name in PublicNameList:
1476 EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % Name, File=self.MetaFile, Line=LineNo)
1477 else:
1478 if Name not in PublicNameList:
1479 PublicNameList.append(Name)
1480 if Name in PrivateNameList:
1481 EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % Name, File=self.MetaFile, Line=LineNo)
1482 if Name not in NameList:
1483 NameList.append(Name)
1484 PpiDict[Arch, Name] = Guid
1485 # use sdict to keep the order
1486 self._Ppis = sdict()
1487 self._PrivatePpis = sdict()
1488 for Name in NameList:
1489 #
1490 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1491 # will automatically turn to 'common' ARCH for trying
1492 #
1493 self._Ppis[Name] = PpiDict[self._Arch, Name]
1494 for Name in PrivateNameList:
1495 self._PrivatePpis[Name] = PrivatePpiDict[self._Arch, Name]
1496 return self._Ppis
1497
1498 ## Retrieve GUID definitions (name/value pairs)
1499 def _GetGuid(self):
1500 if self._Guids == None:
1501 #
1502 # tdict is a special kind of dict, used for selecting correct
1503 # GUID defition for given ARCH
1504 #
1505 GuidDict = tdict(True)
1506 PrivateGuidDict = tdict(True)
1507 NameList = []
1508 PrivateNameList = []
1509 PublicNameList = []
1510 # find out all protocol definitions for specific and 'common' arch
1511 RecordList = self._RawData[MODEL_EFI_GUID, self._Arch]
1512 for Name, Guid, Dummy, Arch, PrivateFlag, ID, LineNo in RecordList:
1513 if PrivateFlag == 'PRIVATE':
1514 if Name not in PrivateNameList:
1515 PrivateNameList.append(Name)
1516 PrivateGuidDict[Arch, Name] = Guid
1517 if Name in PublicNameList:
1518 EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % Name, File=self.MetaFile, Line=LineNo)
1519 else:
1520 if Name not in PublicNameList:
1521 PublicNameList.append(Name)
1522 if Name in PrivateNameList:
1523 EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % Name, File=self.MetaFile, Line=LineNo)
1524 if Name not in NameList:
1525 NameList.append(Name)
1526 GuidDict[Arch, Name] = Guid
1527 # use sdict to keep the order
1528 self._Guids = sdict()
1529 self._PrivateGuids = sdict()
1530 for Name in NameList:
1531 #
1532 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1533 # will automatically turn to 'common' ARCH for trying
1534 #
1535 self._Guids[Name] = GuidDict[self._Arch, Name]
1536 for Name in PrivateNameList:
1537 self._PrivateGuids[Name] = PrivateGuidDict[self._Arch, Name]
1538 return self._Guids
1539
1540 ## Retrieve public include paths declared in this package
1541 def _GetInclude(self):
1542 if self._Includes == None:
1543 self._Includes = []
1544 self._PrivateIncludes = []
1545 PublicInclues = []
1546 RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch]
1547 Macros = self._Macros
1548 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
1549 for Record in RecordList:
1550 File = PathClass(NormPath(Record[0], Macros), self._PackageDir, Arch=self._Arch)
1551 LineNo = Record[-1]
1552 # validate the path
1553 ErrorCode, ErrorInfo = File.Validate()
1554 if ErrorCode != 0:
1555 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
1556
1557 # avoid duplicate include path
1558 if File not in self._Includes:
1559 self._Includes.append(File)
1560 if Record[4] == 'PRIVATE':
1561 if File not in self._PrivateIncludes:
1562 self._PrivateIncludes.append(File)
1563 if File in PublicInclues:
1564 EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % File, File=self.MetaFile, Line=LineNo)
1565 else:
1566 if File not in PublicInclues:
1567 PublicInclues.append(File)
1568 if File in self._PrivateIncludes:
1569 EdkLogger.error('build', OPTION_CONFLICT, "Can't determine %s's attribute, it is both defined as Private and non-Private attribute in DEC file." % File, File=self.MetaFile, Line=LineNo)
1570
1571 return self._Includes
1572
1573 ## Retrieve library class declarations (not used in build at present)
1574 def _GetLibraryClass(self):
1575 if self._LibraryClasses == None:
1576 #
1577 # tdict is a special kind of dict, used for selecting correct
1578 # library class declaration for given ARCH
1579 #
1580 LibraryClassDict = tdict(True)
1581 LibraryClassSet = set()
1582 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch]
1583 Macros = self._Macros
1584 for LibraryClass, File, Dummy, Arch, PrivateFlag, ID, LineNo in RecordList:
1585 File = PathClass(NormPath(File, Macros), self._PackageDir, Arch=self._Arch)
1586 # check the file validation
1587 ErrorCode, ErrorInfo = File.Validate()
1588 if ErrorCode != 0:
1589 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
1590 LibraryClassSet.add(LibraryClass)
1591 LibraryClassDict[Arch, LibraryClass] = File
1592 self._LibraryClasses = sdict()
1593 for LibraryClass in LibraryClassSet:
1594 self._LibraryClasses[LibraryClass] = LibraryClassDict[self._Arch, LibraryClass]
1595 return self._LibraryClasses
1596
1597 ## Retrieve PCD declarations
1598 def _GetPcds(self):
1599 if self._Pcds == None:
1600 self._Pcds = sdict()
1601 self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
1602 self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
1603 self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
1604 self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))
1605 self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
1606 return self._Pcds
1607
1608 ## Retrieve PCD declarations for given type
1609 def _GetPcd(self, Type):
1610 Pcds = sdict()
1611 #
1612 # tdict is a special kind of dict, used for selecting correct
1613 # PCD declaration for given ARCH
1614 #
1615 PcdDict = tdict(True, 3)
1616 # for summarizing PCD
1617 PcdSet = set()
1618 # find out all PCDs of the 'type'
1619 RecordList = self._RawData[Type, self._Arch]
1620 for TokenSpaceGuid, PcdCName, Setting, Arch, PrivateFlag, Dummy1, Dummy2 in RecordList:
1621 PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting
1622 PcdSet.add((PcdCName, TokenSpaceGuid))
1623
1624 for PcdCName, TokenSpaceGuid in PcdSet:
1625 #
1626 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1627 # will automatically turn to 'common' ARCH and try again
1628 #
1629 Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]
1630 if Setting == None:
1631 continue
1632
1633 DefaultValue, DatumType, TokenNumber = AnalyzePcdData(Setting)
1634
1635 validateranges, validlists, expressions = self._RawData.GetValidExpression(TokenSpaceGuid, PcdCName)
1636 Pcds[PcdCName, TokenSpaceGuid, self._PCD_TYPE_STRING_[Type]] = PcdClassObject(
1637 PcdCName,
1638 TokenSpaceGuid,
1639 self._PCD_TYPE_STRING_[Type],
1640 DatumType,
1641 DefaultValue,
1642 TokenNumber,
1643 '',
1644 {},
1645 False,
1646 None,
1647 list(validateranges),
1648 list(validlists),
1649 list(expressions)
1650 )
1651 return Pcds
1652
1653
1654 _Macros = property(_GetMacros)
1655 Arch = property(_GetArch, _SetArch)
1656 PackageName = property(_GetPackageName)
1657 Guid = property(_GetFileGuid)
1658 Version = property(_GetVersion)
1659
1660 Protocols = property(_GetProtocol)
1661 Ppis = property(_GetPpi)
1662 Guids = property(_GetGuid)
1663 Includes = property(_GetInclude)
1664 LibraryClasses = property(_GetLibraryClass)
1665 Pcds = property(_GetPcds)
1666
1667 ## Module build information from INF file
1668 #
1669 # This class is used to retrieve information stored in database and convert them
1670 # into ModuleBuildClassObject form for easier use for AutoGen.
1671 #
1672 class InfBuildData(ModuleBuildClassObject):
1673 # dict used to convert PCD type in database to string used by build tool
1674 _PCD_TYPE_STRING_ = {
1675 MODEL_PCD_FIXED_AT_BUILD : "FixedAtBuild",
1676 MODEL_PCD_PATCHABLE_IN_MODULE : "PatchableInModule",
1677 MODEL_PCD_FEATURE_FLAG : "FeatureFlag",
1678 MODEL_PCD_DYNAMIC : "Dynamic",
1679 MODEL_PCD_DYNAMIC_DEFAULT : "Dynamic",
1680 MODEL_PCD_DYNAMIC_HII : "DynamicHii",
1681 MODEL_PCD_DYNAMIC_VPD : "DynamicVpd",
1682 MODEL_PCD_DYNAMIC_EX : "DynamicEx",
1683 MODEL_PCD_DYNAMIC_EX_DEFAULT : "DynamicEx",
1684 MODEL_PCD_DYNAMIC_EX_HII : "DynamicExHii",
1685 MODEL_PCD_DYNAMIC_EX_VPD : "DynamicExVpd",
1686 }
1687
1688 # dict used to convert part of [Defines] to members of InfBuildData directly
1689 _PROPERTY_ = {
1690 #
1691 # Required Fields
1692 #
1693 TAB_INF_DEFINES_BASE_NAME : "_BaseName",
1694 TAB_INF_DEFINES_FILE_GUID : "_Guid",
1695 TAB_INF_DEFINES_MODULE_TYPE : "_ModuleType",
1696 #
1697 # Optional Fields
1698 #
1699 #TAB_INF_DEFINES_INF_VERSION : "_AutoGenVersion",
1700 TAB_INF_DEFINES_COMPONENT_TYPE : "_ComponentType",
1701 TAB_INF_DEFINES_MAKEFILE_NAME : "_MakefileName",
1702 #TAB_INF_DEFINES_CUSTOM_MAKEFILE : "_CustomMakefile",
1703 TAB_INF_DEFINES_DPX_SOURCE :"_DxsFile",
1704 TAB_INF_DEFINES_VERSION_NUMBER : "_Version",
1705 TAB_INF_DEFINES_VERSION_STRING : "_Version",
1706 TAB_INF_DEFINES_VERSION : "_Version",
1707 TAB_INF_DEFINES_PCD_IS_DRIVER : "_PcdIsDriver",
1708 TAB_INF_DEFINES_SHADOW : "_Shadow",
1709
1710 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH : "_SourceOverridePath",
1711 }
1712
1713 # dict used to convert Component type to Module type
1714 _MODULE_TYPE_ = {
1715 "LIBRARY" : "BASE",
1716 "SECURITY_CORE" : "SEC",
1717 "PEI_CORE" : "PEI_CORE",
1718 "COMBINED_PEIM_DRIVER" : "PEIM",
1719 "PIC_PEIM" : "PEIM",
1720 "RELOCATABLE_PEIM" : "PEIM",
1721 "PE32_PEIM" : "PEIM",
1722 "BS_DRIVER" : "DXE_DRIVER",
1723 "RT_DRIVER" : "DXE_RUNTIME_DRIVER",
1724 "SAL_RT_DRIVER" : "DXE_SAL_DRIVER",
1725 "DXE_SMM_DRIVER" : "DXE_SMM_DRIVER",
1726 # "SMM_DRIVER" : "DXE_SMM_DRIVER",
1727 # "BS_DRIVER" : "DXE_SMM_DRIVER",
1728 # "BS_DRIVER" : "UEFI_DRIVER",
1729 "APPLICATION" : "UEFI_APPLICATION",
1730 "LOGO" : "BASE",
1731 }
1732
1733 # regular expression for converting XXX_FLAGS in [nmake] section to new type
1734 _NMAKE_FLAG_PATTERN_ = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)
1735 # dict used to convert old tool name used in [nmake] section to new ones
1736 _TOOL_CODE_ = {
1737 "C" : "CC",
1738 "LIB" : "SLINK",
1739 "LINK" : "DLINK",
1740 }
1741
1742
1743 ## Constructor of DscBuildData
1744 #
1745 # Initialize object of DscBuildData
1746 #
1747 # @param FilePath The path of platform description file
1748 # @param RawData The raw data of DSC file
1749 # @param BuildDataBase Database used to retrieve module/package information
1750 # @param Arch The target architecture
1751 # @param Platform The name of platform employing this module
1752 # @param Macros Macros used for replacement in DSC file
1753 #
1754 def __init__(self, FilePath, RawData, BuildDatabase, Arch='COMMON', Target=None, Toolchain=None):
1755 self.MetaFile = FilePath
1756 self._ModuleDir = FilePath.Dir
1757 self._RawData = RawData
1758 self._Bdb = BuildDatabase
1759 self._Arch = Arch
1760 self._Target = Target
1761 self._Toolchain = Toolchain
1762 self._Platform = 'COMMON'
1763 self._SourceOverridePath = None
1764 if FilePath.Key in GlobalData.gOverrideDir:
1765 self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key]
1766 self._Clear()
1767
1768 ## XXX[key] = value
1769 def __setitem__(self, key, value):
1770 self.__dict__[self._PROPERTY_[key]] = value
1771
1772 ## value = XXX[key]
1773 def __getitem__(self, key):
1774 return self.__dict__[self._PROPERTY_[key]]
1775
1776 ## "in" test support
1777 def __contains__(self, key):
1778 return key in self._PROPERTY_
1779
1780 ## Set all internal used members of InfBuildData to None
1781 def _Clear(self):
1782 self._HeaderComments = None
1783 self._TailComments = None
1784 self._Header_ = None
1785 self._AutoGenVersion = None
1786 self._BaseName = None
1787 self._DxsFile = None
1788 self._ModuleType = None
1789 self._ComponentType = None
1790 self._BuildType = None
1791 self._Guid = None
1792 self._Version = None
1793 self._PcdIsDriver = None
1794 self._BinaryModule = None
1795 self._Shadow = None
1796 self._MakefileName = None
1797 self._CustomMakefile = None
1798 self._Specification = None
1799 self._LibraryClass = None
1800 self._ModuleEntryPointList = None
1801 self._ModuleUnloadImageList = None
1802 self._ConstructorList = None
1803 self._DestructorList = None
1804 self._Defs = None
1805 self._Binaries = None
1806 self._Sources = None
1807 self._LibraryClasses = None
1808 self._Libraries = None
1809 self._Protocols = None
1810 self._ProtocolComments = None
1811 self._Ppis = None
1812 self._PpiComments = None
1813 self._Guids = None
1814 self._GuidsUsedByPcd = sdict()
1815 self._GuidComments = None
1816 self._Includes = None
1817 self._Packages = None
1818 self._Pcds = None
1819 self._PcdComments = None
1820 self._BuildOptions = None
1821 self._Depex = None
1822 self._DepexExpression = None
1823 self.__Macros = None
1824
1825 ## Get current effective macros
1826 def _GetMacros(self):
1827 if self.__Macros == None:
1828 self.__Macros = {}
1829 # EDK_GLOBAL defined macros can be applied to EDK module
1830 if self.AutoGenVersion < 0x00010005:
1831 self.__Macros.update(GlobalData.gEdkGlobal)
1832 self.__Macros.update(GlobalData.gGlobalDefines)
1833 return self.__Macros
1834
1835 ## Get architecture
1836 def _GetArch(self):
1837 return self._Arch
1838
1839 ## Set architecture
1840 #
1841 # Changing the default ARCH to another may affect all other information
1842 # because all information in a platform may be ARCH-related. That's
1843 # why we need to clear all internal used members, in order to cause all
1844 # information to be re-retrieved.
1845 #
1846 # @param Value The value of ARCH
1847 #
1848 def _SetArch(self, Value):
1849 if self._Arch == Value:
1850 return
1851 self._Arch = Value
1852 self._Clear()
1853
1854 ## Return the name of platform employing this module
1855 def _GetPlatform(self):
1856 return self._Platform
1857
1858 ## Change the name of platform employing this module
1859 #
1860 # Changing the default name of platform to another may affect some information
1861 # because they may be PLATFORM-related. That's why we need to clear all internal
1862 # used members, in order to cause all information to be re-retrieved.
1863 #
1864 def _SetPlatform(self, Value):
1865 if self._Platform == Value:
1866 return
1867 self._Platform = Value
1868 self._Clear()
1869 def _GetHeaderComments(self):
1870 if not self._HeaderComments:
1871 self._HeaderComments = []
1872 RecordList = self._RawData[MODEL_META_DATA_HEADER_COMMENT]
1873 for Record in RecordList:
1874 self._HeaderComments.append(Record[0])
1875 return self._HeaderComments
1876 def _GetTailComments(self):
1877 if not self._TailComments:
1878 self._TailComments = []
1879 RecordList = self._RawData[MODEL_META_DATA_TAIL_COMMENT]
1880 for Record in RecordList:
1881 self._TailComments.append(Record[0])
1882 return self._TailComments
1883 ## Retrieve all information in [Defines] section
1884 #
1885 # (Retriving all [Defines] information in one-shot is just to save time.)
1886 #
1887 def _GetHeaderInfo(self):
1888 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
1889 for Record in RecordList:
1890 Name, Value = Record[1], ReplaceMacro(Record[2], self._Macros, False)
1891 # items defined _PROPERTY_ don't need additional processing
1892 if Name in self:
1893 self[Name] = Value
1894 if self._Defs == None:
1895 self._Defs = sdict()
1896 self._Defs[Name] = Value
1897 self._Macros[Name] = Value
1898 # some special items in [Defines] section need special treatment
1899 elif Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):
1900 if Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):
1901 Name = 'UEFI_SPECIFICATION_VERSION'
1902 if self._Specification == None:
1903 self._Specification = sdict()
1904 self._Specification[Name] = GetHexVerValue(Value)
1905 if self._Specification[Name] == None:
1906 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
1907 "'%s' format is not supported for %s" % (Value, Name),
1908 File=self.MetaFile, Line=Record[-1])
1909 elif Name == 'LIBRARY_CLASS':
1910 if self._LibraryClass == None:
1911 self._LibraryClass = []
1912 ValueList = GetSplitValueList(Value)
1913 LibraryClass = ValueList[0]
1914 if len(ValueList) > 1:
1915 SupModuleList = GetSplitValueList(ValueList[1], ' ')
1916 else:
1917 SupModuleList = SUP_MODULE_LIST
1918 self._LibraryClass.append(LibraryClassObject(LibraryClass, SupModuleList))
1919 elif Name == 'ENTRY_POINT':
1920 if self._ModuleEntryPointList == None:
1921 self._ModuleEntryPointList = []
1922 self._ModuleEntryPointList.append(Value)
1923 elif Name == 'UNLOAD_IMAGE':
1924 if self._ModuleUnloadImageList == None:
1925 self._ModuleUnloadImageList = []
1926 if not Value:
1927 continue
1928 self._ModuleUnloadImageList.append(Value)
1929 elif Name == 'CONSTRUCTOR':
1930 if self._ConstructorList == None:
1931 self._ConstructorList = []
1932 if not Value:
1933 continue
1934 self._ConstructorList.append(Value)
1935 elif Name == 'DESTRUCTOR':
1936 if self._DestructorList == None:
1937 self._DestructorList = []
1938 if not Value:
1939 continue
1940 self._DestructorList.append(Value)
1941 elif Name == TAB_INF_DEFINES_CUSTOM_MAKEFILE:
1942 TokenList = GetSplitValueList(Value)
1943 if self._CustomMakefile == None:
1944 self._CustomMakefile = {}
1945 if len(TokenList) < 2:
1946 self._CustomMakefile['MSFT'] = TokenList[0]
1947 self._CustomMakefile['GCC'] = TokenList[0]
1948 else:
1949 if TokenList[0] not in ['MSFT', 'GCC']:
1950 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
1951 "No supported family [%s]" % TokenList[0],
1952 File=self.MetaFile, Line=Record[-1])
1953 self._CustomMakefile[TokenList[0]] = TokenList[1]
1954 else:
1955 if self._Defs == None:
1956 self._Defs = sdict()
1957 self._Defs[Name] = Value
1958 self._Macros[Name] = Value
1959
1960 #
1961 # Retrieve information in sections specific to Edk.x modules
1962 #
1963 if self.AutoGenVersion >= 0x00010005:
1964 if not self._ModuleType:
1965 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
1966 "MODULE_TYPE is not given", File=self.MetaFile)
1967 if self._ModuleType not in SUP_MODULE_LIST:
1968 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
1969 for Record in RecordList:
1970 Name = Record[1]
1971 if Name == "MODULE_TYPE":
1972 LineNo = Record[6]
1973 break
1974 EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
1975 "MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self._ModuleType, ' '.join(l for l in SUP_MODULE_LIST)),
1976 File=self.MetaFile, Line=LineNo)
1977 if (self._Specification == None) or (not 'PI_SPECIFICATION_VERSION' in self._Specification) or (int(self._Specification['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):
1978 if self._ModuleType == SUP_MODULE_SMM_CORE:
1979 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)
1980 if (self._Specification == None) or (not 'PI_SPECIFICATION_VERSION' in self._Specification) or (int(self._Specification['PI_SPECIFICATION_VERSION'], 16) < 0x00010032):
1981 if self._ModuleType == SUP_MODULE_MM_CORE_STANDALONE:
1982 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)
1983 if self._ModuleType == SUP_MODULE_MM_STANDALONE:
1984 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)
1985 if self._Defs and 'PCI_DEVICE_ID' in self._Defs and 'PCI_VENDOR_ID' in self._Defs \
1986 and 'PCI_CLASS_CODE' in self._Defs and 'PCI_REVISION' in self._Defs:
1987 self._BuildType = 'UEFI_OPTIONROM'
1988 if 'PCI_COMPRESS' in self._Defs:
1989 if self._Defs['PCI_COMPRESS'] not in ('TRUE', 'FALSE'):
1990 EdkLogger.error("build", FORMAT_INVALID, "Expected TRUE/FALSE for PCI_COMPRESS: %s" %self.MetaFile)
1991
1992 elif self._Defs and 'UEFI_HII_RESOURCE_SECTION' in self._Defs \
1993 and self._Defs['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':
1994 self._BuildType = 'UEFI_HII'
1995 else:
1996 self._BuildType = self._ModuleType.upper()
1997
1998 if self._DxsFile:
1999 File = PathClass(NormPath(self._DxsFile), self._ModuleDir, Arch=self._Arch)
2000 # check the file validation
2001 ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)
2002 if ErrorCode != 0:
2003 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo,
2004 File=self.MetaFile, Line=LineNo)
2005 if self.Sources == None:
2006 self._Sources = []
2007 self._Sources.append(File)
2008 else:
2009 if not self._ComponentType:
2010 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
2011 "COMPONENT_TYPE is not given", File=self.MetaFile)
2012 self._BuildType = self._ComponentType.upper()
2013 if self._ComponentType in self._MODULE_TYPE_:
2014 self._ModuleType = self._MODULE_TYPE_[self._ComponentType]
2015 if self._ComponentType == 'LIBRARY':
2016 self._LibraryClass = [LibraryClassObject(self._BaseName, SUP_MODULE_LIST)]
2017 # make use some [nmake] section macros
2018 Macros = self._Macros
2019 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
2020 Macros['PROCESSOR'] = self._Arch
2021 RecordList = self._RawData[MODEL_META_DATA_NMAKE, self._Arch, self._Platform]
2022 for Name, Value, Dummy, Arch, Platform, ID, LineNo in RecordList:
2023 Value = ReplaceMacro(Value, Macros, True)
2024 if Name == "IMAGE_ENTRY_POINT":
2025 if self._ModuleEntryPointList == None:
2026 self._ModuleEntryPointList = []
2027 self._ModuleEntryPointList.append(Value)
2028 elif Name == "DPX_SOURCE":
2029 File = PathClass(NormPath(Value), self._ModuleDir, Arch=self._Arch)
2030 # check the file validation
2031 ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)
2032 if ErrorCode != 0:
2033 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo,
2034 File=self.MetaFile, Line=LineNo)
2035 if self.Sources == None:
2036 self._Sources = []
2037 self._Sources.append(File)
2038 else:
2039 ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name)
2040 if len(ToolList) == 0 or len(ToolList) != 1:
2041 pass
2042 # EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name,
2043 # File=self.MetaFile, Line=LineNo)
2044 else:
2045 if self._BuildOptions == None:
2046 self._BuildOptions = sdict()
2047
2048 if ToolList[0] in self._TOOL_CODE_:
2049 Tool = self._TOOL_CODE_[ToolList[0]]
2050 else:
2051 Tool = ToolList[0]
2052 ToolChain = "*_*_*_%s_FLAGS" % Tool
2053 ToolChainFamily = 'MSFT' # Edk.x only support MSFT tool chain
2054 #ignore not replaced macros in value
2055 ValueList = GetSplitList(' ' + Value, '/D')
2056 Dummy = ValueList[0]
2057 for Index in range(1, len(ValueList)):
2058 if ValueList[Index][-1] == '=' or ValueList[Index] == '':
2059 continue
2060 Dummy = Dummy + ' /D ' + ValueList[Index]
2061 Value = Dummy.strip()
2062 if (ToolChainFamily, ToolChain) not in self._BuildOptions:
2063 self._BuildOptions[ToolChainFamily, ToolChain] = Value
2064 else:
2065 OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
2066 self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Value
2067 # set _Header to non-None in order to avoid database re-querying
2068 self._Header_ = 'DUMMY'
2069
2070 ## Retrieve file version
2071 def _GetInfVersion(self):
2072 if self._AutoGenVersion == None:
2073 RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
2074 for Record in RecordList:
2075 if Record[1] == TAB_INF_DEFINES_INF_VERSION:
2076 if '.' in Record[2]:
2077 ValueList = Record[2].split('.')
2078 Major = '%04o' % int(ValueList[0], 0)
2079 Minor = '%04o' % int(ValueList[1], 0)
2080 self._AutoGenVersion = int('0x' + Major + Minor, 0)
2081 else:
2082 self._AutoGenVersion = int(Record[2], 0)
2083 break
2084 if self._AutoGenVersion == None:
2085 self._AutoGenVersion = 0x00010000
2086 return self._AutoGenVersion
2087
2088 ## Retrieve BASE_NAME
2089 def _GetBaseName(self):
2090 if self._BaseName == None:
2091 if self._Header_ == None:
2092 self._GetHeaderInfo()
2093 if self._BaseName == None:
2094 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BASE_NAME name", File=self.MetaFile)
2095 return self._BaseName
2096
2097 ## Retrieve DxsFile
2098 def _GetDxsFile(self):
2099 if self._DxsFile == None:
2100 if self._Header_ == None:
2101 self._GetHeaderInfo()
2102 if self._DxsFile == None:
2103 self._DxsFile = ''
2104 return self._DxsFile
2105
2106 ## Retrieve MODULE_TYPE
2107 def _GetModuleType(self):
2108 if self._ModuleType == None:
2109 if self._Header_ == None:
2110 self._GetHeaderInfo()
2111 if self._ModuleType == None:
2112 self._ModuleType = 'BASE'
2113 if self._ModuleType not in SUP_MODULE_LIST:
2114 self._ModuleType = "USER_DEFINED"
2115 return self._ModuleType
2116
2117 ## Retrieve COMPONENT_TYPE
2118 def _GetComponentType(self):
2119 if self._ComponentType == None:
2120 if self._Header_ == None:
2121 self._GetHeaderInfo()
2122 if self._ComponentType == None:
2123 self._ComponentType = 'USER_DEFINED'
2124 return self._ComponentType
2125
2126 ## Retrieve "BUILD_TYPE"
2127 def _GetBuildType(self):
2128 if self._BuildType == None:
2129 if self._Header_ == None:
2130 self._GetHeaderInfo()
2131 if not self._BuildType:
2132 self._BuildType = "BASE"
2133 return self._BuildType
2134
2135 ## Retrieve file guid
2136 def _GetFileGuid(self):
2137 if self._Guid == None:
2138 if self._Header_ == None:
2139 self._GetHeaderInfo()
2140 if self._Guid == None:
2141 self._Guid = '00000000-0000-0000-0000-000000000000'
2142 return self._Guid
2143
2144 ## Retrieve module version
2145 def _GetVersion(self):
2146 if self._Version == None:
2147 if self._Header_ == None:
2148 self._GetHeaderInfo()
2149 if self._Version == None:
2150 self._Version = '0.0'
2151 return self._Version
2152
2153 ## Retrieve PCD_IS_DRIVER
2154 def _GetPcdIsDriver(self):
2155 if self._PcdIsDriver == None:
2156 if self._Header_ == None:
2157 self._GetHeaderInfo()
2158 if self._PcdIsDriver == None:
2159 self._PcdIsDriver = ''
2160 return self._PcdIsDriver
2161
2162 ## Retrieve SHADOW
2163 def _GetShadow(self):
2164 if self._Shadow == None:
2165 if self._Header_ == None:
2166 self._GetHeaderInfo()
2167 if self._Shadow != None and self._Shadow.upper() == 'TRUE':
2168 self._Shadow = True
2169 else:
2170 self._Shadow = False
2171 return self._Shadow
2172
2173 ## Retrieve CUSTOM_MAKEFILE
2174 def _GetMakefile(self):
2175 if self._CustomMakefile == None:
2176 if self._Header_ == None:
2177 self._GetHeaderInfo()
2178 if self._CustomMakefile == None:
2179 self._CustomMakefile = {}
2180 return self._CustomMakefile
2181
2182 ## Retrieve EFI_SPECIFICATION_VERSION
2183 def _GetSpec(self):
2184 if self._Specification == None:
2185 if self._Header_ == None:
2186 self._GetHeaderInfo()
2187 if self._Specification == None:
2188 self._Specification = {}
2189 return self._Specification
2190
2191 ## Retrieve LIBRARY_CLASS
2192 def _GetLibraryClass(self):
2193 if self._LibraryClass == None:
2194 if self._Header_ == None:
2195 self._GetHeaderInfo()
2196 if self._LibraryClass == None:
2197 self._LibraryClass = []
2198 return self._LibraryClass
2199
2200 ## Retrieve ENTRY_POINT
2201 def _GetEntryPoint(self):
2202 if self._ModuleEntryPointList == None:
2203 if self._Header_ == None:
2204 self._GetHeaderInfo()
2205 if self._ModuleEntryPointList == None:
2206 self._ModuleEntryPointList = []
2207 return self._ModuleEntryPointList
2208
2209 ## Retrieve UNLOAD_IMAGE
2210 def _GetUnloadImage(self):
2211 if self._ModuleUnloadImageList == None:
2212 if self._Header_ == None:
2213 self._GetHeaderInfo()
2214 if self._ModuleUnloadImageList == None:
2215 self._ModuleUnloadImageList = []
2216 return self._ModuleUnloadImageList
2217
2218 ## Retrieve CONSTRUCTOR
2219 def _GetConstructor(self):
2220 if self._ConstructorList == None:
2221 if self._Header_ == None:
2222 self._GetHeaderInfo()
2223 if self._ConstructorList == None:
2224 self._ConstructorList = []
2225 return self._ConstructorList
2226
2227 ## Retrieve DESTRUCTOR
2228 def _GetDestructor(self):
2229 if self._DestructorList == None:
2230 if self._Header_ == None:
2231 self._GetHeaderInfo()
2232 if self._DestructorList == None:
2233 self._DestructorList = []
2234 return self._DestructorList
2235
2236 ## Retrieve definies other than above ones
2237 def _GetDefines(self):
2238 if self._Defs == None:
2239 if self._Header_ == None:
2240 self._GetHeaderInfo()
2241 if self._Defs == None:
2242 self._Defs = sdict()
2243 return self._Defs
2244
2245 ## Retrieve binary files
2246 def _GetBinaries(self):
2247 if self._Binaries == None:
2248 self._Binaries = []
2249 RecordList = self._RawData[MODEL_EFI_BINARY_FILE, self._Arch, self._Platform]
2250 Macros = self._Macros
2251 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
2252 Macros['PROCESSOR'] = self._Arch
2253 for Record in RecordList:
2254 FileType = Record[0]
2255 LineNo = Record[-1]
2256 Target = 'COMMON'
2257 FeatureFlag = []
2258 if Record[2]:
2259 TokenList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)
2260 if TokenList:
2261 Target = TokenList[0]
2262 if len(TokenList) > 1:
2263 FeatureFlag = Record[1:]
2264
2265 File = PathClass(NormPath(Record[1], Macros), self._ModuleDir, '', FileType, True, self._Arch, '', Target)
2266 # check the file validation
2267 ErrorCode, ErrorInfo = File.Validate()
2268 if ErrorCode != 0:
2269 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
2270 self._Binaries.append(File)
2271 return self._Binaries
2272
2273 ## Retrieve binary files with error check.
2274 def _GetBinaryFiles(self):
2275 Binaries = self._GetBinaries()
2276 if GlobalData.gIgnoreSource and Binaries == []:
2277 ErrorInfo = "The INF file does not contain any Binaries to use in creating the image\n"
2278 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, ExtraData=ErrorInfo, File=self.MetaFile)
2279
2280 return Binaries
2281 ## Check whether it exists the binaries with current ARCH in AsBuild INF
2282 def _IsSupportedArch(self):
2283 if self._GetBinaries() and not self._GetSourceFiles():
2284 return True
2285 else:
2286 return False
2287 ## Retrieve source files
2288 def _GetSourceFiles(self):
2289 #Ignore all source files in a binary build mode
2290 if GlobalData.gIgnoreSource:
2291 self._Sources = []
2292 return self._Sources
2293
2294 if self._Sources == None:
2295 self._Sources = []
2296 RecordList = self._RawData[MODEL_EFI_SOURCE_FILE, self._Arch, self._Platform]
2297 Macros = self._Macros
2298 for Record in RecordList:
2299 LineNo = Record[-1]
2300 ToolChainFamily = Record[1]
2301 TagName = Record[2]
2302 ToolCode = Record[3]
2303 FeatureFlag = Record[4]
2304 if self.AutoGenVersion < 0x00010005:
2305 Macros["EDK_SOURCE"] = GlobalData.gEcpSource
2306 Macros['PROCESSOR'] = self._Arch
2307 SourceFile = NormPath(Record[0], Macros)
2308 if SourceFile[0] == os.path.sep:
2309 SourceFile = mws.join(GlobalData.gWorkspace, SourceFile[1:])
2310 # old module source files (Edk)
2311 File = PathClass(SourceFile, self._ModuleDir, self._SourceOverridePath,
2312 '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)
2313 # check the file validation
2314 ErrorCode, ErrorInfo = File.Validate(CaseSensitive=False)
2315 if ErrorCode != 0:
2316 if File.Ext.lower() == '.h':
2317 EdkLogger.warn('build', 'Include file not found', ExtraData=ErrorInfo,
2318 File=self.MetaFile, Line=LineNo)
2319 continue
2320 else:
2321 EdkLogger.error('build', ErrorCode, ExtraData=File, File=self.MetaFile, Line=LineNo)
2322 else:
2323 File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, '',
2324 '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)
2325 # check the file validation
2326 ErrorCode, ErrorInfo = File.Validate()
2327 if ErrorCode != 0:
2328 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
2329
2330 self._Sources.append(File)
2331 return self._Sources
2332
2333 ## Retrieve library classes employed by this module
2334 def _GetLibraryClassUses(self):
2335 if self._LibraryClasses == None:
2336 self._LibraryClasses = sdict()
2337 RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform]
2338 for Record in RecordList:
2339 Lib = Record[0]
2340 Instance = Record[1]
2341 if Instance:
2342 Instance = NormPath(Instance, self._Macros)
2343 self._LibraryClasses[Lib] = Instance
2344 return self._LibraryClasses
2345
2346 ## Retrieve library names (for Edk.x style of modules)
2347 def _GetLibraryNames(self):
2348 if self._Libraries == None:
2349 self._Libraries = []
2350 RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch, self._Platform]
2351 for Record in RecordList:
2352 LibraryName = ReplaceMacro(Record[0], self._Macros, False)
2353 # in case of name with '.lib' extension, which is unusual in Edk.x inf
2354 LibraryName = os.path.splitext(LibraryName)[0]
2355 if LibraryName not in self._Libraries:
2356 self._Libraries.append(LibraryName)
2357 return self._Libraries
2358
2359 def _GetProtocolComments(self):
2360 self._GetProtocols()
2361 return self._ProtocolComments
2362 ## Retrieve protocols consumed/produced by this module
2363 def _GetProtocols(self):
2364 if self._Protocols == None:
2365 self._Protocols = sdict()
2366 self._ProtocolComments = sdict()
2367 RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self._Platform]
2368 for Record in RecordList:
2369 CName = Record[0]
2370 Value = ProtocolValue(CName, self.Packages, self.MetaFile.Path)
2371 if Value == None:
2372 PackageList = "\n\t".join([str(P) for P in self.Packages])
2373 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
2374 "Value of Protocol [%s] is not found under [Protocols] section in" % CName,
2375 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
2376 self._Protocols[CName] = Value
2377 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
2378 Comments = []
2379 for CmtRec in CommentRecords:
2380 Comments.append(CmtRec[0])
2381 self._ProtocolComments[CName] = Comments
2382 return self._Protocols
2383
2384 def _GetPpiComments(self):
2385 self._GetPpis()
2386 return self._PpiComments
2387 ## Retrieve PPIs consumed/produced by this module
2388 def _GetPpis(self):
2389 if self._Ppis == None:
2390 self._Ppis = sdict()
2391 self._PpiComments = sdict()
2392 RecordList = self._RawData[MODEL_EFI_PPI, self._Arch, self._Platform]
2393 for Record in RecordList:
2394 CName = Record[0]
2395 Value = PpiValue(CName, self.Packages, self.MetaFile.Path)
2396 if Value == None:
2397 PackageList = "\n\t".join([str(P) for P in self.Packages])
2398 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
2399 "Value of PPI [%s] is not found under [Ppis] section in " % CName,
2400 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
2401 self._Ppis[CName] = Value
2402 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
2403 Comments = []
2404 for CmtRec in CommentRecords:
2405 Comments.append(CmtRec[0])
2406 self._PpiComments[CName] = Comments
2407 return self._Ppis
2408
2409 def _GetGuidComments(self):
2410 self._GetGuids()
2411 return self._GuidComments
2412 ## Retrieve GUIDs consumed/produced by this module
2413 def _GetGuids(self):
2414 if self._Guids == None:
2415 self._Guids = sdict()
2416 self._GuidComments = sdict()
2417 RecordList = self._RawData[MODEL_EFI_GUID, self._Arch, self._Platform]
2418 for Record in RecordList:
2419 CName = Record[0]
2420 Value = GuidValue(CName, self.Packages, self.MetaFile.Path)
2421 if Value == None:
2422 PackageList = "\n\t".join([str(P) for P in self.Packages])
2423 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
2424 "Value of Guid [%s] is not found under [Guids] section in" % CName,
2425 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
2426 self._Guids[CName] = Value
2427 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]
2428 Comments = []
2429 for CmtRec in CommentRecords:
2430 Comments.append(CmtRec[0])
2431 self._GuidComments[CName] = Comments
2432 return self._Guids
2433
2434 ## Retrieve include paths necessary for this module (for Edk.x style of modules)
2435 def _GetIncludes(self):
2436 if self._Includes == None:
2437 self._Includes = []
2438 if self._SourceOverridePath:
2439 self._Includes.append(self._SourceOverridePath)
2440
2441 Macros = self._Macros
2442 if 'PROCESSOR' in GlobalData.gEdkGlobal.keys():
2443 Macros['PROCESSOR'] = GlobalData.gEdkGlobal['PROCESSOR']
2444 else:
2445 Macros['PROCESSOR'] = self._Arch
2446 RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform]
2447 for Record in RecordList:
2448 if Record[0].find('EDK_SOURCE') > -1:
2449 Macros['EDK_SOURCE'] = GlobalData.gEcpSource
2450 File = NormPath(Record[0], self._Macros)
2451 if File[0] == '.':
2452 File = os.path.join(self._ModuleDir, File)
2453 else:
2454 File = os.path.join(GlobalData.gWorkspace, File)
2455 File = RealPath(os.path.normpath(File))
2456 if File:
2457 self._Includes.append(File)
2458
2459 #TRICK: let compiler to choose correct header file
2460 Macros['EDK_SOURCE'] = GlobalData.gEdkSource
2461 File = NormPath(Record[0], self._Macros)
2462 if File[0] == '.':
2463 File = os.path.join(self._ModuleDir, File)
2464 else:
2465 File = os.path.join(GlobalData.gWorkspace, File)
2466 File = RealPath(os.path.normpath(File))
2467 if File:
2468 self._Includes.append(File)
2469 else:
2470 File = NormPath(Record[0], Macros)
2471 if File[0] == '.':
2472 File = os.path.join(self._ModuleDir, File)
2473 else:
2474 File = mws.join(GlobalData.gWorkspace, File)
2475 File = RealPath(os.path.normpath(File))
2476 if File:
2477 self._Includes.append(File)
2478 if not File and Record[0].find('EFI_SOURCE') > -1:
2479 # tricky to regard WorkSpace as EFI_SOURCE
2480 Macros['EFI_SOURCE'] = GlobalData.gWorkspace
2481 File = NormPath(Record[0], Macros)
2482 if File[0] == '.':
2483 File = os.path.join(self._ModuleDir, File)
2484 else:
2485 File = os.path.join(GlobalData.gWorkspace, File)
2486 File = RealPath(os.path.normpath(File))
2487 if File:
2488 self._Includes.append(File)
2489 return self._Includes
2490
2491 ## Retrieve packages this module depends on
2492 def _GetPackages(self):
2493 if self._Packages == None:
2494 self._Packages = []
2495 RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch, self._Platform]
2496 Macros = self._Macros
2497 Macros['EDK_SOURCE'] = GlobalData.gEcpSource
2498 for Record in RecordList:
2499 File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
2500 LineNo = Record[-1]
2501 # check the file validation
2502 ErrorCode, ErrorInfo = File.Validate('.dec')
2503 if ErrorCode != 0:
2504 EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
2505 # parse this package now. we need it to get protocol/ppi/guid value
2506 Package = self._Bdb[File, self._Arch, self._Target, self._Toolchain]
2507 self._Packages.append(Package)
2508 return self._Packages
2509
2510 ## Retrieve PCD comments
2511 def _GetPcdComments(self):
2512 self._GetPcds()
2513 return self._PcdComments
2514 ## Retrieve PCDs used in this module
2515 def _GetPcds(self):
2516 if self._Pcds == None:
2517 self._Pcds = sdict()
2518 self._PcdComments = sdict()
2519 self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
2520 self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
2521 self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
2522 self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))
2523 self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
2524 return self._Pcds
2525
2526 ## Retrieve build options specific to this module
2527 def _GetBuildOptions(self):
2528 if self._BuildOptions == None:
2529 self._BuildOptions = sdict()
2530 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, self._Platform]
2531 for Record in RecordList:
2532 ToolChainFamily = Record[0]
2533 ToolChain = Record[1]
2534 Option = Record[2]
2535 if (ToolChainFamily, ToolChain) not in self._BuildOptions or Option.startswith('='):
2536 self._BuildOptions[ToolChainFamily, ToolChain] = Option
2537 else:
2538 # concatenate the option string if they're for the same tool
2539 OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
2540 self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
2541 return self._BuildOptions
2542
2543 ## Retrieve dependency expression
2544 def _GetDepex(self):
2545 if self._Depex == None:
2546 self._Depex = tdict(False, 2)
2547 RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
2548
2549 # If the module has only Binaries and no Sources, then ignore [Depex]
2550 if self.Sources == None or self.Sources == []:
2551 if self.Binaries != None and self.Binaries != []:
2552 return self._Depex
2553
2554 # PEIM and DXE drivers must have a valid [Depex] section
2555 if len(self.LibraryClass) == 0 and len(RecordList) == 0:
2556 if self.ModuleType == 'DXE_DRIVER' or self.ModuleType == 'PEIM' or self.ModuleType == 'DXE_SMM_DRIVER' or \
2557 self.ModuleType == 'DXE_SAL_DRIVER' or self.ModuleType == 'DXE_RUNTIME_DRIVER':
2558 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
2559 % self.ModuleType, File=self.MetaFile)
2560
2561 if len(RecordList) != 0 and self.ModuleType == 'USER_DEFINED':
2562 for Record in RecordList:
2563 if Record[4] not in ['PEIM', 'DXE_DRIVER', 'DXE_SMM_DRIVER']:
2564 EdkLogger.error('build', FORMAT_INVALID,
2565 "'%s' module must specify the type of [Depex] section" % self.ModuleType,
2566 File=self.MetaFile)
2567
2568 Depex = sdict()
2569 for Record in RecordList:
2570 DepexStr = ReplaceMacro(Record[0], self._Macros, False)
2571 Arch = Record[3]
2572 ModuleType = Record[4]
2573 TokenList = DepexStr.split()
2574 if (Arch, ModuleType) not in Depex:
2575 Depex[Arch, ModuleType] = []
2576 DepexList = Depex[Arch, ModuleType]
2577 for Token in TokenList:
2578 if Token in DEPEX_SUPPORTED_OPCODE:
2579 DepexList.append(Token)
2580 elif Token.endswith(".inf"): # module file name
2581 ModuleFile = os.path.normpath(Token)
2582 Module = self.BuildDatabase[ModuleFile]
2583 if Module == None:
2584 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Module is not found in active platform",
2585 ExtraData=Token, File=self.MetaFile, Line=Record[-1])
2586 DepexList.append(Module.Guid)
2587 else:
2588 # get the GUID value now
2589 Value = ProtocolValue(Token, self.Packages, self.MetaFile.Path)
2590 if Value == None:
2591 Value = PpiValue(Token, self.Packages, self.MetaFile.Path)
2592 if Value == None:
2593 Value = GuidValue(Token, self.Packages, self.MetaFile.Path)
2594 if Value == None:
2595 PackageList = "\n\t".join([str(P) for P in self.Packages])
2596 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
2597 "Value of [%s] is not found in" % Token,
2598 ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
2599 DepexList.append(Value)
2600 for Arch, ModuleType in Depex:
2601 self._Depex[Arch, ModuleType] = Depex[Arch, ModuleType]
2602 return self._Depex
2603
2604 ## Retrieve depedency expression
2605 def _GetDepexExpression(self):
2606 if self._DepexExpression == None:
2607 self._DepexExpression = tdict(False, 2)
2608 RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
2609 DepexExpression = sdict()
2610 for Record in RecordList:
2611 DepexStr = ReplaceMacro(Record[0], self._Macros, False)
2612 Arch = Record[3]
2613 ModuleType = Record[4]
2614 TokenList = DepexStr.split()
2615 if (Arch, ModuleType) not in DepexExpression:
2616 DepexExpression[Arch, ModuleType] = ''
2617 for Token in TokenList:
2618 DepexExpression[Arch, ModuleType] = DepexExpression[Arch, ModuleType] + Token.strip() + ' '
2619 for Arch, ModuleType in DepexExpression:
2620 self._DepexExpression[Arch, ModuleType] = DepexExpression[Arch, ModuleType]
2621 return self._DepexExpression
2622
2623 def GetGuidsUsedByPcd(self):
2624 return self._GuidsUsedByPcd
2625 ## Retrieve PCD for given type
2626 def _GetPcd(self, Type):
2627 Pcds = sdict()
2628 PcdDict = tdict(True, 4)
2629 PcdList = []
2630 RecordList = self._RawData[Type, self._Arch, self._Platform]
2631 for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Id, LineNo in RecordList:
2632 PcdDict[Arch, Platform, PcdCName, TokenSpaceGuid] = (Setting, LineNo)
2633 PcdList.append((PcdCName, TokenSpaceGuid))
2634 # get the guid value
2635 if TokenSpaceGuid not in self.Guids:
2636 Value = GuidValue(TokenSpaceGuid, self.Packages, self.MetaFile.Path)
2637 if Value == None:
2638 PackageList = "\n\t".join([str(P) for P in self.Packages])
2639 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
2640 "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid,
2641 ExtraData=PackageList, File=self.MetaFile, Line=LineNo)
2642 self.Guids[TokenSpaceGuid] = Value
2643 self._GuidsUsedByPcd[TokenSpaceGuid] = Value
2644 CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Id]
2645 Comments = []
2646 for CmtRec in CommentRecords:
2647 Comments.append(CmtRec[0])
2648 self._PcdComments[TokenSpaceGuid, PcdCName] = Comments
2649
2650 # resolve PCD type, value, datum info, etc. by getting its definition from package
2651 for PcdCName, TokenSpaceGuid in PcdList:
2652 PcdRealName = PcdCName
2653 Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid]
2654 if Setting == None:
2655 continue
2656 ValueList = AnalyzePcdData(Setting)
2657 DefaultValue = ValueList[0]
2658 Pcd = PcdClassObject(
2659 PcdCName,
2660 TokenSpaceGuid,
2661 '',
2662 '',
2663 DefaultValue,
2664 '',
2665 '',
2666 {},
2667 False,
2668 self.Guids[TokenSpaceGuid]
2669 )
2670 if Type == MODEL_PCD_PATCHABLE_IN_MODULE and ValueList[1]:
2671 # Patch PCD: TokenSpace.PcdCName|Value|Offset
2672 Pcd.Offset = ValueList[1]
2673
2674 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
2675 for Package in self.Packages:
2676 for key in Package.Pcds:
2677 if (Package.Pcds[key].TokenCName, Package.Pcds[key].TokenSpaceGuidCName) == (PcdRealName, TokenSpaceGuid):
2678 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
2679 Pcd_Type = item[0].split('_')[-1]
2680 if Pcd_Type == Package.Pcds[key].Type:
2681 Value = Package.Pcds[key]
2682 Value.TokenCName = Package.Pcds[key].TokenCName + '_' + Pcd_Type
2683 if len(key) == 2:
2684 newkey = (Value.TokenCName, key[1])
2685 elif len(key) == 3:
2686 newkey = (Value.TokenCName, key[1], key[2])
2687 del Package.Pcds[key]
2688 Package.Pcds[newkey] = Value
2689 break
2690 else:
2691 pass
2692 else:
2693 pass
2694
2695 # get necessary info from package declaring this PCD
2696 for Package in self.Packages:
2697 #
2698 # 'dynamic' in INF means its type is determined by platform;
2699 # if platform doesn't give its type, use 'lowest' one in the
2700 # following order, if any
2701 #
2702 # "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"
2703 #
2704 PcdType = self._PCD_TYPE_STRING_[Type]
2705 if Type == MODEL_PCD_DYNAMIC:
2706 Pcd.Pending = True
2707 for T in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:
2708 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
2709 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
2710 if str(item[0]).endswith(T) and (item[0], item[1], T) in Package.Pcds:
2711 PcdType = T
2712 PcdCName = item[0]
2713 break
2714 else:
2715 pass
2716 break
2717 else:
2718 if (PcdRealName, TokenSpaceGuid, T) in Package.Pcds:
2719 PcdType = T
2720 break
2721
2722 else:
2723 Pcd.Pending = False
2724 if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
2725 for item in GlobalData.MixedPcd[(PcdRealName, TokenSpaceGuid)]:
2726 Pcd_Type = item[0].split('_')[-1]
2727 if Pcd_Type == PcdType:
2728 PcdCName = item[0]
2729 break
2730 else:
2731 pass
2732 else:
2733 pass
2734
2735 if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:
2736 PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType]
2737 Pcd.Type = PcdType
2738 Pcd.TokenValue = PcdInPackage.TokenValue
2739
2740 #
2741 # Check whether the token value exist or not.
2742 #
2743 if Pcd.TokenValue == None or Pcd.TokenValue == "":
2744 EdkLogger.error(
2745 'build',
2746 FORMAT_INVALID,
2747 "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid, PcdRealName, str(Package)),
2748 File=self.MetaFile, Line=LineNo,
2749 ExtraData=None
2750 )
2751 #
2752 # Check hexadecimal token value length and format.
2753 #
2754 ReIsValidPcdTokenValue = re.compile(r"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re.DOTALL)
2755 if Pcd.TokenValue.startswith("0x") or Pcd.TokenValue.startswith("0X"):
2756 if ReIsValidPcdTokenValue.match(Pcd.TokenValue) == None:
2757 EdkLogger.error(
2758 'build',
2759 FORMAT_INVALID,
2760 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName, str(Package)),
2761 File=self.MetaFile, Line=LineNo,
2762 ExtraData=None
2763 )
2764
2765 #
2766 # Check decimal token value length and format.
2767 #
2768 else:
2769 try:
2770 TokenValueInt = int (Pcd.TokenValue, 10)
2771 if (TokenValueInt < 0 or TokenValueInt > 4294967295):
2772 EdkLogger.error(
2773 'build',
2774 FORMAT_INVALID,
2775 "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)),
2776 File=self.MetaFile, Line=LineNo,
2777 ExtraData=None
2778 )
2779 except:
2780 EdkLogger.error(
2781 'build',
2782 FORMAT_INVALID,
2783 "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)),
2784 File=self.MetaFile, Line=LineNo,
2785 ExtraData=None
2786 )
2787
2788 Pcd.DatumType = PcdInPackage.DatumType
2789 Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize
2790 Pcd.InfDefaultValue = Pcd.DefaultValue
2791 if Pcd.DefaultValue in [None, '']:
2792 Pcd.DefaultValue = PcdInPackage.DefaultValue
2793 break
2794 else:
2795 EdkLogger.error(
2796 'build',
2797 FORMAT_INVALID,
2798 "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdRealName, self.MetaFile),
2799 File=self.MetaFile, Line=LineNo,
2800 ExtraData="\t%s" % '\n\t'.join([str(P) for P in self.Packages])
2801 )
2802 Pcds[PcdCName, TokenSpaceGuid] = Pcd
2803
2804 return Pcds
2805
2806 ## check whether current module is binary module
2807 def _IsBinaryModule(self):
2808 if self.Binaries and not self.Sources:
2809 return True
2810 elif GlobalData.gIgnoreSource:
2811 return True
2812 else:
2813 return False
2814
2815 _Macros = property(_GetMacros)
2816 Arch = property(_GetArch, _SetArch)
2817 Platform = property(_GetPlatform, _SetPlatform)
2818
2819 HeaderComments = property(_GetHeaderComments)
2820 TailComments = property(_GetTailComments)
2821 AutoGenVersion = property(_GetInfVersion)
2822 BaseName = property(_GetBaseName)
2823 ModuleType = property(_GetModuleType)
2824 ComponentType = property(_GetComponentType)
2825 BuildType = property(_GetBuildType)
2826 Guid = property(_GetFileGuid)
2827 Version = property(_GetVersion)
2828 PcdIsDriver = property(_GetPcdIsDriver)
2829 Shadow = property(_GetShadow)
2830 CustomMakefile = property(_GetMakefile)
2831 Specification = property(_GetSpec)
2832 LibraryClass = property(_GetLibraryClass)
2833 ModuleEntryPointList = property(_GetEntryPoint)
2834 ModuleUnloadImageList = property(_GetUnloadImage)
2835 ConstructorList = property(_GetConstructor)
2836 DestructorList = property(_GetDestructor)
2837 Defines = property(_GetDefines)
2838 DxsFile = property(_GetDxsFile)
2839
2840 Binaries = property(_GetBinaryFiles)
2841 Sources = property(_GetSourceFiles)
2842 LibraryClasses = property(_GetLibraryClassUses)
2843 Libraries = property(_GetLibraryNames)
2844 Protocols = property(_GetProtocols)
2845 ProtocolComments = property(_GetProtocolComments)
2846 Ppis = property(_GetPpis)
2847 PpiComments = property(_GetPpiComments)
2848 Guids = property(_GetGuids)
2849 GuidComments = property(_GetGuidComments)
2850 Includes = property(_GetIncludes)
2851 Packages = property(_GetPackages)
2852 Pcds = property(_GetPcds)
2853 PcdComments = property(_GetPcdComments)
2854 BuildOptions = property(_GetBuildOptions)
2855 Depex = property(_GetDepex)
2856 DepexExpression = property(_GetDepexExpression)
2857 IsBinaryModule = property(_IsBinaryModule)
2858 IsSupportedArch = property(_IsSupportedArch)
2859
2860 ## Database
2861 #
2862 # This class defined the build database for all modules, packages and platform.
2863 # It will call corresponding parser for the given file if it cannot find it in
2864 # the database.
2865 #
2866 # @param DbPath Path of database file
2867 # @param GlobalMacros Global macros used for replacement during file parsing
2868 # @prarm RenewDb=False Create new database file if it's already there
2869 #
2870 class WorkspaceDatabase(object):
2871
2872
2873 #
2874 # internal class used for call corresponding file parser and caching the result
2875 # to avoid unnecessary re-parsing
2876 #
2877 class BuildObjectFactory(object):
2878
2879 _FILE_TYPE_ = {
2880 ".inf" : MODEL_FILE_INF,
2881 ".dec" : MODEL_FILE_DEC,
2882 ".dsc" : MODEL_FILE_DSC,
2883 }
2884
2885 # file parser
2886 _FILE_PARSER_ = {
2887 MODEL_FILE_INF : InfParser,
2888 MODEL_FILE_DEC : DecParser,
2889 MODEL_FILE_DSC : DscParser,
2890 }
2891
2892 # convert to xxxBuildData object
2893 _GENERATOR_ = {
2894 MODEL_FILE_INF : InfBuildData,
2895 MODEL_FILE_DEC : DecBuildData,
2896 MODEL_FILE_DSC : DscBuildData,
2897 }
2898
2899 _CACHE_ = {} # (FilePath, Arch) : <object>
2900
2901 # constructor
2902 def __init__(self, WorkspaceDb):
2903 self.WorkspaceDb = WorkspaceDb
2904
2905 # key = (FilePath, Arch=None)
2906 def __contains__(self, Key):
2907 FilePath = Key[0]
2908 if len(Key) > 1:
2909 Arch = Key[1]
2910 else:
2911 Arch = None
2912 return (FilePath, Arch) in self._CACHE_
2913
2914 # key = (FilePath, Arch=None, Target=None, Toochain=None)
2915 def __getitem__(self, Key):
2916 FilePath = Key[0]
2917 KeyLength = len(Key)
2918 if KeyLength > 1:
2919 Arch = Key[1]
2920 else:
2921 Arch = None
2922 if KeyLength > 2:
2923 Target = Key[2]
2924 else:
2925 Target = None
2926 if KeyLength > 3:
2927 Toolchain = Key[3]
2928 else:
2929 Toolchain = None
2930
2931 # if it's generated before, just return the cached one
2932 Key = (FilePath, Arch, Target, Toolchain)
2933 if Key in self._CACHE_:
2934 return self._CACHE_[Key]
2935
2936 # check file type
2937 Ext = FilePath.Type
2938 if Ext not in self._FILE_TYPE_:
2939 return None
2940 FileType = self._FILE_TYPE_[Ext]
2941 if FileType not in self._GENERATOR_:
2942 return None
2943
2944 # get the parser ready for this file
2945 MetaFile = self._FILE_PARSER_[FileType](
2946 FilePath,
2947 FileType,
2948 Arch,
2949 MetaFileStorage(self.WorkspaceDb.Cur, FilePath, FileType)
2950 )
2951 # alwasy do post-process, in case of macros change
2952 MetaFile.DoPostProcess()
2953 # object the build is based on
2954 BuildObject = self._GENERATOR_[FileType](
2955 FilePath,
2956 MetaFile,
2957 self,
2958 Arch,
2959 Target,
2960 Toolchain
2961 )
2962 self._CACHE_[Key] = BuildObject
2963 return BuildObject
2964
2965 # placeholder for file format conversion
2966 class TransformObjectFactory:
2967 def __init__(self, WorkspaceDb):
2968 self.WorkspaceDb = WorkspaceDb
2969
2970 # key = FilePath, Arch
2971 def __getitem__(self, Key):
2972 pass
2973
2974 ## Constructor of WorkspaceDatabase
2975 #
2976 # @param DbPath Path of database file
2977 # @param GlobalMacros Global macros used for replacement during file parsing
2978 # @prarm RenewDb=False Create new database file if it's already there
2979 #
2980 def __init__(self, DbPath, RenewDb=False):
2981 self._DbClosedFlag = False
2982 if not DbPath:
2983 DbPath = os.path.normpath(mws.join(GlobalData.gWorkspace, 'Conf', GlobalData.gDatabasePath))
2984
2985 # don't create necessary path for db in memory
2986 if DbPath != ':memory:':
2987 DbDir = os.path.split(DbPath)[0]
2988 if not os.path.exists(DbDir):
2989 os.makedirs(DbDir)
2990
2991 # remove db file in case inconsistency between db and file in file system
2992 if self._CheckWhetherDbNeedRenew(RenewDb, DbPath):
2993 os.remove(DbPath)
2994
2995 # create db with optimized parameters
2996 self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')
2997 self.Conn.execute("PRAGMA synchronous=OFF")
2998 self.Conn.execute("PRAGMA temp_store=MEMORY")
2999 self.Conn.execute("PRAGMA count_changes=OFF")
3000 self.Conn.execute("PRAGMA cache_size=8192")
3001 #self.Conn.execute("PRAGMA page_size=8192")
3002
3003 # to avoid non-ascii character conversion issue
3004 self.Conn.text_factory = str
3005 self.Cur = self.Conn.cursor()
3006
3007 # create table for internal uses
3008 self.TblDataModel = TableDataModel(self.Cur)
3009 self.TblFile = TableFile(self.Cur)
3010 self.Platform = None
3011
3012 # conversion object for build or file format conversion purpose
3013 self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self)
3014 self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self)
3015
3016 ## Check whether workspace database need to be renew.
3017 # The renew reason maybe:
3018 # 1) If user force to renew;
3019 # 2) If user do not force renew, and
3020 # a) If the time of last modified python source is newer than database file;
3021 # b) If the time of last modified frozen executable file is newer than database file;
3022 #
3023 # @param force User force renew database
3024 # @param DbPath The absolute path of workspace database file
3025 #
3026 # @return Bool value for whether need renew workspace databse
3027 #
3028 def _CheckWhetherDbNeedRenew (self, force, DbPath):
3029 # if database does not exist, we need do nothing
3030 if not os.path.exists(DbPath): return False
3031
3032 # if user force to renew database, then not check whether database is out of date
3033 if force: return True
3034
3035 #
3036 # Check the time of last modified source file or build.exe
3037 # if is newer than time of database, then database need to be re-created.
3038 #
3039 timeOfToolModified = 0
3040 if hasattr(sys, "frozen"):
3041 exePath = os.path.abspath(sys.executable)
3042 timeOfToolModified = os.stat(exePath).st_mtime
3043 else:
3044 curPath = os.path.dirname(__file__) # curPath is the path of WorkspaceDatabase.py
3045 rootPath = os.path.split(curPath)[0] # rootPath is root path of python source, such as /BaseTools/Source/Python
3046 if rootPath == "" or rootPath == None:
3047 EdkLogger.verbose("\nFail to find the root path of build.exe or python sources, so can not \
3048 determine whether database file is out of date!\n")
3049
3050 # walk the root path of source or build's binary to get the time last modified.
3051
3052 for root, dirs, files in os.walk (rootPath):
3053 for dir in dirs:
3054 # bypass source control folder
3055 if dir.lower() in [".svn", "_svn", "cvs"]:
3056 dirs.remove(dir)
3057
3058 for file in files:
3059 ext = os.path.splitext(file)[1]
3060 if ext.lower() == ".py": # only check .py files
3061 fd = os.stat(os.path.join(root, file))
3062 if timeOfToolModified < fd.st_mtime:
3063 timeOfToolModified = fd.st_mtime
3064 if timeOfToolModified > os.stat(DbPath).st_mtime:
3065 EdkLogger.verbose("\nWorkspace database is out of data!")
3066 return True
3067
3068 return False
3069
3070 ## Initialize build database
3071 def InitDatabase(self):
3072 EdkLogger.verbose("\nInitialize build database started ...")
3073
3074 #
3075 # Create new tables
3076 #
3077 self.TblDataModel.Create(False)
3078 self.TblFile.Create(False)
3079
3080 #
3081 # Initialize table DataModel
3082 #
3083 self.TblDataModel.InitTable()
3084 EdkLogger.verbose("Initialize build database ... DONE!")
3085
3086 ## Query a table
3087 #
3088 # @param Table: The instance of the table to be queried
3089 #
3090 def QueryTable(self, Table):
3091 Table.Query()
3092
3093 def __del__(self):
3094 self.Close()
3095
3096 ## Close entire database
3097 #
3098 # Commit all first
3099 # Close the connection and cursor
3100 #
3101 def Close(self):
3102 if not self._DbClosedFlag:
3103 self.Conn.commit()
3104 self.Cur.close()
3105 self.Conn.close()
3106 self._DbClosedFlag = True
3107
3108 ## Summarize all packages in the database
3109 def GetPackageList(self, Platform, Arch, TargetName, ToolChainTag):
3110 self.Platform = Platform
3111 PackageList = []
3112 Pa = self.BuildObject[self.Platform, 'COMMON']
3113 #
3114 # Get Package related to Modules
3115 #
3116 for Module in Pa.Modules:
3117 ModuleObj = self.BuildObject[Module, Arch, TargetName, ToolChainTag]
3118 for Package in ModuleObj.Packages:
3119 if Package not in PackageList:
3120 PackageList.append(Package)
3121 #
3122 # Get Packages related to Libraries
3123 #
3124 for Lib in Pa.LibraryInstances:
3125 LibObj = self.BuildObject[Lib, Arch, TargetName, ToolChainTag]
3126 for Package in LibObj.Packages:
3127 if Package not in PackageList:
3128 PackageList.append(Package)
3129
3130 return PackageList
3131
3132 ## Summarize all platforms in the database
3133 def _GetPlatformList(self):
3134 PlatformList = []
3135 for PlatformFile in self.TblFile.GetFileList(MODEL_FILE_DSC):
3136 try:
3137 Platform = self.BuildObject[PathClass(PlatformFile), 'COMMON']
3138 except:
3139 Platform = None
3140 if Platform != None:
3141 PlatformList.append(Platform)
3142 return PlatformList
3143
3144 def _MapPlatform(self, Dscfile):
3145 Platform = self.BuildObject[PathClass(Dscfile), 'COMMON']
3146 if Platform == None:
3147 EdkLogger.error('build', PARSER_ERROR, "Failed to parser DSC file: %s" % Dscfile)
3148 return Platform
3149
3150 PlatformList = property(_GetPlatformList)
3151
3152 ##
3153 #
3154 # This acts like the main() function for the script, unless it is 'import'ed into another
3155 # script.
3156 #
3157 if __name__ == '__main__':
3158 pass
3159