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