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