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