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