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