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