]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Fix corner-cases of --hash feature
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
... / ...
CommitLineData
1## @file\r
2# Generate AutoGen.h, AutoGen.c and *.depex files\r
3#\r
4# Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r
5# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>\r
6# Copyright (c) 2019, American Megatrends, Inc. All rights reserved.<BR>\r
7#\r
8# SPDX-License-Identifier: BSD-2-Clause-Patent\r
9#\r
10\r
11## Import Modules\r
12#\r
13from __future__ import print_function\r
14from __future__ import absolute_import\r
15import Common.LongFilePathOs as os\r
16import re\r
17import os.path as path\r
18import copy\r
19import uuid\r
20\r
21from . import GenC\r
22from . import GenMake\r
23from . import GenDepex\r
24from io import BytesIO\r
25\r
26from .StrGather import *\r
27from .BuildEngine import BuildRule\r
28import shutil\r
29from Common.LongFilePathSupport import CopyLongFilePath\r
30from Common.BuildToolError import *\r
31from Common.DataType import *\r
32from Common.Misc import *\r
33from Common.StringUtils import *\r
34import Common.GlobalData as GlobalData\r
35from GenFds.FdfParser import *\r
36from CommonDataClass.CommonClass import SkuInfoClass\r
37from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r
38import Common.VpdInfoFile as VpdInfoFile\r
39from .GenPcdDb import CreatePcdDatabaseCode\r
40from Workspace.MetaFileCommentParser import UsageList\r
41from Workspace.WorkspaceCommon import GetModuleLibInstances\r
42from Common.MultipleWorkspace import MultipleWorkspace as mws\r
43from . import InfSectionParser\r
44import datetime\r
45import hashlib\r
46from .GenVar import VariableMgr, var_info\r
47from collections import OrderedDict\r
48from collections import defaultdict\r
49from Workspace.WorkspaceCommon import OrderedListDict\r
50from Common.ToolDefClassObject import gDefaultToolsDefFile\r
51\r
52from Common.caching import cached_property, cached_class_function\r
53\r
54## Regular expression for splitting Dependency Expression string into tokens\r
55gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
56\r
57## Regular expression for match: PCD(xxxx.yyy)\r
58gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$")\r
59\r
60#\r
61# Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
62# is the former use /I , the Latter used -I to specify include directories\r
63#\r
64gBuildOptIncludePatternMsft = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
65gBuildOptIncludePatternOther = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
66\r
67#\r
68# Match name = variable\r
69#\r
70gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")\r
71#\r
72# The format of guid in efivarstore statement likes following and must be correct:\r
73# guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}\r
74#\r
75gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")\r
76\r
77## Mapping Makefile type\r
78gMakeTypeMap = {TAB_COMPILER_MSFT:"nmake", "GCC":"gmake"}\r
79\r
80\r
81## Build rule configuration file\r
82gDefaultBuildRuleFile = 'build_rule.txt'\r
83\r
84## Build rule default version\r
85AutoGenReqBuildRuleVerNum = "0.1"\r
86\r
87## default file name for AutoGen\r
88gAutoGenCodeFileName = "AutoGen.c"\r
89gAutoGenHeaderFileName = "AutoGen.h"\r
90gAutoGenStringFileName = "%(module_name)sStrDefs.h"\r
91gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r
92gAutoGenDepexFileName = "%(module_name)s.depex"\r
93gAutoGenImageDefFileName = "%(module_name)sImgDefs.h"\r
94gAutoGenIdfFileName = "%(module_name)sIdf.hpk"\r
95gInfSpecVersion = "0x00010017"\r
96\r
97#\r
98# Template string to generic AsBuilt INF\r
99#\r
100gAsBuiltInfHeaderString = TemplateString("""${header_comments}\r
101\r
102# DO NOT EDIT\r
103# FILE auto-generated\r
104\r
105[Defines]\r
106 INF_VERSION = ${module_inf_version}\r
107 BASE_NAME = ${module_name}\r
108 FILE_GUID = ${module_guid}\r
109 MODULE_TYPE = ${module_module_type}${BEGIN}\r
110 VERSION_STRING = ${module_version_string}${END}${BEGIN}\r
111 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}\r
112 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}\r
113 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}\r
114 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}\r
115 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}\r
116 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}\r
117 DESTRUCTOR = ${module_destructor}${END}${BEGIN}\r
118 SHADOW = ${module_shadow}${END}${BEGIN}\r
119 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}\r
120 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}\r
121 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}\r
122 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}\r
123 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}\r
124 SPEC = ${module_spec}${END}${BEGIN}\r
125 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}\r
126 MODULE_UNI_FILE = ${module_uni_file}${END}\r
127\r
128[Packages.${module_arch}]${BEGIN}\r
129 ${package_item}${END}\r
130\r
131[Binaries.${module_arch}]${BEGIN}\r
132 ${binary_item}${END}\r
133\r
134[PatchPcd.${module_arch}]${BEGIN}\r
135 ${patchablepcd_item}\r
136${END}\r
137\r
138[Protocols.${module_arch}]${BEGIN}\r
139 ${protocol_item}\r
140${END}\r
141\r
142[Ppis.${module_arch}]${BEGIN}\r
143 ${ppi_item}\r
144${END}\r
145\r
146[Guids.${module_arch}]${BEGIN}\r
147 ${guid_item}\r
148${END}\r
149\r
150[PcdEx.${module_arch}]${BEGIN}\r
151 ${pcd_item}\r
152${END}\r
153\r
154[LibraryClasses.${module_arch}]\r
155## @LIB_INSTANCES${BEGIN}\r
156# ${libraryclasses_item}${END}\r
157\r
158${depexsection_item}\r
159\r
160${userextension_tianocore_item}\r
161\r
162${tail_comments}\r
163\r
164[BuildOptions.${module_arch}]\r
165## @AsBuilt${BEGIN}\r
166## ${flags_item}${END}\r
167""")\r
168## Split command line option string to list\r
169#\r
170# subprocess.Popen needs the args to be a sequence. Otherwise there's problem\r
171# in non-windows platform to launch command\r
172#\r
173def _SplitOption(OptionString):\r
174 OptionList = []\r
175 LastChar = " "\r
176 OptionStart = 0\r
177 QuotationMark = ""\r
178 for Index in range(0, len(OptionString)):\r
179 CurrentChar = OptionString[Index]\r
180 if CurrentChar in ['"', "'"]:\r
181 if QuotationMark == CurrentChar:\r
182 QuotationMark = ""\r
183 elif QuotationMark == "":\r
184 QuotationMark = CurrentChar\r
185 continue\r
186 elif QuotationMark:\r
187 continue\r
188\r
189 if CurrentChar in ["/", "-"] and LastChar in [" ", "\t", "\r", "\n"]:\r
190 if Index > OptionStart:\r
191 OptionList.append(OptionString[OptionStart:Index - 1])\r
192 OptionStart = Index\r
193 LastChar = CurrentChar\r
194 OptionList.append(OptionString[OptionStart:])\r
195 return OptionList\r
196\r
197#\r
198# Convert string to C format array\r
199#\r
200def _ConvertStringToByteArray(Value):\r
201 Value = Value.strip()\r
202 if not Value:\r
203 return None\r
204 if Value[0] == '{':\r
205 if not Value.endswith('}'):\r
206 return None\r
207 Value = Value.replace(' ', '').replace('{', '').replace('}', '')\r
208 ValFields = Value.split(',')\r
209 try:\r
210 for Index in range(len(ValFields)):\r
211 ValFields[Index] = str(int(ValFields[Index], 0))\r
212 except ValueError:\r
213 return None\r
214 Value = '{' + ','.join(ValFields) + '}'\r
215 return Value\r
216\r
217 Unicode = False\r
218 if Value.startswith('L"'):\r
219 if not Value.endswith('"'):\r
220 return None\r
221 Value = Value[1:]\r
222 Unicode = True\r
223 elif not Value.startswith('"') or not Value.endswith('"'):\r
224 return None\r
225\r
226 Value = eval(Value) # translate escape character\r
227 NewValue = '{'\r
228 for Index in range(0, len(Value)):\r
229 if Unicode:\r
230 NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ','\r
231 else:\r
232 NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ','\r
233 Value = NewValue + '0}'\r
234 return Value\r
235\r
236## Base class for AutoGen\r
237#\r
238# This class just implements the cache mechanism of AutoGen objects.\r
239#\r
240class AutoGen(object):\r
241 # database to maintain the objects in each child class\r
242 __ObjectCache = {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object\r
243\r
244 ## Factory method\r
245 #\r
246 # @param Class class object of real AutoGen class\r
247 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)\r
248 # @param Workspace Workspace directory or WorkspaceAutoGen object\r
249 # @param MetaFile The path of meta file\r
250 # @param Target Build target\r
251 # @param Toolchain Tool chain name\r
252 # @param Arch Target arch\r
253 # @param *args The specific class related parameters\r
254 # @param **kwargs The specific class related dict parameters\r
255 #\r
256 def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
257 # check if the object has been created\r
258 Key = (Target, Toolchain, Arch, MetaFile)\r
259 if Key in cls.__ObjectCache:\r
260 # if it exists, just return it directly\r
261 return cls.__ObjectCache[Key]\r
262 # it didnt exist. create it, cache it, then return it\r
263 RetVal = cls.__ObjectCache[Key] = super(AutoGen, cls).__new__(cls)\r
264 return RetVal\r
265\r
266\r
267 ## hash() operator\r
268 #\r
269 # The file path of platform file will be used to represent hash value of this object\r
270 #\r
271 # @retval int Hash value of the file path of platform file\r
272 #\r
273 def __hash__(self):\r
274 return hash(self.MetaFile)\r
275\r
276 ## str() operator\r
277 #\r
278 # The file path of platform file will be used to represent this object\r
279 #\r
280 # @retval string String of platform file path\r
281 #\r
282 def __str__(self):\r
283 return str(self.MetaFile)\r
284\r
285 ## "==" operator\r
286 def __eq__(self, Other):\r
287 return Other and self.MetaFile == Other\r
288\r
289## Workspace AutoGen class\r
290#\r
291# This class is used mainly to control the whole platform build for different\r
292# architecture. This class will generate top level makefile.\r
293#\r
294class WorkspaceAutoGen(AutoGen):\r
295 # call super().__init__ then call the worker function with different parameter count\r
296 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
297 if not hasattr(self, "_Init"):\r
298 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
299 self._Init = True\r
300\r
301 ## Initialize WorkspaceAutoGen\r
302 #\r
303 # @param WorkspaceDir Root directory of workspace\r
304 # @param ActivePlatform Meta-file of active platform\r
305 # @param Target Build target\r
306 # @param Toolchain Tool chain name\r
307 # @param ArchList List of architecture of current build\r
308 # @param MetaFileDb Database containing meta-files\r
309 # @param BuildConfig Configuration of build\r
310 # @param ToolDefinition Tool chain definitions\r
311 # @param FlashDefinitionFile File of flash definition\r
312 # @param Fds FD list to be generated\r
313 # @param Fvs FV list to be generated\r
314 # @param Caps Capsule list to be generated\r
315 # @param SkuId SKU id from command line\r
316 #\r
317 def _InitWorker(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
318 BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,\r
319 Progress=None, BuildModule=None):\r
320 self.BuildDatabase = MetaFileDb\r
321 self.MetaFile = ActivePlatform\r
322 self.WorkspaceDir = WorkspaceDir\r
323 self.Platform = self.BuildDatabase[self.MetaFile, TAB_ARCH_COMMON, Target, Toolchain]\r
324 GlobalData.gActivePlatform = self.Platform\r
325 self.BuildTarget = Target\r
326 self.ToolChain = Toolchain\r
327 self.ArchList = ArchList\r
328 self.SkuId = SkuId\r
329 self.UniFlag = UniFlag\r
330\r
331 self.TargetTxt = BuildConfig\r
332 self.ToolDef = ToolDefinition\r
333 self.FdfFile = FlashDefinitionFile\r
334 self.FdTargetList = Fds if Fds else []\r
335 self.FvTargetList = Fvs if Fvs else []\r
336 self.CapTargetList = Caps if Caps else []\r
337 self.AutoGenObjectList = []\r
338 self._GuidDict = {}\r
339\r
340 # there's many relative directory operations, so ...\r
341 os.chdir(self.WorkspaceDir)\r
342\r
343 #\r
344 # Merge Arch\r
345 #\r
346 if not self.ArchList:\r
347 ArchList = set(self.Platform.SupArchList)\r
348 else:\r
349 ArchList = set(self.ArchList) & set(self.Platform.SupArchList)\r
350 if not ArchList:\r
351 EdkLogger.error("build", PARAMETER_INVALID,\r
352 ExtraData = "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self.Platform.SupArchList)))\r
353 elif self.ArchList and len(ArchList) != len(self.ArchList):\r
354 SkippedArchList = set(self.ArchList).symmetric_difference(set(self.Platform.SupArchList))\r
355 EdkLogger.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"\r
356 % (" ".join(SkippedArchList), " ".join(self.Platform.SupArchList)))\r
357 self.ArchList = tuple(ArchList)\r
358\r
359 # Validate build target\r
360 if self.BuildTarget not in self.Platform.BuildTargets:\r
361 EdkLogger.error("build", PARAMETER_INVALID,\r
362 ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"\r
363 % (self.BuildTarget, " ".join(self.Platform.BuildTargets)))\r
364\r
365\r
366 # parse FDF file to get PCDs in it, if any\r
367 if not self.FdfFile:\r
368 self.FdfFile = self.Platform.FlashDefinition\r
369\r
370 EdkLogger.info("")\r
371 if self.ArchList:\r
372 EdkLogger.info('%-16s = %s' % ("Architecture(s)", ' '.join(self.ArchList)))\r
373 EdkLogger.info('%-16s = %s' % ("Build target", self.BuildTarget))\r
374 EdkLogger.info('%-16s = %s' % ("Toolchain", self.ToolChain))\r
375\r
376 EdkLogger.info('\n%-24s = %s' % ("Active Platform", self.Platform))\r
377 if BuildModule:\r
378 EdkLogger.info('%-24s = %s' % ("Active Module", BuildModule))\r
379\r
380 if self.FdfFile:\r
381 EdkLogger.info('%-24s = %s' % ("Flash Image Definition", self.FdfFile))\r
382\r
383 EdkLogger.verbose("\nFLASH_DEFINITION = %s" % self.FdfFile)\r
384\r
385 if Progress:\r
386 Progress.Start("\nProcessing meta-data")\r
387\r
388 if self.FdfFile:\r
389 #\r
390 # Mark now build in AutoGen Phase\r
391 #\r
392 GlobalData.gAutoGenPhase = True\r
393 Fdf = FdfParser(self.FdfFile.Path)\r
394 Fdf.ParseFile()\r
395 GlobalData.gFdfParser = Fdf\r
396 GlobalData.gAutoGenPhase = False\r
397 PcdSet = Fdf.Profile.PcdDict\r
398 if Fdf.CurrentFdName and Fdf.CurrentFdName in Fdf.Profile.FdDict:\r
399 FdDict = Fdf.Profile.FdDict[Fdf.CurrentFdName]\r
400 for FdRegion in FdDict.RegionList:\r
401 if str(FdRegion.RegionType) is 'FILE' and self.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
402 if int(FdRegion.Offset) % 8 != 0:\r
403 EdkLogger.error("build", FORMAT_INVALID, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion.Offset))\r
404 ModuleList = Fdf.Profile.InfList\r
405 self.FdfProfile = Fdf.Profile\r
406 for fvname in self.FvTargetList:\r
407 if fvname.upper() not in self.FdfProfile.FvDict:\r
408 EdkLogger.error("build", OPTION_VALUE_INVALID,\r
409 "No such an FV in FDF file: %s" % fvname)\r
410\r
411 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,\r
412 # but the path (self.MetaFile.Path) is the real path\r
413 for key in self.FdfProfile.InfDict:\r
414 if key == 'ArchTBD':\r
415 MetaFile_cache = defaultdict(set)\r
416 for Arch in self.ArchList:\r
417 Current_Platform_cache = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
418 for Pkey in Current_Platform_cache.Modules:\r
419 MetaFile_cache[Arch].add(Current_Platform_cache.Modules[Pkey].MetaFile)\r
420 for Inf in self.FdfProfile.InfDict[key]:\r
421 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
422 for Arch in self.ArchList:\r
423 if ModuleFile in MetaFile_cache[Arch]:\r
424 break\r
425 else:\r
426 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
427 if not ModuleData.IsBinaryModule:\r
428 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
429\r
430 else:\r
431 for Arch in self.ArchList:\r
432 if Arch == key:\r
433 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
434 MetaFileList = set()\r
435 for Pkey in Platform.Modules:\r
436 MetaFileList.add(Platform.Modules[Pkey].MetaFile)\r
437 for Inf in self.FdfProfile.InfDict[key]:\r
438 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
439 if ModuleFile in MetaFileList:\r
440 continue\r
441 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
442 if not ModuleData.IsBinaryModule:\r
443 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
444\r
445 else:\r
446 PcdSet = {}\r
447 ModuleList = []\r
448 self.FdfProfile = None\r
449 if self.FdTargetList:\r
450 EdkLogger.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self.FdTargetList))\r
451 self.FdTargetList = []\r
452 if self.FvTargetList:\r
453 EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvTargetList))\r
454 self.FvTargetList = []\r
455 if self.CapTargetList:\r
456 EdkLogger.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self.CapTargetList))\r
457 self.CapTargetList = []\r
458\r
459 # apply SKU and inject PCDs from Flash Definition file\r
460 for Arch in self.ArchList:\r
461 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
462 PlatformPcds = Platform.Pcds\r
463 self._GuidDict = Platform._GuidDict\r
464 SourcePcdDict = {TAB_PCDS_DYNAMIC_EX:set(), TAB_PCDS_PATCHABLE_IN_MODULE:set(),TAB_PCDS_DYNAMIC:set(),TAB_PCDS_FIXED_AT_BUILD:set()}\r
465 BinaryPcdDict = {TAB_PCDS_DYNAMIC_EX:set(), TAB_PCDS_PATCHABLE_IN_MODULE:set()}\r
466 SourcePcdDict_Keys = SourcePcdDict.keys()\r
467 BinaryPcdDict_Keys = BinaryPcdDict.keys()\r
468\r
469 # generate the SourcePcdDict and BinaryPcdDict\r
470 PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
471 for BuildData in list(PGen.BuildDatabase._CACHE_.values()):\r
472 if BuildData.Arch != Arch:\r
473 continue\r
474 if BuildData.MetaFile.Ext == '.inf':\r
475 for key in BuildData.Pcds:\r
476 if BuildData.Pcds[key].Pending:\r
477 if key in Platform.Pcds:\r
478 PcdInPlatform = Platform.Pcds[key]\r
479 if PcdInPlatform.Type:\r
480 BuildData.Pcds[key].Type = PcdInPlatform.Type\r
481 BuildData.Pcds[key].Pending = False\r
482\r
483 if BuildData.MetaFile in Platform.Modules:\r
484 PlatformModule = Platform.Modules[str(BuildData.MetaFile)]\r
485 if key in PlatformModule.Pcds:\r
486 PcdInPlatform = PlatformModule.Pcds[key]\r
487 if PcdInPlatform.Type:\r
488 BuildData.Pcds[key].Type = PcdInPlatform.Type\r
489 BuildData.Pcds[key].Pending = False\r
490 else:\r
491 #Pcd used in Library, Pcd Type from reference module if Pcd Type is Pending\r
492 if BuildData.Pcds[key].Pending:\r
493 MGen = ModuleAutoGen(self, BuildData.MetaFile, Target, Toolchain, Arch, self.MetaFile)\r
494 if MGen and MGen.IsLibrary:\r
495 if MGen in PGen.LibraryAutoGenList:\r
496 ReferenceModules = MGen.ReferenceModules\r
497 for ReferenceModule in ReferenceModules:\r
498 if ReferenceModule.MetaFile in Platform.Modules:\r
499 RefPlatformModule = Platform.Modules[str(ReferenceModule.MetaFile)]\r
500 if key in RefPlatformModule.Pcds:\r
501 PcdInReferenceModule = RefPlatformModule.Pcds[key]\r
502 if PcdInReferenceModule.Type:\r
503 BuildData.Pcds[key].Type = PcdInReferenceModule.Type\r
504 BuildData.Pcds[key].Pending = False\r
505 break\r
506\r
507 if TAB_PCDS_DYNAMIC_EX in BuildData.Pcds[key].Type:\r
508 if BuildData.IsBinaryModule:\r
509 BinaryPcdDict[TAB_PCDS_DYNAMIC_EX].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
510 else:\r
511 SourcePcdDict[TAB_PCDS_DYNAMIC_EX].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
512\r
513 elif TAB_PCDS_PATCHABLE_IN_MODULE in BuildData.Pcds[key].Type:\r
514 if BuildData.MetaFile.Ext == '.inf':\r
515 if BuildData.IsBinaryModule:\r
516 BinaryPcdDict[TAB_PCDS_PATCHABLE_IN_MODULE].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
517 else:\r
518 SourcePcdDict[TAB_PCDS_PATCHABLE_IN_MODULE].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
519\r
520 elif TAB_PCDS_DYNAMIC in BuildData.Pcds[key].Type:\r
521 SourcePcdDict[TAB_PCDS_DYNAMIC].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
522 elif TAB_PCDS_FIXED_AT_BUILD in BuildData.Pcds[key].Type:\r
523 SourcePcdDict[TAB_PCDS_FIXED_AT_BUILD].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
524 else:\r
525 pass\r
526 #\r
527 # A PCD can only use one type for all source modules\r
528 #\r
529 for i in SourcePcdDict_Keys:\r
530 for j in SourcePcdDict_Keys:\r
531 if i != j:\r
532 Intersections = SourcePcdDict[i].intersection(SourcePcdDict[j])\r
533 if len(Intersections) > 0:\r
534 EdkLogger.error(\r
535 'build',\r
536 FORMAT_INVALID,\r
537 "Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i, j),\r
538 ExtraData='\n\t'.join(str(P[1]+'.'+P[0]) for P in Intersections)\r
539 )\r
540\r
541 #\r
542 # intersection the BinaryPCD for Mixed PCD\r
543 #\r
544 for i in BinaryPcdDict_Keys:\r
545 for j in BinaryPcdDict_Keys:\r
546 if i != j:\r
547 Intersections = BinaryPcdDict[i].intersection(BinaryPcdDict[j])\r
548 for item in Intersections:\r
549 NewPcd1 = (item[0] + '_' + i, item[1])\r
550 NewPcd2 = (item[0] + '_' + j, item[1])\r
551 if item not in GlobalData.MixedPcd:\r
552 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
553 else:\r
554 if NewPcd1 not in GlobalData.MixedPcd[item]:\r
555 GlobalData.MixedPcd[item].append(NewPcd1)\r
556 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
557 GlobalData.MixedPcd[item].append(NewPcd2)\r
558\r
559 #\r
560 # intersection the SourcePCD and BinaryPCD for Mixed PCD\r
561 #\r
562 for i in SourcePcdDict_Keys:\r
563 for j in BinaryPcdDict_Keys:\r
564 if i != j:\r
565 Intersections = SourcePcdDict[i].intersection(BinaryPcdDict[j])\r
566 for item in Intersections:\r
567 NewPcd1 = (item[0] + '_' + i, item[1])\r
568 NewPcd2 = (item[0] + '_' + j, item[1])\r
569 if item not in GlobalData.MixedPcd:\r
570 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
571 else:\r
572 if NewPcd1 not in GlobalData.MixedPcd[item]:\r
573 GlobalData.MixedPcd[item].append(NewPcd1)\r
574 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
575 GlobalData.MixedPcd[item].append(NewPcd2)\r
576\r
577 for BuildData in list(PGen.BuildDatabase._CACHE_.values()):\r
578 if BuildData.Arch != Arch:\r
579 continue\r
580 for key in BuildData.Pcds:\r
581 for SinglePcd in GlobalData.MixedPcd:\r
582 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
583 for item in GlobalData.MixedPcd[SinglePcd]:\r
584 Pcd_Type = item[0].split('_')[-1]\r
585 if (Pcd_Type == BuildData.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and BuildData.Pcds[key].Type in PCD_DYNAMIC_EX_TYPE_SET) or \\r
586 (Pcd_Type == TAB_PCDS_DYNAMIC and BuildData.Pcds[key].Type in PCD_DYNAMIC_TYPE_SET):\r
587 Value = BuildData.Pcds[key]\r
588 Value.TokenCName = BuildData.Pcds[key].TokenCName + '_' + Pcd_Type\r
589 if len(key) == 2:\r
590 newkey = (Value.TokenCName, key[1])\r
591 elif len(key) == 3:\r
592 newkey = (Value.TokenCName, key[1], key[2])\r
593 del BuildData.Pcds[key]\r
594 BuildData.Pcds[newkey] = Value\r
595 break\r
596 break\r
597\r
598 # handle the mixed pcd in FDF file\r
599 for key in PcdSet:\r
600 if key in GlobalData.MixedPcd:\r
601 Value = PcdSet[key]\r
602 del PcdSet[key]\r
603 for item in GlobalData.MixedPcd[key]:\r
604 PcdSet[item] = Value\r
605\r
606 #Collect package set information from INF of FDF\r
607 PkgSet = set()\r
608 for Inf in ModuleList:\r
609 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
610 if ModuleFile in Platform.Modules:\r
611 continue\r
612 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
613 PkgSet.update(ModuleData.Packages)\r
614 Pkgs = list(PkgSet) + list(PGen.PackageList)\r
615 DecPcds = set()\r
616 DecPcdsKey = set()\r
617 for Pkg in Pkgs:\r
618 for Pcd in Pkg.Pcds:\r
619 DecPcds.add((Pcd[0], Pcd[1]))\r
620 DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
621\r
622 Platform.SkuName = self.SkuId\r
623 for Name, Guid,Fileds in PcdSet:\r
624 if (Name, Guid) not in DecPcds:\r
625 EdkLogger.error(\r
626 'build',\r
627 PARSER_ERROR,\r
628 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid, Name),\r
629 File = self.FdfProfile.PcdFileLineDict[Name, Guid, Fileds][0],\r
630 Line = self.FdfProfile.PcdFileLineDict[Name, Guid, Fileds][1]\r
631 )\r
632 else:\r
633 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.\r
634 if (Name, Guid, TAB_PCDS_FIXED_AT_BUILD) in DecPcdsKey \\r
635 or (Name, Guid, TAB_PCDS_PATCHABLE_IN_MODULE) in DecPcdsKey \\r
636 or (Name, Guid, TAB_PCDS_FEATURE_FLAG) in DecPcdsKey:\r
637 continue\r
638 elif (Name, Guid, TAB_PCDS_DYNAMIC) in DecPcdsKey or (Name, Guid, TAB_PCDS_DYNAMIC_EX) in DecPcdsKey:\r
639 EdkLogger.error(\r
640 'build',\r
641 PARSER_ERROR,\r
642 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid, Name),\r
643 File = self.FdfProfile.PcdFileLineDict[Name, Guid, Fileds][0],\r
644 Line = self.FdfProfile.PcdFileLineDict[Name, Guid, Fileds][1]\r
645 )\r
646\r
647 Pa = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
648 #\r
649 # Explicitly collect platform's dynamic PCDs\r
650 #\r
651 Pa.CollectPlatformDynamicPcds()\r
652 Pa.CollectFixedAtBuildPcds()\r
653 self.AutoGenObjectList.append(Pa)\r
654\r
655 #\r
656 # Generate Package level hash value\r
657 #\r
658 GlobalData.gPackageHash = {}\r
659 if GlobalData.gUseHashCache:\r
660 for Pkg in Pkgs:\r
661 self._GenPkgLevelHash(Pkg)\r
662\r
663 #\r
664 # Check PCDs token value conflict in each DEC file.\r
665 #\r
666 self._CheckAllPcdsTokenValueConflict()\r
667\r
668 #\r
669 # Check PCD type and definition between DSC and DEC\r
670 #\r
671 self._CheckPcdDefineAndType()\r
672\r
673 #\r
674 # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.\r
675 #\r
676 content = 'gCommandLineDefines: '\r
677 content += str(GlobalData.gCommandLineDefines)\r
678 content += TAB_LINE_BREAK\r
679 content += 'BuildOptionPcd: '\r
680 content += str(GlobalData.BuildOptionPcd)\r
681 content += TAB_LINE_BREAK\r
682 content += 'Active Platform: '\r
683 content += str(self.Platform)\r
684 content += TAB_LINE_BREAK\r
685 if self.FdfFile:\r
686 content += 'Flash Image Definition: '\r
687 content += str(self.FdfFile)\r
688 content += TAB_LINE_BREAK\r
689 SaveFileOnChange(os.path.join(self.BuildDir, 'BuildOptions'), content, False)\r
690\r
691 #\r
692 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.\r
693 #\r
694 PcdTokenNumber = 'PcdTokenNumber: '\r
695 if Pa.PcdTokenNumber:\r
696 if Pa.DynamicPcdList:\r
697 for Pcd in Pa.DynamicPcdList:\r
698 PcdTokenNumber += TAB_LINE_BREAK\r
699 PcdTokenNumber += str((Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
700 PcdTokenNumber += ' : '\r
701 PcdTokenNumber += str(Pa.PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName])\r
702 SaveFileOnChange(os.path.join(self.BuildDir, 'PcdTokenNumber'), PcdTokenNumber, False)\r
703\r
704 #\r
705 # Get set of workspace metafiles\r
706 #\r
707 AllWorkSpaceMetaFiles = self._GetMetaFiles(Target, Toolchain, Arch)\r
708\r
709 #\r
710 # Retrieve latest modified time of all metafiles\r
711 #\r
712 SrcTimeStamp = 0\r
713 for f in AllWorkSpaceMetaFiles:\r
714 if os.stat(f)[8] > SrcTimeStamp:\r
715 SrcTimeStamp = os.stat(f)[8]\r
716 self._SrcTimeStamp = SrcTimeStamp\r
717\r
718 if GlobalData.gUseHashCache:\r
719 m = hashlib.md5()\r
720 for files in AllWorkSpaceMetaFiles:\r
721 if files.endswith('.dec'):\r
722 continue\r
723 f = open(files, 'rb')\r
724 Content = f.read()\r
725 f.close()\r
726 m.update(Content)\r
727 SaveFileOnChange(os.path.join(self.BuildDir, 'AutoGen.hash'), m.hexdigest(), False)\r
728 GlobalData.gPlatformHash = m.hexdigest()\r
729\r
730 #\r
731 # Write metafile list to build directory\r
732 #\r
733 AutoGenFilePath = os.path.join(self.BuildDir, 'AutoGen')\r
734 if os.path.exists (AutoGenFilePath):\r
735 os.remove(AutoGenFilePath)\r
736 if not os.path.exists(self.BuildDir):\r
737 os.makedirs(self.BuildDir)\r
738 with open(os.path.join(self.BuildDir, 'AutoGen'), 'w+') as file:\r
739 for f in AllWorkSpaceMetaFiles:\r
740 print(f, file=file)\r
741 return True\r
742\r
743 def _GenPkgLevelHash(self, Pkg):\r
744 if Pkg.PackageName in GlobalData.gPackageHash:\r
745 return\r
746\r
747 PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName)\r
748 CreateDirectory(PkgDir)\r
749 HashFile = os.path.join(PkgDir, Pkg.PackageName + '.hash')\r
750 m = hashlib.md5()\r
751 # Get .dec file's hash value\r
752 f = open(Pkg.MetaFile.Path, 'rb')\r
753 Content = f.read()\r
754 f.close()\r
755 m.update(Content)\r
756 # Get include files hash value\r
757 if Pkg.Includes:\r
758 for inc in sorted(Pkg.Includes, key=lambda x: str(x)):\r
759 for Root, Dirs, Files in os.walk(str(inc)):\r
760 for File in sorted(Files):\r
761 File_Path = os.path.join(Root, File)\r
762 f = open(File_Path, 'rb')\r
763 Content = f.read()\r
764 f.close()\r
765 m.update(Content)\r
766 SaveFileOnChange(HashFile, m.hexdigest(), False)\r
767 GlobalData.gPackageHash[Pkg.PackageName] = m.hexdigest()\r
768\r
769 def _GetMetaFiles(self, Target, Toolchain, Arch):\r
770 AllWorkSpaceMetaFiles = set()\r
771 #\r
772 # add fdf\r
773 #\r
774 if self.FdfFile:\r
775 AllWorkSpaceMetaFiles.add (self.FdfFile.Path)\r
776 for f in GlobalData.gFdfParser.GetAllIncludedFile():\r
777 AllWorkSpaceMetaFiles.add (f.FileName)\r
778 #\r
779 # add dsc\r
780 #\r
781 AllWorkSpaceMetaFiles.add(self.MetaFile.Path)\r
782\r
783 #\r
784 # add build_rule.txt & tools_def.txt\r
785 #\r
786 AllWorkSpaceMetaFiles.add(os.path.join(GlobalData.gConfDirectory, gDefaultBuildRuleFile))\r
787 AllWorkSpaceMetaFiles.add(os.path.join(GlobalData.gConfDirectory, gDefaultToolsDefFile))\r
788\r
789 # add BuildOption metafile\r
790 #\r
791 AllWorkSpaceMetaFiles.add(os.path.join(self.BuildDir, 'BuildOptions'))\r
792\r
793 # add PcdToken Number file for Dynamic/DynamicEx Pcd\r
794 #\r
795 AllWorkSpaceMetaFiles.add(os.path.join(self.BuildDir, 'PcdTokenNumber'))\r
796\r
797 for Arch in self.ArchList:\r
798 #\r
799 # add dec\r
800 #\r
801 for Package in PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch).PackageList:\r
802 AllWorkSpaceMetaFiles.add(Package.MetaFile.Path)\r
803\r
804 #\r
805 # add included dsc\r
806 #\r
807 for filePath in self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]._RawData.IncludedFiles:\r
808 AllWorkSpaceMetaFiles.add(filePath.Path)\r
809\r
810 return AllWorkSpaceMetaFiles\r
811\r
812 def _CheckPcdDefineAndType(self):\r
813 PcdTypeSet = {TAB_PCDS_FIXED_AT_BUILD,\r
814 TAB_PCDS_PATCHABLE_IN_MODULE,\r
815 TAB_PCDS_FEATURE_FLAG,\r
816 TAB_PCDS_DYNAMIC,\r
817 TAB_PCDS_DYNAMIC_EX}\r
818\r
819 # This dict store PCDs which are not used by any modules with specified arches\r
820 UnusedPcd = OrderedDict()\r
821 for Pa in self.AutoGenObjectList:\r
822 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
823 for Pcd in Pa.Platform.Pcds:\r
824 PcdType = Pa.Platform.Pcds[Pcd].Type\r
825\r
826 # If no PCD type, this PCD comes from FDF\r
827 if not PcdType:\r
828 continue\r
829\r
830 # Try to remove Hii and Vpd suffix\r
831 if PcdType.startswith(TAB_PCDS_DYNAMIC_EX):\r
832 PcdType = TAB_PCDS_DYNAMIC_EX\r
833 elif PcdType.startswith(TAB_PCDS_DYNAMIC):\r
834 PcdType = TAB_PCDS_DYNAMIC\r
835\r
836 for Package in Pa.PackageList:\r
837 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType\r
838 if (Pcd[0], Pcd[1], PcdType) in Package.Pcds:\r
839 break\r
840 for Type in PcdTypeSet:\r
841 if (Pcd[0], Pcd[1], Type) in Package.Pcds:\r
842 EdkLogger.error(\r
843 'build',\r
844 FORMAT_INVALID,\r
845 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \\r
846 % (Pa.Platform.Pcds[Pcd].Type, Pcd[1], Pcd[0], Type),\r
847 ExtraData=None\r
848 )\r
849 return\r
850 else:\r
851 UnusedPcd.setdefault(Pcd, []).append(Pa.Arch)\r
852\r
853 for Pcd in UnusedPcd:\r
854 EdkLogger.warn(\r
855 'build',\r
856 "The PCD was not specified by any INF module in the platform for the given architecture.\n"\r
857 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"\r
858 % (Pcd[1], Pcd[0], os.path.basename(str(self.MetaFile)), str(UnusedPcd[Pcd])),\r
859 ExtraData=None\r
860 )\r
861\r
862 def __repr__(self):\r
863 return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))\r
864\r
865 ## Return the directory to store FV files\r
866 @cached_property\r
867 def FvDir(self):\r
868 return path.join(self.BuildDir, TAB_FV_DIRECTORY)\r
869\r
870 ## Return the directory to store all intermediate and final files built\r
871 @cached_property\r
872 def BuildDir(self):\r
873 return self.AutoGenObjectList[0].BuildDir\r
874\r
875 ## Return the build output directory platform specifies\r
876 @cached_property\r
877 def OutputDir(self):\r
878 return self.Platform.OutputDirectory\r
879\r
880 ## Return platform name\r
881 @cached_property\r
882 def Name(self):\r
883 return self.Platform.PlatformName\r
884\r
885 ## Return meta-file GUID\r
886 @cached_property\r
887 def Guid(self):\r
888 return self.Platform.Guid\r
889\r
890 ## Return platform version\r
891 @cached_property\r
892 def Version(self):\r
893 return self.Platform.Version\r
894\r
895 ## Return paths of tools\r
896 @cached_property\r
897 def ToolDefinition(self):\r
898 return self.AutoGenObjectList[0].ToolDefinition\r
899\r
900 ## Return directory of platform makefile\r
901 #\r
902 # @retval string Makefile directory\r
903 #\r
904 @cached_property\r
905 def MakeFileDir(self):\r
906 return self.BuildDir\r
907\r
908 ## Return build command string\r
909 #\r
910 # @retval string Build command string\r
911 #\r
912 @cached_property\r
913 def BuildCommand(self):\r
914 # BuildCommand should be all the same. So just get one from platform AutoGen\r
915 return self.AutoGenObjectList[0].BuildCommand\r
916\r
917 ## Check the PCDs token value conflict in each DEC file.\r
918 #\r
919 # Will cause build break and raise error message while two PCDs conflict.\r
920 #\r
921 # @return None\r
922 #\r
923 def _CheckAllPcdsTokenValueConflict(self):\r
924 for Pa in self.AutoGenObjectList:\r
925 for Package in Pa.PackageList:\r
926 PcdList = list(Package.Pcds.values())\r
927 PcdList.sort(key=lambda x: int(x.TokenValue, 0))\r
928 Count = 0\r
929 while (Count < len(PcdList) - 1) :\r
930 Item = PcdList[Count]\r
931 ItemNext = PcdList[Count + 1]\r
932 #\r
933 # Make sure in the same token space the TokenValue should be unique\r
934 #\r
935 if (int(Item.TokenValue, 0) == int(ItemNext.TokenValue, 0)):\r
936 SameTokenValuePcdList = []\r
937 SameTokenValuePcdList.append(Item)\r
938 SameTokenValuePcdList.append(ItemNext)\r
939 RemainPcdListLength = len(PcdList) - Count - 2\r
940 for ValueSameCount in range(RemainPcdListLength):\r
941 if int(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount].TokenValue, 0) == int(Item.TokenValue, 0):\r
942 SameTokenValuePcdList.append(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount])\r
943 else:\r
944 break;\r
945 #\r
946 # Sort same token value PCD list with TokenGuid and TokenCName\r
947 #\r
948 SameTokenValuePcdList.sort(key=lambda x: "%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName))\r
949 SameTokenValuePcdListCount = 0\r
950 while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):\r
951 Flag = False\r
952 TemListItem = SameTokenValuePcdList[SameTokenValuePcdListCount]\r
953 TemListItemNext = SameTokenValuePcdList[SameTokenValuePcdListCount + 1]\r
954\r
955 if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):\r
956 for PcdItem in GlobalData.MixedPcd:\r
957 if (TemListItem.TokenCName, TemListItem.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem] or \\r
958 (TemListItemNext.TokenCName, TemListItemNext.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
959 Flag = True\r
960 if not Flag:\r
961 EdkLogger.error(\r
962 'build',\r
963 FORMAT_INVALID,\r
964 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\\r
965 % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),\r
966 ExtraData=None\r
967 )\r
968 SameTokenValuePcdListCount += 1\r
969 Count += SameTokenValuePcdListCount\r
970 Count += 1\r
971\r
972 PcdList = list(Package.Pcds.values())\r
973 PcdList.sort(key=lambda x: "%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName))\r
974 Count = 0\r
975 while (Count < len(PcdList) - 1) :\r
976 Item = PcdList[Count]\r
977 ItemNext = PcdList[Count + 1]\r
978 #\r
979 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.\r
980 #\r
981 if (Item.TokenSpaceGuidCName == ItemNext.TokenSpaceGuidCName) and (Item.TokenCName == ItemNext.TokenCName) and (int(Item.TokenValue, 0) != int(ItemNext.TokenValue, 0)):\r
982 EdkLogger.error(\r
983 'build',\r
984 FORMAT_INVALID,\r
985 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\\r
986 % (Item.TokenValue, Item.TokenSpaceGuidCName, Item.TokenCName, Package),\r
987 ExtraData=None\r
988 )\r
989 Count += 1\r
990 ## Generate fds command\r
991 @property\r
992 def GenFdsCommand(self):\r
993 return (GenMake.TopLevelMakefile(self)._TEMPLATE_.Replace(GenMake.TopLevelMakefile(self)._TemplateDict)).strip()\r
994\r
995 @property\r
996 def GenFdsCommandDict(self):\r
997 FdsCommandDict = {}\r
998 LogLevel = EdkLogger.GetLevel()\r
999 if LogLevel == EdkLogger.VERBOSE:\r
1000 FdsCommandDict["verbose"] = True\r
1001 elif LogLevel <= EdkLogger.DEBUG_9:\r
1002 FdsCommandDict["debug"] = LogLevel - 1\r
1003 elif LogLevel == EdkLogger.QUIET:\r
1004 FdsCommandDict["quiet"] = True\r
1005\r
1006 if GlobalData.gEnableGenfdsMultiThread:\r
1007 FdsCommandDict["GenfdsMultiThread"] = True\r
1008 if GlobalData.gIgnoreSource:\r
1009 FdsCommandDict["IgnoreSources"] = True\r
1010\r
1011 FdsCommandDict["OptionPcd"] = []\r
1012 for pcd in GlobalData.BuildOptionPcd:\r
1013 if pcd[2]:\r
1014 pcdname = '.'.join(pcd[0:3])\r
1015 else:\r
1016 pcdname = '.'.join(pcd[0:2])\r
1017 if pcd[3].startswith('{'):\r
1018 FdsCommandDict["OptionPcd"].append(pcdname + '=' + 'H' + '"' + pcd[3] + '"')\r
1019 else:\r
1020 FdsCommandDict["OptionPcd"].append(pcdname + '=' + pcd[3])\r
1021\r
1022 MacroList = []\r
1023 # macros passed to GenFds\r
1024 MacroDict = {}\r
1025 MacroDict.update(GlobalData.gGlobalDefines)\r
1026 MacroDict.update(GlobalData.gCommandLineDefines)\r
1027 for MacroName in MacroDict:\r
1028 if MacroDict[MacroName] != "":\r
1029 MacroList.append('"%s=%s"' % (MacroName, MacroDict[MacroName].replace('\\', '\\\\')))\r
1030 else:\r
1031 MacroList.append('"%s"' % MacroName)\r
1032 FdsCommandDict["macro"] = MacroList\r
1033\r
1034 FdsCommandDict["fdf_file"] = [self.FdfFile]\r
1035 FdsCommandDict["build_target"] = self.BuildTarget\r
1036 FdsCommandDict["toolchain_tag"] = self.ToolChain\r
1037 FdsCommandDict["active_platform"] = str(self)\r
1038\r
1039 FdsCommandDict["conf_directory"] = GlobalData.gConfDirectory\r
1040 FdsCommandDict["build_architecture_list"] = ','.join(self.ArchList)\r
1041 FdsCommandDict["platform_build_directory"] = self.BuildDir\r
1042\r
1043 FdsCommandDict["fd"] = self.FdTargetList\r
1044 FdsCommandDict["fv"] = self.FvTargetList\r
1045 FdsCommandDict["cap"] = self.CapTargetList\r
1046 return FdsCommandDict\r
1047\r
1048 ## Create makefile for the platform and modules in it\r
1049 #\r
1050 # @param CreateDepsMakeFile Flag indicating if the makefile for\r
1051 # modules will be created as well\r
1052 #\r
1053 def CreateMakeFile(self, CreateDepsMakeFile=False):\r
1054 if not CreateDepsMakeFile:\r
1055 return\r
1056 for Pa in self.AutoGenObjectList:\r
1057 Pa.CreateMakeFile(True)\r
1058\r
1059 ## Create autogen code for platform and modules\r
1060 #\r
1061 # Since there's no autogen code for platform, this method will do nothing\r
1062 # if CreateModuleCodeFile is set to False.\r
1063 #\r
1064 # @param CreateDepsCodeFile Flag indicating if creating module's\r
1065 # autogen code file or not\r
1066 #\r
1067 def CreateCodeFile(self, CreateDepsCodeFile=False):\r
1068 if not CreateDepsCodeFile:\r
1069 return\r
1070 for Pa in self.AutoGenObjectList:\r
1071 Pa.CreateCodeFile(True)\r
1072\r
1073 ## Create AsBuilt INF file the platform\r
1074 #\r
1075 def CreateAsBuiltInf(self):\r
1076 return\r
1077\r
1078\r
1079## AutoGen class for platform\r
1080#\r
1081# PlatformAutoGen class will process the original information in platform\r
1082# file in order to generate makefile for platform.\r
1083#\r
1084class PlatformAutoGen(AutoGen):\r
1085 # call super().__init__ then call the worker function with different parameter count\r
1086 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
1087 if not hasattr(self, "_Init"):\r
1088 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch)\r
1089 self._Init = True\r
1090 #\r
1091 # Used to store all PCDs for both PEI and DXE phase, in order to generate\r
1092 # correct PCD database\r
1093 #\r
1094 _DynaPcdList_ = []\r
1095 _NonDynaPcdList_ = []\r
1096 _PlatformPcds = {}\r
1097\r
1098 #\r
1099 # The priority list while override build option\r
1100 #\r
1101 PrioList = {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)\r
1102 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
1103 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
1104 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
1105 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
1106 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
1107 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
1108 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE\r
1109 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
1110 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
1111 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE\r
1112 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE\r
1113 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE\r
1114 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE\r
1115 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE\r
1116 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)\r
1117\r
1118 ## Initialize PlatformAutoGen\r
1119 #\r
1120 #\r
1121 # @param Workspace WorkspaceAutoGen object\r
1122 # @param PlatformFile Platform file (DSC file)\r
1123 # @param Target Build target (DEBUG, RELEASE)\r
1124 # @param Toolchain Name of tool chain\r
1125 # @param Arch arch of the platform supports\r
1126 #\r
1127 def _InitWorker(self, Workspace, PlatformFile, Target, Toolchain, Arch):\r
1128 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))\r
1129 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)\r
1130\r
1131 self.MetaFile = PlatformFile\r
1132 self.Workspace = Workspace\r
1133 self.WorkspaceDir = Workspace.WorkspaceDir\r
1134 self.ToolChain = Toolchain\r
1135 self.BuildTarget = Target\r
1136 self.Arch = Arch\r
1137 self.SourceDir = PlatformFile.SubDir\r
1138 self.FdTargetList = self.Workspace.FdTargetList\r
1139 self.FvTargetList = self.Workspace.FvTargetList\r
1140 # get the original module/package/platform objects\r
1141 self.BuildDatabase = Workspace.BuildDatabase\r
1142 self.DscBuildDataObj = Workspace.Platform\r
1143\r
1144 # flag indicating if the makefile/C-code file has been created or not\r
1145 self.IsMakeFileCreated = False\r
1146\r
1147 self._DynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
1148 self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
1149\r
1150 self._AsBuildInfList = []\r
1151 self._AsBuildModuleList = []\r
1152\r
1153 self.VariableInfo = None\r
1154\r
1155 if GlobalData.gFdfParser is not None:\r
1156 self._AsBuildInfList = GlobalData.gFdfParser.Profile.InfList\r
1157 for Inf in self._AsBuildInfList:\r
1158 InfClass = PathClass(NormPath(Inf), GlobalData.gWorkspace, self.Arch)\r
1159 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
1160 if not M.IsBinaryModule:\r
1161 continue\r
1162 self._AsBuildModuleList.append(InfClass)\r
1163 # get library/modules for build\r
1164 self.LibraryBuildDirectoryList = []\r
1165 self.ModuleBuildDirectoryList = []\r
1166\r
1167 return True\r
1168\r
1169 @cached_class_function\r
1170 def __repr__(self):\r
1171 return "%s [%s]" % (self.MetaFile, self.Arch)\r
1172\r
1173 ## Create autogen code for platform and modules\r
1174 #\r
1175 # Since there's no autogen code for platform, this method will do nothing\r
1176 # if CreateModuleCodeFile is set to False.\r
1177 #\r
1178 # @param CreateModuleCodeFile Flag indicating if creating module's\r
1179 # autogen code file or not\r
1180 #\r
1181 @cached_class_function\r
1182 def CreateCodeFile(self, CreateModuleCodeFile=False):\r
1183 # only module has code to be created, so do nothing if CreateModuleCodeFile is False\r
1184 if not CreateModuleCodeFile:\r
1185 return\r
1186\r
1187 for Ma in self.ModuleAutoGenList:\r
1188 Ma.CreateCodeFile(True)\r
1189\r
1190 ## Generate Fds Command\r
1191 @cached_property\r
1192 def GenFdsCommand(self):\r
1193 return self.Workspace.GenFdsCommand\r
1194\r
1195 ## Create makefile for the platform and modules in it\r
1196 #\r
1197 # @param CreateModuleMakeFile Flag indicating if the makefile for\r
1198 # modules will be created as well\r
1199 #\r
1200 def CreateMakeFile(self, CreateModuleMakeFile=False, FfsCommand = {}):\r
1201 if CreateModuleMakeFile:\r
1202 for Ma in self._MaList:\r
1203 key = (Ma.MetaFile.File, self.Arch)\r
1204 if key in FfsCommand:\r
1205 Ma.CreateMakeFile(True, FfsCommand[key])\r
1206 else:\r
1207 Ma.CreateMakeFile(True)\r
1208\r
1209 # no need to create makefile for the platform more than once\r
1210 if self.IsMakeFileCreated:\r
1211 return\r
1212\r
1213 # create library/module build dirs for platform\r
1214 Makefile = GenMake.PlatformMakefile(self)\r
1215 self.LibraryBuildDirectoryList = Makefile.GetLibraryBuildDirectoryList()\r
1216 self.ModuleBuildDirectoryList = Makefile.GetModuleBuildDirectoryList()\r
1217\r
1218 self.IsMakeFileCreated = True\r
1219\r
1220 @property\r
1221 def AllPcdList(self):\r
1222 return self.DynamicPcdList + self.NonDynamicPcdList\r
1223 ## Deal with Shared FixedAtBuild Pcds\r
1224 #\r
1225 def CollectFixedAtBuildPcds(self):\r
1226 for LibAuto in self.LibraryAutoGenList:\r
1227 FixedAtBuildPcds = {}\r
1228 ShareFixedAtBuildPcdsSameValue = {}\r
1229 for Module in LibAuto.ReferenceModules:\r
1230 for Pcd in set(Module.FixedAtBuildPcds + LibAuto.FixedAtBuildPcds):\r
1231 DefaultValue = Pcd.DefaultValue\r
1232 # Cover the case: DSC component override the Pcd value and the Pcd only used in one Lib\r
1233 if Pcd in Module.LibraryPcdList:\r
1234 Index = Module.LibraryPcdList.index(Pcd)\r
1235 DefaultValue = Module.LibraryPcdList[Index].DefaultValue\r
1236 key = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
1237 if key not in FixedAtBuildPcds:\r
1238 ShareFixedAtBuildPcdsSameValue[key] = True\r
1239 FixedAtBuildPcds[key] = DefaultValue\r
1240 else:\r
1241 if FixedAtBuildPcds[key] != DefaultValue:\r
1242 ShareFixedAtBuildPcdsSameValue[key] = False\r
1243 for Pcd in LibAuto.FixedAtBuildPcds:\r
1244 key = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
1245 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in self.NonDynamicPcdDict:\r
1246 continue\r
1247 else:\r
1248 DscPcd = self.NonDynamicPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)]\r
1249 if DscPcd.Type != TAB_PCDS_FIXED_AT_BUILD:\r
1250 continue\r
1251 if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]:\r
1252 LibAuto.ConstPcd[key] = FixedAtBuildPcds[key]\r
1253\r
1254 def CollectVariables(self, DynamicPcdSet):\r
1255 VpdRegionSize = 0\r
1256 VpdRegionBase = 0\r
1257 if self.Workspace.FdfFile:\r
1258 FdDict = self.Workspace.FdfProfile.FdDict[GlobalData.gFdfParser.CurrentFdName]\r
1259 for FdRegion in FdDict.RegionList:\r
1260 for item in FdRegion.RegionDataList:\r
1261 if self.Platform.VpdToolGuid.strip() and self.Platform.VpdToolGuid in item:\r
1262 VpdRegionSize = FdRegion.Size\r
1263 VpdRegionBase = FdRegion.Offset\r
1264 break\r
1265\r
1266 VariableInfo = VariableMgr(self.DscBuildDataObj._GetDefaultStores(), self.DscBuildDataObj.SkuIds)\r
1267 VariableInfo.SetVpdRegionMaxSize(VpdRegionSize)\r
1268 VariableInfo.SetVpdRegionOffset(VpdRegionBase)\r
1269 Index = 0\r
1270 for Pcd in DynamicPcdSet:\r
1271 pcdname = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
1272 for SkuName in Pcd.SkuInfoList:\r
1273 Sku = Pcd.SkuInfoList[SkuName]\r
1274 SkuId = Sku.SkuId\r
1275 if SkuId is None or SkuId == '':\r
1276 continue\r
1277 if len(Sku.VariableName) > 0:\r
1278 if Sku.VariableAttribute and 'NV' not in Sku.VariableAttribute:\r
1279 continue\r
1280 VariableGuidStructure = Sku.VariableGuidValue\r
1281 VariableGuid = GuidStructureStringToGuidString(VariableGuidStructure)\r
1282 for StorageName in Sku.DefaultStoreDict:\r
1283 VariableInfo.append_variable(var_info(Index, pcdname, StorageName, SkuName, StringToArray(Sku.VariableName), VariableGuid, Sku.VariableOffset, Sku.VariableAttribute, Sku.HiiDefaultValue, Sku.DefaultStoreDict[StorageName] if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES else StringToArray(Sku.DefaultStoreDict[StorageName]), Pcd.DatumType, Pcd.CustomAttribute['DscPosition'], Pcd.CustomAttribute.get('IsStru',False)))\r
1284 Index += 1\r
1285 return VariableInfo\r
1286\r
1287 def UpdateNVStoreMaxSize(self, OrgVpdFile):\r
1288 if self.VariableInfo:\r
1289 VpdMapFilePath = os.path.join(self.BuildDir, TAB_FV_DIRECTORY, "%s.map" % self.Platform.VpdToolGuid)\r
1290 PcdNvStoreDfBuffer = [item for item in self._DynamicPcdList if item.TokenCName == "PcdNvStoreDefaultValueBuffer" and item.TokenSpaceGuidCName == "gEfiMdeModulePkgTokenSpaceGuid"]\r
1291\r
1292 if PcdNvStoreDfBuffer:\r
1293 if os.path.exists(VpdMapFilePath):\r
1294 OrgVpdFile.Read(VpdMapFilePath)\r
1295 PcdItems = OrgVpdFile.GetOffset(PcdNvStoreDfBuffer[0])\r
1296 NvStoreOffset = list(PcdItems.values())[0].strip() if PcdItems else '0'\r
1297 else:\r
1298 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
1299\r
1300 NvStoreOffset = int(NvStoreOffset, 16) if NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset)\r
1301 default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get(TAB_DEFAULT)\r
1302 maxsize = self.VariableInfo.VpdRegionSize - NvStoreOffset if self.VariableInfo.VpdRegionSize else len(default_skuobj.DefaultValue.split(","))\r
1303 var_data = self.VariableInfo.PatchNVStoreDefaultMaxSize(maxsize)\r
1304\r
1305 if var_data and default_skuobj:\r
1306 default_skuobj.DefaultValue = var_data\r
1307 PcdNvStoreDfBuffer[0].DefaultValue = var_data\r
1308 PcdNvStoreDfBuffer[0].SkuInfoList.clear()\r
1309 PcdNvStoreDfBuffer[0].SkuInfoList[TAB_DEFAULT] = default_skuobj\r
1310 PcdNvStoreDfBuffer[0].MaxDatumSize = str(len(default_skuobj.DefaultValue.split(",")))\r
1311\r
1312 return OrgVpdFile\r
1313\r
1314 ## Collect dynamic PCDs\r
1315 #\r
1316 # Gather dynamic PCDs list from each module and their settings from platform\r
1317 # This interface should be invoked explicitly when platform action is created.\r
1318 #\r
1319 def CollectPlatformDynamicPcds(self):\r
1320 for key in self.Platform.Pcds:\r
1321 for SinglePcd in GlobalData.MixedPcd:\r
1322 if (self.Platform.Pcds[key].TokenCName, self.Platform.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
1323 for item in GlobalData.MixedPcd[SinglePcd]:\r
1324 Pcd_Type = item[0].split('_')[-1]\r
1325 if (Pcd_Type == self.Platform.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and self.Platform.Pcds[key].Type in PCD_DYNAMIC_EX_TYPE_SET) or \\r
1326 (Pcd_Type == TAB_PCDS_DYNAMIC and self.Platform.Pcds[key].Type in PCD_DYNAMIC_TYPE_SET):\r
1327 Value = self.Platform.Pcds[key]\r
1328 Value.TokenCName = self.Platform.Pcds[key].TokenCName + '_' + Pcd_Type\r
1329 if len(key) == 2:\r
1330 newkey = (Value.TokenCName, key[1])\r
1331 elif len(key) == 3:\r
1332 newkey = (Value.TokenCName, key[1], key[2])\r
1333 del self.Platform.Pcds[key]\r
1334 self.Platform.Pcds[newkey] = Value\r
1335 break\r
1336 break\r
1337\r
1338 # for gathering error information\r
1339 NoDatumTypePcdList = set()\r
1340 FdfModuleList = []\r
1341 for InfName in self._AsBuildInfList:\r
1342 InfName = mws.join(self.WorkspaceDir, InfName)\r
1343 FdfModuleList.append(os.path.normpath(InfName))\r
1344 for M in self._MaList:\r
1345# F is the Module for which M is the module autogen\r
1346 for PcdFromModule in M.ModulePcdList + M.LibraryPcdList:\r
1347 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
1348 if PcdFromModule.DatumType == TAB_VOID and not PcdFromModule.MaxDatumSize:\r
1349 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, M.MetaFile))\r
1350\r
1351 # Check the PCD from Binary INF or Source INF\r
1352 if M.IsBinaryModule == True:\r
1353 PcdFromModule.IsFromBinaryInf = True\r
1354\r
1355 # Check the PCD from DSC or not\r
1356 PcdFromModule.IsFromDsc = (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds\r
1357\r
1358 if PcdFromModule.Type in PCD_DYNAMIC_TYPE_SET or PcdFromModule.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
1359 if M.MetaFile.Path not in FdfModuleList:\r
1360 # If one of the Source built modules listed in the DSC is not listed\r
1361 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic\r
1362 # access method (it is only listed in the DEC file that declares the\r
1363 # PCD as PcdsDynamic), then build tool will report warning message\r
1364 # notify the PI that they are attempting to build a module that must\r
1365 # be included in a flash image in order to be functional. These Dynamic\r
1366 # PCD will not be added into the Database unless it is used by other\r
1367 # modules that are included in the FDF file.\r
1368 if PcdFromModule.Type in PCD_DYNAMIC_TYPE_SET and \\r
1369 PcdFromModule.IsFromBinaryInf == False:\r
1370 # Print warning message to let the developer make a determine.\r
1371 continue\r
1372 # If one of the Source built modules listed in the DSC is not listed in\r
1373 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx\r
1374 # access method (it is only listed in the DEC file that declares the\r
1375 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the\r
1376 # PCD to the Platform's PCD Database.\r
1377 if PcdFromModule.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
1378 continue\r
1379 #\r
1380 # If a dynamic PCD used by a PEM module/PEI module & DXE module,\r
1381 # it should be stored in Pcd PEI database, If a dynamic only\r
1382 # used by DXE module, it should be stored in DXE PCD database.\r
1383 # The default Phase is DXE\r
1384 #\r
1385 if M.ModuleType in SUP_MODULE_SET_PEI:\r
1386 PcdFromModule.Phase = "PEI"\r
1387 if PcdFromModule not in self._DynaPcdList_:\r
1388 self._DynaPcdList_.append(PcdFromModule)\r
1389 elif PcdFromModule.Phase == 'PEI':\r
1390 # overwrite any the same PCD existing, if Phase is PEI\r
1391 Index = self._DynaPcdList_.index(PcdFromModule)\r
1392 self._DynaPcdList_[Index] = PcdFromModule\r
1393 elif PcdFromModule not in self._NonDynaPcdList_:\r
1394 self._NonDynaPcdList_.append(PcdFromModule)\r
1395 elif PcdFromModule in self._NonDynaPcdList_ and PcdFromModule.IsFromBinaryInf == True:\r
1396 Index = self._NonDynaPcdList_.index(PcdFromModule)\r
1397 if self._NonDynaPcdList_[Index].IsFromBinaryInf == False:\r
1398 #The PCD from Binary INF will override the same one from source INF\r
1399 self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])\r
1400 PcdFromModule.Pending = False\r
1401 self._NonDynaPcdList_.append (PcdFromModule)\r
1402 DscModuleSet = {os.path.normpath(ModuleInf.Path) for ModuleInf in self.Platform.Modules}\r
1403 # add the PCD from modules that listed in FDF but not in DSC to Database\r
1404 for InfName in FdfModuleList:\r
1405 if InfName not in DscModuleSet:\r
1406 InfClass = PathClass(InfName)\r
1407 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
1408 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)\r
1409 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.\r
1410 # For binary module, if in current arch, we need to list the PCDs into database.\r
1411 if not M.IsBinaryModule:\r
1412 continue\r
1413 # Override the module PCD setting by platform setting\r
1414 ModulePcdList = self.ApplyPcdSetting(M, M.Pcds)\r
1415 for PcdFromModule in ModulePcdList:\r
1416 PcdFromModule.IsFromBinaryInf = True\r
1417 PcdFromModule.IsFromDsc = False\r
1418 # Only allow the DynamicEx and Patchable PCD in AsBuild INF\r
1419 if PcdFromModule.Type not in PCD_DYNAMIC_EX_TYPE_SET and PcdFromModule.Type not in TAB_PCDS_PATCHABLE_IN_MODULE:\r
1420 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
1421 File=self.MetaFile,\r
1422 ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n"\r
1423 % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName))\r
1424 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
1425 if PcdFromModule.DatumType == TAB_VOID and not PcdFromModule.MaxDatumSize:\r
1426 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))\r
1427 if M.ModuleType in SUP_MODULE_SET_PEI:\r
1428 PcdFromModule.Phase = "PEI"\r
1429 if PcdFromModule not in self._DynaPcdList_ and PcdFromModule.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
1430 self._DynaPcdList_.append(PcdFromModule)\r
1431 elif PcdFromModule not in self._NonDynaPcdList_ and PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE:\r
1432 self._NonDynaPcdList_.append(PcdFromModule)\r
1433 if PcdFromModule in self._DynaPcdList_ and PcdFromModule.Phase == 'PEI' and PcdFromModule.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
1434 # Overwrite the phase of any the same PCD existing, if Phase is PEI.\r
1435 # It is to solve the case that a dynamic PCD used by a PEM module/PEI\r
1436 # module & DXE module at a same time.\r
1437 # Overwrite the type of the PCDs in source INF by the type of AsBuild\r
1438 # INF file as DynamicEx.\r
1439 Index = self._DynaPcdList_.index(PcdFromModule)\r
1440 self._DynaPcdList_[Index].Phase = PcdFromModule.Phase\r
1441 self._DynaPcdList_[Index].Type = PcdFromModule.Type\r
1442 for PcdFromModule in self._NonDynaPcdList_:\r
1443 # If a PCD is not listed in the DSC file, but binary INF files used by\r
1444 # this platform all (that use this PCD) list the PCD in a [PatchPcds]\r
1445 # section, AND all source INF files used by this platform the build\r
1446 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]\r
1447 # section, then the tools must NOT add the PCD to the Platform's PCD\r
1448 # Database; the build must assign the access method for this PCD as\r
1449 # PcdsPatchableInModule.\r
1450 if PcdFromModule not in self._DynaPcdList_:\r
1451 continue\r
1452 Index = self._DynaPcdList_.index(PcdFromModule)\r
1453 if PcdFromModule.IsFromDsc == False and \\r
1454 PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE and \\r
1455 PcdFromModule.IsFromBinaryInf == True and \\r
1456 self._DynaPcdList_[Index].IsFromBinaryInf == False:\r
1457 Index = self._DynaPcdList_.index(PcdFromModule)\r
1458 self._DynaPcdList_.remove (self._DynaPcdList_[Index])\r
1459\r
1460 # print out error information and break the build, if error found\r
1461 if len(NoDatumTypePcdList) > 0:\r
1462 NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)\r
1463 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
1464 File=self.MetaFile,\r
1465 ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"\r
1466 % NoDatumTypePcdListString)\r
1467 self._NonDynamicPcdList = self._NonDynaPcdList_\r
1468 self._DynamicPcdList = self._DynaPcdList_\r
1469 #\r
1470 # Sort dynamic PCD list to:\r
1471 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should\r
1472 # try to be put header of dynamicd List\r
1473 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD\r
1474 #\r
1475 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.\r
1476 #\r
1477 UnicodePcdArray = set()\r
1478 HiiPcdArray = set()\r
1479 OtherPcdArray = set()\r
1480 VpdPcdDict = {}\r
1481 VpdFile = VpdInfoFile.VpdInfoFile()\r
1482 NeedProcessVpdMapFile = False\r
1483\r
1484 for pcd in self.Platform.Pcds:\r
1485 if pcd not in self._PlatformPcds:\r
1486 self._PlatformPcds[pcd] = self.Platform.Pcds[pcd]\r
1487\r
1488 for item in self._PlatformPcds:\r
1489 if self._PlatformPcds[item].DatumType and self._PlatformPcds[item].DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
1490 self._PlatformPcds[item].DatumType = TAB_VOID\r
1491\r
1492 if (self.Workspace.ArchList[-1] == self.Arch):\r
1493 for Pcd in self._DynamicPcdList:\r
1494 # just pick the a value to determine whether is unicode string type\r
1495 Sku = Pcd.SkuInfoList.get(TAB_DEFAULT)\r
1496 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1497\r
1498 if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
1499 Pcd.DatumType = TAB_VOID\r
1500\r
1501 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
1502 # if found HII type PCD then insert to right of UnicodeIndex\r
1503 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
1504 VpdPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)] = Pcd\r
1505\r
1506 #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer\r
1507 PcdNvStoreDfBuffer = VpdPcdDict.get(("PcdNvStoreDefaultValueBuffer", "gEfiMdeModulePkgTokenSpaceGuid"))\r
1508 if PcdNvStoreDfBuffer:\r
1509 self.VariableInfo = self.CollectVariables(self._DynamicPcdList)\r
1510 vardump = self.VariableInfo.dump()\r
1511 if vardump:\r
1512 #\r
1513 #According to PCD_DATABASE_INIT in edk2\MdeModulePkg\Include\Guid\PcdDataBaseSignatureGuid.h,\r
1514 #the max size for string PCD should not exceed USHRT_MAX 65535(0xffff).\r
1515 #typedef UINT16 SIZE_INFO;\r
1516 #//SIZE_INFO SizeTable[];\r
1517 if len(vardump.split(",")) > 0xffff:\r
1518 EdkLogger.error("build", RESOURCE_OVERFLOW, 'The current length of PCD %s value is %d, it exceeds to the max size of String PCD.' %(".".join([PcdNvStoreDfBuffer.TokenSpaceGuidCName,PcdNvStoreDfBuffer.TokenCName]) ,len(vardump.split(","))))\r
1519 PcdNvStoreDfBuffer.DefaultValue = vardump\r
1520 for skuname in PcdNvStoreDfBuffer.SkuInfoList:\r
1521 PcdNvStoreDfBuffer.SkuInfoList[skuname].DefaultValue = vardump\r
1522 PcdNvStoreDfBuffer.MaxDatumSize = str(len(vardump.split(",")))\r
1523 else:\r
1524 #If the end user define [DefaultStores] and [XXX.Menufacturing] in DSC, but forget to configure PcdNvStoreDefaultValueBuffer to PcdsDynamicVpd\r
1525 if [Pcd for Pcd in self._DynamicPcdList if Pcd.UserDefinedDefaultStoresFlag]:\r
1526 EdkLogger.warn("build", "PcdNvStoreDefaultValueBuffer should be defined as PcdsDynamicExVpd in dsc file since the DefaultStores is enabled for this platform.\n%s" %self.Platform.MetaFile.Path)\r
1527 PlatformPcds = sorted(self._PlatformPcds.keys())\r
1528 #\r
1529 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.\r
1530 #\r
1531 VpdSkuMap = {}\r
1532 for PcdKey in PlatformPcds:\r
1533 Pcd = self._PlatformPcds[PcdKey]\r
1534 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD] and \\r
1535 PcdKey in VpdPcdDict:\r
1536 Pcd = VpdPcdDict[PcdKey]\r
1537 SkuValueMap = {}\r
1538 DefaultSku = Pcd.SkuInfoList.get(TAB_DEFAULT)\r
1539 if DefaultSku:\r
1540 PcdValue = DefaultSku.DefaultValue\r
1541 if PcdValue not in SkuValueMap:\r
1542 SkuValueMap[PcdValue] = []\r
1543 VpdFile.Add(Pcd, TAB_DEFAULT, DefaultSku.VpdOffset)\r
1544 SkuValueMap[PcdValue].append(DefaultSku)\r
1545\r
1546 for (SkuName, Sku) in Pcd.SkuInfoList.items():\r
1547 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1548 PcdValue = Sku.DefaultValue\r
1549 if PcdValue == "":\r
1550 PcdValue = Pcd.DefaultValue\r
1551 if Sku.VpdOffset != TAB_STAR:\r
1552 if PcdValue.startswith("{"):\r
1553 Alignment = 8\r
1554 elif PcdValue.startswith("L"):\r
1555 Alignment = 2\r
1556 else:\r
1557 Alignment = 1\r
1558 try:\r
1559 VpdOffset = int(Sku.VpdOffset)\r
1560 except:\r
1561 try:\r
1562 VpdOffset = int(Sku.VpdOffset, 16)\r
1563 except:\r
1564 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
1565 if VpdOffset % Alignment != 0:\r
1566 if PcdValue.startswith("{"):\r
1567 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName), File=self.MetaFile)\r
1568 else:\r
1569 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Alignment))\r
1570 if PcdValue not in SkuValueMap:\r
1571 SkuValueMap[PcdValue] = []\r
1572 VpdFile.Add(Pcd, SkuName, Sku.VpdOffset)\r
1573 SkuValueMap[PcdValue].append(Sku)\r
1574 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
1575 if not NeedProcessVpdMapFile and Sku.VpdOffset == TAB_STAR:\r
1576 NeedProcessVpdMapFile = True\r
1577 if self.Platform.VpdToolGuid is None or self.Platform.VpdToolGuid == '':\r
1578 EdkLogger.error("Build", FILE_NOT_FOUND, \\r
1579 "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")\r
1580\r
1581 VpdSkuMap[PcdKey] = SkuValueMap\r
1582 #\r
1583 # Fix the PCDs define in VPD PCD section that never referenced by module.\r
1584 # An example is PCD for signature usage.\r
1585 #\r
1586 for DscPcd in PlatformPcds:\r
1587 DscPcdEntry = self._PlatformPcds[DscPcd]\r
1588 if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
1589 if not (self.Platform.VpdToolGuid is None or self.Platform.VpdToolGuid == ''):\r
1590 FoundFlag = False\r
1591 for VpdPcd in VpdFile._VpdArray:\r
1592 # This PCD has been referenced by module\r
1593 if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
1594 (VpdPcd.TokenCName == DscPcdEntry.TokenCName):\r
1595 FoundFlag = True\r
1596\r
1597 # Not found, it should be signature\r
1598 if not FoundFlag :\r
1599 # just pick the a value to determine whether is unicode string type\r
1600 SkuValueMap = {}\r
1601 SkuObjList = list(DscPcdEntry.SkuInfoList.items())\r
1602 DefaultSku = DscPcdEntry.SkuInfoList.get(TAB_DEFAULT)\r
1603 if DefaultSku:\r
1604 defaultindex = SkuObjList.index((TAB_DEFAULT, DefaultSku))\r
1605 SkuObjList[0], SkuObjList[defaultindex] = SkuObjList[defaultindex], SkuObjList[0]\r
1606 for (SkuName, Sku) in SkuObjList:\r
1607 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1608\r
1609 # Need to iterate DEC pcd information to get the value & datumtype\r
1610 for eachDec in self.PackageList:\r
1611 for DecPcd in eachDec.Pcds:\r
1612 DecPcdEntry = eachDec.Pcds[DecPcd]\r
1613 if (DecPcdEntry.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
1614 (DecPcdEntry.TokenCName == DscPcdEntry.TokenCName):\r
1615 # Print warning message to let the developer make a determine.\r
1616 EdkLogger.warn("build", "Unreferenced vpd pcd used!",\r
1617 File=self.MetaFile, \\r
1618 ExtraData = "PCD: %s.%s used in the DSC file %s is unreferenced." \\r
1619 %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, self.Platform.MetaFile.Path))\r
1620\r
1621 DscPcdEntry.DatumType = DecPcdEntry.DatumType\r
1622 DscPcdEntry.DefaultValue = DecPcdEntry.DefaultValue\r
1623 DscPcdEntry.TokenValue = DecPcdEntry.TokenValue\r
1624 DscPcdEntry.TokenSpaceGuidValue = eachDec.Guids[DecPcdEntry.TokenSpaceGuidCName]\r
1625 # Only fix the value while no value provided in DSC file.\r
1626 if not Sku.DefaultValue:\r
1627 DscPcdEntry.SkuInfoList[list(DscPcdEntry.SkuInfoList.keys())[0]].DefaultValue = DecPcdEntry.DefaultValue\r
1628\r
1629 if DscPcdEntry not in self._DynamicPcdList:\r
1630 self._DynamicPcdList.append(DscPcdEntry)\r
1631 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1632 PcdValue = Sku.DefaultValue\r
1633 if PcdValue == "":\r
1634 PcdValue = DscPcdEntry.DefaultValue\r
1635 if Sku.VpdOffset != TAB_STAR:\r
1636 if PcdValue.startswith("{"):\r
1637 Alignment = 8\r
1638 elif PcdValue.startswith("L"):\r
1639 Alignment = 2\r
1640 else:\r
1641 Alignment = 1\r
1642 try:\r
1643 VpdOffset = int(Sku.VpdOffset)\r
1644 except:\r
1645 try:\r
1646 VpdOffset = int(Sku.VpdOffset, 16)\r
1647 except:\r
1648 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName))\r
1649 if VpdOffset % Alignment != 0:\r
1650 if PcdValue.startswith("{"):\r
1651 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName), File=self.MetaFile)\r
1652 else:\r
1653 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, Alignment))\r
1654 if PcdValue not in SkuValueMap:\r
1655 SkuValueMap[PcdValue] = []\r
1656 VpdFile.Add(DscPcdEntry, SkuName, Sku.VpdOffset)\r
1657 SkuValueMap[PcdValue].append(Sku)\r
1658 if not NeedProcessVpdMapFile and Sku.VpdOffset == TAB_STAR:\r
1659 NeedProcessVpdMapFile = True\r
1660 if DscPcdEntry.DatumType == TAB_VOID and PcdValue.startswith("L"):\r
1661 UnicodePcdArray.add(DscPcdEntry)\r
1662 elif len(Sku.VariableName) > 0:\r
1663 HiiPcdArray.add(DscPcdEntry)\r
1664 else:\r
1665 OtherPcdArray.add(DscPcdEntry)\r
1666\r
1667 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
1668 VpdSkuMap[DscPcd] = SkuValueMap\r
1669 if (self.Platform.FlashDefinition is None or self.Platform.FlashDefinition == '') and \\r
1670 VpdFile.GetCount() != 0:\r
1671 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,\r
1672 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self.Platform.MetaFile))\r
1673\r
1674 if VpdFile.GetCount() != 0:\r
1675\r
1676 self.FixVpdOffset(VpdFile)\r
1677\r
1678 self.FixVpdOffset(self.UpdateNVStoreMaxSize(VpdFile))\r
1679 PcdNvStoreDfBuffer = [item for item in self._DynamicPcdList if item.TokenCName == "PcdNvStoreDefaultValueBuffer" and item.TokenSpaceGuidCName == "gEfiMdeModulePkgTokenSpaceGuid"]\r
1680 if PcdNvStoreDfBuffer:\r
1681 PcdName,PcdGuid = PcdNvStoreDfBuffer[0].TokenCName, PcdNvStoreDfBuffer[0].TokenSpaceGuidCName\r
1682 if (PcdName,PcdGuid) in VpdSkuMap:\r
1683 DefaultSku = PcdNvStoreDfBuffer[0].SkuInfoList.get(TAB_DEFAULT)\r
1684 VpdSkuMap[(PcdName,PcdGuid)] = {DefaultSku.DefaultValue:[SkuObj for SkuObj in PcdNvStoreDfBuffer[0].SkuInfoList.values() ]}\r
1685\r
1686 # Process VPD map file generated by third party BPDG tool\r
1687 if NeedProcessVpdMapFile:\r
1688 VpdMapFilePath = os.path.join(self.BuildDir, TAB_FV_DIRECTORY, "%s.map" % self.Platform.VpdToolGuid)\r
1689 if os.path.exists(VpdMapFilePath):\r
1690 VpdFile.Read(VpdMapFilePath)\r
1691\r
1692 # Fixup TAB_STAR offset\r
1693 for pcd in VpdSkuMap:\r
1694 vpdinfo = VpdFile.GetVpdInfo(pcd)\r
1695 if vpdinfo is None:\r
1696 # just pick the a value to determine whether is unicode string type\r
1697 continue\r
1698 for pcdvalue in VpdSkuMap[pcd]:\r
1699 for sku in VpdSkuMap[pcd][pcdvalue]:\r
1700 for item in vpdinfo:\r
1701 if item[2] == pcdvalue:\r
1702 sku.VpdOffset = item[1]\r
1703 else:\r
1704 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
1705\r
1706 # Delete the DynamicPcdList At the last time enter into this function\r
1707 for Pcd in self._DynamicPcdList:\r
1708 # just pick the a value to determine whether is unicode string type\r
1709 Sku = Pcd.SkuInfoList.get(TAB_DEFAULT)\r
1710 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1711\r
1712 if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
1713 Pcd.DatumType = TAB_VOID\r
1714\r
1715 PcdValue = Sku.DefaultValue\r
1716 if Pcd.DatumType == TAB_VOID and PcdValue.startswith("L"):\r
1717 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
1718 UnicodePcdArray.add(Pcd)\r
1719 elif len(Sku.VariableName) > 0:\r
1720 # if found HII type PCD then insert to right of UnicodeIndex\r
1721 HiiPcdArray.add(Pcd)\r
1722 else:\r
1723 OtherPcdArray.add(Pcd)\r
1724 del self._DynamicPcdList[:]\r
1725 self._DynamicPcdList.extend(list(UnicodePcdArray))\r
1726 self._DynamicPcdList.extend(list(HiiPcdArray))\r
1727 self._DynamicPcdList.extend(list(OtherPcdArray))\r
1728 allskuset = [(SkuName, Sku.SkuId) for pcd in self._DynamicPcdList for (SkuName, Sku) in pcd.SkuInfoList.items()]\r
1729 for pcd in self._DynamicPcdList:\r
1730 if len(pcd.SkuInfoList) == 1:\r
1731 for (SkuName, SkuId) in allskuset:\r
1732 if isinstance(SkuId, str) and eval(SkuId) == 0 or SkuId == 0:\r
1733 continue\r
1734 pcd.SkuInfoList[SkuName] = copy.deepcopy(pcd.SkuInfoList[TAB_DEFAULT])\r
1735 pcd.SkuInfoList[SkuName].SkuId = SkuId\r
1736 pcd.SkuInfoList[SkuName].SkuIdName = SkuName\r
1737\r
1738 def FixVpdOffset(self, VpdFile ):\r
1739 FvPath = os.path.join(self.BuildDir, TAB_FV_DIRECTORY)\r
1740 if not os.path.exists(FvPath):\r
1741 try:\r
1742 os.makedirs(FvPath)\r
1743 except:\r
1744 EdkLogger.error("build", FILE_WRITE_FAILURE, "Fail to create FV folder under %s" % self.BuildDir)\r
1745\r
1746 VpdFilePath = os.path.join(FvPath, "%s.txt" % self.Platform.VpdToolGuid)\r
1747\r
1748 if VpdFile.Write(VpdFilePath):\r
1749 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.\r
1750 BPDGToolName = None\r
1751 for ToolDef in self.ToolDefinition.values():\r
1752 if TAB_GUID in ToolDef and ToolDef[TAB_GUID] == self.Platform.VpdToolGuid:\r
1753 if "PATH" not in ToolDef:\r
1754 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)\r
1755 BPDGToolName = ToolDef["PATH"]\r
1756 break\r
1757 # Call third party GUID BPDG tool.\r
1758 if BPDGToolName is not None:\r
1759 VpdInfoFile.CallExtenalBPDGTool(BPDGToolName, VpdFilePath)\r
1760 else:\r
1761 EdkLogger.error("Build", FILE_NOT_FOUND, "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")\r
1762\r
1763 ## Return the platform build data object\r
1764 @cached_property\r
1765 def Platform(self):\r
1766 return self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
1767\r
1768 ## Return platform name\r
1769 @cached_property\r
1770 def Name(self):\r
1771 return self.Platform.PlatformName\r
1772\r
1773 ## Return the meta file GUID\r
1774 @cached_property\r
1775 def Guid(self):\r
1776 return self.Platform.Guid\r
1777\r
1778 ## Return the platform version\r
1779 @cached_property\r
1780 def Version(self):\r
1781 return self.Platform.Version\r
1782\r
1783 ## Return the FDF file name\r
1784 @cached_property\r
1785 def FdfFile(self):\r
1786 if self.Workspace.FdfFile:\r
1787 RetVal= mws.join(self.WorkspaceDir, self.Workspace.FdfFile)\r
1788 else:\r
1789 RetVal = ''\r
1790 return RetVal\r
1791\r
1792 ## Return the build output directory platform specifies\r
1793 @cached_property\r
1794 def OutputDir(self):\r
1795 return self.Platform.OutputDirectory\r
1796\r
1797 ## Return the directory to store all intermediate and final files built\r
1798 @cached_property\r
1799 def BuildDir(self):\r
1800 if os.path.isabs(self.OutputDir):\r
1801 GlobalData.gBuildDirectory = RetVal = path.join(\r
1802 path.abspath(self.OutputDir),\r
1803 self.BuildTarget + "_" + self.ToolChain,\r
1804 )\r
1805 else:\r
1806 GlobalData.gBuildDirectory = RetVal = path.join(\r
1807 self.WorkspaceDir,\r
1808 self.OutputDir,\r
1809 self.BuildTarget + "_" + self.ToolChain,\r
1810 )\r
1811 return RetVal\r
1812\r
1813 ## Return directory of platform makefile\r
1814 #\r
1815 # @retval string Makefile directory\r
1816 #\r
1817 @cached_property\r
1818 def MakeFileDir(self):\r
1819 return path.join(self.BuildDir, self.Arch)\r
1820\r
1821 ## Return build command string\r
1822 #\r
1823 # @retval string Build command string\r
1824 #\r
1825 @cached_property\r
1826 def BuildCommand(self):\r
1827 RetVal = []\r
1828 if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:\r
1829 RetVal += _SplitOption(self.ToolDefinition["MAKE"]["PATH"])\r
1830 if "FLAGS" in self.ToolDefinition["MAKE"]:\r
1831 NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()\r
1832 if NewOption != '':\r
1833 RetVal += _SplitOption(NewOption)\r
1834 if "MAKE" in self.EdkIIBuildOption:\r
1835 if "FLAGS" in self.EdkIIBuildOption["MAKE"]:\r
1836 Flags = self.EdkIIBuildOption["MAKE"]["FLAGS"]\r
1837 if Flags.startswith('='):\r
1838 RetVal = [RetVal[0]] + [Flags[1:]]\r
1839 else:\r
1840 RetVal.append(Flags)\r
1841 return RetVal\r
1842\r
1843 ## Get tool chain definition\r
1844 #\r
1845 # Get each tool definition for given tool chain from tools_def.txt and platform\r
1846 #\r
1847 @cached_property\r
1848 def ToolDefinition(self):\r
1849 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary\r
1850 if TAB_TOD_DEFINES_COMMAND_TYPE not in self.Workspace.ToolDef.ToolsDefTxtDatabase:\r
1851 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No tools found in configuration",\r
1852 ExtraData="[%s]" % self.MetaFile)\r
1853 RetVal = {}\r
1854 DllPathList = set()\r
1855 for Def in ToolDefinition:\r
1856 Target, Tag, Arch, Tool, Attr = Def.split("_")\r
1857 if Target != self.BuildTarget or Tag != self.ToolChain or Arch != self.Arch:\r
1858 continue\r
1859\r
1860 Value = ToolDefinition[Def]\r
1861 # don't record the DLL\r
1862 if Attr == "DLL":\r
1863 DllPathList.add(Value)\r
1864 continue\r
1865\r
1866 if Tool not in RetVal:\r
1867 RetVal[Tool] = {}\r
1868 RetVal[Tool][Attr] = Value\r
1869\r
1870 ToolsDef = ''\r
1871 if GlobalData.gOptions.SilentMode and "MAKE" in RetVal:\r
1872 if "FLAGS" not in RetVal["MAKE"]:\r
1873 RetVal["MAKE"]["FLAGS"] = ""\r
1874 RetVal["MAKE"]["FLAGS"] += " -s"\r
1875 MakeFlags = ''\r
1876 for Tool in RetVal:\r
1877 for Attr in RetVal[Tool]:\r
1878 Value = RetVal[Tool][Attr]\r
1879 if Tool in self._BuildOptionWithToolDef(RetVal) and Attr in self._BuildOptionWithToolDef(RetVal)[Tool]:\r
1880 # check if override is indicated\r
1881 if self._BuildOptionWithToolDef(RetVal)[Tool][Attr].startswith('='):\r
1882 Value = self._BuildOptionWithToolDef(RetVal)[Tool][Attr][1:]\r
1883 else:\r
1884 if Attr != 'PATH':\r
1885 Value += " " + self._BuildOptionWithToolDef(RetVal)[Tool][Attr]\r
1886 else:\r
1887 Value = self._BuildOptionWithToolDef(RetVal)[Tool][Attr]\r
1888\r
1889 if Attr == "PATH":\r
1890 # Don't put MAKE definition in the file\r
1891 if Tool != "MAKE":\r
1892 ToolsDef += "%s = %s\n" % (Tool, Value)\r
1893 elif Attr != "DLL":\r
1894 # Don't put MAKE definition in the file\r
1895 if Tool == "MAKE":\r
1896 if Attr == "FLAGS":\r
1897 MakeFlags = Value\r
1898 else:\r
1899 ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)\r
1900 ToolsDef += "\n"\r
1901\r
1902 SaveFileOnChange(self.ToolDefinitionFile, ToolsDef, False)\r
1903 for DllPath in DllPathList:\r
1904 os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]\r
1905 os.environ["MAKE_FLAGS"] = MakeFlags\r
1906\r
1907 return RetVal\r
1908\r
1909 ## Return the paths of tools\r
1910 @cached_property\r
1911 def ToolDefinitionFile(self):\r
1912 return os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)\r
1913\r
1914 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.\r
1915 @cached_property\r
1916 def ToolChainFamily(self):\r
1917 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1918 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \\r
1919 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
1920 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:\r
1921 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1922 % self.ToolChain)\r
1923 RetVal = TAB_COMPILER_MSFT\r
1924 else:\r
1925 RetVal = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]\r
1926 return RetVal\r
1927\r
1928 @cached_property\r
1929 def BuildRuleFamily(self):\r
1930 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1931 if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \\r
1932 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
1933 or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:\r
1934 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1935 % self.ToolChain)\r
1936 return TAB_COMPILER_MSFT\r
1937\r
1938 return ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]\r
1939\r
1940 ## Return the build options specific for all modules in this platform\r
1941 @cached_property\r
1942 def BuildOption(self):\r
1943 return self._ExpandBuildOption(self.Platform.BuildOptions)\r
1944\r
1945 def _BuildOptionWithToolDef(self, ToolDef):\r
1946 return self._ExpandBuildOption(self.Platform.BuildOptions, ToolDef=ToolDef)\r
1947\r
1948 ## Return the build options specific for EDK modules in this platform\r
1949 @cached_property\r
1950 def EdkBuildOption(self):\r
1951 return self._ExpandBuildOption(self.Platform.BuildOptions, EDK_NAME)\r
1952\r
1953 ## Return the build options specific for EDKII modules in this platform\r
1954 @cached_property\r
1955 def EdkIIBuildOption(self):\r
1956 return self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)\r
1957\r
1958 ## Parse build_rule.txt in Conf Directory.\r
1959 #\r
1960 # @retval BuildRule object\r
1961 #\r
1962 @cached_property\r
1963 def BuildRule(self):\r
1964 BuildRuleFile = None\r
1965 if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:\r
1966 BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
1967 if not BuildRuleFile:\r
1968 BuildRuleFile = gDefaultBuildRuleFile\r
1969 RetVal = BuildRule(BuildRuleFile)\r
1970 if RetVal._FileVersion == "":\r
1971 RetVal._FileVersion = AutoGenReqBuildRuleVerNum\r
1972 else:\r
1973 if RetVal._FileVersion < AutoGenReqBuildRuleVerNum :\r
1974 # If Build Rule's version is less than the version number required by the tools, halting the build.\r
1975 EdkLogger.error("build", AUTOGEN_ERROR,\r
1976 ExtraData="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\\r
1977 % (RetVal._FileVersion, AutoGenReqBuildRuleVerNum))\r
1978 return RetVal\r
1979\r
1980 ## Summarize the packages used by modules in this platform\r
1981 @cached_property\r
1982 def PackageList(self):\r
1983 RetVal = set()\r
1984 for La in self.LibraryAutoGenList:\r
1985 RetVal.update(La.DependentPackageList)\r
1986 for Ma in self.ModuleAutoGenList:\r
1987 RetVal.update(Ma.DependentPackageList)\r
1988 #Collect package set information from INF of FDF\r
1989 for ModuleFile in self._AsBuildModuleList:\r
1990 if ModuleFile in self.Platform.Modules:\r
1991 continue\r
1992 ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]\r
1993 RetVal.update(ModuleData.Packages)\r
1994 return list(RetVal)\r
1995\r
1996 @cached_property\r
1997 def NonDynamicPcdDict(self):\r
1998 return {(Pcd.TokenCName, Pcd.TokenSpaceGuidCName):Pcd for Pcd in self.NonDynamicPcdList}\r
1999\r
2000 ## Get list of non-dynamic PCDs\r
2001 @property\r
2002 def NonDynamicPcdList(self):\r
2003 if not self._NonDynamicPcdList:\r
2004 self.CollectPlatformDynamicPcds()\r
2005 return self._NonDynamicPcdList\r
2006\r
2007 ## Get list of dynamic PCDs\r
2008 @property\r
2009 def DynamicPcdList(self):\r
2010 if not self._DynamicPcdList:\r
2011 self.CollectPlatformDynamicPcds()\r
2012 return self._DynamicPcdList\r
2013\r
2014 ## Generate Token Number for all PCD\r
2015 @cached_property\r
2016 def PcdTokenNumber(self):\r
2017 RetVal = OrderedDict()\r
2018 TokenNumber = 1\r
2019 #\r
2020 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.\r
2021 # Such as:\r
2022 #\r
2023 # Dynamic PCD:\r
2024 # TokenNumber 0 ~ 10\r
2025 # DynamicEx PCD:\r
2026 # TokeNumber 11 ~ 20\r
2027 #\r
2028 for Pcd in self.DynamicPcdList:\r
2029 if Pcd.Phase == "PEI" and Pcd.Type in PCD_DYNAMIC_TYPE_SET:\r
2030 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
2031 RetVal[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2032 TokenNumber += 1\r
2033\r
2034 for Pcd in self.DynamicPcdList:\r
2035 if Pcd.Phase == "PEI" and Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
2036 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
2037 RetVal[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2038 TokenNumber += 1\r
2039\r
2040 for Pcd in self.DynamicPcdList:\r
2041 if Pcd.Phase == "DXE" and Pcd.Type in PCD_DYNAMIC_TYPE_SET:\r
2042 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
2043 RetVal[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2044 TokenNumber += 1\r
2045\r
2046 for Pcd in self.DynamicPcdList:\r
2047 if Pcd.Phase == "DXE" and Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
2048 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
2049 RetVal[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2050 TokenNumber += 1\r
2051\r
2052 for Pcd in self.NonDynamicPcdList:\r
2053 RetVal[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
2054 TokenNumber += 1\r
2055 return RetVal\r
2056\r
2057 @cached_property\r
2058 def _MaList(self):\r
2059 for ModuleFile in self.Platform.Modules:\r
2060 Ma = ModuleAutoGen(\r
2061 self.Workspace,\r
2062 ModuleFile,\r
2063 self.BuildTarget,\r
2064 self.ToolChain,\r
2065 self.Arch,\r
2066 self.MetaFile\r
2067 )\r
2068 self.Platform.Modules[ModuleFile].M = Ma\r
2069 return [x.M for x in self.Platform.Modules.values()]\r
2070\r
2071 ## Summarize ModuleAutoGen objects of all modules to be built for this platform\r
2072 @cached_property\r
2073 def ModuleAutoGenList(self):\r
2074 RetVal = []\r
2075 for Ma in self._MaList:\r
2076 if Ma not in RetVal:\r
2077 RetVal.append(Ma)\r
2078 return RetVal\r
2079\r
2080 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform\r
2081 @cached_property\r
2082 def LibraryAutoGenList(self):\r
2083 RetVal = []\r
2084 for Ma in self._MaList:\r
2085 for La in Ma.LibraryAutoGenList:\r
2086 if La not in RetVal:\r
2087 RetVal.append(La)\r
2088 if Ma not in La.ReferenceModules:\r
2089 La.ReferenceModules.append(Ma)\r
2090 return RetVal\r
2091\r
2092 ## Test if a module is supported by the platform\r
2093 #\r
2094 # An error will be raised directly if the module or its arch is not supported\r
2095 # by the platform or current configuration\r
2096 #\r
2097 def ValidModule(self, Module):\r
2098 return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \\r
2099 or Module in self._AsBuildModuleList\r
2100\r
2101 ## Resolve the library classes in a module to library instances\r
2102 #\r
2103 # This method will not only resolve library classes but also sort the library\r
2104 # instances according to the dependency-ship.\r
2105 #\r
2106 # @param Module The module from which the library classes will be resolved\r
2107 #\r
2108 # @retval library_list List of library instances sorted\r
2109 #\r
2110 def ApplyLibraryInstance(self, Module):\r
2111 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly\r
2112 if str(Module) not in self.Platform.Modules:\r
2113 return []\r
2114\r
2115 return GetModuleLibInstances(Module,\r
2116 self.Platform,\r
2117 self.BuildDatabase,\r
2118 self.Arch,\r
2119 self.BuildTarget,\r
2120 self.ToolChain,\r
2121 self.MetaFile,\r
2122 EdkLogger)\r
2123\r
2124 ## Override PCD setting (type, value, ...)\r
2125 #\r
2126 # @param ToPcd The PCD to be overridden\r
2127 # @param FromPcd The PCD overriding from\r
2128 #\r
2129 def _OverridePcd(self, ToPcd, FromPcd, Module="", Msg="", Library=""):\r
2130 #\r
2131 # in case there's PCDs coming from FDF file, which have no type given.\r
2132 # at this point, ToPcd.Type has the type found from dependent\r
2133 # package\r
2134 #\r
2135 TokenCName = ToPcd.TokenCName\r
2136 for PcdItem in GlobalData.MixedPcd:\r
2137 if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
2138 TokenCName = PcdItem[0]\r
2139 break\r
2140 if FromPcd is not None:\r
2141 if ToPcd.Pending and FromPcd.Type:\r
2142 ToPcd.Type = FromPcd.Type\r
2143 elif ToPcd.Type and FromPcd.Type\\r
2144 and ToPcd.Type != FromPcd.Type and ToPcd.Type in FromPcd.Type:\r
2145 if ToPcd.Type.strip() == TAB_PCDS_DYNAMIC_EX:\r
2146 ToPcd.Type = FromPcd.Type\r
2147 elif ToPcd.Type and FromPcd.Type \\r
2148 and ToPcd.Type != FromPcd.Type:\r
2149 if Library:\r
2150 Module = str(Module) + " 's library file (" + str(Library) + ")"\r
2151 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
2152 ExtraData="%s.%s is used as [%s] in module %s, but as [%s] in %s."\\r
2153 % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
2154 ToPcd.Type, Module, FromPcd.Type, Msg),\r
2155 File=self.MetaFile)\r
2156\r
2157 if FromPcd.MaxDatumSize:\r
2158 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2159 ToPcd.MaxSizeUserSet = FromPcd.MaxDatumSize\r
2160 if FromPcd.DefaultValue:\r
2161 ToPcd.DefaultValue = FromPcd.DefaultValue\r
2162 if FromPcd.TokenValue:\r
2163 ToPcd.TokenValue = FromPcd.TokenValue\r
2164 if FromPcd.DatumType:\r
2165 ToPcd.DatumType = FromPcd.DatumType\r
2166 if FromPcd.SkuInfoList:\r
2167 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
2168 if FromPcd.UserDefinedDefaultStoresFlag:\r
2169 ToPcd.UserDefinedDefaultStoresFlag = FromPcd.UserDefinedDefaultStoresFlag\r
2170 # Add Flexible PCD format parse\r
2171 if ToPcd.DefaultValue:\r
2172 try:\r
2173 ToPcd.DefaultValue = ValueExpressionEx(ToPcd.DefaultValue, ToPcd.DatumType, self.Workspace._GuidDict)(True)\r
2174 except BadExpression as Value:\r
2175 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.DefaultValue, Value),\r
2176 File=self.MetaFile)\r
2177\r
2178 # check the validation of datum\r
2179 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
2180 if not IsValid:\r
2181 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
2182 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
2183 ToPcd.validateranges = FromPcd.validateranges\r
2184 ToPcd.validlists = FromPcd.validlists\r
2185 ToPcd.expressions = FromPcd.expressions\r
2186 ToPcd.CustomAttribute = FromPcd.CustomAttribute\r
2187\r
2188 if FromPcd is not None and ToPcd.DatumType == TAB_VOID and not ToPcd.MaxDatumSize:\r
2189 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
2190 % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
2191 Value = ToPcd.DefaultValue\r
2192 if not Value:\r
2193 ToPcd.MaxDatumSize = '1'\r
2194 elif Value[0] == 'L':\r
2195 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
2196 elif Value[0] == '{':\r
2197 ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
2198 else:\r
2199 ToPcd.MaxDatumSize = str(len(Value) - 1)\r
2200\r
2201 # apply default SKU for dynamic PCDS if specified one is not available\r
2202 if (ToPcd.Type in PCD_DYNAMIC_TYPE_SET or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_SET) \\r
2203 and not ToPcd.SkuInfoList:\r
2204 if self.Platform.SkuName in self.Platform.SkuIds:\r
2205 SkuName = self.Platform.SkuName\r
2206 else:\r
2207 SkuName = TAB_DEFAULT\r
2208 ToPcd.SkuInfoList = {\r
2209 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName][0], '', '', '', '', '', ToPcd.DefaultValue)\r
2210 }\r
2211\r
2212 ## Apply PCD setting defined platform to a module\r
2213 #\r
2214 # @param Module The module from which the PCD setting will be overridden\r
2215 #\r
2216 # @retval PCD_list The list PCDs with settings from platform\r
2217 #\r
2218 def ApplyPcdSetting(self, Module, Pcds, Library=""):\r
2219 # for each PCD in module\r
2220 for Name, Guid in Pcds:\r
2221 PcdInModule = Pcds[Name, Guid]\r
2222 # find out the PCD setting in platform\r
2223 if (Name, Guid) in self.Platform.Pcds:\r
2224 PcdInPlatform = self.Platform.Pcds[Name, Guid]\r
2225 else:\r
2226 PcdInPlatform = None\r
2227 # then override the settings if any\r
2228 self._OverridePcd(PcdInModule, PcdInPlatform, Module, Msg="DSC PCD sections", Library=Library)\r
2229 # resolve the VariableGuid value\r
2230 for SkuId in PcdInModule.SkuInfoList:\r
2231 Sku = PcdInModule.SkuInfoList[SkuId]\r
2232 if Sku.VariableGuid == '': continue\r
2233 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
2234 if Sku.VariableGuidValue is None:\r
2235 PackageList = "\n\t".join(str(P) for P in self.PackageList)\r
2236 EdkLogger.error(\r
2237 'build',\r
2238 RESOURCE_NOT_AVAILABLE,\r
2239 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
2240 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
2241 % (Guid, Name, str(Module)),\r
2242 File=self.MetaFile\r
2243 )\r
2244\r
2245 # override PCD settings with module specific setting\r
2246 if Module in self.Platform.Modules:\r
2247 PlatformModule = self.Platform.Modules[str(Module)]\r
2248 for Key in PlatformModule.Pcds:\r
2249 if GlobalData.BuildOptionPcd:\r
2250 for pcd in GlobalData.BuildOptionPcd:\r
2251 (TokenSpaceGuidCName, TokenCName, FieldName, pcdvalue, _) = pcd\r
2252 if (TokenCName, TokenSpaceGuidCName) == Key and FieldName =="":\r
2253 PlatformModule.Pcds[Key].DefaultValue = pcdvalue\r
2254 PlatformModule.Pcds[Key].PcdValueFromComm = pcdvalue\r
2255 break\r
2256 Flag = False\r
2257 if Key in Pcds:\r
2258 ToPcd = Pcds[Key]\r
2259 Flag = True\r
2260 elif Key in GlobalData.MixedPcd:\r
2261 for PcdItem in GlobalData.MixedPcd[Key]:\r
2262 if PcdItem in Pcds:\r
2263 ToPcd = Pcds[PcdItem]\r
2264 Flag = True\r
2265 break\r
2266 if Flag:\r
2267 self._OverridePcd(ToPcd, PlatformModule.Pcds[Key], Module, Msg="DSC Components Module scoped PCD section", Library=Library)\r
2268 # use PCD value to calculate the MaxDatumSize when it is not specified\r
2269 for Name, Guid in Pcds:\r
2270 Pcd = Pcds[Name, Guid]\r
2271 if Pcd.DatumType == TAB_VOID and not Pcd.MaxDatumSize:\r
2272 Pcd.MaxSizeUserSet = None\r
2273 Value = Pcd.DefaultValue\r
2274 if not Value:\r
2275 Pcd.MaxDatumSize = '1'\r
2276 elif Value[0] == 'L':\r
2277 Pcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
2278 elif Value[0] == '{':\r
2279 Pcd.MaxDatumSize = str(len(Value.split(',')))\r
2280 else:\r
2281 Pcd.MaxDatumSize = str(len(Value) - 1)\r
2282 return list(Pcds.values())\r
2283\r
2284\r
2285\r
2286 ## Calculate the priority value of the build option\r
2287 #\r
2288 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2289 #\r
2290 # @retval Value Priority value based on the priority list.\r
2291 #\r
2292 def CalculatePriorityValue(self, Key):\r
2293 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')\r
2294 PriorityValue = 0x11111\r
2295 if Target == TAB_STAR:\r
2296 PriorityValue &= 0x01111\r
2297 if ToolChain == TAB_STAR:\r
2298 PriorityValue &= 0x10111\r
2299 if Arch == TAB_STAR:\r
2300 PriorityValue &= 0x11011\r
2301 if CommandType == TAB_STAR:\r
2302 PriorityValue &= 0x11101\r
2303 if Attr == TAB_STAR:\r
2304 PriorityValue &= 0x11110\r
2305\r
2306 return self.PrioList["0x%0.5x" % PriorityValue]\r
2307\r
2308\r
2309 ## Expand * in build option key\r
2310 #\r
2311 # @param Options Options to be expanded\r
2312 # @param ToolDef Use specified ToolDef instead of full version.\r
2313 # This is needed during initialization to prevent\r
2314 # infinite recursion betweeh BuildOptions,\r
2315 # ToolDefinition, and this function.\r
2316 #\r
2317 # @retval options Options expanded\r
2318 #\r
2319 def _ExpandBuildOption(self, Options, ModuleStyle=None, ToolDef=None):\r
2320 if not ToolDef:\r
2321 ToolDef = self.ToolDefinition\r
2322 BuildOptions = {}\r
2323 FamilyMatch = False\r
2324 FamilyIsNull = True\r
2325\r
2326 OverrideList = {}\r
2327 #\r
2328 # Construct a list contain the build options which need override.\r
2329 #\r
2330 for Key in Options:\r
2331 #\r
2332 # Key[0] -- tool family\r
2333 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2334 #\r
2335 if (Key[0] == self.BuildRuleFamily and\r
2336 (ModuleStyle is None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):\r
2337 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
2338 if (Target == self.BuildTarget or Target == TAB_STAR) and\\r
2339 (ToolChain == self.ToolChain or ToolChain == TAB_STAR) and\\r
2340 (Arch == self.Arch or Arch == TAB_STAR) and\\r
2341 Options[Key].startswith("="):\r
2342\r
2343 if OverrideList.get(Key[1]) is not None:\r
2344 OverrideList.pop(Key[1])\r
2345 OverrideList[Key[1]] = Options[Key]\r
2346\r
2347 #\r
2348 # Use the highest priority value.\r
2349 #\r
2350 if (len(OverrideList) >= 2):\r
2351 KeyList = list(OverrideList.keys())\r
2352 for Index in range(len(KeyList)):\r
2353 NowKey = KeyList[Index]\r
2354 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
2355 for Index1 in range(len(KeyList) - Index - 1):\r
2356 NextKey = KeyList[Index1 + Index + 1]\r
2357 #\r
2358 # Compare two Key, if one is included by another, choose the higher priority one\r
2359 #\r
2360 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
2361 if (Target1 == Target2 or Target1 == TAB_STAR or Target2 == TAB_STAR) and\\r
2362 (ToolChain1 == ToolChain2 or ToolChain1 == TAB_STAR or ToolChain2 == TAB_STAR) and\\r
2363 (Arch1 == Arch2 or Arch1 == TAB_STAR or Arch2 == TAB_STAR) and\\r
2364 (CommandType1 == CommandType2 or CommandType1 == TAB_STAR or CommandType2 == TAB_STAR) and\\r
2365 (Attr1 == Attr2 or Attr1 == TAB_STAR or Attr2 == TAB_STAR):\r
2366\r
2367 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):\r
2368 if Options.get((self.BuildRuleFamily, NextKey)) is not None:\r
2369 Options.pop((self.BuildRuleFamily, NextKey))\r
2370 else:\r
2371 if Options.get((self.BuildRuleFamily, NowKey)) is not None:\r
2372 Options.pop((self.BuildRuleFamily, NowKey))\r
2373\r
2374 for Key in Options:\r
2375 if ModuleStyle is not None and len (Key) > 2:\r
2376 # Check Module style is EDK or EDKII.\r
2377 # Only append build option for the matched style module.\r
2378 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2379 continue\r
2380 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2381 continue\r
2382 Family = Key[0]\r
2383 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2384 # if tool chain family doesn't match, skip it\r
2385 if Tool in ToolDef and Family != "":\r
2386 FamilyIsNull = False\r
2387 if ToolDef[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
2388 if Family != ToolDef[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
2389 continue\r
2390 elif Family != ToolDef[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2391 continue\r
2392 FamilyMatch = True\r
2393 # expand any wildcard\r
2394 if Target == TAB_STAR or Target == self.BuildTarget:\r
2395 if Tag == TAB_STAR or Tag == self.ToolChain:\r
2396 if Arch == TAB_STAR or Arch == self.Arch:\r
2397 if Tool not in BuildOptions:\r
2398 BuildOptions[Tool] = {}\r
2399 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
2400 BuildOptions[Tool][Attr] = Options[Key]\r
2401 else:\r
2402 # append options for the same tool except PATH\r
2403 if Attr != 'PATH':\r
2404 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2405 else:\r
2406 BuildOptions[Tool][Attr] = Options[Key]\r
2407 # Build Option Family has been checked, which need't to be checked again for family.\r
2408 if FamilyMatch or FamilyIsNull:\r
2409 return BuildOptions\r
2410\r
2411 for Key in Options:\r
2412 if ModuleStyle is not None and len (Key) > 2:\r
2413 # Check Module style is EDK or EDKII.\r
2414 # Only append build option for the matched style module.\r
2415 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2416 continue\r
2417 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2418 continue\r
2419 Family = Key[0]\r
2420 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2421 # if tool chain family doesn't match, skip it\r
2422 if Tool not in ToolDef or Family == "":\r
2423 continue\r
2424 # option has been added before\r
2425 if Family != ToolDef[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2426 continue\r
2427\r
2428 # expand any wildcard\r
2429 if Target == TAB_STAR or Target == self.BuildTarget:\r
2430 if Tag == TAB_STAR or Tag == self.ToolChain:\r
2431 if Arch == TAB_STAR or Arch == self.Arch:\r
2432 if Tool not in BuildOptions:\r
2433 BuildOptions[Tool] = {}\r
2434 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
2435 BuildOptions[Tool][Attr] = Options[Key]\r
2436 else:\r
2437 # append options for the same tool except PATH\r
2438 if Attr != 'PATH':\r
2439 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2440 else:\r
2441 BuildOptions[Tool][Attr] = Options[Key]\r
2442 return BuildOptions\r
2443\r
2444 ## Append build options in platform to a module\r
2445 #\r
2446 # @param Module The module to which the build options will be appended\r
2447 #\r
2448 # @retval options The options appended with build options in platform\r
2449 #\r
2450 def ApplyBuildOption(self, Module):\r
2451 # Get the different options for the different style module\r
2452 PlatformOptions = self.EdkIIBuildOption\r
2453 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDKII_NAME, Module.ModuleType)\r
2454 ModuleTypeOptions = self._ExpandBuildOption(ModuleTypeOptions)\r
2455 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)\r
2456 if Module in self.Platform.Modules:\r
2457 PlatformModule = self.Platform.Modules[str(Module)]\r
2458 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)\r
2459 else:\r
2460 PlatformModuleOptions = {}\r
2461\r
2462 BuildRuleOrder = None\r
2463 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
2464 for Tool in Options:\r
2465 for Attr in Options[Tool]:\r
2466 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2467 BuildRuleOrder = Options[Tool][Attr]\r
2468\r
2469 AllTools = set(list(ModuleOptions.keys()) + list(PlatformOptions.keys()) +\r
2470 list(PlatformModuleOptions.keys()) + list(ModuleTypeOptions.keys()) +\r
2471 list(self.ToolDefinition.keys()))\r
2472 BuildOptions = defaultdict(lambda: defaultdict(str))\r
2473 for Tool in AllTools:\r
2474 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
2475 if Tool not in Options:\r
2476 continue\r
2477 for Attr in Options[Tool]:\r
2478 #\r
2479 # Do not generate it in Makefile\r
2480 #\r
2481 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2482 continue\r
2483 Value = Options[Tool][Attr]\r
2484 # check if override is indicated\r
2485 if Value.startswith('='):\r
2486 BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:])\r
2487 else:\r
2488 if Attr != 'PATH':\r
2489 BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value)\r
2490 else:\r
2491 BuildOptions[Tool][Attr] = mws.handleWsMacro(Value)\r
2492\r
2493 return BuildOptions, BuildRuleOrder\r
2494\r
2495#\r
2496# extend lists contained in a dictionary with lists stored in another dictionary\r
2497# if CopyToDict is not derived from DefaultDict(list) then this may raise exception\r
2498#\r
2499def ExtendCopyDictionaryLists(CopyToDict, CopyFromDict):\r
2500 for Key in CopyFromDict:\r
2501 CopyToDict[Key].extend(CopyFromDict[Key])\r
2502\r
2503# Create a directory specified by a set of path elements and return the full path\r
2504def _MakeDir(PathList):\r
2505 RetVal = path.join(*PathList)\r
2506 CreateDirectory(RetVal)\r
2507 return RetVal\r
2508\r
2509## ModuleAutoGen class\r
2510#\r
2511# This class encapsules the AutoGen behaviors for the build tools. In addition to\r
2512# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r
2513# to the [depex] section in module's inf file.\r
2514#\r
2515class ModuleAutoGen(AutoGen):\r
2516 # call super().__init__ then call the worker function with different parameter count\r
2517 def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
2518 if not hasattr(self, "_Init"):\r
2519 self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args)\r
2520 self._Init = True\r
2521\r
2522 ## Cache the timestamps of metafiles of every module in a class attribute\r
2523 #\r
2524 TimeDict = {}\r
2525\r
2526 def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
2527 # check if this module is employed by active platform\r
2528 if not PlatformAutoGen(Workspace, args[0], Target, Toolchain, Arch).ValidModule(MetaFile):\r
2529 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
2530 % (MetaFile, Arch))\r
2531 return None\r
2532 return super(ModuleAutoGen, cls).__new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
2533\r
2534 ## Initialize ModuleAutoGen\r
2535 #\r
2536 # @param Workspace EdkIIWorkspaceBuild object\r
2537 # @param ModuleFile The path of module file\r
2538 # @param Target Build target (DEBUG, RELEASE)\r
2539 # @param Toolchain Name of tool chain\r
2540 # @param Arch The arch the module supports\r
2541 # @param PlatformFile Platform meta-file\r
2542 #\r
2543 def _InitWorker(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
2544 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
2545 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
2546\r
2547 self.Workspace = Workspace\r
2548 self.WorkspaceDir = Workspace.WorkspaceDir\r
2549 self.MetaFile = ModuleFile\r
2550 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
2551\r
2552 self.SourceDir = self.MetaFile.SubDir\r
2553 self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r
2554\r
2555 self.ToolChain = Toolchain\r
2556 self.BuildTarget = Target\r
2557 self.Arch = Arch\r
2558 self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r
2559 self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r
2560\r
2561 self.IsCodeFileCreated = False\r
2562 self.IsAsBuiltInfCreated = False\r
2563 self.DepexGenerated = False\r
2564\r
2565 self.BuildDatabase = self.Workspace.BuildDatabase\r
2566 self.BuildRuleOrder = None\r
2567 self.BuildTime = 0\r
2568\r
2569 self._PcdComments = OrderedListDict()\r
2570 self._GuidComments = OrderedListDict()\r
2571 self._ProtocolComments = OrderedListDict()\r
2572 self._PpiComments = OrderedListDict()\r
2573 self._BuildTargets = None\r
2574 self._IntroBuildTargetList = None\r
2575 self._FinalBuildTargetList = None\r
2576 self._FileTypes = None\r
2577\r
2578 self.AutoGenDepSet = set()\r
2579 self.ReferenceModules = []\r
2580 self.ConstPcd = {}\r
2581\r
2582\r
2583 def __repr__(self):\r
2584 return "%s [%s]" % (self.MetaFile, self.Arch)\r
2585\r
2586 # Get FixedAtBuild Pcds of this Module\r
2587 @cached_property\r
2588 def FixedAtBuildPcds(self):\r
2589 RetVal = []\r
2590 for Pcd in self.ModulePcdList:\r
2591 if Pcd.Type != TAB_PCDS_FIXED_AT_BUILD:\r
2592 continue\r
2593 if Pcd not in RetVal:\r
2594 RetVal.append(Pcd)\r
2595 return RetVal\r
2596\r
2597 @cached_property\r
2598 def FixedVoidTypePcds(self):\r
2599 RetVal = {}\r
2600 for Pcd in self.FixedAtBuildPcds:\r
2601 if Pcd.DatumType == TAB_VOID:\r
2602 if '{}.{}'.format(Pcd.TokenSpaceGuidCName, Pcd.TokenCName) not in RetVal:\r
2603 RetVal['{}.{}'.format(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)] = Pcd.DefaultValue\r
2604 return RetVal\r
2605\r
2606 @property\r
2607 def UniqueBaseName(self):\r
2608 BaseName = self.Name\r
2609 for Module in self.PlatformInfo.ModuleAutoGenList:\r
2610 if Module.MetaFile == self.MetaFile:\r
2611 continue\r
2612 if Module.Name == self.Name:\r
2613 if uuid.UUID(Module.Guid) == uuid.UUID(self.Guid):\r
2614 EdkLogger.error("build", FILE_DUPLICATED, 'Modules have same BaseName and FILE_GUID:\n'\r
2615 ' %s\n %s' % (Module.MetaFile, self.MetaFile))\r
2616 BaseName = '%s_%s' % (self.Name, self.Guid)\r
2617 return BaseName\r
2618\r
2619 # Macros could be used in build_rule.txt (also Makefile)\r
2620 @cached_property\r
2621 def Macros(self):\r
2622 return OrderedDict((\r
2623 ("WORKSPACE" ,self.WorkspaceDir),\r
2624 ("MODULE_NAME" ,self.Name),\r
2625 ("MODULE_NAME_GUID" ,self.UniqueBaseName),\r
2626 ("MODULE_GUID" ,self.Guid),\r
2627 ("MODULE_VERSION" ,self.Version),\r
2628 ("MODULE_TYPE" ,self.ModuleType),\r
2629 ("MODULE_FILE" ,str(self.MetaFile)),\r
2630 ("MODULE_FILE_BASE_NAME" ,self.MetaFile.BaseName),\r
2631 ("MODULE_RELATIVE_DIR" ,self.SourceDir),\r
2632 ("MODULE_DIR" ,self.SourceDir),\r
2633 ("BASE_NAME" ,self.Name),\r
2634 ("ARCH" ,self.Arch),\r
2635 ("TOOLCHAIN" ,self.ToolChain),\r
2636 ("TOOLCHAIN_TAG" ,self.ToolChain),\r
2637 ("TOOL_CHAIN_TAG" ,self.ToolChain),\r
2638 ("TARGET" ,self.BuildTarget),\r
2639 ("BUILD_DIR" ,self.PlatformInfo.BuildDir),\r
2640 ("BIN_DIR" ,os.path.join(self.PlatformInfo.BuildDir, self.Arch)),\r
2641 ("LIB_DIR" ,os.path.join(self.PlatformInfo.BuildDir, self.Arch)),\r
2642 ("MODULE_BUILD_DIR" ,self.BuildDir),\r
2643 ("OUTPUT_DIR" ,self.OutputDir),\r
2644 ("DEBUG_DIR" ,self.DebugDir),\r
2645 ("DEST_DIR_OUTPUT" ,self.OutputDir),\r
2646 ("DEST_DIR_DEBUG" ,self.DebugDir),\r
2647 ("PLATFORM_NAME" ,self.PlatformInfo.Name),\r
2648 ("PLATFORM_GUID" ,self.PlatformInfo.Guid),\r
2649 ("PLATFORM_VERSION" ,self.PlatformInfo.Version),\r
2650 ("PLATFORM_RELATIVE_DIR" ,self.PlatformInfo.SourceDir),\r
2651 ("PLATFORM_DIR" ,mws.join(self.WorkspaceDir, self.PlatformInfo.SourceDir)),\r
2652 ("PLATFORM_OUTPUT_DIR" ,self.PlatformInfo.OutputDir),\r
2653 ("FFS_OUTPUT_DIR" ,self.FfsOutputDir)\r
2654 ))\r
2655\r
2656 ## Return the module build data object\r
2657 @cached_property\r
2658 def Module(self):\r
2659 return self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
2660\r
2661 ## Return the module name\r
2662 @cached_property\r
2663 def Name(self):\r
2664 return self.Module.BaseName\r
2665\r
2666 ## Return the module DxsFile if exist\r
2667 @cached_property\r
2668 def DxsFile(self):\r
2669 return self.Module.DxsFile\r
2670\r
2671 ## Return the module meta-file GUID\r
2672 @cached_property\r
2673 def Guid(self):\r
2674 #\r
2675 # To build same module more than once, the module path with FILE_GUID overridden has\r
2676 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the real path\r
2677 # in DSC. The overridden GUID can be retrieved from file name\r
2678 #\r
2679 if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):\r
2680 #\r
2681 # Length of GUID is 36\r
2682 #\r
2683 return os.path.basename(self.MetaFile.Path)[:36]\r
2684 return self.Module.Guid\r
2685\r
2686 ## Return the module version\r
2687 @cached_property\r
2688 def Version(self):\r
2689 return self.Module.Version\r
2690\r
2691 ## Return the module type\r
2692 @cached_property\r
2693 def ModuleType(self):\r
2694 return self.Module.ModuleType\r
2695\r
2696 ## Return the component type (for Edk.x style of module)\r
2697 @cached_property\r
2698 def ComponentType(self):\r
2699 return self.Module.ComponentType\r
2700\r
2701 ## Return the build type\r
2702 @cached_property\r
2703 def BuildType(self):\r
2704 return self.Module.BuildType\r
2705\r
2706 ## Return the PCD_IS_DRIVER setting\r
2707 @cached_property\r
2708 def PcdIsDriver(self):\r
2709 return self.Module.PcdIsDriver\r
2710\r
2711 ## Return the autogen version, i.e. module meta-file version\r
2712 @cached_property\r
2713 def AutoGenVersion(self):\r
2714 return self.Module.AutoGenVersion\r
2715\r
2716 ## Check if the module is library or not\r
2717 @cached_property\r
2718 def IsLibrary(self):\r
2719 return bool(self.Module.LibraryClass)\r
2720\r
2721 ## Check if the module is binary module or not\r
2722 @cached_property\r
2723 def IsBinaryModule(self):\r
2724 return self.Module.IsBinaryModule\r
2725\r
2726 ## Return the directory to store intermediate files of the module\r
2727 @cached_property\r
2728 def BuildDir(self):\r
2729 return _MakeDir((\r
2730 self.PlatformInfo.BuildDir,\r
2731 self.Arch,\r
2732 self.SourceDir,\r
2733 self.MetaFile.BaseName\r
2734 ))\r
2735\r
2736 ## Return the directory to store the intermediate object files of the module\r
2737 @cached_property\r
2738 def OutputDir(self):\r
2739 return _MakeDir((self.BuildDir, "OUTPUT"))\r
2740\r
2741 ## Return the directory path to store ffs file\r
2742 @cached_property\r
2743 def FfsOutputDir(self):\r
2744 if GlobalData.gFdfParser:\r
2745 return path.join(self.PlatformInfo.BuildDir, TAB_FV_DIRECTORY, "Ffs", self.Guid + self.Name)\r
2746 return ''\r
2747\r
2748 ## Return the directory to store auto-gened source files of the module\r
2749 @cached_property\r
2750 def DebugDir(self):\r
2751 return _MakeDir((self.BuildDir, "DEBUG"))\r
2752\r
2753 ## Return the path of custom file\r
2754 @cached_property\r
2755 def CustomMakefile(self):\r
2756 RetVal = {}\r
2757 for Type in self.Module.CustomMakefile:\r
2758 MakeType = gMakeTypeMap[Type] if Type in gMakeTypeMap else 'nmake'\r
2759 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2760 RetVal[MakeType] = File\r
2761 return RetVal\r
2762\r
2763 ## Return the directory of the makefile\r
2764 #\r
2765 # @retval string The directory string of module's makefile\r
2766 #\r
2767 @cached_property\r
2768 def MakeFileDir(self):\r
2769 return self.BuildDir\r
2770\r
2771 ## Return build command string\r
2772 #\r
2773 # @retval string Build command string\r
2774 #\r
2775 @cached_property\r
2776 def BuildCommand(self):\r
2777 return self.PlatformInfo.BuildCommand\r
2778\r
2779 ## Get object list of all packages the module and its dependent libraries belong to\r
2780 #\r
2781 # @retval list The list of package object\r
2782 #\r
2783 @cached_property\r
2784 def DerivedPackageList(self):\r
2785 PackageList = []\r
2786 for M in [self.Module] + self.DependentLibraryList:\r
2787 for Package in M.Packages:\r
2788 if Package in PackageList:\r
2789 continue\r
2790 PackageList.append(Package)\r
2791 return PackageList\r
2792\r
2793 ## Get the depex string\r
2794 #\r
2795 # @return : a string contain all depex expression.\r
2796 def _GetDepexExpresionString(self):\r
2797 DepexStr = ''\r
2798 DepexList = []\r
2799 ## DPX_SOURCE IN Define section.\r
2800 if self.Module.DxsFile:\r
2801 return DepexStr\r
2802 for M in [self.Module] + self.DependentLibraryList:\r
2803 Filename = M.MetaFile.Path\r
2804 InfObj = InfSectionParser.InfSectionParser(Filename)\r
2805 DepexExpressionList = InfObj.GetDepexExpresionList()\r
2806 for DepexExpression in DepexExpressionList:\r
2807 for key in DepexExpression:\r
2808 Arch, ModuleType = key\r
2809 DepexExpr = [x for x in DepexExpression[key] if not str(x).startswith('#')]\r
2810 # the type of build module is USER_DEFINED.\r
2811 # All different DEPEX section tags would be copied into the As Built INF file\r
2812 # and there would be separate DEPEX section tags\r
2813 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2814 if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):\r
2815 DepexList.append({(Arch, ModuleType): DepexExpr})\r
2816 else:\r
2817 if Arch.upper() == TAB_ARCH_COMMON or \\r
2818 (Arch.upper() == self.Arch.upper() and \\r
2819 ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):\r
2820 DepexList.append({(Arch, ModuleType): DepexExpr})\r
2821\r
2822 #the type of build module is USER_DEFINED.\r
2823 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2824 for Depex in DepexList:\r
2825 for key in Depex:\r
2826 DepexStr += '[Depex.%s.%s]\n' % key\r
2827 DepexStr += '\n'.join('# '+ val for val in Depex[key])\r
2828 DepexStr += '\n\n'\r
2829 if not DepexStr:\r
2830 return '[Depex.%s]\n' % self.Arch\r
2831 return DepexStr\r
2832\r
2833 #the type of build module not is USER_DEFINED.\r
2834 Count = 0\r
2835 for Depex in DepexList:\r
2836 Count += 1\r
2837 if DepexStr != '':\r
2838 DepexStr += ' AND '\r
2839 DepexStr += '('\r
2840 for D in Depex.values():\r
2841 DepexStr += ' '.join(val for val in D)\r
2842 Index = DepexStr.find('END')\r
2843 if Index > -1 and Index == len(DepexStr) - 3:\r
2844 DepexStr = DepexStr[:-3]\r
2845 DepexStr = DepexStr.strip()\r
2846 DepexStr += ')'\r
2847 if Count == 1:\r
2848 DepexStr = DepexStr.lstrip('(').rstrip(')').strip()\r
2849 if not DepexStr:\r
2850 return '[Depex.%s]\n' % self.Arch\r
2851 return '[Depex.%s]\n# ' % self.Arch + DepexStr\r
2852\r
2853 ## Merge dependency expression\r
2854 #\r
2855 # @retval list The token list of the dependency expression after parsed\r
2856 #\r
2857 @cached_property\r
2858 def DepexList(self):\r
2859 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
2860 return {}\r
2861\r
2862 DepexList = []\r
2863 #\r
2864 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expression\r
2865 #\r
2866 for M in [self.Module] + self.DependentLibraryList:\r
2867 Inherited = False\r
2868 for D in M.Depex[self.Arch, self.ModuleType]:\r
2869 if DepexList != []:\r
2870 DepexList.append('AND')\r
2871 DepexList.append('(')\r
2872 #replace D with value if D is FixedAtBuild PCD\r
2873 NewList = []\r
2874 for item in D:\r
2875 if '.' not in item:\r
2876 NewList.append(item)\r
2877 else:\r
2878 FixedVoidTypePcds = {}\r
2879 if item in self.FixedVoidTypePcds:\r
2880 FixedVoidTypePcds = self.FixedVoidTypePcds\r
2881 elif M in self.PlatformInfo.LibraryAutoGenList:\r
2882 Index = self.PlatformInfo.LibraryAutoGenList.index(M)\r
2883 FixedVoidTypePcds = self.PlatformInfo.LibraryAutoGenList[Index].FixedVoidTypePcds\r
2884 if item not in FixedVoidTypePcds:\r
2885 EdkLogger.error("build", FORMAT_INVALID, "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type in the module.".format(item))\r
2886 else:\r
2887 Value = FixedVoidTypePcds[item]\r
2888 if len(Value.split(',')) != 16:\r
2889 EdkLogger.error("build", FORMAT_INVALID,\r
2890 "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type and 16 bytes in the module.".format(item))\r
2891 NewList.append(Value)\r
2892 DepexList.extend(NewList)\r
2893 if DepexList[-1] == 'END': # no need of a END at this time\r
2894 DepexList.pop()\r
2895 DepexList.append(')')\r
2896 Inherited = True\r
2897 if Inherited:\r
2898 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))\r
2899 if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
2900 break\r
2901 if len(DepexList) > 0:\r
2902 EdkLogger.verbose('')\r
2903 return {self.ModuleType:DepexList}\r
2904\r
2905 ## Merge dependency expression\r
2906 #\r
2907 # @retval list The token list of the dependency expression after parsed\r
2908 #\r
2909 @cached_property\r
2910 def DepexExpressionDict(self):\r
2911 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
2912 return {}\r
2913\r
2914 DepexExpressionString = ''\r
2915 #\r
2916 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2917 #\r
2918 for M in [self.Module] + self.DependentLibraryList:\r
2919 Inherited = False\r
2920 for D in M.DepexExpression[self.Arch, self.ModuleType]:\r
2921 if DepexExpressionString != '':\r
2922 DepexExpressionString += ' AND '\r
2923 DepexExpressionString += '('\r
2924 DepexExpressionString += D\r
2925 DepexExpressionString = DepexExpressionString.rstrip('END').strip()\r
2926 DepexExpressionString += ')'\r
2927 Inherited = True\r
2928 if Inherited:\r
2929 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionString))\r
2930 if 'BEFORE' in DepexExpressionString or 'AFTER' in DepexExpressionString:\r
2931 break\r
2932 if len(DepexExpressionString) > 0:\r
2933 EdkLogger.verbose('')\r
2934\r
2935 return {self.ModuleType:DepexExpressionString}\r
2936\r
2937 # Get the tiano core user extension, it is contain dependent library.\r
2938 # @retval: a list contain tiano core userextension.\r
2939 #\r
2940 def _GetTianoCoreUserExtensionList(self):\r
2941 TianoCoreUserExtentionList = []\r
2942 for M in [self.Module] + self.DependentLibraryList:\r
2943 Filename = M.MetaFile.Path\r
2944 InfObj = InfSectionParser.InfSectionParser(Filename)\r
2945 TianoCoreUserExtenList = InfObj.GetUserExtensionTianoCore()\r
2946 for TianoCoreUserExtent in TianoCoreUserExtenList:\r
2947 for Section in TianoCoreUserExtent:\r
2948 ItemList = Section.split(TAB_SPLIT)\r
2949 Arch = self.Arch\r
2950 if len(ItemList) == 4:\r
2951 Arch = ItemList[3]\r
2952 if Arch.upper() == TAB_ARCH_COMMON or Arch.upper() == self.Arch.upper():\r
2953 TianoCoreList = []\r
2954 TianoCoreList.extend([TAB_SECTION_START + Section + TAB_SECTION_END])\r
2955 TianoCoreList.extend(TianoCoreUserExtent[Section][:])\r
2956 TianoCoreList.append('\n')\r
2957 TianoCoreUserExtentionList.append(TianoCoreList)\r
2958\r
2959 return TianoCoreUserExtentionList\r
2960\r
2961 ## Return the list of specification version required for the module\r
2962 #\r
2963 # @retval list The list of specification defined in module file\r
2964 #\r
2965 @cached_property\r
2966 def Specification(self):\r
2967 return self.Module.Specification\r
2968\r
2969 ## Tool option for the module build\r
2970 #\r
2971 # @param PlatformInfo The object of PlatformBuildInfo\r
2972 # @retval dict The dict containing valid options\r
2973 #\r
2974 @cached_property\r
2975 def BuildOption(self):\r
2976 RetVal, self.BuildRuleOrder = self.PlatformInfo.ApplyBuildOption(self.Module)\r
2977 if self.BuildRuleOrder:\r
2978 self.BuildRuleOrder = ['.%s' % Ext for Ext in self.BuildRuleOrder.split()]\r
2979 return RetVal\r
2980\r
2981 ## Get include path list from tool option for the module build\r
2982 #\r
2983 # @retval list The include path list\r
2984 #\r
2985 @cached_property\r
2986 def BuildOptionIncPathList(self):\r
2987 #\r
2988 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
2989 # is the former use /I , the Latter used -I to specify include directories\r
2990 #\r
2991 if self.PlatformInfo.ToolChainFamily in (TAB_COMPILER_MSFT):\r
2992 BuildOptIncludeRegEx = gBuildOptIncludePatternMsft\r
2993 elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
2994 BuildOptIncludeRegEx = gBuildOptIncludePatternOther\r
2995 else:\r
2996 #\r
2997 # New ToolChainFamily, don't known whether there is option to specify include directories\r
2998 #\r
2999 return []\r
3000\r
3001 RetVal = []\r
3002 for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):\r
3003 try:\r
3004 FlagOption = self.BuildOption[Tool]['FLAGS']\r
3005 except KeyError:\r
3006 FlagOption = ''\r
3007\r
3008 if self.ToolChainFamily != 'RVCT':\r
3009 IncPathList = [NormPath(Path, self.Macros) for Path in BuildOptIncludeRegEx.findall(FlagOption)]\r
3010 else:\r
3011 #\r
3012 # RVCT may specify a list of directory seperated by commas\r
3013 #\r
3014 IncPathList = []\r
3015 for Path in BuildOptIncludeRegEx.findall(FlagOption):\r
3016 PathList = GetSplitList(Path, TAB_COMMA_SPLIT)\r
3017 IncPathList.extend(NormPath(PathEntry, self.Macros) for PathEntry in PathList)\r
3018\r
3019 #\r
3020 # EDK II modules must not reference header files outside of the packages they depend on or\r
3021 # within the module's directory tree. Report error if violation.\r
3022 #\r
3023 if GlobalData.gDisableIncludePathCheck == False:\r
3024 for Path in IncPathList:\r
3025 if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r
3026 ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)\r
3027 EdkLogger.error("build",\r
3028 PARAMETER_INVALID,\r
3029 ExtraData=ErrMsg,\r
3030 File=str(self.MetaFile))\r
3031 RetVal += IncPathList\r
3032 return RetVal\r
3033\r
3034 ## Return a list of files which can be built from source\r
3035 #\r
3036 # What kind of files can be built is determined by build rules in\r
3037 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.\r
3038 #\r
3039 @cached_property\r
3040 def SourceFileList(self):\r
3041 RetVal = []\r
3042 ToolChainTagSet = {"", TAB_STAR, self.ToolChain}\r
3043 ToolChainFamilySet = {"", TAB_STAR, self.ToolChainFamily, self.BuildRuleFamily}\r
3044 for F in self.Module.Sources:\r
3045 # match tool chain\r
3046 if F.TagName not in ToolChainTagSet:\r
3047 EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "\r
3048 "but [%s] is currently used" % (F.TagName, str(F), self.ToolChain))\r
3049 continue\r
3050 # match tool chain family or build rule family\r
3051 if F.ToolChainFamily not in ToolChainFamilySet:\r
3052 EdkLogger.debug(\r
3053 EdkLogger.DEBUG_0,\r
3054 "The file [%s] must be built by tools of [%s], " \\r
3055 "but current toolchain family is [%s], buildrule family is [%s]" \\r
3056 % (str(F), F.ToolChainFamily, self.ToolChainFamily, self.BuildRuleFamily))\r
3057 continue\r
3058\r
3059 # add the file path into search path list for file including\r
3060 if F.Dir not in self.IncludePathList:\r
3061 self.IncludePathList.insert(0, F.Dir)\r
3062 RetVal.append(F)\r
3063\r
3064 self._MatchBuildRuleOrder(RetVal)\r
3065\r
3066 for F in RetVal:\r
3067 self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)\r
3068 return RetVal\r
3069\r
3070 def _MatchBuildRuleOrder(self, FileList):\r
3071 Order_Dict = {}\r
3072 self.BuildOption\r
3073 for SingleFile in FileList:\r
3074 if self.BuildRuleOrder and SingleFile.Ext in self.BuildRuleOrder and SingleFile.Ext in self.BuildRules:\r
3075 key = SingleFile.Path.rsplit(SingleFile.Ext,1)[0]\r
3076 if key in Order_Dict:\r
3077 Order_Dict[key].append(SingleFile.Ext)\r
3078 else:\r
3079 Order_Dict[key] = [SingleFile.Ext]\r
3080\r
3081 RemoveList = []\r
3082 for F in Order_Dict:\r
3083 if len(Order_Dict[F]) > 1:\r
3084 Order_Dict[F].sort(key=lambda i: self.BuildRuleOrder.index(i))\r
3085 for Ext in Order_Dict[F][1:]:\r
3086 RemoveList.append(F + Ext)\r
3087\r
3088 for item in RemoveList:\r
3089 FileList.remove(item)\r
3090\r
3091 return FileList\r
3092\r
3093 ## Return the list of unicode files\r
3094 @cached_property\r
3095 def UnicodeFileList(self):\r
3096 return self.FileTypes.get(TAB_UNICODE_FILE,[])\r
3097\r
3098 ## Return the list of vfr files\r
3099 @cached_property\r
3100 def VfrFileList(self):\r
3101 return self.FileTypes.get(TAB_VFR_FILE, [])\r
3102\r
3103 ## Return the list of Image Definition files\r
3104 @cached_property\r
3105 def IdfFileList(self):\r
3106 return self.FileTypes.get(TAB_IMAGE_FILE,[])\r
3107\r
3108 ## Return a list of files which can be built from binary\r
3109 #\r
3110 # "Build" binary files are just to copy them to build directory.\r
3111 #\r
3112 # @retval list The list of files which can be built later\r
3113 #\r
3114 @cached_property\r
3115 def BinaryFileList(self):\r
3116 RetVal = []\r
3117 for F in self.Module.Binaries:\r
3118 if F.Target not in [TAB_ARCH_COMMON, TAB_STAR] and F.Target != self.BuildTarget:\r
3119 continue\r
3120 RetVal.append(F)\r
3121 self._ApplyBuildRule(F, F.Type, BinaryFileList=RetVal)\r
3122 return RetVal\r
3123\r
3124 @cached_property\r
3125 def BuildRules(self):\r
3126 RetVal = {}\r
3127 BuildRuleDatabase = self.PlatformInfo.BuildRule\r
3128 for Type in BuildRuleDatabase.FileTypeList:\r
3129 #first try getting build rule by BuildRuleFamily\r
3130 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]\r
3131 if not RuleObject:\r
3132 # build type is always module type, but ...\r
3133 if self.ModuleType != self.BuildType:\r
3134 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]\r
3135 #second try getting build rule by ToolChainFamily\r
3136 if not RuleObject:\r
3137 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]\r
3138 if not RuleObject:\r
3139 # build type is always module type, but ...\r
3140 if self.ModuleType != self.BuildType:\r
3141 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]\r
3142 if not RuleObject:\r
3143 continue\r
3144 RuleObject = RuleObject.Instantiate(self.Macros)\r
3145 RetVal[Type] = RuleObject\r
3146 for Ext in RuleObject.SourceFileExtList:\r
3147 RetVal[Ext] = RuleObject\r
3148 return RetVal\r
3149\r
3150 def _ApplyBuildRule(self, File, FileType, BinaryFileList=None):\r
3151 if self._BuildTargets is None:\r
3152 self._IntroBuildTargetList = set()\r
3153 self._FinalBuildTargetList = set()\r
3154 self._BuildTargets = defaultdict(set)\r
3155 self._FileTypes = defaultdict(set)\r
3156\r
3157 if not BinaryFileList:\r
3158 BinaryFileList = self.BinaryFileList\r
3159\r
3160 SubDirectory = os.path.join(self.OutputDir, File.SubDir)\r
3161 if not os.path.exists(SubDirectory):\r
3162 CreateDirectory(SubDirectory)\r
3163 LastTarget = None\r
3164 RuleChain = set()\r
3165 SourceList = [File]\r
3166 Index = 0\r
3167 #\r
3168 # Make sure to get build rule order value\r
3169 #\r
3170 self.BuildOption\r
3171\r
3172 while Index < len(SourceList):\r
3173 Source = SourceList[Index]\r
3174 Index = Index + 1\r
3175\r
3176 if Source != File:\r
3177 CreateDirectory(Source.Dir)\r
3178\r
3179 if File.IsBinary and File == Source and File in BinaryFileList:\r
3180 # Skip all files that are not binary libraries\r
3181 if not self.IsLibrary:\r
3182 continue\r
3183 RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]\r
3184 elif FileType in self.BuildRules:\r
3185 RuleObject = self.BuildRules[FileType]\r
3186 elif Source.Ext in self.BuildRules:\r
3187 RuleObject = self.BuildRules[Source.Ext]\r
3188 else:\r
3189 # stop at no more rules\r
3190 if LastTarget:\r
3191 self._FinalBuildTargetList.add(LastTarget)\r
3192 break\r
3193\r
3194 FileType = RuleObject.SourceFileType\r
3195 self._FileTypes[FileType].add(Source)\r
3196\r
3197 # stop at STATIC_LIBRARY for library\r
3198 if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:\r
3199 if LastTarget:\r
3200 self._FinalBuildTargetList.add(LastTarget)\r
3201 break\r
3202\r
3203 Target = RuleObject.Apply(Source, self.BuildRuleOrder)\r
3204 if not Target:\r
3205 if LastTarget:\r
3206 self._FinalBuildTargetList.add(LastTarget)\r
3207 break\r
3208 elif not Target.Outputs:\r
3209 # Only do build for target with outputs\r
3210 self._FinalBuildTargetList.add(Target)\r
3211\r
3212 self._BuildTargets[FileType].add(Target)\r
3213\r
3214 if not Source.IsBinary and Source == File:\r
3215 self._IntroBuildTargetList.add(Target)\r
3216\r
3217 # to avoid cyclic rule\r
3218 if FileType in RuleChain:\r
3219 break\r
3220\r
3221 RuleChain.add(FileType)\r
3222 SourceList.extend(Target.Outputs)\r
3223 LastTarget = Target\r
3224 FileType = TAB_UNKNOWN_FILE\r
3225\r
3226 @cached_property\r
3227 def Targets(self):\r
3228 if self._BuildTargets is None:\r
3229 self._IntroBuildTargetList = set()\r
3230 self._FinalBuildTargetList = set()\r
3231 self._BuildTargets = defaultdict(set)\r
3232 self._FileTypes = defaultdict(set)\r
3233\r
3234 #TRICK: call SourceFileList property to apply build rule for source files\r
3235 self.SourceFileList\r
3236\r
3237 #TRICK: call _GetBinaryFileList to apply build rule for binary files\r
3238 self.BinaryFileList\r
3239\r
3240 return self._BuildTargets\r
3241\r
3242 @cached_property\r
3243 def IntroTargetList(self):\r
3244 self.Targets\r
3245 return self._IntroBuildTargetList\r
3246\r
3247 @cached_property\r
3248 def CodaTargetList(self):\r
3249 self.Targets\r
3250 return self._FinalBuildTargetList\r
3251\r
3252 @cached_property\r
3253 def FileTypes(self):\r
3254 self.Targets\r
3255 return self._FileTypes\r
3256\r
3257 ## Get the list of package object the module depends on\r
3258 #\r
3259 # @retval list The package object list\r
3260 #\r
3261 @cached_property\r
3262 def DependentPackageList(self):\r
3263 return self.Module.Packages\r
3264\r
3265 ## Return the list of auto-generated code file\r
3266 #\r
3267 # @retval list The list of auto-generated file\r
3268 #\r
3269 @cached_property\r
3270 def AutoGenFileList(self):\r
3271 AutoGenUniIdf = self.BuildType != 'UEFI_HII'\r
3272 UniStringBinBuffer = BytesIO()\r
3273 IdfGenBinBuffer = BytesIO()\r
3274 RetVal = {}\r
3275 AutoGenC = TemplateString()\r
3276 AutoGenH = TemplateString()\r
3277 StringH = TemplateString()\r
3278 StringIdf = TemplateString()\r
3279 GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, AutoGenUniIdf, UniStringBinBuffer, StringIdf, AutoGenUniIdf, IdfGenBinBuffer)\r
3280 #\r
3281 # AutoGen.c is generated if there are library classes in inf, or there are object files\r
3282 #\r
3283 if str(AutoGenC) != "" and (len(self.Module.LibraryClasses) > 0\r
3284 or TAB_OBJECT_FILE in self.FileTypes):\r
3285 AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)\r
3286 RetVal[AutoFile] = str(AutoGenC)\r
3287 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3288 if str(AutoGenH) != "":\r
3289 AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)\r
3290 RetVal[AutoFile] = str(AutoGenH)\r
3291 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3292 if str(StringH) != "":\r
3293 AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)\r
3294 RetVal[AutoFile] = str(StringH)\r
3295 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3296 if UniStringBinBuffer is not None and UniStringBinBuffer.getvalue() != b"":\r
3297 AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)\r
3298 RetVal[AutoFile] = UniStringBinBuffer.getvalue()\r
3299 AutoFile.IsBinary = True\r
3300 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3301 if UniStringBinBuffer is not None:\r
3302 UniStringBinBuffer.close()\r
3303 if str(StringIdf) != "":\r
3304 AutoFile = PathClass(gAutoGenImageDefFileName % {"module_name":self.Name}, self.DebugDir)\r
3305 RetVal[AutoFile] = str(StringIdf)\r
3306 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3307 if IdfGenBinBuffer is not None and IdfGenBinBuffer.getvalue() != b"":\r
3308 AutoFile = PathClass(gAutoGenIdfFileName % {"module_name":self.Name}, self.OutputDir)\r
3309 RetVal[AutoFile] = IdfGenBinBuffer.getvalue()\r
3310 AutoFile.IsBinary = True\r
3311 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3312 if IdfGenBinBuffer is not None:\r
3313 IdfGenBinBuffer.close()\r
3314 return RetVal\r
3315\r
3316 ## Return the list of library modules explicitly or implicitly used by this module\r
3317 @cached_property\r
3318 def DependentLibraryList(self):\r
3319 # only merge library classes and PCD for non-library module\r
3320 if self.IsLibrary:\r
3321 return []\r
3322 return self.PlatformInfo.ApplyLibraryInstance(self.Module)\r
3323\r
3324 ## Get the list of PCDs from current module\r
3325 #\r
3326 # @retval list The list of PCD\r
3327 #\r
3328 @cached_property\r
3329 def ModulePcdList(self):\r
3330 # apply PCD settings from platform\r
3331 RetVal = self.PlatformInfo.ApplyPcdSetting(self.Module, self.Module.Pcds)\r
3332 ExtendCopyDictionaryLists(self._PcdComments, self.Module.PcdComments)\r
3333 return RetVal\r
3334\r
3335 ## Get the list of PCDs from dependent libraries\r
3336 #\r
3337 # @retval list The list of PCD\r
3338 #\r
3339 @cached_property\r
3340 def LibraryPcdList(self):\r
3341 if self.IsLibrary:\r
3342 return []\r
3343 RetVal = []\r
3344 Pcds = set()\r
3345 # get PCDs from dependent libraries\r
3346 for Library in self.DependentLibraryList:\r
3347 PcdsInLibrary = OrderedDict()\r
3348 ExtendCopyDictionaryLists(self._PcdComments, Library.PcdComments)\r
3349 for Key in Library.Pcds:\r
3350 # skip duplicated PCDs\r
3351 if Key in self.Module.Pcds or Key in Pcds:\r
3352 continue\r
3353 Pcds.add(Key)\r
3354 PcdsInLibrary[Key] = copy.copy(Library.Pcds[Key])\r
3355 RetVal.extend(self.PlatformInfo.ApplyPcdSetting(self.Module, PcdsInLibrary, Library=Library))\r
3356 return RetVal\r
3357\r
3358 ## Get the GUID value mapping\r
3359 #\r
3360 # @retval dict The mapping between GUID cname and its value\r
3361 #\r
3362 @cached_property\r
3363 def GuidList(self):\r
3364 RetVal = OrderedDict(self.Module.Guids)\r
3365 for Library in self.DependentLibraryList:\r
3366 RetVal.update(Library.Guids)\r
3367 ExtendCopyDictionaryLists(self._GuidComments, Library.GuidComments)\r
3368 ExtendCopyDictionaryLists(self._GuidComments, self.Module.GuidComments)\r
3369 return RetVal\r
3370\r
3371 @cached_property\r
3372 def GetGuidsUsedByPcd(self):\r
3373 RetVal = OrderedDict(self.Module.GetGuidsUsedByPcd())\r
3374 for Library in self.DependentLibraryList:\r
3375 RetVal.update(Library.GetGuidsUsedByPcd())\r
3376 return RetVal\r
3377 ## Get the protocol value mapping\r
3378 #\r
3379 # @retval dict The mapping between protocol cname and its value\r
3380 #\r
3381 @cached_property\r
3382 def ProtocolList(self):\r
3383 RetVal = OrderedDict(self.Module.Protocols)\r
3384 for Library in self.DependentLibraryList:\r
3385 RetVal.update(Library.Protocols)\r
3386 ExtendCopyDictionaryLists(self._ProtocolComments, Library.ProtocolComments)\r
3387 ExtendCopyDictionaryLists(self._ProtocolComments, self.Module.ProtocolComments)\r
3388 return RetVal\r
3389\r
3390 ## Get the PPI value mapping\r
3391 #\r
3392 # @retval dict The mapping between PPI cname and its value\r
3393 #\r
3394 @cached_property\r
3395 def PpiList(self):\r
3396 RetVal = OrderedDict(self.Module.Ppis)\r
3397 for Library in self.DependentLibraryList:\r
3398 RetVal.update(Library.Ppis)\r
3399 ExtendCopyDictionaryLists(self._PpiComments, Library.PpiComments)\r
3400 ExtendCopyDictionaryLists(self._PpiComments, self.Module.PpiComments)\r
3401 return RetVal\r
3402\r
3403 ## Get the list of include search path\r
3404 #\r
3405 # @retval list The list path\r
3406 #\r
3407 @cached_property\r
3408 def IncludePathList(self):\r
3409 RetVal = []\r
3410 RetVal.append(self.MetaFile.Dir)\r
3411 RetVal.append(self.DebugDir)\r
3412\r
3413 for Package in self.Module.Packages:\r
3414 PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)\r
3415 if PackageDir not in RetVal:\r
3416 RetVal.append(PackageDir)\r
3417 IncludesList = Package.Includes\r
3418 if Package._PrivateIncludes:\r
3419 if not self.MetaFile.Path.startswith(PackageDir):\r
3420 IncludesList = list(set(Package.Includes).difference(set(Package._PrivateIncludes)))\r
3421 for Inc in IncludesList:\r
3422 if Inc not in RetVal:\r
3423 RetVal.append(str(Inc))\r
3424 return RetVal\r
3425\r
3426 @cached_property\r
3427 def IncludePathLength(self):\r
3428 return sum(len(inc)+1 for inc in self.IncludePathList)\r
3429\r
3430 ## Get HII EX PCDs which maybe used by VFR\r
3431 #\r
3432 # efivarstore used by VFR may relate with HII EX PCDs\r
3433 # Get the variable name and GUID from efivarstore and HII EX PCD\r
3434 # List the HII EX PCDs in As Built INF if both name and GUID match.\r
3435 #\r
3436 # @retval list HII EX PCDs\r
3437 #\r
3438 def _GetPcdsMaybeUsedByVfr(self):\r
3439 if not self.SourceFileList:\r
3440 return []\r
3441\r
3442 NameGuids = set()\r
3443 for SrcFile in self.SourceFileList:\r
3444 if SrcFile.Ext.lower() != '.vfr':\r
3445 continue\r
3446 Vfri = os.path.join(self.OutputDir, SrcFile.BaseName + '.i')\r
3447 if not os.path.exists(Vfri):\r
3448 continue\r
3449 VfriFile = open(Vfri, 'r')\r
3450 Content = VfriFile.read()\r
3451 VfriFile.close()\r
3452 Pos = Content.find('efivarstore')\r
3453 while Pos != -1:\r
3454 #\r
3455 # Make sure 'efivarstore' is the start of efivarstore statement\r
3456 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'\r
3457 #\r
3458 Index = Pos - 1\r
3459 while Index >= 0 and Content[Index] in ' \t\r\n':\r
3460 Index -= 1\r
3461 if Index >= 0 and Content[Index] != ';':\r
3462 Pos = Content.find('efivarstore', Pos + len('efivarstore'))\r
3463 continue\r
3464 #\r
3465 # 'efivarstore' must be followed by name and guid\r
3466 #\r
3467 Name = gEfiVarStoreNamePattern.search(Content, Pos)\r
3468 if not Name:\r
3469 break\r
3470 Guid = gEfiVarStoreGuidPattern.search(Content, Pos)\r
3471 if not Guid:\r
3472 break\r
3473 NameArray = _ConvertStringToByteArray('L"' + Name.group(1) + '"')\r
3474 NameGuids.add((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
3475 Pos = Content.find('efivarstore', Name.end())\r
3476 if not NameGuids:\r
3477 return []\r
3478 HiiExPcds = []\r
3479 for Pcd in self.PlatformInfo.Platform.Pcds.values():\r
3480 if Pcd.Type != TAB_PCDS_DYNAMIC_EX_HII:\r
3481 continue\r
3482 for SkuInfo in Pcd.SkuInfoList.values():\r
3483 Value = GuidValue(SkuInfo.VariableGuid, self.PlatformInfo.PackageList, self.MetaFile.Path)\r
3484 if not Value:\r
3485 continue\r
3486 Name = _ConvertStringToByteArray(SkuInfo.VariableName)\r
3487 Guid = GuidStructureStringToGuidString(Value)\r
3488 if (Name, Guid) in NameGuids and Pcd not in HiiExPcds:\r
3489 HiiExPcds.append(Pcd)\r
3490 break\r
3491\r
3492 return HiiExPcds\r
3493\r
3494 def _GenOffsetBin(self):\r
3495 VfrUniBaseName = {}\r
3496 for SourceFile in self.Module.Sources:\r
3497 if SourceFile.Type.upper() == ".VFR" :\r
3498 #\r
3499 # search the .map file to find the offset of vfr binary in the PE32+/TE file.\r
3500 #\r
3501 VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")\r
3502 elif SourceFile.Type.upper() == ".UNI" :\r
3503 #\r
3504 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.\r
3505 #\r
3506 VfrUniBaseName["UniOffsetName"] = (self.Name + "Strings")\r
3507\r
3508 if not VfrUniBaseName:\r
3509 return None\r
3510 MapFileName = os.path.join(self.OutputDir, self.Name + ".map")\r
3511 EfiFileName = os.path.join(self.OutputDir, self.Name + ".efi")\r
3512 VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, list(VfrUniBaseName.values()))\r
3513 if not VfrUniOffsetList:\r
3514 return None\r
3515\r
3516 OutputName = '%sOffset.bin' % self.Name\r
3517 UniVfrOffsetFileName = os.path.join( self.OutputDir, OutputName)\r
3518\r
3519 try:\r
3520 fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r
3521 except:\r
3522 EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName, None)\r
3523\r
3524 # Use a instance of BytesIO to cache data\r
3525 fStringIO = BytesIO()\r
3526\r
3527 for Item in VfrUniOffsetList:\r
3528 if (Item[0].find("Strings") != -1):\r
3529 #\r
3530 # UNI offset in image.\r
3531 # GUID + Offset\r
3532 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r
3533 #\r
3534 UniGuid = b'\xe0\xc5\x13\x89\xf63\x86M\x9b\xf1C\xef\x89\xfc\x06f'\r
3535 fStringIO.write(UniGuid)\r
3536 UniValue = pack ('Q', int (Item[1], 16))\r
3537 fStringIO.write (UniValue)\r
3538 else:\r
3539 #\r
3540 # VFR binary offset in image.\r
3541 # GUID + Offset\r
3542 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r
3543 #\r
3544 VfrGuid = b'\xb4|\xbc\xd0Gj_I\xaa\x11q\x07F\xda\x06\xa2'\r
3545 fStringIO.write(VfrGuid)\r
3546 VfrValue = pack ('Q', int (Item[1], 16))\r
3547 fStringIO.write (VfrValue)\r
3548 #\r
3549 # write data into file.\r
3550 #\r
3551 try :\r
3552 fInputfile.write (fStringIO.getvalue())\r
3553 except:\r
3554 EdkLogger.error("build", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the "\r
3555 "file been locked or using by other applications." %UniVfrOffsetFileName, None)\r
3556\r
3557 fStringIO.close ()\r
3558 fInputfile.close ()\r
3559 return OutputName\r
3560\r
3561 ## Create AsBuilt INF file the module\r
3562 #\r
3563 def CreateAsBuiltInf(self, IsOnlyCopy = False):\r
3564 self.OutputFile = set()\r
3565 if IsOnlyCopy and GlobalData.gBinCacheDest:\r
3566 self.CopyModuleToCache()\r
3567 return\r
3568\r
3569 if self.IsAsBuiltInfCreated:\r
3570 return\r
3571\r
3572 # Skip the following code for libraries\r
3573 if self.IsLibrary:\r
3574 return\r
3575\r
3576 # Skip the following code for modules with no source files\r
3577 if not self.SourceFileList:\r
3578 return\r
3579\r
3580 # Skip the following code for modules without any binary files\r
3581 if self.BinaryFileList:\r
3582 return\r
3583\r
3584 ### TODO: How to handles mixed source and binary modules\r
3585\r
3586 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries\r
3587 # Also find all packages that the DynamicEx PCDs depend on\r
3588 Pcds = []\r
3589 PatchablePcds = []\r
3590 Packages = []\r
3591 PcdCheckList = []\r
3592 PcdTokenSpaceList = []\r
3593 for Pcd in self.ModulePcdList + self.LibraryPcdList:\r
3594 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
3595 PatchablePcds.append(Pcd)\r
3596 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, TAB_PCDS_PATCHABLE_IN_MODULE))\r
3597 elif Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
3598 if Pcd not in Pcds:\r
3599 Pcds.append(Pcd)\r
3600 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, TAB_PCDS_DYNAMIC_EX))\r
3601 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, TAB_PCDS_DYNAMIC))\r
3602 PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r
3603 GuidList = OrderedDict(self.GuidList)\r
3604 for TokenSpace in self.GetGuidsUsedByPcd:\r
3605 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list\r
3606 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs\r
3607 if TokenSpace not in PcdTokenSpaceList and TokenSpace in GuidList:\r
3608 GuidList.pop(TokenSpace)\r
3609 CheckList = (GuidList, self.PpiList, self.ProtocolList, PcdCheckList)\r
3610 for Package in self.DerivedPackageList:\r
3611 if Package in Packages:\r
3612 continue\r
3613 BeChecked = (Package.Guids, Package.Ppis, Package.Protocols, Package.Pcds)\r
3614 Found = False\r
3615 for Index in range(len(BeChecked)):\r
3616 for Item in CheckList[Index]:\r
3617 if Item in BeChecked[Index]:\r
3618 Packages.append(Package)\r
3619 Found = True\r
3620 break\r
3621 if Found:\r
3622 break\r
3623\r
3624 VfrPcds = self._GetPcdsMaybeUsedByVfr()\r
3625 for Pkg in self.PlatformInfo.PackageList:\r
3626 if Pkg in Packages:\r
3627 continue\r
3628 for VfrPcd in VfrPcds:\r
3629 if ((VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, TAB_PCDS_DYNAMIC_EX) in Pkg.Pcds or\r
3630 (VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, TAB_PCDS_DYNAMIC) in Pkg.Pcds):\r
3631 Packages.append(Pkg)\r
3632 break\r
3633\r
3634 ModuleType = SUP_MODULE_DXE_DRIVER if self.ModuleType == SUP_MODULE_UEFI_DRIVER and self.DepexGenerated else self.ModuleType\r
3635 DriverType = self.PcdIsDriver if self.PcdIsDriver else ''\r
3636 Guid = self.Guid\r
3637 MDefs = self.Module.Defines\r
3638\r
3639 AsBuiltInfDict = {\r
3640 'module_name' : self.Name,\r
3641 'module_guid' : Guid,\r
3642 'module_module_type' : ModuleType,\r
3643 'module_version_string' : [MDefs['VERSION_STRING']] if 'VERSION_STRING' in MDefs else [],\r
3644 'pcd_is_driver_string' : [],\r
3645 'module_uefi_specification_version' : [],\r
3646 'module_pi_specification_version' : [],\r
3647 'module_entry_point' : self.Module.ModuleEntryPointList,\r
3648 'module_unload_image' : self.Module.ModuleUnloadImageList,\r
3649 'module_constructor' : self.Module.ConstructorList,\r
3650 'module_destructor' : self.Module.DestructorList,\r
3651 'module_shadow' : [MDefs['SHADOW']] if 'SHADOW' in MDefs else [],\r
3652 'module_pci_vendor_id' : [MDefs['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs else [],\r
3653 'module_pci_device_id' : [MDefs['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs else [],\r
3654 'module_pci_class_code' : [MDefs['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs else [],\r
3655 'module_pci_revision' : [MDefs['PCI_REVISION']] if 'PCI_REVISION' in MDefs else [],\r
3656 'module_build_number' : [MDefs['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs else [],\r
3657 'module_spec' : [MDefs['SPEC']] if 'SPEC' in MDefs else [],\r
3658 'module_uefi_hii_resource_section' : [MDefs['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs else [],\r
3659 'module_uni_file' : [MDefs['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs else [],\r
3660 'module_arch' : self.Arch,\r
3661 'package_item' : [Package.MetaFile.File.replace('\\', '/') for Package in Packages],\r
3662 'binary_item' : [],\r
3663 'patchablepcd_item' : [],\r
3664 'pcd_item' : [],\r
3665 'protocol_item' : [],\r
3666 'ppi_item' : [],\r
3667 'guid_item' : [],\r
3668 'flags_item' : [],\r
3669 'libraryclasses_item' : []\r
3670 }\r
3671\r
3672 if 'MODULE_UNI_FILE' in MDefs:\r
3673 UNIFile = os.path.join(self.MetaFile.Dir, MDefs['MODULE_UNI_FILE'])\r
3674 if os.path.isfile(UNIFile):\r
3675 shutil.copy2(UNIFile, self.OutputDir)\r
3676\r
3677 if self.AutoGenVersion > int(gInfSpecVersion, 0):\r
3678 AsBuiltInfDict['module_inf_version'] = '0x%08x' % self.AutoGenVersion\r
3679 else:\r
3680 AsBuiltInfDict['module_inf_version'] = gInfSpecVersion\r
3681\r
3682 if DriverType:\r
3683 AsBuiltInfDict['pcd_is_driver_string'].append(DriverType)\r
3684\r
3685 if 'UEFI_SPECIFICATION_VERSION' in self.Specification:\r
3686 AsBuiltInfDict['module_uefi_specification_version'].append(self.Specification['UEFI_SPECIFICATION_VERSION'])\r
3687 if 'PI_SPECIFICATION_VERSION' in self.Specification:\r
3688 AsBuiltInfDict['module_pi_specification_version'].append(self.Specification['PI_SPECIFICATION_VERSION'])\r
3689\r
3690 OutputDir = self.OutputDir.replace('\\', '/').strip('/')\r
3691 DebugDir = self.DebugDir.replace('\\', '/').strip('/')\r
3692 for Item in self.CodaTargetList:\r
3693 File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')\r
3694 self.OutputFile.add(File)\r
3695 if os.path.isabs(File):\r
3696 File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')\r
3697 if Item.Target.Ext.lower() == '.aml':\r
3698 AsBuiltInfDict['binary_item'].append('ASL|' + File)\r
3699 elif Item.Target.Ext.lower() == '.acpi':\r
3700 AsBuiltInfDict['binary_item'].append('ACPI|' + File)\r
3701 elif Item.Target.Ext.lower() == '.efi':\r
3702 AsBuiltInfDict['binary_item'].append('PE32|' + self.Name + '.efi')\r
3703 else:\r
3704 AsBuiltInfDict['binary_item'].append('BIN|' + File)\r
3705 if not self.DepexGenerated:\r
3706 DepexFile = os.path.join(self.OutputDir, self.Name + '.depex')\r
3707 if os.path.exists(DepexFile):\r
3708 self.DepexGenerated = True\r
3709 if self.DepexGenerated:\r
3710 self.OutputFile.add(self.Name + '.depex')\r
3711 if self.ModuleType in [SUP_MODULE_PEIM]:\r
3712 AsBuiltInfDict['binary_item'].append('PEI_DEPEX|' + self.Name + '.depex')\r
3713 elif self.ModuleType in [SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]:\r
3714 AsBuiltInfDict['binary_item'].append('DXE_DEPEX|' + self.Name + '.depex')\r
3715 elif self.ModuleType in [SUP_MODULE_DXE_SMM_DRIVER]:\r
3716 AsBuiltInfDict['binary_item'].append('SMM_DEPEX|' + self.Name + '.depex')\r
3717\r
3718 Bin = self._GenOffsetBin()\r
3719 if Bin:\r
3720 AsBuiltInfDict['binary_item'].append('BIN|%s' % Bin)\r
3721 self.OutputFile.add(Bin)\r
3722\r
3723 for Root, Dirs, Files in os.walk(OutputDir):\r
3724 for File in Files:\r
3725 if File.lower().endswith('.pdb'):\r
3726 AsBuiltInfDict['binary_item'].append('DISPOSABLE|' + File)\r
3727 self.OutputFile.add(File)\r
3728 HeaderComments = self.Module.HeaderComments\r
3729 StartPos = 0\r
3730 for Index in range(len(HeaderComments)):\r
3731 if HeaderComments[Index].find('@BinaryHeader') != -1:\r
3732 HeaderComments[Index] = HeaderComments[Index].replace('@BinaryHeader', '@file')\r
3733 StartPos = Index\r
3734 break\r
3735 AsBuiltInfDict['header_comments'] = '\n'.join(HeaderComments[StartPos:]).replace(':#', '://')\r
3736 AsBuiltInfDict['tail_comments'] = '\n'.join(self.Module.TailComments)\r
3737\r
3738 GenList = [\r
3739 (self.ProtocolList, self._ProtocolComments, 'protocol_item'),\r
3740 (self.PpiList, self._PpiComments, 'ppi_item'),\r
3741 (GuidList, self._GuidComments, 'guid_item')\r
3742 ]\r
3743 for Item in GenList:\r
3744 for CName in Item[0]:\r
3745 Comments = '\n '.join(Item[1][CName]) if CName in Item[1] else ''\r
3746 Entry = Comments + '\n ' + CName if Comments else CName\r
3747 AsBuiltInfDict[Item[2]].append(Entry)\r
3748 PatchList = parsePcdInfoFromMapFile(\r
3749 os.path.join(self.OutputDir, self.Name + '.map'),\r
3750 os.path.join(self.OutputDir, self.Name + '.efi')\r
3751 )\r
3752 if PatchList:\r
3753 for Pcd in PatchablePcds:\r
3754 TokenCName = Pcd.TokenCName\r
3755 for PcdItem in GlobalData.MixedPcd:\r
3756 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
3757 TokenCName = PcdItem[0]\r
3758 break\r
3759 for PatchPcd in PatchList:\r
3760 if TokenCName == PatchPcd[0]:\r
3761 break\r
3762 else:\r
3763 continue\r
3764 PcdValue = ''\r
3765 if Pcd.DatumType == 'BOOLEAN':\r
3766 BoolValue = Pcd.DefaultValue.upper()\r
3767 if BoolValue == 'TRUE':\r
3768 Pcd.DefaultValue = '1'\r
3769 elif BoolValue == 'FALSE':\r
3770 Pcd.DefaultValue = '0'\r
3771\r
3772 if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES:\r
3773 HexFormat = '0x%02x'\r
3774 if Pcd.DatumType == TAB_UINT16:\r
3775 HexFormat = '0x%04x'\r
3776 elif Pcd.DatumType == TAB_UINT32:\r
3777 HexFormat = '0x%08x'\r
3778 elif Pcd.DatumType == TAB_UINT64:\r
3779 HexFormat = '0x%016x'\r
3780 PcdValue = HexFormat % int(Pcd.DefaultValue, 0)\r
3781 else:\r
3782 if Pcd.MaxDatumSize is None or Pcd.MaxDatumSize == '':\r
3783 EdkLogger.error("build", AUTOGEN_ERROR,\r
3784 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName)\r
3785 )\r
3786 ArraySize = int(Pcd.MaxDatumSize, 0)\r
3787 PcdValue = Pcd.DefaultValue\r
3788 if PcdValue[0] != '{':\r
3789 Unicode = False\r
3790 if PcdValue[0] == 'L':\r
3791 Unicode = True\r
3792 PcdValue = PcdValue.lstrip('L')\r
3793 PcdValue = eval(PcdValue)\r
3794 NewValue = '{'\r
3795 for Index in range(0, len(PcdValue)):\r
3796 if Unicode:\r
3797 CharVal = ord(PcdValue[Index])\r
3798 NewValue = NewValue + '0x%02x' % (CharVal & 0x00FF) + ', ' \\r
3799 + '0x%02x' % (CharVal >> 8) + ', '\r
3800 else:\r
3801 NewValue = NewValue + '0x%02x' % (ord(PcdValue[Index]) % 0x100) + ', '\r
3802 Padding = '0x00, '\r
3803 if Unicode:\r
3804 Padding = Padding * 2\r
3805 ArraySize = ArraySize // 2\r
3806 if ArraySize < (len(PcdValue) + 1):\r
3807 if Pcd.MaxSizeUserSet:\r
3808 EdkLogger.error("build", AUTOGEN_ERROR,\r
3809 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
3810 )\r
3811 else:\r
3812 ArraySize = len(PcdValue) + 1\r
3813 if ArraySize > len(PcdValue) + 1:\r
3814 NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r
3815 PcdValue = NewValue + Padding.strip().rstrip(',') + '}'\r
3816 elif len(PcdValue.split(',')) <= ArraySize:\r
3817 PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))\r
3818 PcdValue += '}'\r
3819 else:\r
3820 if Pcd.MaxSizeUserSet:\r
3821 EdkLogger.error("build", AUTOGEN_ERROR,\r
3822 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
3823 )\r
3824 else:\r
3825 ArraySize = len(PcdValue) + 1\r
3826 PcdItem = '%s.%s|%s|0x%X' % \\r
3827 (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])\r
3828 PcdComments = ''\r
3829 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
3830 PcdComments = '\n '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])\r
3831 if PcdComments:\r
3832 PcdItem = PcdComments + '\n ' + PcdItem\r
3833 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r
3834\r
3835 for Pcd in Pcds + VfrPcds:\r
3836 PcdCommentList = []\r
3837 HiiInfo = ''\r
3838 TokenCName = Pcd.TokenCName\r
3839 for PcdItem in GlobalData.MixedPcd:\r
3840 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
3841 TokenCName = PcdItem[0]\r
3842 break\r
3843 if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:\r
3844 for SkuName in Pcd.SkuInfoList:\r
3845 SkuInfo = Pcd.SkuInfoList[SkuName]\r
3846 HiiInfo = '## %s|%s|%s' % (SkuInfo.VariableName, SkuInfo.VariableGuid, SkuInfo.VariableOffset)\r
3847 break\r
3848 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
3849 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]\r
3850 if HiiInfo:\r
3851 UsageIndex = -1\r
3852 UsageStr = ''\r
3853 for Index, Comment in enumerate(PcdCommentList):\r
3854 for Usage in UsageList:\r
3855 if Comment.find(Usage) != -1:\r
3856 UsageStr = Usage\r
3857 UsageIndex = Index\r
3858 break\r
3859 if UsageIndex != -1:\r
3860 PcdCommentList[UsageIndex] = '## %s %s %s' % (UsageStr, HiiInfo, PcdCommentList[UsageIndex].replace(UsageStr, ''))\r
3861 else:\r
3862 PcdCommentList.append('## UNDEFINED ' + HiiInfo)\r
3863 PcdComments = '\n '.join(PcdCommentList)\r
3864 PcdEntry = Pcd.TokenSpaceGuidCName + '.' + TokenCName\r
3865 if PcdComments:\r
3866 PcdEntry = PcdComments + '\n ' + PcdEntry\r
3867 AsBuiltInfDict['pcd_item'].append(PcdEntry)\r
3868 for Item in self.BuildOption:\r
3869 if 'FLAGS' in self.BuildOption[Item]:\r
3870 AsBuiltInfDict['flags_item'].append('%s:%s_%s_%s_%s_FLAGS = %s' % (self.ToolChainFamily, self.BuildTarget, self.ToolChain, self.Arch, Item, self.BuildOption[Item]['FLAGS'].strip()))\r
3871\r
3872 # Generated LibraryClasses section in comments.\r
3873 for Library in self.LibraryAutoGenList:\r
3874 AsBuiltInfDict['libraryclasses_item'].append(Library.MetaFile.File.replace('\\', '/'))\r
3875\r
3876 # Generated UserExtensions TianoCore section.\r
3877 # All tianocore user extensions are copied.\r
3878 UserExtStr = ''\r
3879 for TianoCore in self._GetTianoCoreUserExtensionList():\r
3880 UserExtStr += '\n'.join(TianoCore)\r
3881 ExtensionFile = os.path.join(self.MetaFile.Dir, TianoCore[1])\r
3882 if os.path.isfile(ExtensionFile):\r
3883 shutil.copy2(ExtensionFile, self.OutputDir)\r
3884 AsBuiltInfDict['userextension_tianocore_item'] = UserExtStr\r
3885\r
3886 # Generated depex expression section in comments.\r
3887 DepexExpression = self._GetDepexExpresionString()\r
3888 AsBuiltInfDict['depexsection_item'] = DepexExpression if DepexExpression else ''\r
3889\r
3890 AsBuiltInf = TemplateString()\r
3891 AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))\r
3892\r
3893 SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r
3894\r
3895 self.IsAsBuiltInfCreated = True\r
3896 if GlobalData.gBinCacheDest:\r
3897 self.CopyModuleToCache()\r
3898\r
3899 def CopyModuleToCache(self):\r
3900 FileDir = path.join(GlobalData.gBinCacheDest, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
3901 CreateDirectory (FileDir)\r
3902 HashFile = path.join(self.BuildDir, self.Name + '.hash')\r
3903 ModuleFile = path.join(self.OutputDir, self.Name + '.inf')\r
3904 if os.path.exists(HashFile):\r
3905 shutil.copy2(HashFile, FileDir)\r
3906 if os.path.exists(ModuleFile):\r
3907 shutil.copy2(ModuleFile, FileDir)\r
3908 if not self.OutputFile:\r
3909 Ma = self.BuildDatabase[PathClass(ModuleFile), self.Arch, self.BuildTarget, self.ToolChain]\r
3910 self.OutputFile = Ma.Binaries\r
3911 if self.OutputFile:\r
3912 for File in self.OutputFile:\r
3913 File = str(File)\r
3914 if not os.path.isabs(File):\r
3915 File = os.path.join(self.OutputDir, File)\r
3916 if os.path.exists(File):\r
3917 shutil.copy2(File, FileDir)\r
3918\r
3919 def AttemptModuleCacheCopy(self):\r
3920 # If library or Module is binary do not skip by hash\r
3921 if self.IsBinaryModule:\r
3922 return False\r
3923 # .inc is contains binary information so do not skip by hash as well\r
3924 for f_ext in self.SourceFileList:\r
3925 if '.inc' in str(f_ext):\r
3926 return False\r
3927 FileDir = path.join(GlobalData.gBinCacheSource, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
3928 HashFile = path.join(FileDir, self.Name + '.hash')\r
3929 if os.path.exists(HashFile):\r
3930 f = open(HashFile, 'r')\r
3931 CacheHash = f.read()\r
3932 f.close()\r
3933 if GlobalData.gModuleHash[self.Arch][self.Name]:\r
3934 if CacheHash == GlobalData.gModuleHash[self.Arch][self.Name]:\r
3935 for root, dir, files in os.walk(FileDir):\r
3936 for f in files:\r
3937 if self.Name + '.hash' in f:\r
3938 shutil.copy2(HashFile, self.BuildDir)\r
3939 else:\r
3940 File = path.join(root, f)\r
3941 shutil.copy2(File, self.OutputDir)\r
3942 if self.Name == "PcdPeim" or self.Name == "PcdDxe":\r
3943 CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
3944 return True\r
3945 return False\r
3946\r
3947 ## Create makefile for the module and its dependent libraries\r
3948 #\r
3949 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of\r
3950 # dependent libraries will be created\r
3951 #\r
3952 @cached_class_function\r
3953 def CreateMakeFile(self, CreateLibraryMakeFile=True, GenFfsList = []):\r
3954 # nest this function inside it's only caller.\r
3955 def CreateTimeStamp():\r
3956 FileSet = {self.MetaFile.Path}\r
3957\r
3958 for SourceFile in self.Module.Sources:\r
3959 FileSet.add (SourceFile.Path)\r
3960\r
3961 for Lib in self.DependentLibraryList:\r
3962 FileSet.add (Lib.MetaFile.Path)\r
3963\r
3964 for f in self.AutoGenDepSet:\r
3965 FileSet.add (f.Path)\r
3966\r
3967 if os.path.exists (self.TimeStampPath):\r
3968 os.remove (self.TimeStampPath)\r
3969 with open(self.TimeStampPath, 'w+') as file:\r
3970 for f in FileSet:\r
3971 print(f, file=file)\r
3972\r
3973 # Ignore generating makefile when it is a binary module\r
3974 if self.IsBinaryModule:\r
3975 return\r
3976\r
3977 self.GenFfsList = GenFfsList\r
3978 if not self.IsLibrary and CreateLibraryMakeFile:\r
3979 for LibraryAutoGen in self.LibraryAutoGenList:\r
3980 LibraryAutoGen.CreateMakeFile()\r
3981\r
3982 if self.CanSkip():\r
3983 return\r
3984\r
3985 if len(self.CustomMakefile) == 0:\r
3986 Makefile = GenMake.ModuleMakefile(self)\r
3987 else:\r
3988 Makefile = GenMake.CustomMakefile(self)\r
3989 if Makefile.Generate():\r
3990 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %\r
3991 (self.Name, self.Arch))\r
3992 else:\r
3993 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %\r
3994 (self.Name, self.Arch))\r
3995\r
3996 CreateTimeStamp()\r
3997\r
3998 def CopyBinaryFiles(self):\r
3999 for File in self.Module.Binaries:\r
4000 SrcPath = File.Path\r
4001 DstPath = os.path.join(self.OutputDir, os.path.basename(SrcPath))\r
4002 CopyLongFilePath(SrcPath, DstPath)\r
4003 ## Create autogen code for the module and its dependent libraries\r
4004 #\r
4005 # @param CreateLibraryCodeFile Flag indicating if or not the code of\r
4006 # dependent libraries will be created\r
4007 #\r
4008 def CreateCodeFile(self, CreateLibraryCodeFile=True):\r
4009 if self.IsCodeFileCreated:\r
4010 return\r
4011\r
4012 # Need to generate PcdDatabase even PcdDriver is binarymodule\r
4013 if self.IsBinaryModule and self.PcdIsDriver != '':\r
4014 CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
4015 return\r
4016 if self.IsBinaryModule:\r
4017 if self.IsLibrary:\r
4018 self.CopyBinaryFiles()\r
4019 return\r
4020\r
4021 if not self.IsLibrary and CreateLibraryCodeFile:\r
4022 for LibraryAutoGen in self.LibraryAutoGenList:\r
4023 LibraryAutoGen.CreateCodeFile()\r
4024\r
4025 if self.CanSkip():\r
4026 return\r
4027\r
4028 AutoGenList = []\r
4029 IgoredAutoGenList = []\r
4030\r
4031 for File in self.AutoGenFileList:\r
4032 if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):\r
4033 AutoGenList.append(str(File))\r
4034 else:\r
4035 IgoredAutoGenList.append(str(File))\r
4036\r
4037\r
4038 for ModuleType in self.DepexList:\r
4039 # Ignore empty [depex] section or [depex] section for SUP_MODULE_USER_DEFINED module\r
4040 if len(self.DepexList[ModuleType]) == 0 or ModuleType == SUP_MODULE_USER_DEFINED:\r
4041 continue\r
4042\r
4043 Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)\r
4044 DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}\r
4045\r
4046 if len(Dpx.PostfixNotation) != 0:\r
4047 self.DepexGenerated = True\r
4048\r
4049 if Dpx.Generate(path.join(self.OutputDir, DpxFile)):\r
4050 AutoGenList.append(str(DpxFile))\r
4051 else:\r
4052 IgoredAutoGenList.append(str(DpxFile))\r
4053\r
4054 if IgoredAutoGenList == []:\r
4055 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %\r
4056 (" ".join(AutoGenList), self.Name, self.Arch))\r
4057 elif AutoGenList == []:\r
4058 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %\r
4059 (" ".join(IgoredAutoGenList), self.Name, self.Arch))\r
4060 else:\r
4061 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %\r
4062 (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))\r
4063\r
4064 self.IsCodeFileCreated = True\r
4065 return AutoGenList\r
4066\r
4067 ## Summarize the ModuleAutoGen objects of all libraries used by this module\r
4068 @cached_property\r
4069 def LibraryAutoGenList(self):\r
4070 RetVal = []\r
4071 for Library in self.DependentLibraryList:\r
4072 La = ModuleAutoGen(\r
4073 self.Workspace,\r
4074 Library.MetaFile,\r
4075 self.BuildTarget,\r
4076 self.ToolChain,\r
4077 self.Arch,\r
4078 self.PlatformInfo.MetaFile\r
4079 )\r
4080 if La not in RetVal:\r
4081 RetVal.append(La)\r
4082 for Lib in La.CodaTargetList:\r
4083 self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)\r
4084 return RetVal\r
4085\r
4086 def GenModuleHash(self):\r
4087 if self.Arch not in GlobalData.gModuleHash:\r
4088 GlobalData.gModuleHash[self.Arch] = {}\r
4089 if self.Name in GlobalData.gModuleHash[self.Arch] and GlobalData.gBinCacheSource and self.AttemptModuleCacheCopy():\r
4090 return False\r
4091 m = hashlib.md5()\r
4092 # Add Platform level hash\r
4093 m.update(GlobalData.gPlatformHash.encode('utf-8'))\r
4094 # Add Package level hash\r
4095 if self.DependentPackageList:\r
4096 for Pkg in sorted(self.DependentPackageList, key=lambda x: x.PackageName):\r
4097 if Pkg.PackageName in GlobalData.gPackageHash:\r
4098 m.update(GlobalData.gPackageHash[Pkg.PackageName].encode('utf-8'))\r
4099\r
4100 # Add Library hash\r
4101 if self.LibraryAutoGenList:\r
4102 for Lib in sorted(self.LibraryAutoGenList, key=lambda x: x.Name):\r
4103 if Lib.Name not in GlobalData.gModuleHash[self.Arch]:\r
4104 Lib.GenModuleHash()\r
4105 m.update(GlobalData.gModuleHash[self.Arch][Lib.Name].encode('utf-8'))\r
4106\r
4107 # Add Module self\r
4108 f = open(str(self.MetaFile), 'rb')\r
4109 Content = f.read()\r
4110 f.close()\r
4111 m.update(Content)\r
4112 # Add Module's source files\r
4113 if self.SourceFileList:\r
4114 for File in sorted(self.SourceFileList, key=lambda x: str(x)):\r
4115 f = open(str(File), 'rb')\r
4116 Content = f.read()\r
4117 f.close()\r
4118 m.update(Content)\r
4119\r
4120 ModuleHashFile = path.join(self.BuildDir, self.Name + ".hash")\r
4121 if self.Name not in GlobalData.gModuleHash[self.Arch]:\r
4122 GlobalData.gModuleHash[self.Arch][self.Name] = m.hexdigest()\r
4123 if GlobalData.gBinCacheSource and self.AttemptModuleCacheCopy():\r
4124 return False\r
4125 return SaveFileOnChange(ModuleHashFile, m.hexdigest(), False)\r
4126\r
4127 ## Decide whether we can skip the ModuleAutoGen process\r
4128 def CanSkipbyHash(self):\r
4129 # If library or Module is binary do not skip by hash\r
4130 if self.IsBinaryModule:\r
4131 return False\r
4132 # .inc is contains binary information so do not skip by hash as well\r
4133 for f_ext in self.SourceFileList:\r
4134 if '.inc' in str(f_ext):\r
4135 return False\r
4136 if GlobalData.gUseHashCache:\r
4137 # If there is a valid hash or function generated a valid hash; function will return False\r
4138 # and the statement below will return True\r
4139 return not self.GenModuleHash()\r
4140 return False\r
4141\r
4142 ## Decide whether we can skip the ModuleAutoGen process\r
4143 # If any source file is newer than the module than we cannot skip\r
4144 #\r
4145 def CanSkip(self):\r
4146 if self.MakeFileDir in GlobalData.gSikpAutoGenCache:\r
4147 return True\r
4148 if not os.path.exists(self.TimeStampPath):\r
4149 return False\r
4150 #last creation time of the module\r
4151 DstTimeStamp = os.stat(self.TimeStampPath)[8]\r
4152\r
4153 SrcTimeStamp = self.Workspace._SrcTimeStamp\r
4154 if SrcTimeStamp > DstTimeStamp:\r
4155 return False\r
4156\r
4157 with open(self.TimeStampPath,'r') as f:\r
4158 for source in f:\r
4159 source = source.rstrip('\n')\r
4160 if not os.path.exists(source):\r
4161 return False\r
4162 if source not in ModuleAutoGen.TimeDict :\r
4163 ModuleAutoGen.TimeDict[source] = os.stat(source)[8]\r
4164 if ModuleAutoGen.TimeDict[source] > DstTimeStamp:\r
4165 return False\r
4166 GlobalData.gSikpAutoGenCache.add(self.MakeFileDir)\r
4167 return True\r
4168\r
4169 @cached_property\r
4170 def TimeStampPath(self):\r
4171 return os.path.join(self.MakeFileDir, 'AutoGenTimeStamp')\r