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