2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
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
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.
18 from __future__
import print_function
19 from __future__
import absolute_import
20 import Common
.LongFilePathOs
as os
22 import os
.path
as path
28 from . import GenDepex
29 from io
import BytesIO
31 from .StrGather
import *
32 from .BuildEngine
import BuildRule
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
51 from .GenVar
import VariableMgr
, var_info
52 from collections
import OrderedDict
53 from collections
import defaultdict
54 from Workspace
.WorkspaceCommon
import OrderedListDict
56 from Common
.caching
import cached_property
, cached_class_function
58 ## Regular expression for splitting Dependency Expression string into tokens
59 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
61 ## Regular expression for match: PCD(xxxx.yyy)
62 gPCDAsGuidPattern
= re
.compile(r
"^PCD\(.+\..+\)$")
65 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
66 # is the former use /I , the Latter used -I to specify include directories
68 gBuildOptIncludePatternMsft
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
69 gBuildOptIncludePatternOther
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
72 # Match name = variable
74 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
76 # The format of guid in efivarstore statement likes following and must be correct:
77 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
79 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
81 ## Mapping Makefile type
82 gMakeTypeMap
= {"MSFT":"nmake", "GCC":"gmake"}
85 ## Build rule configuration file
86 gDefaultBuildRuleFile
= 'build_rule.txt'
88 ## Tools definition configuration file
89 gDefaultToolsDefFile
= 'tools_def.txt'
91 ## Build rule default version
92 AutoGenReqBuildRuleVerNum
= "0.1"
94 ## default file name for AutoGen
95 gAutoGenCodeFileName
= "AutoGen.c"
96 gAutoGenHeaderFileName
= "AutoGen.h"
97 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
98 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
99 gAutoGenDepexFileName
= "%(module_name)s.depex"
100 gAutoGenImageDefFileName
= "%(module_name)sImgDefs.h"
101 gAutoGenIdfFileName
= "%(module_name)sIdf.hpk"
102 gInfSpecVersion
= "0x00010017"
105 # Template string to generic AsBuilt INF
107 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
110 # FILE auto-generated
113 INF_VERSION = ${module_inf_version}
114 BASE_NAME = ${module_name}
115 FILE_GUID = ${module_guid}
116 MODULE_TYPE = ${module_module_type}${BEGIN}
117 VERSION_STRING = ${module_version_string}${END}${BEGIN}
118 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
119 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
120 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
121 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
122 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
123 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
124 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
125 SHADOW = ${module_shadow}${END}${BEGIN}
126 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
127 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
128 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
129 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
130 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
131 SPEC = ${module_spec}${END}${BEGIN}
132 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
133 MODULE_UNI_FILE = ${module_uni_file}${END}
135 [Packages.${module_arch}]${BEGIN}
136 ${package_item}${END}
138 [Binaries.${module_arch}]${BEGIN}
141 [PatchPcd.${module_arch}]${BEGIN}
145 [Protocols.${module_arch}]${BEGIN}
149 [Ppis.${module_arch}]${BEGIN}
153 [Guids.${module_arch}]${BEGIN}
157 [PcdEx.${module_arch}]${BEGIN}
161 [LibraryClasses.${module_arch}]
162 ## @LIB_INSTANCES${BEGIN}
163 # ${libraryclasses_item}${END}
167 ${userextension_tianocore_item}
171 [BuildOptions.${module_arch}]
173 ## ${flags_item}${END}
176 ## Base class for AutoGen
178 # This class just implements the cache mechanism of AutoGen objects.
180 class AutoGen(object):
181 # database to maintain the objects in each child class
182 __ObjectCache
= {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object
186 # @param Class class object of real AutoGen class
187 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
188 # @param Workspace Workspace directory or WorkspaceAutoGen object
189 # @param MetaFile The path of meta file
190 # @param Target Build target
191 # @param Toolchain Tool chain name
192 # @param Arch Target arch
193 # @param *args The specific class related parameters
194 # @param **kwargs The specific class related dict parameters
196 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
197 # check if the object has been created
198 Key
= (Target
, Toolchain
, Arch
, MetaFile
)
199 if Key
in cls
.__ObjectCache
:
200 # if it exists, just return it directly
201 return cls
.__ObjectCache
[Key
]
202 # it didnt exist. create it, cache it, then return it
203 RetVal
= cls
.__ObjectCache
[Key
] = super(AutoGen
, cls
).__new
__(cls
)
206 def __init__ (self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
207 super(AutoGen
, self
).__init
__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
211 # The file path of platform file will be used to represent hash value of this object
213 # @retval int Hash value of the file path of platform file
216 return hash(self
.MetaFile
)
220 # The file path of platform file will be used to represent this object
222 # @retval string String of platform file path
225 return str(self
.MetaFile
)
228 def __eq__(self
, Other
):
229 return Other
and self
.MetaFile
== Other
231 ## Workspace AutoGen class
233 # This class is used mainly to control the whole platform build for different
234 # architecture. This class will generate top level makefile.
236 class WorkspaceAutoGen(AutoGen
):
237 # call super().__init__ then call the worker function with different parameter count
238 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
239 if not hasattr(self
, "_Init"):
240 super(WorkspaceAutoGen
, self
).__init
__(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
241 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
244 ## Initialize WorkspaceAutoGen
246 # @param WorkspaceDir Root directory of workspace
247 # @param ActivePlatform Meta-file of active platform
248 # @param Target Build target
249 # @param Toolchain Tool chain name
250 # @param ArchList List of architecture of current build
251 # @param MetaFileDb Database containing meta-files
252 # @param BuildConfig Configuration of build
253 # @param ToolDefinition Tool chain definitions
254 # @param FlashDefinitionFile File of flash definition
255 # @param Fds FD list to be generated
256 # @param Fvs FV list to be generated
257 # @param Caps Capsule list to be generated
258 # @param SkuId SKU id from command line
260 def _InitWorker(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
261 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
262 Progress
=None, BuildModule
=None):
263 self
.BuildDatabase
= MetaFileDb
264 self
.MetaFile
= ActivePlatform
265 self
.WorkspaceDir
= WorkspaceDir
266 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, TAB_ARCH_COMMON
, Target
, Toolchain
]
267 GlobalData
.gActivePlatform
= self
.Platform
268 self
.BuildTarget
= Target
269 self
.ToolChain
= Toolchain
270 self
.ArchList
= ArchList
272 self
.UniFlag
= UniFlag
274 self
.TargetTxt
= BuildConfig
275 self
.ToolDef
= ToolDefinition
276 self
.FdfFile
= FlashDefinitionFile
277 self
.FdTargetList
= Fds
if Fds
else []
278 self
.FvTargetList
= Fvs
if Fvs
else []
279 self
.CapTargetList
= Caps
if Caps
else []
280 self
.AutoGenObjectList
= []
281 self
._BuildDir
= None
283 self
._MakeFileDir
= None
284 self
._BuildCommand
= None
287 # there's many relative directory operations, so ...
288 os
.chdir(self
.WorkspaceDir
)
293 if not self
.ArchList
:
294 ArchList
= set(self
.Platform
.SupArchList
)
296 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
298 EdkLogger
.error("build", PARAMETER_INVALID
,
299 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
300 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
301 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
302 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
303 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
304 self
.ArchList
= tuple(ArchList
)
306 # Validate build target
307 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
308 EdkLogger
.error("build", PARAMETER_INVALID
,
309 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
310 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
313 # parse FDF file to get PCDs in it, if any
315 self
.FdfFile
= self
.Platform
.FlashDefinition
319 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
320 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
321 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
323 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
325 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
328 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
330 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
333 Progress
.Start("\nProcessing meta-data")
337 # Mark now build in AutoGen Phase
339 GlobalData
.gAutoGenPhase
= True
340 Fdf
= FdfParser(self
.FdfFile
.Path
)
342 GlobalData
.gFdfParser
= Fdf
343 GlobalData
.gAutoGenPhase
= False
344 PcdSet
= Fdf
.Profile
.PcdDict
345 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
346 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
347 for FdRegion
in FdDict
.RegionList
:
348 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
349 if int(FdRegion
.Offset
) % 8 != 0:
350 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
351 ModuleList
= Fdf
.Profile
.InfList
352 self
.FdfProfile
= Fdf
.Profile
353 for fvname
in self
.FvTargetList
:
354 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
355 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
356 "No such an FV in FDF file: %s" % fvname
)
358 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
359 # but the path (self.MetaFile.Path) is the real path
360 for key
in self
.FdfProfile
.InfDict
:
362 MetaFile_cache
= defaultdict(set)
363 for Arch
in self
.ArchList
:
364 Current_Platform_cache
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
365 for Pkey
in Current_Platform_cache
.Modules
:
366 MetaFile_cache
[Arch
].add(Current_Platform_cache
.Modules
[Pkey
].MetaFile
)
367 for Inf
in self
.FdfProfile
.InfDict
[key
]:
368 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
369 for Arch
in self
.ArchList
:
370 if ModuleFile
in MetaFile_cache
[Arch
]:
373 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
374 if not ModuleData
.IsBinaryModule
:
375 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
378 for Arch
in self
.ArchList
:
380 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
382 for Pkey
in Platform
.Modules
:
383 MetaFileList
.add(Platform
.Modules
[Pkey
].MetaFile
)
384 for Inf
in self
.FdfProfile
.InfDict
[key
]:
385 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
386 if ModuleFile
in MetaFileList
:
388 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
389 if not ModuleData
.IsBinaryModule
:
390 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
395 self
.FdfProfile
= None
396 if self
.FdTargetList
:
397 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
398 self
.FdTargetList
= []
399 if self
.FvTargetList
:
400 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
401 self
.FvTargetList
= []
402 if self
.CapTargetList
:
403 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
404 self
.CapTargetList
= []
406 # apply SKU and inject PCDs from Flash Definition file
407 for Arch
in self
.ArchList
:
408 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
409 PlatformPcds
= Platform
.Pcds
410 self
._GuidDict
= Platform
._GuidDict
411 SourcePcdDict
= {TAB_PCDS_DYNAMIC_EX
:set(), TAB_PCDS_PATCHABLE_IN_MODULE
:set(),TAB_PCDS_DYNAMIC
:set(),TAB_PCDS_FIXED_AT_BUILD
:set()}
412 BinaryPcdDict
= {TAB_PCDS_DYNAMIC_EX
:set(), TAB_PCDS_PATCHABLE_IN_MODULE
:set()}
413 SourcePcdDict_Keys
= SourcePcdDict
.keys()
414 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
416 # generate the SourcePcdDict and BinaryPcdDict
417 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
418 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
419 if BuildData
.Arch
!= Arch
:
421 if BuildData
.MetaFile
.Ext
== '.inf':
422 for key
in BuildData
.Pcds
:
423 if BuildData
.Pcds
[key
].Pending
:
424 if key
in Platform
.Pcds
:
425 PcdInPlatform
= Platform
.Pcds
[key
]
426 if PcdInPlatform
.Type
:
427 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
428 BuildData
.Pcds
[key
].Pending
= False
430 if BuildData
.MetaFile
in Platform
.Modules
:
431 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
432 if key
in PlatformModule
.Pcds
:
433 PcdInPlatform
= PlatformModule
.Pcds
[key
]
434 if PcdInPlatform
.Type
:
435 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
436 BuildData
.Pcds
[key
].Pending
= False
438 #Pcd used in Library, Pcd Type from reference module if Pcd Type is Pending
439 if BuildData
.Pcds
[key
].Pending
:
440 MGen
= ModuleAutoGen(self
, BuildData
.MetaFile
, Target
, Toolchain
, Arch
, self
.MetaFile
)
441 if MGen
and MGen
.IsLibrary
:
442 if MGen
in PGen
.LibraryAutoGenList
:
443 ReferenceModules
= MGen
.ReferenceModules
444 for ReferenceModule
in ReferenceModules
:
445 if ReferenceModule
.MetaFile
in Platform
.Modules
:
446 RefPlatformModule
= Platform
.Modules
[str(ReferenceModule
.MetaFile
)]
447 if key
in RefPlatformModule
.Pcds
:
448 PcdInReferenceModule
= RefPlatformModule
.Pcds
[key
]
449 if PcdInReferenceModule
.Type
:
450 BuildData
.Pcds
[key
].Type
= PcdInReferenceModule
.Type
451 BuildData
.Pcds
[key
].Pending
= False
454 if TAB_PCDS_DYNAMIC_EX
in BuildData
.Pcds
[key
].Type
:
455 if BuildData
.IsBinaryModule
:
456 BinaryPcdDict
[TAB_PCDS_DYNAMIC_EX
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
458 SourcePcdDict
[TAB_PCDS_DYNAMIC_EX
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
460 elif TAB_PCDS_PATCHABLE_IN_MODULE
in BuildData
.Pcds
[key
].Type
:
461 if BuildData
.MetaFile
.Ext
== '.inf':
462 if BuildData
.IsBinaryModule
:
463 BinaryPcdDict
[TAB_PCDS_PATCHABLE_IN_MODULE
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
465 SourcePcdDict
[TAB_PCDS_PATCHABLE_IN_MODULE
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
467 elif TAB_PCDS_DYNAMIC
in BuildData
.Pcds
[key
].Type
:
468 SourcePcdDict
[TAB_PCDS_DYNAMIC
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
469 elif TAB_PCDS_FIXED_AT_BUILD
in BuildData
.Pcds
[key
].Type
:
470 SourcePcdDict
[TAB_PCDS_FIXED_AT_BUILD
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
474 # A PCD can only use one type for all source modules
476 for i
in SourcePcdDict_Keys
:
477 for j
in SourcePcdDict_Keys
:
479 Intersections
= SourcePcdDict
[i
].intersection(SourcePcdDict
[j
])
480 if len(Intersections
) > 0:
484 "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
),
485 ExtraData
='\n\t'.join(str(P
[1]+'.'+P
[0]) for P
in Intersections
)
489 # intersection the BinaryPCD for Mixed PCD
491 for i
in BinaryPcdDict_Keys
:
492 for j
in BinaryPcdDict_Keys
:
494 Intersections
= BinaryPcdDict
[i
].intersection(BinaryPcdDict
[j
])
495 for item
in Intersections
:
496 NewPcd1
= (item
[0] + '_' + i
, item
[1])
497 NewPcd2
= (item
[0] + '_' + j
, item
[1])
498 if item
not in GlobalData
.MixedPcd
:
499 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
501 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
502 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
503 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
504 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
507 # intersection the SourcePCD and BinaryPCD for Mixed PCD
509 for i
in SourcePcdDict_Keys
:
510 for j
in BinaryPcdDict_Keys
:
512 Intersections
= SourcePcdDict
[i
].intersection(BinaryPcdDict
[j
])
513 for item
in Intersections
:
514 NewPcd1
= (item
[0] + '_' + i
, item
[1])
515 NewPcd2
= (item
[0] + '_' + j
, item
[1])
516 if item
not in GlobalData
.MixedPcd
:
517 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
519 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
520 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
521 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
522 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
524 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
525 if BuildData
.Arch
!= Arch
:
527 for key
in BuildData
.Pcds
:
528 for SinglePcd
in GlobalData
.MixedPcd
:
529 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
530 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
531 Pcd_Type
= item
[0].split('_')[-1]
532 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 \
533 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in PCD_DYNAMIC_TYPE_SET
):
534 Value
= BuildData
.Pcds
[key
]
535 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
537 newkey
= (Value
.TokenCName
, key
[1])
539 newkey
= (Value
.TokenCName
, key
[1], key
[2])
540 del BuildData
.Pcds
[key
]
541 BuildData
.Pcds
[newkey
] = Value
545 # handle the mixed pcd in FDF file
547 if key
in GlobalData
.MixedPcd
:
550 for item
in GlobalData
.MixedPcd
[key
]:
553 #Collect package set information from INF of FDF
555 for Inf
in ModuleList
:
556 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
557 if ModuleFile
in Platform
.Modules
:
559 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
560 PkgSet
.update(ModuleData
.Packages
)
561 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
566 DecPcds
.add((Pcd
[0], Pcd
[1]))
567 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
569 Platform
.SkuName
= self
.SkuId
570 for Name
, Guid
,Fileds
in PcdSet
:
571 if (Name
, Guid
) not in DecPcds
:
575 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
576 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
577 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
580 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
581 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
582 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
583 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
585 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
589 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
590 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
591 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
594 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
596 # Explicitly collect platform's dynamic PCDs
598 Pa
.CollectPlatformDynamicPcds()
599 Pa
.CollectFixedAtBuildPcds()
600 self
.AutoGenObjectList
.append(Pa
)
603 # Generate Package level hash value
605 GlobalData
.gPackageHash
[Arch
] = {}
606 if GlobalData
.gUseHashCache
:
608 self
._GenPkgLevelHash
(Pkg
)
611 # Check PCDs token value conflict in each DEC file.
613 self
._CheckAllPcdsTokenValueConflict
()
616 # Check PCD type and definition between DSC and DEC
618 self
._CheckPcdDefineAndType
()
621 # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.
623 content
= 'gCommandLineDefines: '
624 content
+= str(GlobalData
.gCommandLineDefines
)
625 content
+= os
.linesep
626 content
+= 'BuildOptionPcd: '
627 content
+= str(GlobalData
.BuildOptionPcd
)
628 content
+= os
.linesep
629 content
+= 'Active Platform: '
630 content
+= str(self
.Platform
)
631 content
+= os
.linesep
633 content
+= 'Flash Image Definition: '
634 content
+= str(self
.FdfFile
)
635 content
+= os
.linesep
636 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'BuildOptions'), content
, False)
639 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.
641 PcdTokenNumber
= 'PcdTokenNumber: '
642 if Pa
.PcdTokenNumber
:
643 if Pa
.DynamicPcdList
:
644 for Pcd
in Pa
.DynamicPcdList
:
645 PcdTokenNumber
+= os
.linesep
646 PcdTokenNumber
+= str((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
))
647 PcdTokenNumber
+= ' : '
648 PcdTokenNumber
+= str(Pa
.PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
])
649 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'), PcdTokenNumber
, False)
652 # Get set of workspace metafiles
654 AllWorkSpaceMetaFiles
= self
._GetMetaFiles
(Target
, Toolchain
, Arch
)
657 # Retrieve latest modified time of all metafiles
660 for f
in AllWorkSpaceMetaFiles
:
661 if os
.stat(f
)[8] > SrcTimeStamp
:
662 SrcTimeStamp
= os
.stat(f
)[8]
663 self
._SrcTimeStamp
= SrcTimeStamp
665 if GlobalData
.gUseHashCache
:
667 for files
in AllWorkSpaceMetaFiles
:
668 if files
.endswith('.dec'):
674 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'AutoGen.hash'), m
.hexdigest(), True)
675 GlobalData
.gPlatformHash
= m
.hexdigest()
678 # Write metafile list to build directory
680 AutoGenFilePath
= os
.path
.join(self
.BuildDir
, 'AutoGen')
681 if os
.path
.exists (AutoGenFilePath
):
682 os
.remove(AutoGenFilePath
)
683 if not os
.path
.exists(self
.BuildDir
):
684 os
.makedirs(self
.BuildDir
)
685 with
open(os
.path
.join(self
.BuildDir
, 'AutoGen'), 'w+') as file:
686 for f
in AllWorkSpaceMetaFiles
:
690 def _GenPkgLevelHash(self
, Pkg
):
691 if Pkg
.PackageName
in GlobalData
.gPackageHash
[Pkg
.Arch
]:
694 PkgDir
= os
.path
.join(self
.BuildDir
, Pkg
.Arch
, Pkg
.PackageName
)
695 CreateDirectory(PkgDir
)
696 HashFile
= os
.path
.join(PkgDir
, Pkg
.PackageName
+ '.hash')
698 # Get .dec file's hash value
699 f
= open(Pkg
.MetaFile
.Path
, 'r')
703 # Get include files hash value
705 for inc
in sorted(Pkg
.Includes
, key
=lambda x
: str(x
)):
706 for Root
, Dirs
, Files
in os
.walk(str(inc
)):
707 for File
in sorted(Files
):
708 File_Path
= os
.path
.join(Root
, File
)
709 f
= open(File_Path
, 'r')
713 SaveFileOnChange(HashFile
, m
.hexdigest(), True)
714 GlobalData
.gPackageHash
[Pkg
.Arch
][Pkg
.PackageName
] = m
.hexdigest()
716 def _GetMetaFiles(self
, Target
, Toolchain
, Arch
):
717 AllWorkSpaceMetaFiles
= set()
722 AllWorkSpaceMetaFiles
.add (self
.FdfFile
.Path
)
723 for f
in GlobalData
.gFdfParser
.GetAllIncludedFile():
724 AllWorkSpaceMetaFiles
.add (f
.FileName
)
728 AllWorkSpaceMetaFiles
.add(self
.MetaFile
.Path
)
731 # add build_rule.txt & tools_def.txt
733 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultBuildRuleFile
))
734 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultToolsDefFile
))
736 # add BuildOption metafile
738 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'BuildOptions'))
740 # add PcdToken Number file for Dynamic/DynamicEx Pcd
742 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'))
744 for Arch
in self
.ArchList
:
748 for Package
in PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
).PackageList
:
749 AllWorkSpaceMetaFiles
.add(Package
.MetaFile
.Path
)
754 for filePath
in self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]._RawData
.IncludedFiles
:
755 AllWorkSpaceMetaFiles
.add(filePath
.Path
)
757 return AllWorkSpaceMetaFiles
759 def _CheckPcdDefineAndType(self
):
760 PcdTypeSet
= {TAB_PCDS_FIXED_AT_BUILD
,
761 TAB_PCDS_PATCHABLE_IN_MODULE
,
762 TAB_PCDS_FEATURE_FLAG
,
766 # This dict store PCDs which are not used by any modules with specified arches
767 UnusedPcd
= OrderedDict()
768 for Pa
in self
.AutoGenObjectList
:
769 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
770 for Pcd
in Pa
.Platform
.Pcds
:
771 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
773 # If no PCD type, this PCD comes from FDF
777 # Try to remove Hii and Vpd suffix
778 if PcdType
.startswith(TAB_PCDS_DYNAMIC_EX
):
779 PcdType
= TAB_PCDS_DYNAMIC_EX
780 elif PcdType
.startswith(TAB_PCDS_DYNAMIC
):
781 PcdType
= TAB_PCDS_DYNAMIC
783 for Package
in Pa
.PackageList
:
784 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
785 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
787 for Type
in PcdTypeSet
:
788 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
792 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
793 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
798 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
800 for Pcd
in UnusedPcd
:
803 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
804 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
805 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
810 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
812 ## Return the directory to store FV files
814 if self
._FvDir
is None:
815 self
._FvDir
= path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
818 ## Return the directory to store all intermediate and final files built
819 def _GetBuildDir(self
):
820 if self
._BuildDir
is None:
821 return self
.AutoGenObjectList
[0].BuildDir
823 ## Return the build output directory platform specifies
824 def _GetOutputDir(self
):
825 return self
.Platform
.OutputDirectory
827 ## Return platform name
829 return self
.Platform
.PlatformName
831 ## Return meta-file GUID
833 return self
.Platform
.Guid
835 ## Return platform version
836 def _GetVersion(self
):
837 return self
.Platform
.Version
839 ## Return paths of tools
840 def _GetToolDefinition(self
):
841 return self
.AutoGenObjectList
[0].ToolDefinition
843 ## Return directory of platform makefile
845 # @retval string Makefile directory
847 def _GetMakeFileDir(self
):
848 if self
._MakeFileDir
is None:
849 self
._MakeFileDir
= self
.BuildDir
850 return self
._MakeFileDir
852 ## Return build command string
854 # @retval string Build command string
856 def _GetBuildCommand(self
):
857 if self
._BuildCommand
is None:
858 # BuildCommand should be all the same. So just get one from platform AutoGen
859 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
860 return self
._BuildCommand
862 ## Check the PCDs token value conflict in each DEC file.
864 # Will cause build break and raise error message while two PCDs conflict.
868 def _CheckAllPcdsTokenValueConflict(self
):
869 for Pa
in self
.AutoGenObjectList
:
870 for Package
in Pa
.PackageList
:
871 PcdList
= Package
.Pcds
.values()
872 PcdList
.sort(key
=lambda x
: int(x
.TokenValue
, 0))
874 while (Count
< len(PcdList
) - 1) :
875 Item
= PcdList
[Count
]
876 ItemNext
= PcdList
[Count
+ 1]
878 # Make sure in the same token space the TokenValue should be unique
880 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
881 SameTokenValuePcdList
= []
882 SameTokenValuePcdList
.append(Item
)
883 SameTokenValuePcdList
.append(ItemNext
)
884 RemainPcdListLength
= len(PcdList
) - Count
- 2
885 for ValueSameCount
in range(RemainPcdListLength
):
886 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
887 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
891 # Sort same token value PCD list with TokenGuid and TokenCName
893 SameTokenValuePcdList
.sort(key
=lambda x
: "%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
))
894 SameTokenValuePcdListCount
= 0
895 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
897 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
898 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
900 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
901 for PcdItem
in GlobalData
.MixedPcd
:
902 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
903 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
909 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
910 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
913 SameTokenValuePcdListCount
+= 1
914 Count
+= SameTokenValuePcdListCount
917 PcdList
= Package
.Pcds
.values()
918 PcdList
.sort(key
=lambda x
: "%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
))
920 while (Count
< len(PcdList
) - 1) :
921 Item
= PcdList
[Count
]
922 ItemNext
= PcdList
[Count
+ 1]
924 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
926 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
930 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
931 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
935 ## Generate fds command
936 def _GenFdsCommand(self
):
937 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
939 ## Create makefile for the platform and modules in it
941 # @param CreateDepsMakeFile Flag indicating if the makefile for
942 # modules will be created as well
944 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
945 if not CreateDepsMakeFile
:
947 for Pa
in self
.AutoGenObjectList
:
948 Pa
.CreateMakeFile(True)
950 ## Create autogen code for platform and modules
952 # Since there's no autogen code for platform, this method will do nothing
953 # if CreateModuleCodeFile is set to False.
955 # @param CreateDepsCodeFile Flag indicating if creating module's
956 # autogen code file or not
958 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
959 if not CreateDepsCodeFile
:
961 for Pa
in self
.AutoGenObjectList
:
962 Pa
.CreateCodeFile(True)
964 ## Create AsBuilt INF file the platform
966 def CreateAsBuiltInf(self
):
969 Name
= property(_GetName
)
970 Guid
= property(_GetGuid
)
971 Version
= property(_GetVersion
)
972 OutputDir
= property(_GetOutputDir
)
974 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
976 BuildDir
= property(_GetBuildDir
)
977 FvDir
= property(_GetFvDir
)
978 MakeFileDir
= property(_GetMakeFileDir
)
979 BuildCommand
= property(_GetBuildCommand
)
980 GenFdsCommand
= property(_GenFdsCommand
)
982 ## AutoGen class for platform
984 # PlatformAutoGen class will process the original information in platform
985 # file in order to generate makefile for platform.
987 class PlatformAutoGen(AutoGen
):
988 # call super().__init__ then call the worker function with different parameter count
989 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
990 if not hasattr(self
, "_Init"):
991 super(PlatformAutoGen
, self
).__init
__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
992 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
)
995 # Used to store all PCDs for both PEI and DXE phase, in order to generate
996 # correct PCD database
999 _NonDynaPcdList_
= []
1003 # The priority list while override build option
1005 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
1006 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1007 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1008 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1009 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1010 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1011 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1012 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1013 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1014 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1015 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1016 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1017 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1018 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1019 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1020 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1022 ## Initialize PlatformAutoGen
1025 # @param Workspace WorkspaceAutoGen object
1026 # @param PlatformFile Platform file (DSC file)
1027 # @param Target Build target (DEBUG, RELEASE)
1028 # @param Toolchain Name of tool chain
1029 # @param Arch arch of the platform supports
1031 def _InitWorker(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1032 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1033 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1035 self
.MetaFile
= PlatformFile
1036 self
.Workspace
= Workspace
1037 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1038 self
.ToolChain
= Toolchain
1039 self
.BuildTarget
= Target
1041 self
.SourceDir
= PlatformFile
.SubDir
1042 self
.SourceOverrideDir
= None
1043 self
.FdTargetList
= self
.Workspace
.FdTargetList
1044 self
.FvTargetList
= self
.Workspace
.FvTargetList
1045 self
.AllPcdList
= []
1046 # get the original module/package/platform objects
1047 self
.BuildDatabase
= Workspace
.BuildDatabase
1048 self
.DscBuildDataObj
= Workspace
.Platform
1049 self
._GuidDict
= Workspace
._GuidDict
1051 # flag indicating if the makefile/C-code file has been created or not
1052 self
.IsMakeFileCreated
= False
1053 self
.IsCodeFileCreated
= False
1055 self
._Platform
= None
1058 self
._Version
= None
1060 self
._BuildRule
= None
1061 self
._SourceDir
= None
1062 self
._BuildDir
= None
1063 self
._OutputDir
= None
1065 self
._MakeFileDir
= None
1066 self
._FdfFile
= None
1068 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
1069 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1070 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1071 self
._NonDynamicPcdDict
= {}
1073 self
._ToolDefinitions
= None
1074 self
._ToolDefFile
= None # toolcode : tool path
1075 self
._ToolChainFamily
= None
1076 self
._BuildRuleFamily
= None
1077 self
._BuildOption
= None # toolcode : option
1078 self
._EdkBuildOption
= None # edktoolcode : option
1079 self
._EdkIIBuildOption
= None # edkiitoolcode : option
1080 self
._PackageList
= None
1081 self
._ModuleAutoGenList
= None
1082 self
._LibraryAutoGenList
= None
1083 self
._BuildCommand
= None
1084 self
._AsBuildInfList
= []
1085 self
._AsBuildModuleList
= []
1087 self
.VariableInfo
= None
1089 if GlobalData
.gFdfParser
is not None:
1090 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1091 for Inf
in self
._AsBuildInfList
:
1092 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1093 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1094 if not M
.IsSupportedArch
:
1096 self
._AsBuildModuleList
.append(InfClass
)
1097 # get library/modules for build
1098 self
.LibraryBuildDirectoryList
= []
1099 self
.ModuleBuildDirectoryList
= []
1104 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1106 ## Create autogen code for platform and modules
1108 # Since there's no autogen code for platform, this method will do nothing
1109 # if CreateModuleCodeFile is set to False.
1111 # @param CreateModuleCodeFile Flag indicating if creating module's
1112 # autogen code file or not
1114 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1115 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1116 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
1119 for Ma
in self
.ModuleAutoGenList
:
1120 Ma
.CreateCodeFile(True)
1122 # don't do this twice
1123 self
.IsCodeFileCreated
= True
1125 ## Generate Fds Command
1126 def _GenFdsCommand(self
):
1127 return self
.Workspace
.GenFdsCommand
1129 ## Create makefile for the platform and mdoules in it
1131 # @param CreateModuleMakeFile Flag indicating if the makefile for
1132 # modules will be created as well
1134 def CreateMakeFile(self
, CreateModuleMakeFile
=False, FfsCommand
= {}):
1135 if CreateModuleMakeFile
:
1136 for ModuleFile
in self
.Platform
.Modules
:
1137 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
1138 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1139 if (ModuleFile
.File
, self
.Arch
) in FfsCommand
:
1140 Ma
.CreateMakeFile(True, FfsCommand
[ModuleFile
.File
, self
.Arch
])
1142 Ma
.CreateMakeFile(True)
1143 #Ma.CreateAsBuiltInf()
1145 # no need to create makefile for the platform more than once
1146 if self
.IsMakeFileCreated
:
1149 # create library/module build dirs for platform
1150 Makefile
= GenMake
.PlatformMakefile(self
)
1151 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1152 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1154 self
.IsMakeFileCreated
= True
1156 ## Deal with Shared FixedAtBuild Pcds
1158 def CollectFixedAtBuildPcds(self
):
1159 for LibAuto
in self
.LibraryAutoGenList
:
1160 FixedAtBuildPcds
= {}
1161 ShareFixedAtBuildPcdsSameValue
= {}
1162 for Module
in LibAuto
.ReferenceModules
:
1163 for Pcd
in set(Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
):
1164 DefaultValue
= Pcd
.DefaultValue
1165 # Cover the case: DSC component override the Pcd value and the Pcd only used in one Lib
1166 if Pcd
in Module
.LibraryPcdList
:
1167 Index
= Module
.LibraryPcdList
.index(Pcd
)
1168 DefaultValue
= Module
.LibraryPcdList
[Index
].DefaultValue
1169 key
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1170 if key
not in FixedAtBuildPcds
:
1171 ShareFixedAtBuildPcdsSameValue
[key
] = True
1172 FixedAtBuildPcds
[key
] = DefaultValue
1174 if FixedAtBuildPcds
[key
] != DefaultValue
:
1175 ShareFixedAtBuildPcdsSameValue
[key
] = False
1176 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1177 key
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1178 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1181 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)]
1182 if DscPcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
1184 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1185 LibAuto
.ConstPcd
[key
] = FixedAtBuildPcds
[key
]
1187 def CollectVariables(self
, DynamicPcdSet
):
1191 if self
.Workspace
.FdfFile
:
1192 FdDict
= self
.Workspace
.FdfProfile
.FdDict
[GlobalData
.gFdfParser
.CurrentFdName
]
1193 for FdRegion
in FdDict
.RegionList
:
1194 for item
in FdRegion
.RegionDataList
:
1195 if self
.Platform
.VpdToolGuid
.strip() and self
.Platform
.VpdToolGuid
in item
:
1196 VpdRegionSize
= FdRegion
.Size
1197 VpdRegionBase
= FdRegion
.Offset
1201 VariableInfo
= VariableMgr(self
.DscBuildDataObj
._GetDefaultStores
(), self
.DscBuildDataObj
._GetSkuIds
())
1202 VariableInfo
.SetVpdRegionMaxSize(VpdRegionSize
)
1203 VariableInfo
.SetVpdRegionOffset(VpdRegionBase
)
1205 for Pcd
in DynamicPcdSet
:
1206 pcdname
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1207 for SkuName
in Pcd
.SkuInfoList
:
1208 Sku
= Pcd
.SkuInfoList
[SkuName
]
1210 if SkuId
is None or SkuId
== '':
1212 if len(Sku
.VariableName
) > 0:
1213 VariableGuidStructure
= Sku
.VariableGuidValue
1214 VariableGuid
= GuidStructureStringToGuidString(VariableGuidStructure
)
1215 for StorageName
in Sku
.DefaultStoreDict
:
1216 VariableInfo
.append_variable(var_info(Index
, pcdname
, StorageName
, SkuName
, StringToArray(Sku
.VariableName
), VariableGuid
, Sku
.VariableOffset
, Sku
.VariableAttribute
, Sku
.HiiDefaultValue
, Sku
.DefaultStoreDict
[StorageName
], Pcd
.DatumType
))
1220 def UpdateNVStoreMaxSize(self
, OrgVpdFile
):
1221 if self
.VariableInfo
:
1222 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
1223 PcdNvStoreDfBuffer
= [item
for item
in self
._DynamicPcdList
if item
.TokenCName
== "PcdNvStoreDefaultValueBuffer" and item
.TokenSpaceGuidCName
== "gEfiMdeModulePkgTokenSpaceGuid"]
1225 if PcdNvStoreDfBuffer
:
1226 if os
.path
.exists(VpdMapFilePath
):
1227 OrgVpdFile
.Read(VpdMapFilePath
)
1228 PcdItems
= OrgVpdFile
.GetOffset(PcdNvStoreDfBuffer
[0])
1229 NvStoreOffset
= PcdItems
.values()[0].strip() if PcdItems
else '0'
1231 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1233 NvStoreOffset
= int(NvStoreOffset
, 16) if NvStoreOffset
.upper().startswith("0X") else int(NvStoreOffset
)
1234 default_skuobj
= PcdNvStoreDfBuffer
[0].SkuInfoList
.get(TAB_DEFAULT
)
1235 maxsize
= self
.VariableInfo
.VpdRegionSize
- NvStoreOffset
if self
.VariableInfo
.VpdRegionSize
else len(default_skuobj
.DefaultValue
.split(","))
1236 var_data
= self
.VariableInfo
.PatchNVStoreDefaultMaxSize(maxsize
)
1238 if var_data
and default_skuobj
:
1239 default_skuobj
.DefaultValue
= var_data
1240 PcdNvStoreDfBuffer
[0].DefaultValue
= var_data
1241 PcdNvStoreDfBuffer
[0].SkuInfoList
.clear()
1242 PcdNvStoreDfBuffer
[0].SkuInfoList
[TAB_DEFAULT
] = default_skuobj
1243 PcdNvStoreDfBuffer
[0].MaxDatumSize
= str(len(default_skuobj
.DefaultValue
.split(",")))
1247 ## Collect dynamic PCDs
1249 # Gather dynamic PCDs list from each module and their settings from platform
1250 # This interface should be invoked explicitly when platform action is created.
1252 def CollectPlatformDynamicPcds(self
):
1254 for key
in self
.Platform
.Pcds
:
1255 for SinglePcd
in GlobalData
.MixedPcd
:
1256 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1257 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1258 Pcd_Type
= item
[0].split('_')[-1]
1259 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 \
1260 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in PCD_DYNAMIC_TYPE_SET
):
1261 Value
= self
.Platform
.Pcds
[key
]
1262 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1264 newkey
= (Value
.TokenCName
, key
[1])
1266 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1267 del self
.Platform
.Pcds
[key
]
1268 self
.Platform
.Pcds
[newkey
] = Value
1272 # for gathering error information
1273 NoDatumTypePcdList
= set()
1275 for InfName
in self
._AsBuildInfList
:
1276 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1277 FdfModuleList
.append(os
.path
.normpath(InfName
))
1278 for F
in self
.Platform
.Modules
.keys():
1279 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1280 #GuidValue.update(M.Guids)
1282 self
.Platform
.Modules
[F
].M
= M
1284 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1285 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1286 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
1287 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1289 # Check the PCD from Binary INF or Source INF
1290 if M
.IsBinaryModule
== True:
1291 PcdFromModule
.IsFromBinaryInf
= True
1293 # Check the PCD from DSC or not
1294 PcdFromModule
.IsFromDsc
= (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
1296 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
or PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1297 if F
.Path
not in FdfModuleList
:
1298 # If one of the Source built modules listed in the DSC is not listed
1299 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1300 # access method (it is only listed in the DEC file that declares the
1301 # PCD as PcdsDynamic), then build tool will report warning message
1302 # notify the PI that they are attempting to build a module that must
1303 # be included in a flash image in order to be functional. These Dynamic
1304 # PCD will not be added into the Database unless it is used by other
1305 # modules that are included in the FDF file.
1306 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
and \
1307 PcdFromModule
.IsFromBinaryInf
== False:
1308 # Print warning message to let the developer make a determine.
1310 # If one of the Source built modules listed in the DSC is not listed in
1311 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1312 # access method (it is only listed in the DEC file that declares the
1313 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1314 # PCD to the Platform's PCD Database.
1315 if PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1318 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1319 # it should be stored in Pcd PEI database, If a dynamic only
1320 # used by DXE module, it should be stored in DXE PCD database.
1321 # The default Phase is DXE
1323 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
1324 PcdFromModule
.Phase
= "PEI"
1325 if PcdFromModule
not in self
._DynaPcdList
_:
1326 self
._DynaPcdList
_.append(PcdFromModule
)
1327 elif PcdFromModule
.Phase
== 'PEI':
1328 # overwrite any the same PCD existing, if Phase is PEI
1329 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1330 self
._DynaPcdList
_[Index
] = PcdFromModule
1331 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1332 self
._NonDynaPcdList
_.append(PcdFromModule
)
1333 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1334 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1335 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1336 #The PCD from Binary INF will override the same one from source INF
1337 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1338 PcdFromModule
.Pending
= False
1339 self
._NonDynaPcdList
_.append (PcdFromModule
)
1340 DscModuleSet
= {os
.path
.normpath(ModuleInf
.Path
) for ModuleInf
in self
.Platform
.Modules
}
1341 # add the PCD from modules that listed in FDF but not in DSC to Database
1342 for InfName
in FdfModuleList
:
1343 if InfName
not in DscModuleSet
:
1344 InfClass
= PathClass(InfName
)
1345 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1346 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1347 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1348 # For binary module, if in current arch, we need to list the PCDs into database.
1349 if not M
.IsSupportedArch
:
1351 # Override the module PCD setting by platform setting
1352 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1353 for PcdFromModule
in ModulePcdList
:
1354 PcdFromModule
.IsFromBinaryInf
= True
1355 PcdFromModule
.IsFromDsc
= False
1356 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1357 if PcdFromModule
.Type
not in PCD_DYNAMIC_EX_TYPE_SET
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1358 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1360 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1361 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1362 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1363 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
1364 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1365 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
1366 PcdFromModule
.Phase
= "PEI"
1367 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1368 self
._DynaPcdList
_.append(PcdFromModule
)
1369 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1370 self
._NonDynaPcdList
_.append(PcdFromModule
)
1371 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1372 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1373 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1374 # module & DXE module at a same time.
1375 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1376 # INF file as DynamicEx.
1377 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1378 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1379 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1380 for PcdFromModule
in self
._NonDynaPcdList
_:
1381 # If a PCD is not listed in the DSC file, but binary INF files used by
1382 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1383 # section, AND all source INF files used by this platform the build
1384 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1385 # section, then the tools must NOT add the PCD to the Platform's PCD
1386 # Database; the build must assign the access method for this PCD as
1387 # PcdsPatchableInModule.
1388 if PcdFromModule
not in self
._DynaPcdList
_:
1390 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1391 if PcdFromModule
.IsFromDsc
== False and \
1392 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1393 PcdFromModule
.IsFromBinaryInf
== True and \
1394 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1395 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1396 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1398 # print out error information and break the build, if error found
1399 if len(NoDatumTypePcdList
) > 0:
1400 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1401 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1403 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1404 % NoDatumTypePcdListString
)
1405 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1406 self
._DynamicPcdList
= self
._DynaPcdList
_
1408 # Sort dynamic PCD list to:
1409 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1410 # try to be put header of dynamicd List
1411 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1413 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1415 UnicodePcdArray
= set()
1417 OtherPcdArray
= set()
1419 VpdFile
= VpdInfoFile
.VpdInfoFile()
1420 NeedProcessVpdMapFile
= False
1422 for pcd
in self
.Platform
.Pcds
:
1423 if pcd
not in self
._PlatformPcds
:
1424 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1426 for item
in self
._PlatformPcds
:
1427 if self
._PlatformPcds
[item
].DatumType
and self
._PlatformPcds
[item
].DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1428 self
._PlatformPcds
[item
].DatumType
= TAB_VOID
1430 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1431 for Pcd
in self
._DynamicPcdList
:
1432 # just pick the a value to determine whether is unicode string type
1433 Sku
= Pcd
.SkuInfoList
.values()[0]
1434 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1436 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1437 Pcd
.DatumType
= TAB_VOID
1439 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1440 # if found HII type PCD then insert to right of UnicodeIndex
1441 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1442 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1444 #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer
1445 PcdNvStoreDfBuffer
= VpdPcdDict
.get(("PcdNvStoreDefaultValueBuffer", "gEfiMdeModulePkgTokenSpaceGuid"))
1446 if PcdNvStoreDfBuffer
:
1447 self
.VariableInfo
= self
.CollectVariables(self
._DynamicPcdList
)
1448 vardump
= self
.VariableInfo
.dump()
1450 PcdNvStoreDfBuffer
.DefaultValue
= vardump
1451 for skuname
in PcdNvStoreDfBuffer
.SkuInfoList
:
1452 PcdNvStoreDfBuffer
.SkuInfoList
[skuname
].DefaultValue
= vardump
1453 PcdNvStoreDfBuffer
.MaxDatumSize
= str(len(vardump
.split(",")))
1455 PlatformPcds
= sorted(self
._PlatformPcds
.keys())
1457 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1460 for PcdKey
in PlatformPcds
:
1461 Pcd
= self
._PlatformPcds
[PcdKey
]
1462 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1463 PcdKey
in VpdPcdDict
:
1464 Pcd
= VpdPcdDict
[PcdKey
]
1466 DefaultSku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
1468 PcdValue
= DefaultSku
.DefaultValue
1469 if PcdValue
not in SkuValueMap
:
1470 SkuValueMap
[PcdValue
] = []
1471 VpdFile
.Add(Pcd
, TAB_DEFAULT
, DefaultSku
.VpdOffset
)
1472 SkuValueMap
[PcdValue
].append(DefaultSku
)
1474 for (SkuName
, Sku
) in Pcd
.SkuInfoList
.items():
1475 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1476 PcdValue
= Sku
.DefaultValue
1478 PcdValue
= Pcd
.DefaultValue
1479 if Sku
.VpdOffset
!= '*':
1480 if PcdValue
.startswith("{"):
1482 elif PcdValue
.startswith("L"):
1487 VpdOffset
= int(Sku
.VpdOffset
)
1490 VpdOffset
= int(Sku
.VpdOffset
, 16)
1492 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1493 if VpdOffset
% Alignment
!= 0:
1494 if PcdValue
.startswith("{"):
1495 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1497 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1498 if PcdValue
not in SkuValueMap
:
1499 SkuValueMap
[PcdValue
] = []
1500 VpdFile
.Add(Pcd
, SkuName
, Sku
.VpdOffset
)
1501 SkuValueMap
[PcdValue
].append(Sku
)
1502 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1503 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1504 NeedProcessVpdMapFile
= True
1505 if self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== '':
1506 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1507 "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.")
1509 VpdSkuMap
[PcdKey
] = SkuValueMap
1511 # Fix the PCDs define in VPD PCD section that never referenced by module.
1512 # An example is PCD for signature usage.
1514 for DscPcd
in PlatformPcds
:
1515 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1516 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1517 if not (self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== ''):
1519 for VpdPcd
in VpdFile
._VpdArray
:
1520 # This PCD has been referenced by module
1521 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1522 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1525 # Not found, it should be signature
1527 # just pick the a value to determine whether is unicode string type
1529 SkuObjList
= DscPcdEntry
.SkuInfoList
.items()
1530 DefaultSku
= DscPcdEntry
.SkuInfoList
.get(TAB_DEFAULT
)
1532 defaultindex
= SkuObjList
.index((TAB_DEFAULT
, DefaultSku
))
1533 SkuObjList
[0], SkuObjList
[defaultindex
] = SkuObjList
[defaultindex
], SkuObjList
[0]
1534 for (SkuName
, Sku
) in SkuObjList
:
1535 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1537 # Need to iterate DEC pcd information to get the value & datumtype
1538 for eachDec
in self
.PackageList
:
1539 for DecPcd
in eachDec
.Pcds
:
1540 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1541 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1542 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1543 # Print warning message to let the developer make a determine.
1544 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1545 File
=self
.MetaFile
, \
1546 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1547 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1549 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1550 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1551 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1552 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1553 # Only fix the value while no value provided in DSC file.
1554 if not Sku
.DefaultValue
:
1555 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1557 if DscPcdEntry
not in self
._DynamicPcdList
:
1558 self
._DynamicPcdList
.append(DscPcdEntry
)
1559 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1560 PcdValue
= Sku
.DefaultValue
1562 PcdValue
= DscPcdEntry
.DefaultValue
1563 if Sku
.VpdOffset
!= '*':
1564 if PcdValue
.startswith("{"):
1566 elif PcdValue
.startswith("L"):
1571 VpdOffset
= int(Sku
.VpdOffset
)
1574 VpdOffset
= int(Sku
.VpdOffset
, 16)
1576 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1577 if VpdOffset
% Alignment
!= 0:
1578 if PcdValue
.startswith("{"):
1579 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1581 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1582 if PcdValue
not in SkuValueMap
:
1583 SkuValueMap
[PcdValue
] = []
1584 VpdFile
.Add(DscPcdEntry
, SkuName
, Sku
.VpdOffset
)
1585 SkuValueMap
[PcdValue
].append(Sku
)
1586 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1587 NeedProcessVpdMapFile
= True
1588 if DscPcdEntry
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
1589 UnicodePcdArray
.add(DscPcdEntry
)
1590 elif len(Sku
.VariableName
) > 0:
1591 HiiPcdArray
.add(DscPcdEntry
)
1593 OtherPcdArray
.add(DscPcdEntry
)
1595 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1596 VpdSkuMap
[DscPcd
] = SkuValueMap
1597 if (self
.Platform
.FlashDefinition
is None or self
.Platform
.FlashDefinition
== '') and \
1598 VpdFile
.GetCount() != 0:
1599 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1600 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1602 if VpdFile
.GetCount() != 0:
1604 self
.FixVpdOffset(VpdFile
)
1606 self
.FixVpdOffset(self
.UpdateNVStoreMaxSize(VpdFile
))
1608 # Process VPD map file generated by third party BPDG tool
1609 if NeedProcessVpdMapFile
:
1610 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
1611 if os
.path
.exists(VpdMapFilePath
):
1612 VpdFile
.Read(VpdMapFilePath
)
1615 for pcd
in VpdSkuMap
:
1616 vpdinfo
= VpdFile
.GetVpdInfo(pcd
)
1618 # just pick the a value to determine whether is unicode string type
1620 for pcdvalue
in VpdSkuMap
[pcd
]:
1621 for sku
in VpdSkuMap
[pcd
][pcdvalue
]:
1622 for item
in vpdinfo
:
1623 if item
[2] == pcdvalue
:
1624 sku
.VpdOffset
= item
[1]
1626 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1628 # Delete the DynamicPcdList At the last time enter into this function
1629 for Pcd
in self
._DynamicPcdList
:
1630 # just pick the a value to determine whether is unicode string type
1631 Sku
= Pcd
.SkuInfoList
.values()[0]
1632 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1634 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1635 Pcd
.DatumType
= TAB_VOID
1637 PcdValue
= Sku
.DefaultValue
1638 if Pcd
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
1639 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1640 UnicodePcdArray
.add(Pcd
)
1641 elif len(Sku
.VariableName
) > 0:
1642 # if found HII type PCD then insert to right of UnicodeIndex
1643 HiiPcdArray
.add(Pcd
)
1645 OtherPcdArray
.add(Pcd
)
1646 del self
._DynamicPcdList
[:]
1647 self
._DynamicPcdList
.extend(list(UnicodePcdArray
))
1648 self
._DynamicPcdList
.extend(list(HiiPcdArray
))
1649 self
._DynamicPcdList
.extend(list(OtherPcdArray
))
1650 allskuset
= [(SkuName
, Sku
.SkuId
) for pcd
in self
._DynamicPcdList
for (SkuName
, Sku
) in pcd
.SkuInfoList
.items()]
1651 for pcd
in self
._DynamicPcdList
:
1652 if len(pcd
.SkuInfoList
) == 1:
1653 for (SkuName
, SkuId
) in allskuset
:
1654 if type(SkuId
) in (str, unicode) and eval(SkuId
) == 0 or SkuId
== 0:
1656 pcd
.SkuInfoList
[SkuName
] = copy
.deepcopy(pcd
.SkuInfoList
[TAB_DEFAULT
])
1657 pcd
.SkuInfoList
[SkuName
].SkuId
= SkuId
1658 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1660 def FixVpdOffset(self
, VpdFile
):
1661 FvPath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
1662 if not os
.path
.exists(FvPath
):
1666 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1668 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1670 if VpdFile
.Write(VpdFilePath
):
1671 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1673 for ToolDef
in self
.ToolDefinition
.values():
1674 if TAB_GUID
in ToolDef
and ToolDef
[TAB_GUID
] == self
.Platform
.VpdToolGuid
:
1675 if "PATH" not in ToolDef
:
1676 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1677 BPDGToolName
= ToolDef
["PATH"]
1679 # Call third party GUID BPDG tool.
1680 if BPDGToolName
is not None:
1681 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1683 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.")
1685 ## Return the platform build data object
1686 def _GetPlatform(self
):
1687 if self
._Platform
is None:
1688 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1689 return self
._Platform
1691 ## Return platform name
1693 return self
.Platform
.PlatformName
1695 ## Return the meta file GUID
1697 return self
.Platform
.Guid
1699 ## Return the platform version
1700 def _GetVersion(self
):
1701 return self
.Platform
.Version
1703 ## Return the FDF file name
1704 def _GetFdfFile(self
):
1705 if self
._FdfFile
is None:
1706 if self
.Workspace
.FdfFile
!= "":
1707 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1710 return self
._FdfFile
1712 ## Return the build output directory platform specifies
1713 def _GetOutputDir(self
):
1714 return self
.Platform
.OutputDirectory
1716 ## Return the directory to store all intermediate and final files built
1717 def _GetBuildDir(self
):
1718 if self
._BuildDir
is None:
1719 if os
.path
.isabs(self
.OutputDir
):
1720 self
._BuildDir
= path
.join(
1721 path
.abspath(self
.OutputDir
),
1722 self
.BuildTarget
+ "_" + self
.ToolChain
,
1725 self
._BuildDir
= path
.join(
1728 self
.BuildTarget
+ "_" + self
.ToolChain
,
1730 GlobalData
.gBuildDirectory
= self
._BuildDir
1731 return self
._BuildDir
1733 ## Return directory of platform makefile
1735 # @retval string Makefile directory
1737 def _GetMakeFileDir(self
):
1738 if self
._MakeFileDir
is None:
1739 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1740 return self
._MakeFileDir
1742 ## Return build command string
1744 # @retval string Build command string
1746 def _GetBuildCommand(self
):
1747 if self
._BuildCommand
is None:
1748 self
._BuildCommand
= []
1749 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1750 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1751 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1752 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1754 self
._BuildCommand
+= SplitOption(NewOption
)
1755 if "MAKE" in self
.EdkIIBuildOption
:
1756 if "FLAGS" in self
.EdkIIBuildOption
["MAKE"]:
1757 Flags
= self
.EdkIIBuildOption
["MAKE"]["FLAGS"]
1758 if Flags
.startswith('='):
1759 self
._BuildCommand
= [self
._BuildCommand
[0]] + [Flags
[1:]]
1761 self
._BuildCommand
.append(Flags
)
1762 return self
._BuildCommand
1764 ## Get tool chain definition
1766 # Get each tool defition for given tool chain from tools_def.txt and platform
1768 def _GetToolDefinition(self
):
1769 if self
._ToolDefinitions
is None:
1770 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1771 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1772 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1773 ExtraData
="[%s]" % self
.MetaFile
)
1774 self
._ToolDefinitions
= {}
1776 for Def
in ToolDefinition
:
1777 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1778 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1781 Value
= ToolDefinition
[Def
]
1782 # don't record the DLL
1784 DllPathList
.add(Value
)
1787 if Tool
not in self
._ToolDefinitions
:
1788 self
._ToolDefinitions
[Tool
] = {}
1789 self
._ToolDefinitions
[Tool
][Attr
] = Value
1792 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1793 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1794 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1795 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1797 for Tool
in self
._ToolDefinitions
:
1798 for Attr
in self
._ToolDefinitions
[Tool
]:
1799 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1800 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1801 # check if override is indicated
1802 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1803 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1806 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1808 Value
= self
.BuildOption
[Tool
][Attr
]
1811 # Don't put MAKE definition in the file
1813 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1815 # Don't put MAKE definition in the file
1820 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1823 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1824 for DllPath
in DllPathList
:
1825 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1826 os
.environ
["MAKE_FLAGS"] = MakeFlags
1828 return self
._ToolDefinitions
1830 ## Return the paths of tools
1831 def _GetToolDefFile(self
):
1832 if self
._ToolDefFile
is None:
1833 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1834 return self
._ToolDefFile
1836 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1837 def _GetToolChainFamily(self
):
1838 if self
._ToolChainFamily
is None:
1839 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1840 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1841 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1842 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1843 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1845 self
._ToolChainFamily
= "MSFT"
1847 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1848 return self
._ToolChainFamily
1850 def _GetBuildRuleFamily(self
):
1851 if self
._BuildRuleFamily
is None:
1852 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1853 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1854 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1855 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1856 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1858 self
._BuildRuleFamily
= "MSFT"
1860 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1861 return self
._BuildRuleFamily
1863 ## Return the build options specific for all modules in this platform
1864 def _GetBuildOptions(self
):
1865 if self
._BuildOption
is None:
1866 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1867 return self
._BuildOption
1869 ## Return the build options specific for EDK modules in this platform
1870 def _GetEdkBuildOptions(self
):
1871 if self
._EdkBuildOption
is None:
1872 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1873 return self
._EdkBuildOption
1875 ## Return the build options specific for EDKII modules in this platform
1876 def _GetEdkIIBuildOptions(self
):
1877 if self
._EdkIIBuildOption
is None:
1878 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1879 return self
._EdkIIBuildOption
1881 ## Parse build_rule.txt in Conf Directory.
1883 # @retval BuildRule object
1885 def _GetBuildRule(self
):
1886 if self
._BuildRule
is None:
1887 BuildRuleFile
= None
1888 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1889 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1890 if not BuildRuleFile
:
1891 BuildRuleFile
= gDefaultBuildRuleFile
1892 self
._BuildRule
= BuildRule(BuildRuleFile
)
1893 if self
._BuildRule
._FileVersion
== "":
1894 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
1896 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1897 # If Build Rule's version is less than the version number required by the tools, halting the build.
1898 EdkLogger
.error("build", AUTOGEN_ERROR
,
1899 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])"\
1900 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1902 return self
._BuildRule
1904 ## Summarize the packages used by modules in this platform
1905 def _GetPackageList(self
):
1906 if self
._PackageList
is None:
1907 self
._PackageList
= set()
1908 for La
in self
.LibraryAutoGenList
:
1909 self
._PackageList
.update(La
.DependentPackageList
)
1910 for Ma
in self
.ModuleAutoGenList
:
1911 self
._PackageList
.update(Ma
.DependentPackageList
)
1912 #Collect package set information from INF of FDF
1914 for ModuleFile
in self
._AsBuildModuleList
:
1915 if ModuleFile
in self
.Platform
.Modules
:
1917 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1918 PkgSet
.update(ModuleData
.Packages
)
1919 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
1920 return self
._PackageList
1922 def _GetNonDynamicPcdDict(self
):
1923 if self
._NonDynamicPcdDict
:
1924 return self
._NonDynamicPcdDict
1925 for Pcd
in self
.NonDynamicPcdList
:
1926 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1927 return self
._NonDynamicPcdDict
1929 ## Get list of non-dynamic PCDs
1930 def _GetNonDynamicPcdList(self
):
1931 if self
._NonDynamicPcdList
is None:
1932 self
.CollectPlatformDynamicPcds()
1933 return self
._NonDynamicPcdList
1935 ## Get list of dynamic PCDs
1936 def _GetDynamicPcdList(self
):
1937 if self
._DynamicPcdList
is None:
1938 self
.CollectPlatformDynamicPcds()
1939 return self
._DynamicPcdList
1941 ## Generate Token Number for all PCD
1942 def _GetPcdTokenNumbers(self
):
1943 if self
._PcdTokenNumber
is None:
1944 self
._PcdTokenNumber
= OrderedDict()
1947 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1951 # TokenNumber 0 ~ 10
1953 # TokeNumber 11 ~ 20
1955 for Pcd
in self
.DynamicPcdList
:
1956 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
1957 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1958 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1961 for Pcd
in self
.DynamicPcdList
:
1962 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1963 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1964 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1967 for Pcd
in self
.DynamicPcdList
:
1968 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
1969 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1970 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1973 for Pcd
in self
.DynamicPcdList
:
1974 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1975 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1976 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1979 for Pcd
in self
.NonDynamicPcdList
:
1980 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1982 return self
._PcdTokenNumber
1984 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
1985 def _GetAutoGenObjectList(self
):
1986 self
._ModuleAutoGenList
= []
1987 self
._LibraryAutoGenList
= []
1988 for ModuleFile
in self
.Platform
.Modules
:
1997 if Ma
not in self
._ModuleAutoGenList
:
1998 self
._ModuleAutoGenList
.append(Ma
)
1999 for La
in Ma
.LibraryAutoGenList
:
2000 if La
not in self
._LibraryAutoGenList
:
2001 self
._LibraryAutoGenList
.append(La
)
2002 if Ma
not in La
.ReferenceModules
:
2003 La
.ReferenceModules
.append(Ma
)
2005 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
2006 def _GetModuleAutoGenList(self
):
2007 if self
._ModuleAutoGenList
is None:
2008 self
._GetAutoGenObjectList
()
2009 return self
._ModuleAutoGenList
2011 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
2012 def _GetLibraryAutoGenList(self
):
2013 if self
._LibraryAutoGenList
is None:
2014 self
._GetAutoGenObjectList
()
2015 return self
._LibraryAutoGenList
2017 ## Test if a module is supported by the platform
2019 # An error will be raised directly if the module or its arch is not supported
2020 # by the platform or current configuration
2022 def ValidModule(self
, Module
):
2023 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
2024 or Module
in self
._AsBuildModuleList
2026 ## Resolve the library classes in a module to library instances
2028 # This method will not only resolve library classes but also sort the library
2029 # instances according to the dependency-ship.
2031 # @param Module The module from which the library classes will be resolved
2033 # @retval library_list List of library instances sorted
2035 def ApplyLibraryInstance(self
, Module
):
2036 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
2037 if str(Module
) not in self
.Platform
.Modules
:
2040 return GetModuleLibInstances(Module
,
2049 ## Override PCD setting (type, value, ...)
2051 # @param ToPcd The PCD to be overrided
2052 # @param FromPcd The PCD overrideing from
2054 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
="", Msg
="", Library
=""):
2056 # in case there's PCDs coming from FDF file, which have no type given.
2057 # at this point, ToPcd.Type has the type found from dependent
2060 TokenCName
= ToPcd
.TokenCName
2061 for PcdItem
in GlobalData
.MixedPcd
:
2062 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2063 TokenCName
= PcdItem
[0]
2065 if FromPcd
is not None:
2066 if ToPcd
.Pending
and FromPcd
.Type
:
2067 ToPcd
.Type
= FromPcd
.Type
2068 elif ToPcd
.Type
and FromPcd
.Type\
2069 and ToPcd
.Type
!= FromPcd
.Type
and ToPcd
.Type
in FromPcd
.Type
:
2070 if ToPcd
.Type
.strip() == TAB_PCDS_DYNAMIC_EX
:
2071 ToPcd
.Type
= FromPcd
.Type
2072 elif ToPcd
.Type
and FromPcd
.Type \
2073 and ToPcd
.Type
!= FromPcd
.Type
:
2075 Module
= str(Module
) + " 's library file (" + str(Library
) + ")"
2076 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2077 ExtraData
="%s.%s is used as [%s] in module %s, but as [%s] in %s."\
2078 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2079 ToPcd
.Type
, Module
, FromPcd
.Type
, Msg
),
2082 if FromPcd
.MaxDatumSize
:
2083 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2084 ToPcd
.MaxSizeUserSet
= FromPcd
.MaxDatumSize
2085 if FromPcd
.DefaultValue
:
2086 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2087 if FromPcd
.TokenValue
:
2088 ToPcd
.TokenValue
= FromPcd
.TokenValue
2089 if FromPcd
.DatumType
:
2090 ToPcd
.DatumType
= FromPcd
.DatumType
2091 if FromPcd
.SkuInfoList
:
2092 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2093 # Add Flexible PCD format parse
2094 if ToPcd
.DefaultValue
:
2096 ToPcd
.DefaultValue
= ValueExpressionEx(ToPcd
.DefaultValue
, ToPcd
.DatumType
, self
._GuidDict
)(True)
2097 except BadExpression
as Value
:
2098 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %(ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
, ToPcd
.DefaultValue
, Value
),
2101 # check the validation of datum
2102 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2104 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2105 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2106 ToPcd
.validateranges
= FromPcd
.validateranges
2107 ToPcd
.validlists
= FromPcd
.validlists
2108 ToPcd
.expressions
= FromPcd
.expressions
2110 if FromPcd
is not None and ToPcd
.DatumType
== TAB_VOID
and not ToPcd
.MaxDatumSize
:
2111 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2112 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2113 Value
= ToPcd
.DefaultValue
2115 ToPcd
.MaxDatumSize
= '1'
2116 elif Value
[0] == 'L':
2117 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2118 elif Value
[0] == '{':
2119 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2121 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2123 # apply default SKU for dynamic PCDS if specified one is not available
2124 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_SET
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
) \
2125 and not ToPcd
.SkuInfoList
:
2126 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2127 SkuName
= self
.Platform
.SkuName
2129 SkuName
= TAB_DEFAULT
2130 ToPcd
.SkuInfoList
= {
2131 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
][0], '', '', '', '', '', ToPcd
.DefaultValue
)
2134 ## Apply PCD setting defined platform to a module
2136 # @param Module The module from which the PCD setting will be overrided
2138 # @retval PCD_list The list PCDs with settings from platform
2140 def ApplyPcdSetting(self
, Module
, Pcds
, Library
=""):
2141 # for each PCD in module
2142 for Name
, Guid
in Pcds
:
2143 PcdInModule
= Pcds
[Name
, Guid
]
2144 # find out the PCD setting in platform
2145 if (Name
, Guid
) in self
.Platform
.Pcds
:
2146 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2148 PcdInPlatform
= None
2149 # then override the settings if any
2150 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
, Msg
="DSC PCD sections", Library
=Library
)
2151 # resolve the VariableGuid value
2152 for SkuId
in PcdInModule
.SkuInfoList
:
2153 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2154 if Sku
.VariableGuid
== '': continue
2155 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
2156 if Sku
.VariableGuidValue
is None:
2157 PackageList
= "\n\t".join(str(P
) for P
in self
.PackageList
)
2160 RESOURCE_NOT_AVAILABLE
,
2161 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2162 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2163 % (Guid
, Name
, str(Module
)),
2167 # override PCD settings with module specific setting
2168 if Module
in self
.Platform
.Modules
:
2169 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2170 for Key
in PlatformModule
.Pcds
:
2175 elif Key
in GlobalData
.MixedPcd
:
2176 for PcdItem
in GlobalData
.MixedPcd
[Key
]:
2178 ToPcd
= Pcds
[PcdItem
]
2182 self
._OverridePcd
(ToPcd
, PlatformModule
.Pcds
[Key
], Module
, Msg
="DSC Components Module scoped PCD section", Library
=Library
)
2183 # use PCD value to calculate the MaxDatumSize when it is not specified
2184 for Name
, Guid
in Pcds
:
2185 Pcd
= Pcds
[Name
, Guid
]
2186 if Pcd
.DatumType
== TAB_VOID
and not Pcd
.MaxDatumSize
:
2187 Pcd
.MaxSizeUserSet
= None
2188 Value
= Pcd
.DefaultValue
2190 Pcd
.MaxDatumSize
= '1'
2191 elif Value
[0] == 'L':
2192 Pcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2193 elif Value
[0] == '{':
2194 Pcd
.MaxDatumSize
= str(len(Value
.split(',')))
2196 Pcd
.MaxDatumSize
= str(len(Value
) - 1)
2197 return Pcds
.values()
2199 ## Resolve library names to library modules
2201 # (for Edk.x modules)
2203 # @param Module The module from which the library names will be resolved
2205 # @retval library_list The list of library modules
2207 def ResolveLibraryReference(self
, Module
):
2208 EdkLogger
.verbose("")
2209 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2210 LibraryConsumerList
= [Module
]
2212 # "CompilerStub" is a must for Edk modules
2213 if Module
.Libraries
:
2214 Module
.Libraries
.append("CompilerStub")
2216 while len(LibraryConsumerList
) > 0:
2217 M
= LibraryConsumerList
.pop()
2218 for LibraryName
in M
.Libraries
:
2219 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2221 for Key
in self
.Platform
.LibraryClasses
.data
:
2222 if LibraryName
.upper() == Key
.upper():
2223 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2226 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2227 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2230 if Library
not in LibraryList
:
2231 LibraryList
.append(Library
)
2232 LibraryConsumerList
.append(Library
)
2233 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2236 ## Calculate the priority value of the build option
2238 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2240 # @retval Value Priority value based on the priority list.
2242 def CalculatePriorityValue(self
, Key
):
2243 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2244 PriorityValue
= 0x11111
2246 PriorityValue
&= 0x01111
2247 if ToolChain
== "*":
2248 PriorityValue
&= 0x10111
2250 PriorityValue
&= 0x11011
2251 if CommandType
== "*":
2252 PriorityValue
&= 0x11101
2254 PriorityValue
&= 0x11110
2256 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2259 ## Expand * in build option key
2261 # @param Options Options to be expanded
2263 # @retval options Options expanded
2265 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2272 # Construct a list contain the build options which need override.
2276 # Key[0] -- tool family
2277 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2279 if (Key
[0] == self
.BuildRuleFamily
and
2280 (ModuleStyle
is None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2281 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2282 if (Target
== self
.BuildTarget
or Target
== "*") and\
2283 (ToolChain
== self
.ToolChain
or ToolChain
== "*") and\
2284 (Arch
== self
.Arch
or Arch
== "*") and\
2285 Options
[Key
].startswith("="):
2287 if OverrideList
.get(Key
[1]) is not None:
2288 OverrideList
.pop(Key
[1])
2289 OverrideList
[Key
[1]] = Options
[Key
]
2292 # Use the highest priority value.
2294 if (len(OverrideList
) >= 2):
2295 KeyList
= OverrideList
.keys()
2296 for Index
in range(len(KeyList
)):
2297 NowKey
= KeyList
[Index
]
2298 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2299 for Index1
in range(len(KeyList
) - Index
- 1):
2300 NextKey
= KeyList
[Index1
+ Index
+ 1]
2302 # Compare two Key, if one is included by another, choose the higher priority one
2304 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2305 if (Target1
== Target2
or Target1
== "*" or Target2
== "*") and\
2306 (ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*") and\
2307 (Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*") and\
2308 (CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*") and\
2309 (Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*"):
2311 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2312 if Options
.get((self
.BuildRuleFamily
, NextKey
)) is not None:
2313 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2315 if Options
.get((self
.BuildRuleFamily
, NowKey
)) is not None:
2316 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2319 if ModuleStyle
is not None and len (Key
) > 2:
2320 # Check Module style is EDK or EDKII.
2321 # Only append build option for the matched style module.
2322 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2324 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2327 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2328 # if tool chain family doesn't match, skip it
2329 if Tool
in self
.ToolDefinition
and Family
!= "":
2330 FamilyIsNull
= False
2331 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2332 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2334 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2337 # expand any wildcard
2338 if Target
== "*" or Target
== self
.BuildTarget
:
2339 if Tag
== "*" or Tag
== self
.ToolChain
:
2340 if Arch
== "*" or Arch
== self
.Arch
:
2341 if Tool
not in BuildOptions
:
2342 BuildOptions
[Tool
] = {}
2343 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2344 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2346 # append options for the same tool except PATH
2348 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2350 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2351 # Build Option Family has been checked, which need't to be checked again for family.
2352 if FamilyMatch
or FamilyIsNull
:
2356 if ModuleStyle
is not None and len (Key
) > 2:
2357 # Check Module style is EDK or EDKII.
2358 # Only append build option for the matched style module.
2359 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2361 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2364 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2365 # if tool chain family doesn't match, skip it
2366 if Tool
not in self
.ToolDefinition
or Family
== "":
2368 # option has been added before
2369 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2372 # expand any wildcard
2373 if Target
== "*" or Target
== self
.BuildTarget
:
2374 if Tag
== "*" or Tag
== self
.ToolChain
:
2375 if Arch
== "*" or Arch
== self
.Arch
:
2376 if Tool
not in BuildOptions
:
2377 BuildOptions
[Tool
] = {}
2378 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2379 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2381 # append options for the same tool except PATH
2383 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2385 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2388 ## Append build options in platform to a module
2390 # @param Module The module to which the build options will be appened
2392 # @retval options The options appended with build options in platform
2394 def ApplyBuildOption(self
, Module
):
2395 # Get the different options for the different style module
2396 if Module
.AutoGenVersion
< 0x00010005:
2397 PlatformOptions
= self
.EdkBuildOption
2398 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2400 PlatformOptions
= self
.EdkIIBuildOption
2401 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2402 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2403 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2404 if Module
in self
.Platform
.Modules
:
2405 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2406 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2408 PlatformModuleOptions
= {}
2410 BuildRuleOrder
= None
2411 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2412 for Tool
in Options
:
2413 for Attr
in Options
[Tool
]:
2414 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2415 BuildRuleOrder
= Options
[Tool
][Attr
]
2417 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2418 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2419 self
.ToolDefinition
.keys())
2420 BuildOptions
= defaultdict(lambda: defaultdict(str))
2421 for Tool
in AllTools
:
2422 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2423 if Tool
not in Options
:
2425 for Attr
in Options
[Tool
]:
2427 # Do not generate it in Makefile
2429 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2431 Value
= Options
[Tool
][Attr
]
2432 # check if override is indicated
2433 if Value
.startswith('='):
2434 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
[1:])
2437 BuildOptions
[Tool
][Attr
] += " " + mws
.handleWsMacro(Value
)
2439 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
)
2441 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
is not None:
2443 # Override UNI flag only for EDK module.
2445 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2446 return BuildOptions
, BuildRuleOrder
2448 Platform
= property(_GetPlatform
)
2449 Name
= property(_GetName
)
2450 Guid
= property(_GetGuid
)
2451 Version
= property(_GetVersion
)
2453 OutputDir
= property(_GetOutputDir
)
2454 BuildDir
= property(_GetBuildDir
)
2455 MakeFileDir
= property(_GetMakeFileDir
)
2456 FdfFile
= property(_GetFdfFile
)
2458 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2459 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2460 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2461 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2462 PackageList
= property(_GetPackageList
)
2464 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2465 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2466 ToolChainFamily
= property(_GetToolChainFamily
)
2467 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2468 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2469 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2470 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2472 BuildCommand
= property(_GetBuildCommand
)
2473 BuildRule
= property(_GetBuildRule
)
2474 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2475 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2476 GenFdsCommand
= property(_GenFdsCommand
)
2479 # extend lists contained in a dictionary with lists stored in another dictionary
2480 # if CopyToDict is not derived from DefaultDict(list) then this may raise exception
2482 def ExtendCopyDictionaryLists(CopyToDict
, CopyFromDict
):
2483 for Key
in CopyFromDict
:
2484 CopyToDict
[Key
].extend(CopyFromDict
[Key
])
2486 # Create a directory specified by a set of path elements and return the full path
2487 def _MakeDir(PathList
):
2488 RetVal
= path
.join(*PathList
)
2489 CreateDirectory(RetVal
)
2492 ## ModuleAutoGen class
2494 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2495 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2496 # to the [depex] section in module's inf file.
2498 class ModuleAutoGen(AutoGen
):
2499 # call super().__init__ then call the worker function with different parameter count
2500 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2501 if not hasattr(self
, "_Init"):
2502 super(ModuleAutoGen
, self
).__init
__(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2503 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
)
2506 ## Cache the timestamps of metafiles of every module in a class attribute
2510 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2511 # check if this module is employed by active platform
2512 if not PlatformAutoGen(Workspace
, args
[0], Target
, Toolchain
, Arch
).ValidModule(MetaFile
):
2513 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2516 return super(ModuleAutoGen
, cls
).__new
__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2518 ## Initialize ModuleAutoGen
2520 # @param Workspace EdkIIWorkspaceBuild object
2521 # @param ModuleFile The path of module file
2522 # @param Target Build target (DEBUG, RELEASE)
2523 # @param Toolchain Name of tool chain
2524 # @param Arch The arch the module supports
2525 # @param PlatformFile Platform meta-file
2527 def _InitWorker(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2528 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2529 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2531 self
.Workspace
= Workspace
2532 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2533 self
._GuidDict
= Workspace
._GuidDict
2534 self
.MetaFile
= ModuleFile
2535 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2537 self
.SourceDir
= self
.MetaFile
.SubDir
2538 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2540 self
.SourceOverrideDir
= None
2541 # use overrided path defined in DSC file
2542 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2543 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2545 self
.ToolChain
= Toolchain
2546 self
.BuildTarget
= Target
2548 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2549 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2551 self
.IsCodeFileCreated
= False
2552 self
.IsAsBuiltInfCreated
= False
2553 self
.DepexGenerated
= False
2555 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2556 self
.BuildRuleOrder
= None
2559 self
._PcdComments
= OrderedListDict()
2560 self
._GuidComments
= OrderedListDict()
2561 self
._ProtocolComments
= OrderedListDict()
2562 self
._PpiComments
= OrderedListDict()
2563 self
._BuildTargets
= None
2564 self
._IntroBuildTargetList
= None
2565 self
._FinalBuildTargetList
= None
2566 self
._FileTypes
= None
2568 self
.AutoGenDepSet
= set()
2569 self
.ReferenceModules
= []
2574 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2576 # Get FixedAtBuild Pcds of this Module
2578 def FixedAtBuildPcds(self
):
2580 for Pcd
in self
.ModulePcdList
:
2581 if Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
2583 if Pcd
not in RetVal
:
2588 def FixedVoidTypePcds(self
):
2590 for Pcd
in self
.FixedAtBuildPcds
:
2591 if Pcd
.DatumType
== TAB_VOID
:
2592 if '{}.{}'.format(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in RetVal
:
2593 RetVal
['{}.{}'.format(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)] = Pcd
.DefaultValue
2597 def UniqueBaseName(self
):
2598 BaseName
= self
.Name
2599 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2600 if Module
.MetaFile
== self
.MetaFile
:
2602 if Module
.Name
== self
.Name
:
2603 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2604 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2605 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2606 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2609 # Macros could be used in build_rule.txt (also Makefile)
2612 return OrderedDict((
2613 ("WORKSPACE" ,self
.WorkspaceDir
),
2614 ("MODULE_NAME" ,self
.Name
),
2615 ("MODULE_NAME_GUID" ,self
.UniqueBaseName
),
2616 ("MODULE_GUID" ,self
.Guid
),
2617 ("MODULE_VERSION" ,self
.Version
),
2618 ("MODULE_TYPE" ,self
.ModuleType
),
2619 ("MODULE_FILE" ,str(self
.MetaFile
)),
2620 ("MODULE_FILE_BASE_NAME" ,self
.MetaFile
.BaseName
),
2621 ("MODULE_RELATIVE_DIR" ,self
.SourceDir
),
2622 ("MODULE_DIR" ,self
.SourceDir
),
2623 ("BASE_NAME" ,self
.Name
),
2624 ("ARCH" ,self
.Arch
),
2625 ("TOOLCHAIN" ,self
.ToolChain
),
2626 ("TOOLCHAIN_TAG" ,self
.ToolChain
),
2627 ("TOOL_CHAIN_TAG" ,self
.ToolChain
),
2628 ("TARGET" ,self
.BuildTarget
),
2629 ("BUILD_DIR" ,self
.PlatformInfo
.BuildDir
),
2630 ("BIN_DIR" ,os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)),
2631 ("LIB_DIR" ,os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)),
2632 ("MODULE_BUILD_DIR" ,self
.BuildDir
),
2633 ("OUTPUT_DIR" ,self
.OutputDir
),
2634 ("DEBUG_DIR" ,self
.DebugDir
),
2635 ("DEST_DIR_OUTPUT" ,self
.OutputDir
),
2636 ("DEST_DIR_DEBUG" ,self
.DebugDir
),
2637 ("PLATFORM_NAME" ,self
.PlatformInfo
.Name
),
2638 ("PLATFORM_GUID" ,self
.PlatformInfo
.Guid
),
2639 ("PLATFORM_VERSION" ,self
.PlatformInfo
.Version
),
2640 ("PLATFORM_RELATIVE_DIR" ,self
.PlatformInfo
.SourceDir
),
2641 ("PLATFORM_DIR" ,mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)),
2642 ("PLATFORM_OUTPUT_DIR" ,self
.PlatformInfo
.OutputDir
),
2643 ("FFS_OUTPUT_DIR" ,self
.FfsOutputDir
)
2646 ## Return the module build data object
2649 return self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2651 ## Return the module name
2654 return self
.Module
.BaseName
2656 ## Return the module DxsFile if exist
2659 return self
.Module
.DxsFile
2661 ## Return the module meta-file GUID
2665 # To build same module more than once, the module path with FILE_GUID overridden has
2666 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2667 # in DSC. The overridden GUID can be retrieved from file name
2669 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2671 # Length of GUID is 36
2673 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2674 return self
.Module
.Guid
2676 ## Return the module version
2679 return self
.Module
.Version
2681 ## Return the module type
2683 def ModuleType(self
):
2684 return self
.Module
.ModuleType
2686 ## Return the component type (for Edk.x style of module)
2688 def ComponentType(self
):
2689 return self
.Module
.ComponentType
2691 ## Return the build type
2693 def BuildType(self
):
2694 return self
.Module
.BuildType
2696 ## Return the PCD_IS_DRIVER setting
2698 def PcdIsDriver(self
):
2699 return self
.Module
.PcdIsDriver
2701 ## Return the autogen version, i.e. module meta-file version
2703 def AutoGenVersion(self
):
2704 return self
.Module
.AutoGenVersion
2706 ## Check if the module is library or not
2708 def IsLibrary(self
):
2709 return bool(self
.Module
.LibraryClass
)
2711 ## Check if the module is binary module or not
2713 def IsBinaryModule(self
):
2714 return self
.Module
.IsBinaryModule
2716 ## Return the directory to store intermediate files of the module
2720 self
.PlatformInfo
.BuildDir
,
2723 self
.MetaFile
.BaseName
2726 ## Return the directory to store the intermediate object files of the mdoule
2728 def OutputDir(self
):
2729 return _MakeDir((self
.BuildDir
, "OUTPUT"))
2731 ## Return the directory path to store ffs file
2733 def FfsOutputDir(self
):
2734 if GlobalData
.gFdfParser
:
2735 return path
.join(self
.PlatformInfo
.BuildDir
, TAB_FV_DIRECTORY
, "Ffs", self
.Guid
+ self
.Name
)
2738 ## Return the directory to store auto-gened source files of the mdoule
2741 return _MakeDir((self
.BuildDir
, "DEBUG"))
2743 ## Return the path of custom file
2745 def CustomMakefile(self
):
2747 for Type
in self
.Module
.CustomMakefile
:
2748 MakeType
= gMakeTypeMap
[Type
] if Type
in gMakeTypeMap
else 'nmake'
2749 if self
.SourceOverrideDir
is not None:
2750 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2751 if not os
.path
.exists(File
):
2752 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2754 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2755 RetVal
[MakeType
] = File
2758 ## Return the directory of the makefile
2760 # @retval string The directory string of module's makefile
2763 def MakeFileDir(self
):
2764 return self
.BuildDir
2766 ## Return build command string
2768 # @retval string Build command string
2771 def BuildCommand(self
):
2772 return self
.PlatformInfo
.BuildCommand
2774 ## Get object list of all packages the module and its dependent libraries belong to
2776 # @retval list The list of package object
2779 def DerivedPackageList(self
):
2781 for M
in [self
.Module
] + self
.DependentLibraryList
:
2782 for Package
in M
.Packages
:
2783 if Package
in PackageList
:
2785 PackageList
.append(Package
)
2788 ## Get the depex string
2790 # @return : a string contain all depex expresion.
2791 def _GetDepexExpresionString(self
):
2794 ## DPX_SOURCE IN Define section.
2795 if self
.Module
.DxsFile
:
2797 for M
in [self
.Module
] + self
.DependentLibraryList
:
2798 Filename
= M
.MetaFile
.Path
2799 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2800 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2801 for DepexExpresion
in DepexExpresionList
:
2802 for key
in DepexExpresion
:
2803 Arch
, ModuleType
= key
2804 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
2805 # the type of build module is USER_DEFINED.
2806 # All different DEPEX section tags would be copied into the As Built INF file
2807 # and there would be separate DEPEX section tags
2808 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2809 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2810 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2812 if Arch
.upper() == TAB_ARCH_COMMON
or \
2813 (Arch
.upper() == self
.Arch
.upper() and \
2814 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2815 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2817 #the type of build module is USER_DEFINED.
2818 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2819 for Depex
in DepexList
:
2821 DepexStr
+= '[Depex.%s.%s]\n' % key
2822 DepexStr
+= '\n'.join('# '+ val
for val
in Depex
[key
])
2825 return '[Depex.%s]\n' % self
.Arch
2828 #the type of build module not is USER_DEFINED.
2830 for Depex
in DepexList
:
2835 for D
in Depex
.values():
2836 DepexStr
+= ' '.join(val
for val
in D
)
2837 Index
= DepexStr
.find('END')
2838 if Index
> -1 and Index
== len(DepexStr
) - 3:
2839 DepexStr
= DepexStr
[:-3]
2840 DepexStr
= DepexStr
.strip()
2843 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
2845 return '[Depex.%s]\n' % self
.Arch
2846 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
2848 ## Merge dependency expression
2850 # @retval list The token list of the dependency expression after parsed
2853 def DepexList(self
):
2854 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2859 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2861 for M
in [self
.Module
] + self
.DependentLibraryList
:
2863 for D
in M
.Depex
[self
.Arch
, self
.ModuleType
]:
2865 DepexList
.append('AND')
2866 DepexList
.append('(')
2867 #replace D with value if D is FixedAtBuild PCD
2871 NewList
.append(item
)
2873 if item
not in self
._FixedPcdVoidTypeDict
:
2874 EdkLogger
.error("build", FORMAT_INVALID
, "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type in the module.".format(item
))
2876 Value
= self
._FixedPcdVoidTypeDict
[item
]
2877 if len(Value
.split(',')) != 16:
2878 EdkLogger
.error("build", FORMAT_INVALID
,
2879 "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type and 16 bytes in the module.".format(item
))
2880 NewList
.append(Value
)
2881 DepexList
.extend(NewList
)
2882 if DepexList
[-1] == 'END': # no need of a END at this time
2884 DepexList
.append(')')
2887 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
2888 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
2890 if len(DepexList
) > 0:
2891 EdkLogger
.verbose('')
2892 return {self
.ModuleType
:DepexList
}
2894 ## Merge dependency expression
2896 # @retval list The token list of the dependency expression after parsed
2899 def DepexExpressionDict(self
):
2900 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2903 DepexExpressionString
= ''
2905 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2907 for M
in [self
.Module
] + self
.DependentLibraryList
:
2909 for D
in M
.DepexExpression
[self
.Arch
, self
.ModuleType
]:
2910 if DepexExpressionString
!= '':
2911 DepexExpressionString
+= ' AND '
2912 DepexExpressionString
+= '('
2913 DepexExpressionString
+= D
2914 DepexExpressionString
= DepexExpressionString
.rstrip('END').strip()
2915 DepexExpressionString
+= ')'
2918 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionString
))
2919 if 'BEFORE' in DepexExpressionString
or 'AFTER' in DepexExpressionString
:
2921 if len(DepexExpressionString
) > 0:
2922 EdkLogger
.verbose('')
2924 return {self
.ModuleType
:DepexExpressionString
}
2926 # Get the tiano core user extension, it is contain dependent library.
2927 # @retval: a list contain tiano core userextension.
2929 def _GetTianoCoreUserExtensionList(self
):
2930 TianoCoreUserExtentionList
= []
2931 for M
in [self
.Module
] + self
.DependentLibraryList
:
2932 Filename
= M
.MetaFile
.Path
2933 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2934 TianoCoreUserExtenList
= InfObj
.GetUserExtensionTianoCore()
2935 for TianoCoreUserExtent
in TianoCoreUserExtenList
:
2936 for Section
in TianoCoreUserExtent
:
2937 ItemList
= Section
.split(TAB_SPLIT
)
2939 if len(ItemList
) == 4:
2941 if Arch
.upper() == TAB_ARCH_COMMON
or Arch
.upper() == self
.Arch
.upper():
2943 TianoCoreList
.extend([TAB_SECTION_START
+ Section
+ TAB_SECTION_END
])
2944 TianoCoreList
.extend(TianoCoreUserExtent
[Section
][:])
2945 TianoCoreList
.append('\n')
2946 TianoCoreUserExtentionList
.append(TianoCoreList
)
2948 return TianoCoreUserExtentionList
2950 ## Return the list of specification version required for the module
2952 # @retval list The list of specification defined in module file
2955 def Specification(self
):
2956 return self
.Module
.Specification
2958 ## Tool option for the module build
2960 # @param PlatformInfo The object of PlatformBuildInfo
2961 # @retval dict The dict containing valid options
2964 def BuildOption(self
):
2965 RetVal
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
2966 if self
.BuildRuleOrder
:
2967 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
2970 ## Get include path list from tool option for the module build
2972 # @retval list The include path list
2975 def BuildOptionIncPathList(self
):
2977 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
2978 # is the former use /I , the Latter used -I to specify include directories
2980 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
2981 BuildOptIncludeRegEx
= gBuildOptIncludePatternMsft
2982 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
2983 BuildOptIncludeRegEx
= gBuildOptIncludePatternOther
2986 # New ToolChainFamily, don't known whether there is option to specify include directories
2991 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
2993 FlagOption
= self
.BuildOption
[Tool
]['FLAGS']
2997 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
2998 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in BuildOptIncludeRegEx
.findall(FlagOption
)]
3001 # RVCT may specify a list of directory seperated by commas
3004 for Path
in BuildOptIncludeRegEx
.findall(FlagOption
):
3005 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3006 IncPathList
.extend(NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
)
3009 # EDK II modules must not reference header files outside of the packages they depend on or
3010 # within the module's directory tree. Report error if violation.
3012 if self
.AutoGenVersion
>= 0x00010005:
3013 for Path
in IncPathList
:
3014 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3015 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3016 EdkLogger
.error("build",
3019 File
=str(self
.MetaFile
))
3020 RetVal
+= IncPathList
3023 ## Return a list of files which can be built from source
3025 # What kind of files can be built is determined by build rules in
3026 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3029 def SourceFileList(self
):
3031 ToolChainTagSet
= {"", "*", self
.ToolChain
}
3032 ToolChainFamilySet
= {"", "*", self
.ToolChainFamily
, self
.BuildRuleFamily
}
3033 for F
in self
.Module
.Sources
:
3035 if F
.TagName
not in ToolChainTagSet
:
3036 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3037 "but [%s] is currently used" % (F
.TagName
, str(F
), self
.ToolChain
))
3039 # match tool chain family or build rule family
3040 if F
.ToolChainFamily
not in ToolChainFamilySet
:
3043 "The file [%s] must be built by tools of [%s], " \
3044 "but current toolchain family is [%s], buildrule family is [%s]" \
3045 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
, self
.BuildRuleFamily
))
3048 # add the file path into search path list for file including
3049 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3050 self
.IncludePathList
.insert(0, F
.Dir
)
3053 self
._MatchBuildRuleOrder
(RetVal
)
3056 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3059 def _MatchBuildRuleOrder(self
, FileList
):
3062 for SingleFile
in FileList
:
3063 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3064 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3065 if key
in Order_Dict
:
3066 Order_Dict
[key
].append(SingleFile
.Ext
)
3068 Order_Dict
[key
] = [SingleFile
.Ext
]
3071 for F
in Order_Dict
:
3072 if len(Order_Dict
[F
]) > 1:
3073 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3074 for Ext
in Order_Dict
[F
][1:]:
3075 RemoveList
.append(F
+ Ext
)
3077 for item
in RemoveList
:
3078 FileList
.remove(item
)
3082 ## Return the list of unicode files
3084 def UnicodeFileList(self
):
3085 return self
.FileTypes
.get(TAB_UNICODE_FILE
,[])
3087 ## Return the list of vfr files
3089 def VfrFileList(self
):
3090 return self
.FileTypes
.get(TAB_VFR_FILE
, [])
3092 ## Return the list of Image Definition files
3094 def IdfFileList(self
):
3095 return self
.FileTypes
.get(TAB_IMAGE_FILE
,[])
3097 ## Return a list of files which can be built from binary
3099 # "Build" binary files are just to copy them to build directory.
3101 # @retval list The list of files which can be built later
3104 def BinaryFileList(self
):
3106 for F
in self
.Module
.Binaries
:
3107 if F
.Target
not in [TAB_ARCH_COMMON
, '*'] and F
.Target
!= self
.BuildTarget
:
3110 self
._ApplyBuildRule
(F
, F
.Type
, BinaryFileList
=RetVal
)
3114 def BuildRules(self
):
3116 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3117 for Type
in BuildRuleDatabase
.FileTypeList
:
3118 #first try getting build rule by BuildRuleFamily
3119 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3121 # build type is always module type, but ...
3122 if self
.ModuleType
!= self
.BuildType
:
3123 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3124 #second try getting build rule by ToolChainFamily
3126 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3128 # build type is always module type, but ...
3129 if self
.ModuleType
!= self
.BuildType
:
3130 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3133 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3134 RetVal
[Type
] = RuleObject
3135 for Ext
in RuleObject
.SourceFileExtList
:
3136 RetVal
[Ext
] = RuleObject
3139 def _ApplyBuildRule(self
, File
, FileType
, BinaryFileList
=None):
3140 if self
._BuildTargets
is None:
3141 self
._IntroBuildTargetList
= set()
3142 self
._FinalBuildTargetList
= set()
3143 self
._BuildTargets
= defaultdict(set)
3144 self
._FileTypes
= defaultdict(set)
3146 if not BinaryFileList
:
3147 BinaryFileList
= self
.BinaryFileList
3149 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3150 if not os
.path
.exists(SubDirectory
):
3151 CreateDirectory(SubDirectory
)
3157 # Make sure to get build rule order value
3161 while Index
< len(SourceList
):
3162 Source
= SourceList
[Index
]
3166 CreateDirectory(Source
.Dir
)
3168 if File
.IsBinary
and File
== Source
and File
in BinaryFileList
:
3169 # Skip all files that are not binary libraries
3170 if not self
.IsLibrary
:
3172 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3173 elif FileType
in self
.BuildRules
:
3174 RuleObject
= self
.BuildRules
[FileType
]
3175 elif Source
.Ext
in self
.BuildRules
:
3176 RuleObject
= self
.BuildRules
[Source
.Ext
]
3178 # stop at no more rules
3180 self
._FinalBuildTargetList
.add(LastTarget
)
3183 FileType
= RuleObject
.SourceFileType
3184 self
._FileTypes
[FileType
].add(Source
)
3186 # stop at STATIC_LIBRARY for library
3187 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3189 self
._FinalBuildTargetList
.add(LastTarget
)
3192 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3195 self
._FinalBuildTargetList
.add(LastTarget
)
3197 elif not Target
.Outputs
:
3198 # Only do build for target with outputs
3199 self
._FinalBuildTargetList
.add(Target
)
3201 self
._BuildTargets
[FileType
].add(Target
)
3203 if not Source
.IsBinary
and Source
== File
:
3204 self
._IntroBuildTargetList
.add(Target
)
3206 # to avoid cyclic rule
3207 if FileType
in RuleChain
:
3210 RuleChain
.add(FileType
)
3211 SourceList
.extend(Target
.Outputs
)
3213 FileType
= TAB_UNKNOWN_FILE
3217 if self
._BuildTargets
is None:
3218 self
._IntroBuildTargetList
= set()
3219 self
._FinalBuildTargetList
= set()
3220 self
._BuildTargets
= defaultdict(set)
3221 self
._FileTypes
= defaultdict(set)
3223 #TRICK: call SourceFileList property to apply build rule for source files
3226 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3229 return self
._BuildTargets
3232 def IntroTargetList(self
):
3234 return self
._IntroBuildTargetList
3237 def CodaTargetList(self
):
3239 return self
._FinalBuildTargetList
3242 def FileTypes(self
):
3244 return self
._FileTypes
3246 ## Get the list of package object the module depends on
3248 # @retval list The package object list
3251 def DependentPackageList(self
):
3252 return self
.Module
.Packages
3254 ## Return the list of auto-generated code file
3256 # @retval list The list of auto-generated file
3259 def AutoGenFileList(self
):
3260 AutoGenUniIdf
= self
.BuildType
!= 'UEFI_HII'
3261 UniStringBinBuffer
= BytesIO()
3262 IdfGenBinBuffer
= BytesIO()
3264 AutoGenC
= TemplateString()
3265 AutoGenH
= TemplateString()
3266 StringH
= TemplateString()
3267 StringIdf
= TemplateString()
3268 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, AutoGenUniIdf
, UniStringBinBuffer
, StringIdf
, AutoGenUniIdf
, IdfGenBinBuffer
)
3270 # AutoGen.c is generated if there are library classes in inf, or there are object files
3272 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3273 or TAB_OBJECT_FILE
in self
.FileTypes
):
3274 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3275 RetVal
[AutoFile
] = str(AutoGenC
)
3276 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3277 if str(AutoGenH
) != "":
3278 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3279 RetVal
[AutoFile
] = str(AutoGenH
)
3280 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3281 if str(StringH
) != "":
3282 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3283 RetVal
[AutoFile
] = str(StringH
)
3284 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3285 if UniStringBinBuffer
is not None and UniStringBinBuffer
.getvalue() != "":
3286 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3287 RetVal
[AutoFile
] = UniStringBinBuffer
.getvalue()
3288 AutoFile
.IsBinary
= True
3289 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3290 if UniStringBinBuffer
is not None:
3291 UniStringBinBuffer
.close()
3292 if str(StringIdf
) != "":
3293 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3294 RetVal
[AutoFile
] = str(StringIdf
)
3295 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3296 if IdfGenBinBuffer
is not None and IdfGenBinBuffer
.getvalue() != "":
3297 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3298 RetVal
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3299 AutoFile
.IsBinary
= True
3300 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3301 if IdfGenBinBuffer
is not None:
3302 IdfGenBinBuffer
.close()
3305 ## Return the list of library modules explicitly or implicityly used by this module
3307 def DependentLibraryList(self
):
3308 # only merge library classes and PCD for non-library module
3311 if self
.AutoGenVersion
< 0x00010005:
3312 return self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3313 return self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3315 ## Get the list of PCDs from current module
3317 # @retval list The list of PCD
3320 def ModulePcdList(self
):
3321 # apply PCD settings from platform
3322 RetVal
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3323 ExtendCopyDictionaryLists(self
._PcdComments
, self
.Module
.PcdComments
)
3326 ## Get the list of PCDs from dependent libraries
3328 # @retval list The list of PCD
3331 def LibraryPcdList(self
):
3336 # get PCDs from dependent libraries
3337 for Library
in self
.DependentLibraryList
:
3338 PcdsInLibrary
= OrderedDict()
3339 ExtendCopyDictionaryLists(self
._PcdComments
, Library
.PcdComments
)
3340 for Key
in Library
.Pcds
:
3341 # skip duplicated PCDs
3342 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3345 PcdsInLibrary
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3346 RetVal
.extend(self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, PcdsInLibrary
, Library
=Library
))
3349 ## Get the GUID value mapping
3351 # @retval dict The mapping between GUID cname and its value
3355 RetVal
= OrderedDict(self
.Module
.Guids
)
3356 for Library
in self
.DependentLibraryList
:
3357 RetVal
.update(Library
.Guids
)
3358 ExtendCopyDictionaryLists(self
._GuidComments
, Library
.GuidComments
)
3359 ExtendCopyDictionaryLists(self
._GuidComments
, self
.Module
.GuidComments
)
3363 def GetGuidsUsedByPcd(self
):
3364 RetVal
= OrderedDict(self
.Module
.GetGuidsUsedByPcd())
3365 for Library
in self
.DependentLibraryList
:
3366 RetVal
.update(Library
.GetGuidsUsedByPcd())
3368 ## Get the protocol value mapping
3370 # @retval dict The mapping between protocol cname and its value
3373 def ProtocolList(self
):
3374 RetVal
= OrderedDict(self
.Module
.Protocols
)
3375 for Library
in self
.DependentLibraryList
:
3376 RetVal
.update(Library
.Protocols
)
3377 ExtendCopyDictionaryLists(self
._ProtocolComments
, Library
.ProtocolComments
)
3378 ExtendCopyDictionaryLists(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3381 ## Get the PPI value mapping
3383 # @retval dict The mapping between PPI cname and its value
3387 RetVal
= OrderedDict(self
.Module
.Ppis
)
3388 for Library
in self
.DependentLibraryList
:
3389 RetVal
.update(Library
.Ppis
)
3390 ExtendCopyDictionaryLists(self
._PpiComments
, Library
.PpiComments
)
3391 ExtendCopyDictionaryLists(self
._PpiComments
, self
.Module
.PpiComments
)
3394 ## Get the list of include search path
3396 # @retval list The list path
3399 def IncludePathList(self
):
3401 if self
.AutoGenVersion
< 0x00010005:
3402 for Inc
in self
.Module
.Includes
:
3403 if Inc
not in RetVal
:
3406 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3407 if os
.path
.exists(Inc
) and Inc
not in RetVal
:
3409 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3410 RetVal
.append(self
.DebugDir
)
3412 RetVal
.append(self
.MetaFile
.Dir
)
3413 RetVal
.append(self
.DebugDir
)
3415 for Package
in self
.Module
.Packages
:
3416 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3417 if PackageDir
not in RetVal
:
3418 RetVal
.append(PackageDir
)
3419 IncludesList
= Package
.Includes
3420 if Package
._PrivateIncludes
:
3421 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3422 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3423 for Inc
in IncludesList
:
3424 if Inc
not in RetVal
:
3425 RetVal
.append(str(Inc
))
3429 def IncludePathLength(self
):
3430 return sum(len(inc
)+1 for inc
in self
.IncludePathList
)
3432 ## Get HII EX PCDs which maybe used by VFR
3434 # efivarstore used by VFR may relate with HII EX PCDs
3435 # Get the variable name and GUID from efivarstore and HII EX PCD
3436 # List the HII EX PCDs in As Built INF if both name and GUID match.
3438 # @retval list HII EX PCDs
3440 def _GetPcdsMaybeUsedByVfr(self
):
3441 if not self
.SourceFileList
:
3445 for SrcFile
in self
.SourceFileList
:
3446 if SrcFile
.Ext
.lower() != '.vfr':
3448 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3449 if not os
.path
.exists(Vfri
):
3451 VfriFile
= open(Vfri
, 'r')
3452 Content
= VfriFile
.read()
3454 Pos
= Content
.find('efivarstore')
3457 # Make sure 'efivarstore' is the start of efivarstore statement
3458 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3461 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3463 if Index
>= 0 and Content
[Index
] != ';':
3464 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3467 # 'efivarstore' must be followed by name and guid
3469 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3472 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3475 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3476 NameGuids
.add((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3477 Pos
= Content
.find('efivarstore', Name
.end())
3481 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3482 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3484 for SkuInfo
in Pcd
.SkuInfoList
.values():
3485 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3488 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3489 Guid
= GuidStructureStringToGuidString(Value
)
3490 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3491 HiiExPcds
.append(Pcd
)
3496 def _GenOffsetBin(self
):
3498 for SourceFile
in self
.Module
.Sources
:
3499 if SourceFile
.Type
.upper() == ".VFR" :
3501 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3503 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3504 elif SourceFile
.Type
.upper() == ".UNI" :
3506 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3508 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3510 if not VfrUniBaseName
:
3512 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3513 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3514 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3515 if not VfrUniOffsetList
:
3518 OutputName
= '%sOffset.bin' % self
.Name
3519 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3522 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3524 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
, None)
3526 # Use a instance of BytesIO to cache data
3527 fStringIO
= BytesIO('')
3529 for Item
in VfrUniOffsetList
:
3530 if (Item
[0].find("Strings") != -1):
3532 # UNI offset in image.
3534 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3536 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3537 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3538 fStringIO
.write(''.join(UniGuid
))
3539 UniValue
= pack ('Q', int (Item
[1], 16))
3540 fStringIO
.write (UniValue
)
3543 # VFR binary offset in image.
3545 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3547 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3548 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3549 fStringIO
.write(''.join(VfrGuid
))
3550 VfrValue
= pack ('Q', int (Item
[1], 16))
3551 fStringIO
.write (VfrValue
)
3553 # write data into file.
3556 fInputfile
.write (fStringIO
.getvalue())
3558 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3559 "file been locked or using by other applications." %UniVfrOffsetFileName
, None)
3565 ## Create AsBuilt INF file the module
3567 def CreateAsBuiltInf(self
, IsOnlyCopy
= False):
3568 self
.OutputFile
= set()
3569 if IsOnlyCopy
and GlobalData
.gBinCacheDest
:
3570 self
.CopyModuleToCache()
3573 if self
.IsAsBuiltInfCreated
:
3576 # Skip the following code for EDK I inf
3577 if self
.AutoGenVersion
< 0x00010005:
3580 # Skip the following code for libraries
3584 # Skip the following code for modules with no source files
3585 if not self
.SourceFileList
:
3588 # Skip the following code for modules without any binary files
3589 if self
.BinaryFileList
:
3592 ### TODO: How to handles mixed source and binary modules
3594 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3595 # Also find all packages that the DynamicEx PCDs depend on
3600 PcdTokenSpaceList
= []
3601 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3602 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3603 PatchablePcds
.append(Pcd
)
3604 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_PATCHABLE_IN_MODULE
))
3605 elif Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
3608 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC_EX
))
3609 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC
))
3610 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3611 GuidList
= OrderedDict(self
.GuidList
)
3612 for TokenSpace
in self
.GetGuidsUsedByPcd
:
3613 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3614 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3615 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3616 GuidList
.pop(TokenSpace
)
3617 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3618 for Package
in self
.DerivedPackageList
:
3619 if Package
in Packages
:
3621 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3623 for Index
in range(len(BeChecked
)):
3624 for Item
in CheckList
[Index
]:
3625 if Item
in BeChecked
[Index
]:
3626 Packages
.append(Package
)
3632 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3633 for Pkg
in self
.PlatformInfo
.PackageList
:
3636 for VfrPcd
in VfrPcds
:
3637 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC_EX
) in Pkg
.Pcds
or
3638 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC
) in Pkg
.Pcds
):
3639 Packages
.append(Pkg
)
3642 ModuleType
= SUP_MODULE_DXE_DRIVER
if self
.ModuleType
== SUP_MODULE_UEFI_DRIVER
and self
.DepexGenerated
else self
.ModuleType
3643 DriverType
= self
.PcdIsDriver
if self
.PcdIsDriver
else ''
3645 MDefs
= self
.Module
.Defines
3648 'module_name' : self
.Name
,
3649 'module_guid' : Guid
,
3650 'module_module_type' : ModuleType
,
3651 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3652 'pcd_is_driver_string' : [],
3653 'module_uefi_specification_version' : [],
3654 'module_pi_specification_version' : [],
3655 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3656 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3657 'module_constructor' : self
.Module
.ConstructorList
,
3658 'module_destructor' : self
.Module
.DestructorList
,
3659 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3660 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3661 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3662 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3663 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3664 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3665 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3666 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3667 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3668 'module_arch' : self
.Arch
,
3669 'package_item' : [Package
.MetaFile
.File
.replace('\\', '/') for Package
in Packages
],
3671 'patchablepcd_item' : [],
3673 'protocol_item' : [],
3677 'libraryclasses_item' : []
3680 if 'MODULE_UNI_FILE' in MDefs
:
3681 UNIFile
= os
.path
.join(self
.MetaFile
.Dir
, MDefs
['MODULE_UNI_FILE'])
3682 if os
.path
.isfile(UNIFile
):
3683 shutil
.copy2(UNIFile
, self
.OutputDir
)
3685 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3686 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3688 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3691 AsBuiltInfDict
['pcd_is_driver_string'].append(DriverType
)
3693 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3694 AsBuiltInfDict
['module_uefi_specification_version'].append(self
.Specification
['UEFI_SPECIFICATION_VERSION'])
3695 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3696 AsBuiltInfDict
['module_pi_specification_version'].append(self
.Specification
['PI_SPECIFICATION_VERSION'])
3698 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3699 DebugDir
= self
.DebugDir
.replace('\\', '/').strip('/')
3700 for Item
in self
.CodaTargetList
:
3701 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(DebugDir
, '').replace(OutputDir
, '').strip('/')
3702 self
.OutputFile
.add(File
)
3703 if os
.path
.isabs(File
):
3704 File
= File
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3705 if Item
.Target
.Ext
.lower() == '.aml':
3706 AsBuiltInfDict
['binary_item'].append('ASL|' + File
)
3707 elif Item
.Target
.Ext
.lower() == '.acpi':
3708 AsBuiltInfDict
['binary_item'].append('ACPI|' + File
)
3709 elif Item
.Target
.Ext
.lower() == '.efi':
3710 AsBuiltInfDict
['binary_item'].append('PE32|' + self
.Name
+ '.efi')
3712 AsBuiltInfDict
['binary_item'].append('BIN|' + File
)
3713 if self
.DepexGenerated
:
3714 self
.OutputFile
.add(self
.Name
+ '.depex')
3715 if self
.ModuleType
in [SUP_MODULE_PEIM
]:
3716 AsBuiltInfDict
['binary_item'].append('PEI_DEPEX|' + self
.Name
+ '.depex')
3717 elif self
.ModuleType
in [SUP_MODULE_DXE_DRIVER
, SUP_MODULE_DXE_RUNTIME_DRIVER
, SUP_MODULE_DXE_SAL_DRIVER
, SUP_MODULE_UEFI_DRIVER
]:
3718 AsBuiltInfDict
['binary_item'].append('DXE_DEPEX|' + self
.Name
+ '.depex')
3719 elif self
.ModuleType
in [SUP_MODULE_DXE_SMM_DRIVER
]:
3720 AsBuiltInfDict
['binary_item'].append('SMM_DEPEX|' + self
.Name
+ '.depex')
3722 Bin
= self
._GenOffsetBin
()
3724 AsBuiltInfDict
['binary_item'].append('BIN|%s' % Bin
)
3725 self
.OutputFile
.add(Bin
)
3727 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3729 if File
.lower().endswith('.pdb'):
3730 AsBuiltInfDict
['binary_item'].append('DISPOSABLE|' + File
)
3731 self
.OutputFile
.add(File
)
3732 HeaderComments
= self
.Module
.HeaderComments
3734 for Index
in range(len(HeaderComments
)):
3735 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3736 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3739 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3740 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3743 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3744 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3745 (GuidList
, self
._GuidComments
, 'guid_item')
3747 for Item
in GenList
:
3748 for CName
in Item
[0]:
3749 Comments
= '\n '.join(Item
[1][CName
]) if CName
in Item
[1] else ''
3750 Entry
= Comments
+ '\n ' + CName
if Comments
else CName
3751 AsBuiltInfDict
[Item
[2]].append(Entry
)
3752 PatchList
= parsePcdInfoFromMapFile(
3753 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3754 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3757 for Pcd
in PatchablePcds
:
3758 TokenCName
= Pcd
.TokenCName
3759 for PcdItem
in GlobalData
.MixedPcd
:
3760 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3761 TokenCName
= PcdItem
[0]
3763 for PatchPcd
in PatchList
:
3764 if TokenCName
== PatchPcd
[0]:
3769 if Pcd
.DatumType
== 'BOOLEAN':
3770 BoolValue
= Pcd
.DefaultValue
.upper()
3771 if BoolValue
== 'TRUE':
3772 Pcd
.DefaultValue
= '1'
3773 elif BoolValue
== 'FALSE':
3774 Pcd
.DefaultValue
= '0'
3776 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
3777 HexFormat
= '0x%02x'
3778 if Pcd
.DatumType
== TAB_UINT16
:
3779 HexFormat
= '0x%04x'
3780 elif Pcd
.DatumType
== TAB_UINT32
:
3781 HexFormat
= '0x%08x'
3782 elif Pcd
.DatumType
== TAB_UINT64
:
3783 HexFormat
= '0x%016x'
3784 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3786 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
3787 EdkLogger
.error("build", AUTOGEN_ERROR
,
3788 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3790 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3791 PcdValue
= Pcd
.DefaultValue
3792 if PcdValue
[0] != '{':
3794 if PcdValue
[0] == 'L':
3796 PcdValue
= PcdValue
.lstrip('L')
3797 PcdValue
= eval(PcdValue
)
3799 for Index
in range(0, len(PcdValue
)):
3801 CharVal
= ord(PcdValue
[Index
])
3802 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3803 + '0x%02x' % (CharVal
>> 8) + ', '
3805 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3808 Padding
= Padding
* 2
3809 ArraySize
= ArraySize
/ 2
3810 if ArraySize
< (len(PcdValue
) + 1):
3811 if Pcd
.MaxSizeUserSet
:
3812 EdkLogger
.error("build", AUTOGEN_ERROR
,
3813 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3816 ArraySize
= len(PcdValue
) + 1
3817 if ArraySize
> len(PcdValue
) + 1:
3818 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3819 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3820 elif len(PcdValue
.split(',')) <= ArraySize
:
3821 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3824 if Pcd
.MaxSizeUserSet
:
3825 EdkLogger
.error("build", AUTOGEN_ERROR
,
3826 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3829 ArraySize
= len(PcdValue
) + 1
3830 PcdItem
= '%s.%s|%s|0x%X' % \
3831 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
3833 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3834 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
3836 PcdItem
= PcdComments
+ '\n ' + PcdItem
3837 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
3839 for Pcd
in Pcds
+ VfrPcds
:
3842 TokenCName
= Pcd
.TokenCName
3843 for PcdItem
in GlobalData
.MixedPcd
:
3844 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3845 TokenCName
= PcdItem
[0]
3847 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
3848 for SkuName
in Pcd
.SkuInfoList
:
3849 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3850 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
3852 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3853 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
3857 for Index
, Comment
in enumerate(PcdCommentList
):
3858 for Usage
in UsageList
:
3859 if Comment
.find(Usage
) != -1:
3863 if UsageIndex
!= -1:
3864 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
3866 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
3867 PcdComments
= '\n '.join(PcdCommentList
)
3868 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
3870 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
3871 AsBuiltInfDict
['pcd_item'].append(PcdEntry
)
3872 for Item
in self
.BuildOption
:
3873 if 'FLAGS' in self
.BuildOption
[Item
]:
3874 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()))
3876 # Generated LibraryClasses section in comments.
3877 for Library
in self
.LibraryAutoGenList
:
3878 AsBuiltInfDict
['libraryclasses_item'].append(Library
.MetaFile
.File
.replace('\\', '/'))
3880 # Generated UserExtensions TianoCore section.
3881 # All tianocore user extensions are copied.
3883 for TianoCore
in self
._GetTianoCoreUserExtensionList
():
3884 UserExtStr
+= '\n'.join(TianoCore
)
3885 ExtensionFile
= os
.path
.join(self
.MetaFile
.Dir
, TianoCore
[1])
3886 if os
.path
.isfile(ExtensionFile
):
3887 shutil
.copy2(ExtensionFile
, self
.OutputDir
)
3888 AsBuiltInfDict
['userextension_tianocore_item'] = UserExtStr
3890 # Generated depex expression section in comments.
3891 DepexExpresion
= self
._GetDepexExpresionString
()
3892 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
if DepexExpresion
else ''
3894 AsBuiltInf
= TemplateString()
3895 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
3897 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
3899 self
.IsAsBuiltInfCreated
= True
3900 if GlobalData
.gBinCacheDest
:
3901 self
.CopyModuleToCache()
3903 def CopyModuleToCache(self
):
3904 FileDir
= path
.join(GlobalData
.gBinCacheDest
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
3905 CreateDirectory (FileDir
)
3906 HashFile
= path
.join(self
.BuildDir
, self
.Name
+ '.hash')
3907 ModuleFile
= path
.join(self
.OutputDir
, self
.Name
+ '.inf')
3908 if os
.path
.exists(HashFile
):
3909 shutil
.copy2(HashFile
, FileDir
)
3910 if os
.path
.exists(ModuleFile
):
3911 shutil
.copy2(ModuleFile
, FileDir
)
3912 if not self
.OutputFile
:
3913 Ma
= self
.Workspace
.BuildDatabase
[PathClass(ModuleFile
), self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
3914 self
.OutputFile
= Ma
.Binaries
3916 for File
in self
.OutputFile
:
3918 if not os
.path
.isabs(File
):
3919 File
= os
.path
.join(self
.OutputDir
, File
)
3920 if os
.path
.exists(File
):
3921 shutil
.copy2(File
, FileDir
)
3923 def AttemptModuleCacheCopy(self
):
3924 if self
.IsBinaryModule
:
3926 FileDir
= path
.join(GlobalData
.gBinCacheSource
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
3927 HashFile
= path
.join(FileDir
, self
.Name
+ '.hash')
3928 if os
.path
.exists(HashFile
):
3929 f
= open(HashFile
, 'r')
3930 CacheHash
= f
.read()
3932 if GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
3933 if CacheHash
== GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
3934 for root
, dir, files
in os
.walk(FileDir
):
3936 if self
.Name
+ '.hash' in f
:
3937 shutil
.copy2(HashFile
, self
.BuildDir
)
3939 File
= path
.join(root
, f
)
3940 shutil
.copy2(File
, self
.OutputDir
)
3941 if self
.Name
== "PcdPeim" or self
.Name
== "PcdDxe":
3942 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
3946 ## Create makefile for the module and its dependent libraries
3948 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
3949 # dependent libraries will be created
3951 @cached_class_function
3952 def CreateMakeFile(self
, CreateLibraryMakeFile
=True, GenFfsList
= []):
3953 # nest this function inside it's only caller.
3954 def CreateTimeStamp():
3955 FileSet
= {self
.MetaFile
.Path
}
3957 for SourceFile
in self
.Module
.Sources
:
3958 FileSet
.add (SourceFile
.Path
)
3960 for Lib
in self
.DependentLibraryList
:
3961 FileSet
.add (Lib
.MetaFile
.Path
)
3963 for f
in self
.AutoGenDepSet
:
3964 FileSet
.add (f
.Path
)
3966 if os
.path
.exists (self
.TimeStampPath
):
3967 os
.remove (self
.TimeStampPath
)
3968 with
open(self
.TimeStampPath
, 'w+') as file:
3972 # Ignore generating makefile when it is a binary module
3973 if self
.IsBinaryModule
:
3976 self
.GenFfsList
= GenFfsList
3977 if not self
.IsLibrary
and CreateLibraryMakeFile
:
3978 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3979 LibraryAutoGen
.CreateMakeFile()
3984 if len(self
.CustomMakefile
) == 0:
3985 Makefile
= GenMake
.ModuleMakefile(self
)
3987 Makefile
= GenMake
.CustomMakefile(self
)
3988 if Makefile
.Generate():
3989 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
3990 (self
.Name
, self
.Arch
))
3992 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
3993 (self
.Name
, self
.Arch
))
3997 def CopyBinaryFiles(self
):
3998 for File
in self
.Module
.Binaries
:
4000 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4001 CopyLongFilePath(SrcPath
, DstPath
)
4002 ## Create autogen code for the module and its dependent libraries
4004 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4005 # dependent libraries will be created
4007 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4008 if self
.IsCodeFileCreated
:
4011 # Need to generate PcdDatabase even PcdDriver is binarymodule
4012 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4013 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4015 if self
.IsBinaryModule
:
4017 self
.CopyBinaryFiles()
4020 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4021 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4022 LibraryAutoGen
.CreateCodeFile()
4028 IgoredAutoGenList
= []
4030 for File
in self
.AutoGenFileList
:
4031 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4032 #Ignore Edk AutoGen.c
4033 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
4036 AutoGenList
.append(str(File
))
4038 IgoredAutoGenList
.append(str(File
))
4040 # Skip the following code for EDK I inf
4041 if self
.AutoGenVersion
< 0x00010005:
4044 for ModuleType
in self
.DepexList
:
4045 # Ignore empty [depex] section or [depex] section for SUP_MODULE_USER_DEFINED module
4046 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== SUP_MODULE_USER_DEFINED
:
4049 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4050 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4052 if len(Dpx
.PostfixNotation
) != 0:
4053 self
.DepexGenerated
= True
4055 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4056 AutoGenList
.append(str(DpxFile
))
4058 IgoredAutoGenList
.append(str(DpxFile
))
4060 if IgoredAutoGenList
== []:
4061 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4062 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4063 elif AutoGenList
== []:
4064 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4065 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4067 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4068 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4070 self
.IsCodeFileCreated
= True
4073 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4075 def LibraryAutoGenList(self
):
4077 for Library
in self
.DependentLibraryList
:
4084 self
.PlatformInfo
.MetaFile
4086 if La
not in RetVal
:
4088 for Lib
in La
.CodaTargetList
:
4089 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4092 def GenModuleHash(self
):
4093 if self
.Arch
not in GlobalData
.gModuleHash
:
4094 GlobalData
.gModuleHash
[self
.Arch
] = {}
4096 # Add Platform level hash
4097 m
.update(GlobalData
.gPlatformHash
)
4098 # Add Package level hash
4099 if self
.DependentPackageList
:
4100 for Pkg
in sorted(self
.DependentPackageList
, key
=lambda x
: x
.PackageName
):
4101 if Pkg
.PackageName
in GlobalData
.gPackageHash
[self
.Arch
]:
4102 m
.update(GlobalData
.gPackageHash
[self
.Arch
][Pkg
.PackageName
])
4105 if self
.LibraryAutoGenList
:
4106 for Lib
in sorted(self
.LibraryAutoGenList
, key
=lambda x
: x
.Name
):
4107 if Lib
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4109 m
.update(GlobalData
.gModuleHash
[self
.Arch
][Lib
.Name
])
4112 f
= open(str(self
.MetaFile
), 'r')
4116 # Add Module's source files
4117 if self
.SourceFileList
:
4118 for File
in sorted(self
.SourceFileList
, key
=lambda x
: str(x
)):
4119 f
= open(str(File
), 'r')
4124 ModuleHashFile
= path
.join(self
.BuildDir
, self
.Name
+ ".hash")
4125 if self
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4126 GlobalData
.gModuleHash
[self
.Arch
][self
.Name
] = m
.hexdigest()
4127 if GlobalData
.gBinCacheSource
:
4128 if self
.AttemptModuleCacheCopy():
4130 return SaveFileOnChange(ModuleHashFile
, m
.hexdigest(), True)
4132 ## Decide whether we can skip the ModuleAutoGen process
4133 def CanSkipbyHash(self
):
4134 if GlobalData
.gUseHashCache
:
4135 return not self
.GenModuleHash()
4138 ## Decide whether we can skip the ModuleAutoGen process
4139 # If any source file is newer than the module than we cannot skip
4142 if self
.MakeFileDir
in GlobalData
.gSikpAutoGenCache
:
4144 if not os
.path
.exists(self
.TimeStampPath
):
4146 #last creation time of the module
4147 DstTimeStamp
= os
.stat(self
.TimeStampPath
)[8]
4149 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4150 if SrcTimeStamp
> DstTimeStamp
:
4153 with
open(self
.TimeStampPath
,'r') as f
:
4155 source
= source
.rstrip('\n')
4156 if not os
.path
.exists(source
):
4158 if source
not in ModuleAutoGen
.TimeDict
:
4159 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4160 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4162 GlobalData
.gSikpAutoGenCache
.add(self
.MakeFileDir
)
4166 def TimeStampPath(self
):
4167 return os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')