2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
5 # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
6 # Copyright (c) 2019, American Megatrends, Inc. All rights reserved.<BR>
8 # SPDX-License-Identifier: BSD-2-Clause-Patent
13 from __future__
import print_function
14 from __future__
import absolute_import
15 import Common
.LongFilePathOs
as os
17 import os
.path
as path
23 from . import GenDepex
24 from io
import BytesIO
26 from .StrGather
import *
27 from .BuildEngine
import BuildRule
29 from Common
.LongFilePathSupport
import CopyLongFilePath
30 from Common
.BuildToolError
import *
31 from Common
.DataType
import *
32 from Common
.Misc
import *
33 from Common
.StringUtils
import *
34 import Common
.GlobalData
as GlobalData
35 from GenFds
.FdfParser
import *
36 from CommonDataClass
.CommonClass
import SkuInfoClass
37 from GenPatchPcdTable
.GenPatchPcdTable
import parsePcdInfoFromMapFile
38 import Common
.VpdInfoFile
as VpdInfoFile
39 from .GenPcdDb
import CreatePcdDatabaseCode
40 from Workspace
.MetaFileCommentParser
import UsageList
41 from Workspace
.WorkspaceCommon
import GetModuleLibInstances
42 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
43 from . import InfSectionParser
46 from .GenVar
import VariableMgr
, var_info
47 from collections
import OrderedDict
48 from collections
import defaultdict
49 from Workspace
.WorkspaceCommon
import OrderedListDict
50 from Common
.ToolDefClassObject
import gDefaultToolsDefFile
52 from Common
.caching
import cached_property
, cached_class_function
54 ## Regular expression for splitting Dependency Expression string into tokens
55 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
57 ## Regular expression for match: PCD(xxxx.yyy)
58 gPCDAsGuidPattern
= re
.compile(r
"^PCD\(.+\..+\)$")
61 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
62 # is the former use /I , the Latter used -I to specify include directories
64 gBuildOptIncludePatternMsft
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
65 gBuildOptIncludePatternOther
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
68 # Match name = variable
70 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
72 # The format of guid in efivarstore statement likes following and must be correct:
73 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
75 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
77 ## Mapping Makefile type
78 gMakeTypeMap
= {TAB_COMPILER_MSFT
:"nmake", "GCC":"gmake"}
81 ## Build rule configuration file
82 gDefaultBuildRuleFile
= 'build_rule.txt'
84 ## Build rule default version
85 AutoGenReqBuildRuleVerNum
= "0.1"
87 ## default file name for AutoGen
88 gAutoGenCodeFileName
= "AutoGen.c"
89 gAutoGenHeaderFileName
= "AutoGen.h"
90 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
91 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
92 gAutoGenDepexFileName
= "%(module_name)s.depex"
93 gAutoGenImageDefFileName
= "%(module_name)sImgDefs.h"
94 gAutoGenIdfFileName
= "%(module_name)sIdf.hpk"
95 gInfSpecVersion
= "0x00010017"
98 # Template string to generic AsBuilt INF
100 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
103 # FILE auto-generated
106 INF_VERSION = ${module_inf_version}
107 BASE_NAME = ${module_name}
108 FILE_GUID = ${module_guid}
109 MODULE_TYPE = ${module_module_type}${BEGIN}
110 VERSION_STRING = ${module_version_string}${END}${BEGIN}
111 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
112 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
113 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
114 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
115 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
116 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
117 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
118 SHADOW = ${module_shadow}${END}${BEGIN}
119 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
120 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
121 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
122 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
123 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
124 SPEC = ${module_spec}${END}${BEGIN}
125 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
126 MODULE_UNI_FILE = ${module_uni_file}${END}
128 [Packages.${module_arch}]${BEGIN}
129 ${package_item}${END}
131 [Binaries.${module_arch}]${BEGIN}
134 [PatchPcd.${module_arch}]${BEGIN}
138 [Protocols.${module_arch}]${BEGIN}
142 [Ppis.${module_arch}]${BEGIN}
146 [Guids.${module_arch}]${BEGIN}
150 [PcdEx.${module_arch}]${BEGIN}
154 [LibraryClasses.${module_arch}]
155 ## @LIB_INSTANCES${BEGIN}
156 # ${libraryclasses_item}${END}
160 ${userextension_tianocore_item}
164 [BuildOptions.${module_arch}]
166 ## ${flags_item}${END}
168 ## Split command line option string to list
170 # subprocess.Popen needs the args to be a sequence. Otherwise there's problem
171 # in non-windows platform to launch command
173 def _SplitOption(OptionString
):
178 for Index
in range(0, len(OptionString
)):
179 CurrentChar
= OptionString
[Index
]
180 if CurrentChar
in ['"', "'"]:
181 if QuotationMark
== CurrentChar
:
183 elif QuotationMark
== "":
184 QuotationMark
= CurrentChar
189 if CurrentChar
in ["/", "-"] and LastChar
in [" ", "\t", "\r", "\n"]:
190 if Index
> OptionStart
:
191 OptionList
.append(OptionString
[OptionStart
:Index
- 1])
193 LastChar
= CurrentChar
194 OptionList
.append(OptionString
[OptionStart
:])
198 # Convert string to C format array
200 def _ConvertStringToByteArray(Value
):
201 Value
= Value
.strip()
205 if not Value
.endswith('}'):
207 Value
= Value
.replace(' ', '').replace('{', '').replace('}', '')
208 ValFields
= Value
.split(',')
210 for Index
in range(len(ValFields
)):
211 ValFields
[Index
] = str(int(ValFields
[Index
], 0))
214 Value
= '{' + ','.join(ValFields
) + '}'
218 if Value
.startswith('L"'):
219 if not Value
.endswith('"'):
223 elif not Value
.startswith('"') or not Value
.endswith('"'):
226 Value
= eval(Value
) # translate escape character
228 for Index
in range(0, len(Value
)):
230 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x10000) + ','
232 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x100) + ','
233 Value
= NewValue
+ '0}'
236 ## Base class for AutoGen
238 # This class just implements the cache mechanism of AutoGen objects.
240 class AutoGen(object):
241 # database to maintain the objects in each child class
242 __ObjectCache
= {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object
246 # @param Class class object of real AutoGen class
247 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
248 # @param Workspace Workspace directory or WorkspaceAutoGen object
249 # @param MetaFile The path of meta file
250 # @param Target Build target
251 # @param Toolchain Tool chain name
252 # @param Arch Target arch
253 # @param *args The specific class related parameters
254 # @param **kwargs The specific class related dict parameters
256 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
257 # check if the object has been created
258 Key
= (Target
, Toolchain
, Arch
, MetaFile
)
259 if Key
in cls
.__ObjectCache
:
260 # if it exists, just return it directly
261 return cls
.__ObjectCache
[Key
]
262 # it didnt exist. create it, cache it, then return it
263 RetVal
= cls
.__ObjectCache
[Key
] = super(AutoGen
, cls
).__new
__(cls
)
269 # The file path of platform file will be used to represent hash value of this object
271 # @retval int Hash value of the file path of platform file
274 return hash(self
.MetaFile
)
278 # The file path of platform file will be used to represent this object
280 # @retval string String of platform file path
283 return str(self
.MetaFile
)
286 def __eq__(self
, Other
):
287 return Other
and self
.MetaFile
== Other
289 ## Workspace AutoGen class
291 # This class is used mainly to control the whole platform build for different
292 # architecture. This class will generate top level makefile.
294 class WorkspaceAutoGen(AutoGen
):
295 # call super().__init__ then call the worker function with different parameter count
296 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
297 if not hasattr(self
, "_Init"):
298 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
301 ## Initialize WorkspaceAutoGen
303 # @param WorkspaceDir Root directory of workspace
304 # @param ActivePlatform Meta-file of active platform
305 # @param Target Build target
306 # @param Toolchain Tool chain name
307 # @param ArchList List of architecture of current build
308 # @param MetaFileDb Database containing meta-files
309 # @param BuildConfig Configuration of build
310 # @param ToolDefinition Tool chain definitions
311 # @param FlashDefinitionFile File of flash definition
312 # @param Fds FD list to be generated
313 # @param Fvs FV list to be generated
314 # @param Caps Capsule list to be generated
315 # @param SkuId SKU id from command line
317 def _InitWorker(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
318 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
319 Progress
=None, BuildModule
=None):
320 self
.BuildDatabase
= MetaFileDb
321 self
.MetaFile
= ActivePlatform
322 self
.WorkspaceDir
= WorkspaceDir
323 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, TAB_ARCH_COMMON
, Target
, Toolchain
]
324 GlobalData
.gActivePlatform
= self
.Platform
325 self
.BuildTarget
= Target
326 self
.ToolChain
= Toolchain
327 self
.ArchList
= ArchList
329 self
.UniFlag
= UniFlag
331 self
.TargetTxt
= BuildConfig
332 self
.ToolDef
= ToolDefinition
333 self
.FdfFile
= FlashDefinitionFile
334 self
.FdTargetList
= Fds
if Fds
else []
335 self
.FvTargetList
= Fvs
if Fvs
else []
336 self
.CapTargetList
= Caps
if Caps
else []
337 self
.AutoGenObjectList
= []
340 # there's many relative directory operations, so ...
341 os
.chdir(self
.WorkspaceDir
)
346 if not self
.ArchList
:
347 ArchList
= set(self
.Platform
.SupArchList
)
349 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
351 EdkLogger
.error("build", PARAMETER_INVALID
,
352 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
353 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
354 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
355 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
356 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
357 self
.ArchList
= tuple(ArchList
)
359 # Validate build target
360 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
361 EdkLogger
.error("build", PARAMETER_INVALID
,
362 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
363 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
366 # parse FDF file to get PCDs in it, if any
368 self
.FdfFile
= self
.Platform
.FlashDefinition
372 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
373 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
374 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
376 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
378 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
381 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
383 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
386 Progress
.Start("\nProcessing meta-data")
390 # Mark now build in AutoGen Phase
392 GlobalData
.gAutoGenPhase
= True
393 Fdf
= FdfParser(self
.FdfFile
.Path
)
395 GlobalData
.gFdfParser
= Fdf
396 GlobalData
.gAutoGenPhase
= False
397 PcdSet
= Fdf
.Profile
.PcdDict
398 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
399 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
400 for FdRegion
in FdDict
.RegionList
:
401 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
402 if int(FdRegion
.Offset
) % 8 != 0:
403 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
404 ModuleList
= Fdf
.Profile
.InfList
405 self
.FdfProfile
= Fdf
.Profile
406 for fvname
in self
.FvTargetList
:
407 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
408 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
409 "No such an FV in FDF file: %s" % fvname
)
411 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
412 # but the path (self.MetaFile.Path) is the real path
413 for key
in self
.FdfProfile
.InfDict
:
415 MetaFile_cache
= defaultdict(set)
416 for Arch
in self
.ArchList
:
417 Current_Platform_cache
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
418 for Pkey
in Current_Platform_cache
.Modules
:
419 MetaFile_cache
[Arch
].add(Current_Platform_cache
.Modules
[Pkey
].MetaFile
)
420 for Inf
in self
.FdfProfile
.InfDict
[key
]:
421 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
422 for Arch
in self
.ArchList
:
423 if ModuleFile
in MetaFile_cache
[Arch
]:
426 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
427 if not ModuleData
.IsBinaryModule
:
428 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
431 for Arch
in self
.ArchList
:
433 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
435 for Pkey
in Platform
.Modules
:
436 MetaFileList
.add(Platform
.Modules
[Pkey
].MetaFile
)
437 for Inf
in self
.FdfProfile
.InfDict
[key
]:
438 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
439 if ModuleFile
in MetaFileList
:
441 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
442 if not ModuleData
.IsBinaryModule
:
443 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
448 self
.FdfProfile
= None
449 if self
.FdTargetList
:
450 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
451 self
.FdTargetList
= []
452 if self
.FvTargetList
:
453 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
454 self
.FvTargetList
= []
455 if self
.CapTargetList
:
456 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
457 self
.CapTargetList
= []
459 # apply SKU and inject PCDs from Flash Definition file
460 for Arch
in self
.ArchList
:
461 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
462 PlatformPcds
= Platform
.Pcds
463 self
._GuidDict
= Platform
._GuidDict
464 SourcePcdDict
= {TAB_PCDS_DYNAMIC_EX
:set(), TAB_PCDS_PATCHABLE_IN_MODULE
:set(),TAB_PCDS_DYNAMIC
:set(),TAB_PCDS_FIXED_AT_BUILD
:set()}
465 BinaryPcdDict
= {TAB_PCDS_DYNAMIC_EX
:set(), TAB_PCDS_PATCHABLE_IN_MODULE
:set()}
466 SourcePcdDict_Keys
= SourcePcdDict
.keys()
467 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
469 # generate the SourcePcdDict and BinaryPcdDict
470 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
471 for BuildData
in list(PGen
.BuildDatabase
._CACHE
_.values()):
472 if BuildData
.Arch
!= Arch
:
474 if BuildData
.MetaFile
.Ext
== '.inf':
475 for key
in BuildData
.Pcds
:
476 if BuildData
.Pcds
[key
].Pending
:
477 if key
in Platform
.Pcds
:
478 PcdInPlatform
= Platform
.Pcds
[key
]
479 if PcdInPlatform
.Type
:
480 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
481 BuildData
.Pcds
[key
].Pending
= False
483 if BuildData
.MetaFile
in Platform
.Modules
:
484 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
485 if key
in PlatformModule
.Pcds
:
486 PcdInPlatform
= PlatformModule
.Pcds
[key
]
487 if PcdInPlatform
.Type
:
488 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
489 BuildData
.Pcds
[key
].Pending
= False
491 #Pcd used in Library, Pcd Type from reference module if Pcd Type is Pending
492 if BuildData
.Pcds
[key
].Pending
:
493 MGen
= ModuleAutoGen(self
, BuildData
.MetaFile
, Target
, Toolchain
, Arch
, self
.MetaFile
)
494 if MGen
and MGen
.IsLibrary
:
495 if MGen
in PGen
.LibraryAutoGenList
:
496 ReferenceModules
= MGen
.ReferenceModules
497 for ReferenceModule
in ReferenceModules
:
498 if ReferenceModule
.MetaFile
in Platform
.Modules
:
499 RefPlatformModule
= Platform
.Modules
[str(ReferenceModule
.MetaFile
)]
500 if key
in RefPlatformModule
.Pcds
:
501 PcdInReferenceModule
= RefPlatformModule
.Pcds
[key
]
502 if PcdInReferenceModule
.Type
:
503 BuildData
.Pcds
[key
].Type
= PcdInReferenceModule
.Type
504 BuildData
.Pcds
[key
].Pending
= False
507 if TAB_PCDS_DYNAMIC_EX
in BuildData
.Pcds
[key
].Type
:
508 if BuildData
.IsBinaryModule
:
509 BinaryPcdDict
[TAB_PCDS_DYNAMIC_EX
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
511 SourcePcdDict
[TAB_PCDS_DYNAMIC_EX
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
513 elif TAB_PCDS_PATCHABLE_IN_MODULE
in BuildData
.Pcds
[key
].Type
:
514 if BuildData
.MetaFile
.Ext
== '.inf':
515 if BuildData
.IsBinaryModule
:
516 BinaryPcdDict
[TAB_PCDS_PATCHABLE_IN_MODULE
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
518 SourcePcdDict
[TAB_PCDS_PATCHABLE_IN_MODULE
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
520 elif TAB_PCDS_DYNAMIC
in BuildData
.Pcds
[key
].Type
:
521 SourcePcdDict
[TAB_PCDS_DYNAMIC
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
522 elif TAB_PCDS_FIXED_AT_BUILD
in BuildData
.Pcds
[key
].Type
:
523 SourcePcdDict
[TAB_PCDS_FIXED_AT_BUILD
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
527 # A PCD can only use one type for all source modules
529 for i
in SourcePcdDict_Keys
:
530 for j
in SourcePcdDict_Keys
:
532 Intersections
= SourcePcdDict
[i
].intersection(SourcePcdDict
[j
])
533 if len(Intersections
) > 0:
537 "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
),
538 ExtraData
='\n\t'.join(str(P
[1]+'.'+P
[0]) for P
in Intersections
)
542 # intersection the BinaryPCD for Mixed PCD
544 for i
in BinaryPcdDict_Keys
:
545 for j
in BinaryPcdDict_Keys
:
547 Intersections
= BinaryPcdDict
[i
].intersection(BinaryPcdDict
[j
])
548 for item
in Intersections
:
549 NewPcd1
= (item
[0] + '_' + i
, item
[1])
550 NewPcd2
= (item
[0] + '_' + j
, item
[1])
551 if item
not in GlobalData
.MixedPcd
:
552 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
554 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
555 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
556 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
557 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
560 # intersection the SourcePCD and BinaryPCD for Mixed PCD
562 for i
in SourcePcdDict_Keys
:
563 for j
in BinaryPcdDict_Keys
:
565 Intersections
= SourcePcdDict
[i
].intersection(BinaryPcdDict
[j
])
566 for item
in Intersections
:
567 NewPcd1
= (item
[0] + '_' + i
, item
[1])
568 NewPcd2
= (item
[0] + '_' + j
, item
[1])
569 if item
not in GlobalData
.MixedPcd
:
570 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
572 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
573 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
574 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
575 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
577 for BuildData
in list(PGen
.BuildDatabase
._CACHE
_.values()):
578 if BuildData
.Arch
!= Arch
:
580 for key
in BuildData
.Pcds
:
581 for SinglePcd
in GlobalData
.MixedPcd
:
582 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
583 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
584 Pcd_Type
= item
[0].split('_')[-1]
585 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 \
586 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in PCD_DYNAMIC_TYPE_SET
):
587 Value
= BuildData
.Pcds
[key
]
588 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
590 newkey
= (Value
.TokenCName
, key
[1])
592 newkey
= (Value
.TokenCName
, key
[1], key
[2])
593 del BuildData
.Pcds
[key
]
594 BuildData
.Pcds
[newkey
] = Value
598 # handle the mixed pcd in FDF file
600 if key
in GlobalData
.MixedPcd
:
603 for item
in GlobalData
.MixedPcd
[key
]:
606 #Collect package set information from INF of FDF
608 for Inf
in ModuleList
:
609 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
610 if ModuleFile
in Platform
.Modules
:
612 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
613 PkgSet
.update(ModuleData
.Packages
)
614 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
619 DecPcds
.add((Pcd
[0], Pcd
[1]))
620 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
622 Platform
.SkuName
= self
.SkuId
623 for Name
, Guid
,Fileds
in PcdSet
:
624 if (Name
, Guid
) not in DecPcds
:
628 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
629 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
, Fileds
][0],
630 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
, Fileds
][1]
633 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
634 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
635 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
636 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
638 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
642 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
643 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
, Fileds
][0],
644 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
, Fileds
][1]
647 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
649 # Explicitly collect platform's dynamic PCDs
651 Pa
.CollectPlatformDynamicPcds()
652 Pa
.CollectFixedAtBuildPcds()
653 self
.AutoGenObjectList
.append(Pa
)
656 # Generate Package level hash value
658 GlobalData
.gPackageHash
= {}
659 if GlobalData
.gUseHashCache
:
661 self
._GenPkgLevelHash
(Pkg
)
664 # Check PCDs token value conflict in each DEC file.
666 self
._CheckAllPcdsTokenValueConflict
()
669 # Check PCD type and definition between DSC and DEC
671 self
._CheckPcdDefineAndType
()
674 # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.
676 content
= 'gCommandLineDefines: '
677 content
+= str(GlobalData
.gCommandLineDefines
)
678 content
+= TAB_LINE_BREAK
679 content
+= 'BuildOptionPcd: '
680 content
+= str(GlobalData
.BuildOptionPcd
)
681 content
+= TAB_LINE_BREAK
682 content
+= 'Active Platform: '
683 content
+= str(self
.Platform
)
684 content
+= TAB_LINE_BREAK
686 content
+= 'Flash Image Definition: '
687 content
+= str(self
.FdfFile
)
688 content
+= TAB_LINE_BREAK
689 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'BuildOptions'), content
, False)
692 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.
694 PcdTokenNumber
= 'PcdTokenNumber: '
695 if Pa
.PcdTokenNumber
:
696 if Pa
.DynamicPcdList
:
697 for Pcd
in Pa
.DynamicPcdList
:
698 PcdTokenNumber
+= TAB_LINE_BREAK
699 PcdTokenNumber
+= str((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
))
700 PcdTokenNumber
+= ' : '
701 PcdTokenNumber
+= str(Pa
.PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
])
702 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'), PcdTokenNumber
, False)
705 # Get set of workspace metafiles
707 AllWorkSpaceMetaFiles
= self
._GetMetaFiles
(Target
, Toolchain
, Arch
)
710 # Retrieve latest modified time of all metafiles
713 for f
in AllWorkSpaceMetaFiles
:
714 if os
.stat(f
)[8] > SrcTimeStamp
:
715 SrcTimeStamp
= os
.stat(f
)[8]
716 self
._SrcTimeStamp
= SrcTimeStamp
718 if GlobalData
.gUseHashCache
:
720 for files
in AllWorkSpaceMetaFiles
:
721 if files
.endswith('.dec'):
723 f
= open(files
, 'rb')
727 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'AutoGen.hash'), m
.hexdigest(), False)
728 GlobalData
.gPlatformHash
= m
.hexdigest()
731 # Write metafile list to build directory
733 AutoGenFilePath
= os
.path
.join(self
.BuildDir
, 'AutoGen')
734 if os
.path
.exists (AutoGenFilePath
):
735 os
.remove(AutoGenFilePath
)
736 if not os
.path
.exists(self
.BuildDir
):
737 os
.makedirs(self
.BuildDir
)
738 with
open(os
.path
.join(self
.BuildDir
, 'AutoGen'), 'w+') as file:
739 for f
in AllWorkSpaceMetaFiles
:
743 def _GenPkgLevelHash(self
, Pkg
):
744 if Pkg
.PackageName
in GlobalData
.gPackageHash
:
747 PkgDir
= os
.path
.join(self
.BuildDir
, Pkg
.Arch
, Pkg
.PackageName
)
748 CreateDirectory(PkgDir
)
749 HashFile
= os
.path
.join(PkgDir
, Pkg
.PackageName
+ '.hash')
751 # Get .dec file's hash value
752 f
= open(Pkg
.MetaFile
.Path
, 'rb')
756 # Get include files hash value
758 for inc
in sorted(Pkg
.Includes
, key
=lambda x
: str(x
)):
759 for Root
, Dirs
, Files
in os
.walk(str(inc
)):
760 for File
in sorted(Files
):
761 File_Path
= os
.path
.join(Root
, File
)
762 f
= open(File_Path
, 'rb')
766 SaveFileOnChange(HashFile
, m
.hexdigest(), False)
767 GlobalData
.gPackageHash
[Pkg
.PackageName
] = m
.hexdigest()
769 def _GetMetaFiles(self
, Target
, Toolchain
, Arch
):
770 AllWorkSpaceMetaFiles
= set()
775 AllWorkSpaceMetaFiles
.add (self
.FdfFile
.Path
)
776 for f
in GlobalData
.gFdfParser
.GetAllIncludedFile():
777 AllWorkSpaceMetaFiles
.add (f
.FileName
)
781 AllWorkSpaceMetaFiles
.add(self
.MetaFile
.Path
)
784 # add build_rule.txt & tools_def.txt
786 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultBuildRuleFile
))
787 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultToolsDefFile
))
789 # add BuildOption metafile
791 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'BuildOptions'))
793 # add PcdToken Number file for Dynamic/DynamicEx Pcd
795 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'))
797 for Arch
in self
.ArchList
:
801 for Package
in PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
).PackageList
:
802 AllWorkSpaceMetaFiles
.add(Package
.MetaFile
.Path
)
807 for filePath
in self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]._RawData
.IncludedFiles
:
808 AllWorkSpaceMetaFiles
.add(filePath
.Path
)
810 return AllWorkSpaceMetaFiles
812 def _CheckPcdDefineAndType(self
):
813 PcdTypeSet
= {TAB_PCDS_FIXED_AT_BUILD
,
814 TAB_PCDS_PATCHABLE_IN_MODULE
,
815 TAB_PCDS_FEATURE_FLAG
,
819 # This dict store PCDs which are not used by any modules with specified arches
820 UnusedPcd
= OrderedDict()
821 for Pa
in self
.AutoGenObjectList
:
822 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
823 for Pcd
in Pa
.Platform
.Pcds
:
824 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
826 # If no PCD type, this PCD comes from FDF
830 # Try to remove Hii and Vpd suffix
831 if PcdType
.startswith(TAB_PCDS_DYNAMIC_EX
):
832 PcdType
= TAB_PCDS_DYNAMIC_EX
833 elif PcdType
.startswith(TAB_PCDS_DYNAMIC
):
834 PcdType
= TAB_PCDS_DYNAMIC
836 for Package
in Pa
.PackageList
:
837 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
838 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
840 for Type
in PcdTypeSet
:
841 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
845 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
846 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
851 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
853 for Pcd
in UnusedPcd
:
856 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
857 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
858 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
863 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
865 ## Return the directory to store FV files
868 return path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
870 ## Return the directory to store all intermediate and final files built
873 return self
.AutoGenObjectList
[0].BuildDir
875 ## Return the build output directory platform specifies
878 return self
.Platform
.OutputDirectory
880 ## Return platform name
883 return self
.Platform
.PlatformName
885 ## Return meta-file GUID
888 return self
.Platform
.Guid
890 ## Return platform version
893 return self
.Platform
.Version
895 ## Return paths of tools
897 def ToolDefinition(self
):
898 return self
.AutoGenObjectList
[0].ToolDefinition
900 ## Return directory of platform makefile
902 # @retval string Makefile directory
905 def MakeFileDir(self
):
908 ## Return build command string
910 # @retval string Build command string
913 def BuildCommand(self
):
914 # BuildCommand should be all the same. So just get one from platform AutoGen
915 return self
.AutoGenObjectList
[0].BuildCommand
917 ## Check the PCDs token value conflict in each DEC file.
919 # Will cause build break and raise error message while two PCDs conflict.
923 def _CheckAllPcdsTokenValueConflict(self
):
924 for Pa
in self
.AutoGenObjectList
:
925 for Package
in Pa
.PackageList
:
926 PcdList
= list(Package
.Pcds
.values())
927 PcdList
.sort(key
=lambda x
: int(x
.TokenValue
, 0))
929 while (Count
< len(PcdList
) - 1) :
930 Item
= PcdList
[Count
]
931 ItemNext
= PcdList
[Count
+ 1]
933 # Make sure in the same token space the TokenValue should be unique
935 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
936 SameTokenValuePcdList
= []
937 SameTokenValuePcdList
.append(Item
)
938 SameTokenValuePcdList
.append(ItemNext
)
939 RemainPcdListLength
= len(PcdList
) - Count
- 2
940 for ValueSameCount
in range(RemainPcdListLength
):
941 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
942 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
946 # Sort same token value PCD list with TokenGuid and TokenCName
948 SameTokenValuePcdList
.sort(key
=lambda x
: "%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
))
949 SameTokenValuePcdListCount
= 0
950 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
952 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
953 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
955 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
956 for PcdItem
in GlobalData
.MixedPcd
:
957 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
958 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
964 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
965 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
968 SameTokenValuePcdListCount
+= 1
969 Count
+= SameTokenValuePcdListCount
972 PcdList
= list(Package
.Pcds
.values())
973 PcdList
.sort(key
=lambda x
: "%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
))
975 while (Count
< len(PcdList
) - 1) :
976 Item
= PcdList
[Count
]
977 ItemNext
= PcdList
[Count
+ 1]
979 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
981 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
985 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
986 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
990 ## Generate fds command
992 def GenFdsCommand(self
):
993 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
996 def GenFdsCommandDict(self
):
998 LogLevel
= EdkLogger
.GetLevel()
999 if LogLevel
== EdkLogger
.VERBOSE
:
1000 FdsCommandDict
["verbose"] = True
1001 elif LogLevel
<= EdkLogger
.DEBUG_9
:
1002 FdsCommandDict
["debug"] = LogLevel
- 1
1003 elif LogLevel
== EdkLogger
.QUIET
:
1004 FdsCommandDict
["quiet"] = True
1006 if GlobalData
.gEnableGenfdsMultiThread
:
1007 FdsCommandDict
["GenfdsMultiThread"] = True
1008 if GlobalData
.gIgnoreSource
:
1009 FdsCommandDict
["IgnoreSources"] = True
1011 FdsCommandDict
["OptionPcd"] = []
1012 for pcd
in GlobalData
.BuildOptionPcd
:
1014 pcdname
= '.'.join(pcd
[0:3])
1016 pcdname
= '.'.join(pcd
[0:2])
1017 if pcd
[3].startswith('{'):
1018 FdsCommandDict
["OptionPcd"].append(pcdname
+ '=' + 'H' + '"' + pcd
[3] + '"')
1020 FdsCommandDict
["OptionPcd"].append(pcdname
+ '=' + pcd
[3])
1023 # macros passed to GenFds
1025 MacroDict
.update(GlobalData
.gGlobalDefines
)
1026 MacroDict
.update(GlobalData
.gCommandLineDefines
)
1027 for MacroName
in MacroDict
:
1028 if MacroDict
[MacroName
] != "":
1029 MacroList
.append('"%s=%s"' % (MacroName
, MacroDict
[MacroName
].replace('\\', '\\\\')))
1031 MacroList
.append('"%s"' % MacroName
)
1032 FdsCommandDict
["macro"] = MacroList
1034 FdsCommandDict
["fdf_file"] = [self
.FdfFile
]
1035 FdsCommandDict
["build_target"] = self
.BuildTarget
1036 FdsCommandDict
["toolchain_tag"] = self
.ToolChain
1037 FdsCommandDict
["active_platform"] = str(self
)
1039 FdsCommandDict
["conf_directory"] = GlobalData
.gConfDirectory
1040 FdsCommandDict
["build_architecture_list"] = ','.join(self
.ArchList
)
1041 FdsCommandDict
["platform_build_directory"] = self
.BuildDir
1043 FdsCommandDict
["fd"] = self
.FdTargetList
1044 FdsCommandDict
["fv"] = self
.FvTargetList
1045 FdsCommandDict
["cap"] = self
.CapTargetList
1046 return FdsCommandDict
1048 ## Create makefile for the platform and modules in it
1050 # @param CreateDepsMakeFile Flag indicating if the makefile for
1051 # modules will be created as well
1053 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
1054 if not CreateDepsMakeFile
:
1056 for Pa
in self
.AutoGenObjectList
:
1057 Pa
.CreateMakeFile(True)
1059 ## Create autogen code for platform and modules
1061 # Since there's no autogen code for platform, this method will do nothing
1062 # if CreateModuleCodeFile is set to False.
1064 # @param CreateDepsCodeFile Flag indicating if creating module's
1065 # autogen code file or not
1067 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
1068 if not CreateDepsCodeFile
:
1070 for Pa
in self
.AutoGenObjectList
:
1071 Pa
.CreateCodeFile(True)
1073 ## Create AsBuilt INF file the platform
1075 def CreateAsBuiltInf(self
):
1079 ## AutoGen class for platform
1081 # PlatformAutoGen class will process the original information in platform
1082 # file in order to generate makefile for platform.
1084 class PlatformAutoGen(AutoGen
):
1085 # call super().__init__ then call the worker function with different parameter count
1086 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
1087 if not hasattr(self
, "_Init"):
1088 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
)
1091 # Used to store all PCDs for both PEI and DXE phase, in order to generate
1092 # correct PCD database
1095 _NonDynaPcdList_
= []
1099 # The priority list while override build option
1101 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
1102 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1103 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1104 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1105 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1106 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1107 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1108 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1109 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1110 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1111 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1112 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1113 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1114 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1115 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1116 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1118 ## Initialize PlatformAutoGen
1121 # @param Workspace WorkspaceAutoGen object
1122 # @param PlatformFile Platform file (DSC file)
1123 # @param Target Build target (DEBUG, RELEASE)
1124 # @param Toolchain Name of tool chain
1125 # @param Arch arch of the platform supports
1127 def _InitWorker(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1128 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1129 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1131 self
.MetaFile
= PlatformFile
1132 self
.Workspace
= Workspace
1133 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1134 self
.ToolChain
= Toolchain
1135 self
.BuildTarget
= Target
1137 self
.SourceDir
= PlatformFile
.SubDir
1138 self
.FdTargetList
= self
.Workspace
.FdTargetList
1139 self
.FvTargetList
= self
.Workspace
.FvTargetList
1140 # get the original module/package/platform objects
1141 self
.BuildDatabase
= Workspace
.BuildDatabase
1142 self
.DscBuildDataObj
= Workspace
.Platform
1144 # flag indicating if the makefile/C-code file has been created or not
1145 self
.IsMakeFileCreated
= False
1147 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1148 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1150 self
._AsBuildInfList
= []
1151 self
._AsBuildModuleList
= []
1153 self
.VariableInfo
= None
1155 if GlobalData
.gFdfParser
is not None:
1156 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1157 for Inf
in self
._AsBuildInfList
:
1158 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1159 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1160 if not M
.IsBinaryModule
:
1162 self
._AsBuildModuleList
.append(InfClass
)
1163 # get library/modules for build
1164 self
.LibraryBuildDirectoryList
= []
1165 self
.ModuleBuildDirectoryList
= []
1169 ## hash() operator of PlatformAutoGen
1171 # The platform file path and arch string will be used to represent
1172 # hash value of this object
1174 # @retval int Hash value of the platform file path and arch
1176 @cached_class_function
1178 return hash((self
.MetaFile
, self
.Arch
))
1180 @cached_class_function
1182 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1184 ## Create autogen code for platform and modules
1186 # Since there's no autogen code for platform, this method will do nothing
1187 # if CreateModuleCodeFile is set to False.
1189 # @param CreateModuleCodeFile Flag indicating if creating module's
1190 # autogen code file or not
1192 @cached_class_function
1193 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1194 # only module has code to be created, so do nothing if CreateModuleCodeFile is False
1195 if not CreateModuleCodeFile
:
1198 for Ma
in self
.ModuleAutoGenList
:
1199 Ma
.CreateCodeFile(True)
1201 ## Generate Fds Command
1203 def GenFdsCommand(self
):
1204 return self
.Workspace
.GenFdsCommand
1206 ## Create makefile for the platform and modules in it
1208 # @param CreateModuleMakeFile Flag indicating if the makefile for
1209 # modules will be created as well
1211 def CreateMakeFile(self
, CreateModuleMakeFile
=False, FfsCommand
= {}):
1212 if CreateModuleMakeFile
:
1213 for Ma
in self
._MaList
:
1214 key
= (Ma
.MetaFile
.File
, self
.Arch
)
1215 if key
in FfsCommand
:
1216 Ma
.CreateMakeFile(True, FfsCommand
[key
])
1218 Ma
.CreateMakeFile(True)
1220 # no need to create makefile for the platform more than once
1221 if self
.IsMakeFileCreated
:
1224 # create library/module build dirs for platform
1225 Makefile
= GenMake
.PlatformMakefile(self
)
1226 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1227 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1229 self
.IsMakeFileCreated
= True
1232 def AllPcdList(self
):
1233 return self
.DynamicPcdList
+ self
.NonDynamicPcdList
1234 ## Deal with Shared FixedAtBuild Pcds
1236 def CollectFixedAtBuildPcds(self
):
1237 for LibAuto
in self
.LibraryAutoGenList
:
1238 FixedAtBuildPcds
= {}
1239 ShareFixedAtBuildPcdsSameValue
= {}
1240 for Module
in LibAuto
.ReferenceModules
:
1241 for Pcd
in set(Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
):
1242 DefaultValue
= Pcd
.DefaultValue
1243 # Cover the case: DSC component override the Pcd value and the Pcd only used in one Lib
1244 if Pcd
in Module
.LibraryPcdList
:
1245 Index
= Module
.LibraryPcdList
.index(Pcd
)
1246 DefaultValue
= Module
.LibraryPcdList
[Index
].DefaultValue
1247 key
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1248 if key
not in FixedAtBuildPcds
:
1249 ShareFixedAtBuildPcdsSameValue
[key
] = True
1250 FixedAtBuildPcds
[key
] = DefaultValue
1252 if FixedAtBuildPcds
[key
] != DefaultValue
:
1253 ShareFixedAtBuildPcdsSameValue
[key
] = False
1254 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1255 key
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1256 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1259 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)]
1260 if DscPcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
1262 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1263 LibAuto
.ConstPcd
[key
] = FixedAtBuildPcds
[key
]
1265 def CollectVariables(self
, DynamicPcdSet
):
1268 if self
.Workspace
.FdfFile
:
1269 FdDict
= self
.Workspace
.FdfProfile
.FdDict
[GlobalData
.gFdfParser
.CurrentFdName
]
1270 for FdRegion
in FdDict
.RegionList
:
1271 for item
in FdRegion
.RegionDataList
:
1272 if self
.Platform
.VpdToolGuid
.strip() and self
.Platform
.VpdToolGuid
in item
:
1273 VpdRegionSize
= FdRegion
.Size
1274 VpdRegionBase
= FdRegion
.Offset
1277 VariableInfo
= VariableMgr(self
.DscBuildDataObj
._GetDefaultStores
(), self
.DscBuildDataObj
.SkuIds
)
1278 VariableInfo
.SetVpdRegionMaxSize(VpdRegionSize
)
1279 VariableInfo
.SetVpdRegionOffset(VpdRegionBase
)
1281 for Pcd
in DynamicPcdSet
:
1282 pcdname
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1283 for SkuName
in Pcd
.SkuInfoList
:
1284 Sku
= Pcd
.SkuInfoList
[SkuName
]
1286 if SkuId
is None or SkuId
== '':
1288 if len(Sku
.VariableName
) > 0:
1289 if Sku
.VariableAttribute
and 'NV' not in Sku
.VariableAttribute
:
1291 VariableGuidStructure
= Sku
.VariableGuidValue
1292 VariableGuid
= GuidStructureStringToGuidString(VariableGuidStructure
)
1293 for StorageName
in Sku
.DefaultStoreDict
:
1294 VariableInfo
.append_variable(var_info(Index
, pcdname
, StorageName
, SkuName
, StringToArray(Sku
.VariableName
), VariableGuid
, Sku
.VariableOffset
, Sku
.VariableAttribute
, Sku
.HiiDefaultValue
, Sku
.DefaultStoreDict
[StorageName
] if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
else StringToArray(Sku
.DefaultStoreDict
[StorageName
]), Pcd
.DatumType
, Pcd
.CustomAttribute
['DscPosition'], Pcd
.CustomAttribute
.get('IsStru',False)))
1298 def UpdateNVStoreMaxSize(self
, OrgVpdFile
):
1299 if self
.VariableInfo
:
1300 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
1301 PcdNvStoreDfBuffer
= [item
for item
in self
._DynamicPcdList
if item
.TokenCName
== "PcdNvStoreDefaultValueBuffer" and item
.TokenSpaceGuidCName
== "gEfiMdeModulePkgTokenSpaceGuid"]
1303 if PcdNvStoreDfBuffer
:
1304 if os
.path
.exists(VpdMapFilePath
):
1305 OrgVpdFile
.Read(VpdMapFilePath
)
1306 PcdItems
= OrgVpdFile
.GetOffset(PcdNvStoreDfBuffer
[0])
1307 NvStoreOffset
= list(PcdItems
.values())[0].strip() if PcdItems
else '0'
1309 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1311 NvStoreOffset
= int(NvStoreOffset
, 16) if NvStoreOffset
.upper().startswith("0X") else int(NvStoreOffset
)
1312 default_skuobj
= PcdNvStoreDfBuffer
[0].SkuInfoList
.get(TAB_DEFAULT
)
1313 maxsize
= self
.VariableInfo
.VpdRegionSize
- NvStoreOffset
if self
.VariableInfo
.VpdRegionSize
else len(default_skuobj
.DefaultValue
.split(","))
1314 var_data
= self
.VariableInfo
.PatchNVStoreDefaultMaxSize(maxsize
)
1316 if var_data
and default_skuobj
:
1317 default_skuobj
.DefaultValue
= var_data
1318 PcdNvStoreDfBuffer
[0].DefaultValue
= var_data
1319 PcdNvStoreDfBuffer
[0].SkuInfoList
.clear()
1320 PcdNvStoreDfBuffer
[0].SkuInfoList
[TAB_DEFAULT
] = default_skuobj
1321 PcdNvStoreDfBuffer
[0].MaxDatumSize
= str(len(default_skuobj
.DefaultValue
.split(",")))
1325 ## Collect dynamic PCDs
1327 # Gather dynamic PCDs list from each module and their settings from platform
1328 # This interface should be invoked explicitly when platform action is created.
1330 def CollectPlatformDynamicPcds(self
):
1331 for key
in self
.Platform
.Pcds
:
1332 for SinglePcd
in GlobalData
.MixedPcd
:
1333 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1334 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1335 Pcd_Type
= item
[0].split('_')[-1]
1336 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 \
1337 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in PCD_DYNAMIC_TYPE_SET
):
1338 Value
= self
.Platform
.Pcds
[key
]
1339 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1341 newkey
= (Value
.TokenCName
, key
[1])
1343 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1344 del self
.Platform
.Pcds
[key
]
1345 self
.Platform
.Pcds
[newkey
] = Value
1349 # for gathering error information
1350 NoDatumTypePcdList
= set()
1352 for InfName
in self
._AsBuildInfList
:
1353 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1354 FdfModuleList
.append(os
.path
.normpath(InfName
))
1355 for M
in self
._MaList
:
1356 # F is the Module for which M is the module autogen
1357 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1358 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1359 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
1360 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, M
.MetaFile
))
1362 # Check the PCD from Binary INF or Source INF
1363 if M
.IsBinaryModule
== True:
1364 PcdFromModule
.IsFromBinaryInf
= True
1366 # Check the PCD from DSC or not
1367 PcdFromModule
.IsFromDsc
= (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
1369 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
or PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1370 if M
.MetaFile
.Path
not in FdfModuleList
:
1371 # If one of the Source built modules listed in the DSC is not listed
1372 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1373 # access method (it is only listed in the DEC file that declares the
1374 # PCD as PcdsDynamic), then build tool will report warning message
1375 # notify the PI that they are attempting to build a module that must
1376 # be included in a flash image in order to be functional. These Dynamic
1377 # PCD will not be added into the Database unless it is used by other
1378 # modules that are included in the FDF file.
1379 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
and \
1380 PcdFromModule
.IsFromBinaryInf
== False:
1381 # Print warning message to let the developer make a determine.
1383 # If one of the Source built modules listed in the DSC is not listed in
1384 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1385 # access method (it is only listed in the DEC file that declares the
1386 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1387 # PCD to the Platform's PCD Database.
1388 if PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1391 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1392 # it should be stored in Pcd PEI database, If a dynamic only
1393 # used by DXE module, it should be stored in DXE PCD database.
1394 # The default Phase is DXE
1396 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
1397 PcdFromModule
.Phase
= "PEI"
1398 if PcdFromModule
not in self
._DynaPcdList
_:
1399 self
._DynaPcdList
_.append(PcdFromModule
)
1400 elif PcdFromModule
.Phase
== 'PEI':
1401 # overwrite any the same PCD existing, if Phase is PEI
1402 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1403 self
._DynaPcdList
_[Index
] = PcdFromModule
1404 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1405 self
._NonDynaPcdList
_.append(PcdFromModule
)
1406 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1407 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1408 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1409 #The PCD from Binary INF will override the same one from source INF
1410 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1411 PcdFromModule
.Pending
= False
1412 self
._NonDynaPcdList
_.append (PcdFromModule
)
1413 DscModuleSet
= {os
.path
.normpath(ModuleInf
.Path
) for ModuleInf
in self
.Platform
.Modules
}
1414 # add the PCD from modules that listed in FDF but not in DSC to Database
1415 for InfName
in FdfModuleList
:
1416 if InfName
not in DscModuleSet
:
1417 InfClass
= PathClass(InfName
)
1418 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1419 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1420 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1421 # For binary module, if in current arch, we need to list the PCDs into database.
1422 if not M
.IsBinaryModule
:
1424 # Override the module PCD setting by platform setting
1425 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1426 for PcdFromModule
in ModulePcdList
:
1427 PcdFromModule
.IsFromBinaryInf
= True
1428 PcdFromModule
.IsFromDsc
= False
1429 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1430 if PcdFromModule
.Type
not in PCD_DYNAMIC_EX_TYPE_SET
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1431 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1433 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1434 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1435 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1436 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
1437 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1438 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
1439 PcdFromModule
.Phase
= "PEI"
1440 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1441 self
._DynaPcdList
_.append(PcdFromModule
)
1442 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1443 self
._NonDynaPcdList
_.append(PcdFromModule
)
1444 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1445 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1446 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1447 # module & DXE module at a same time.
1448 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1449 # INF file as DynamicEx.
1450 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1451 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1452 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1453 for PcdFromModule
in self
._NonDynaPcdList
_:
1454 # If a PCD is not listed in the DSC file, but binary INF files used by
1455 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1456 # section, AND all source INF files used by this platform the build
1457 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1458 # section, then the tools must NOT add the PCD to the Platform's PCD
1459 # Database; the build must assign the access method for this PCD as
1460 # PcdsPatchableInModule.
1461 if PcdFromModule
not in self
._DynaPcdList
_:
1463 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1464 if PcdFromModule
.IsFromDsc
== False and \
1465 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1466 PcdFromModule
.IsFromBinaryInf
== True and \
1467 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1468 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1469 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1471 # print out error information and break the build, if error found
1472 if len(NoDatumTypePcdList
) > 0:
1473 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1474 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1476 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1477 % NoDatumTypePcdListString
)
1478 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1479 self
._DynamicPcdList
= self
._DynaPcdList
_
1481 # Sort dynamic PCD list to:
1482 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1483 # try to be put header of dynamicd List
1484 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1486 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1488 UnicodePcdArray
= set()
1490 OtherPcdArray
= set()
1492 VpdFile
= VpdInfoFile
.VpdInfoFile()
1493 NeedProcessVpdMapFile
= False
1495 for pcd
in self
.Platform
.Pcds
:
1496 if pcd
not in self
._PlatformPcds
:
1497 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1499 for item
in self
._PlatformPcds
:
1500 if self
._PlatformPcds
[item
].DatumType
and self
._PlatformPcds
[item
].DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1501 self
._PlatformPcds
[item
].DatumType
= TAB_VOID
1503 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1504 for Pcd
in self
._DynamicPcdList
:
1505 # just pick the a value to determine whether is unicode string type
1506 Sku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
1507 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1509 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1510 Pcd
.DatumType
= TAB_VOID
1512 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1513 # if found HII type PCD then insert to right of UnicodeIndex
1514 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1515 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1517 #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer
1518 PcdNvStoreDfBuffer
= VpdPcdDict
.get(("PcdNvStoreDefaultValueBuffer", "gEfiMdeModulePkgTokenSpaceGuid"))
1519 if PcdNvStoreDfBuffer
:
1520 self
.VariableInfo
= self
.CollectVariables(self
._DynamicPcdList
)
1521 vardump
= self
.VariableInfo
.dump()
1524 #According to PCD_DATABASE_INIT in edk2\MdeModulePkg\Include\Guid\PcdDataBaseSignatureGuid.h,
1525 #the max size for string PCD should not exceed USHRT_MAX 65535(0xffff).
1526 #typedef UINT16 SIZE_INFO;
1527 #//SIZE_INFO SizeTable[];
1528 if len(vardump
.split(",")) > 0xffff:
1529 EdkLogger
.error("build", RESOURCE_OVERFLOW
, 'The current length of PCD %s value is %d, it exceeds to the max size of String PCD.' %(".".join([PcdNvStoreDfBuffer
.TokenSpaceGuidCName
,PcdNvStoreDfBuffer
.TokenCName
]) ,len(vardump
.split(","))))
1530 PcdNvStoreDfBuffer
.DefaultValue
= vardump
1531 for skuname
in PcdNvStoreDfBuffer
.SkuInfoList
:
1532 PcdNvStoreDfBuffer
.SkuInfoList
[skuname
].DefaultValue
= vardump
1533 PcdNvStoreDfBuffer
.MaxDatumSize
= str(len(vardump
.split(",")))
1535 #If the end user define [DefaultStores] and [XXX.Menufacturing] in DSC, but forget to configure PcdNvStoreDefaultValueBuffer to PcdsDynamicVpd
1536 if [Pcd
for Pcd
in self
._DynamicPcdList
if Pcd
.UserDefinedDefaultStoresFlag
]:
1537 EdkLogger
.warn("build", "PcdNvStoreDefaultValueBuffer should be defined as PcdsDynamicExVpd in dsc file since the DefaultStores is enabled for this platform.\n%s" %self
.Platform
.MetaFile
.Path
)
1538 PlatformPcds
= sorted(self
._PlatformPcds
.keys())
1540 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1543 for PcdKey
in PlatformPcds
:
1544 Pcd
= self
._PlatformPcds
[PcdKey
]
1545 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1546 PcdKey
in VpdPcdDict
:
1547 Pcd
= VpdPcdDict
[PcdKey
]
1549 DefaultSku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
1551 PcdValue
= DefaultSku
.DefaultValue
1552 if PcdValue
not in SkuValueMap
:
1553 SkuValueMap
[PcdValue
] = []
1554 VpdFile
.Add(Pcd
, TAB_DEFAULT
, DefaultSku
.VpdOffset
)
1555 SkuValueMap
[PcdValue
].append(DefaultSku
)
1557 for (SkuName
, Sku
) in Pcd
.SkuInfoList
.items():
1558 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1559 PcdValue
= Sku
.DefaultValue
1561 PcdValue
= Pcd
.DefaultValue
1562 if Sku
.VpdOffset
!= TAB_STAR
:
1563 if PcdValue
.startswith("{"):
1565 elif PcdValue
.startswith("L"):
1570 VpdOffset
= int(Sku
.VpdOffset
)
1573 VpdOffset
= int(Sku
.VpdOffset
, 16)
1575 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1576 if VpdOffset
% Alignment
!= 0:
1577 if PcdValue
.startswith("{"):
1578 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1580 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1581 if PcdValue
not in SkuValueMap
:
1582 SkuValueMap
[PcdValue
] = []
1583 VpdFile
.Add(Pcd
, SkuName
, Sku
.VpdOffset
)
1584 SkuValueMap
[PcdValue
].append(Sku
)
1585 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1586 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== TAB_STAR
:
1587 NeedProcessVpdMapFile
= True
1588 if self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== '':
1589 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1590 "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.")
1592 VpdSkuMap
[PcdKey
] = SkuValueMap
1594 # Fix the PCDs define in VPD PCD section that never referenced by module.
1595 # An example is PCD for signature usage.
1597 for DscPcd
in PlatformPcds
:
1598 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1599 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1600 if not (self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== ''):
1602 for VpdPcd
in VpdFile
._VpdArray
:
1603 # This PCD has been referenced by module
1604 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1605 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1608 # Not found, it should be signature
1610 # just pick the a value to determine whether is unicode string type
1612 SkuObjList
= list(DscPcdEntry
.SkuInfoList
.items())
1613 DefaultSku
= DscPcdEntry
.SkuInfoList
.get(TAB_DEFAULT
)
1615 defaultindex
= SkuObjList
.index((TAB_DEFAULT
, DefaultSku
))
1616 SkuObjList
[0], SkuObjList
[defaultindex
] = SkuObjList
[defaultindex
], SkuObjList
[0]
1617 for (SkuName
, Sku
) in SkuObjList
:
1618 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1620 # Need to iterate DEC pcd information to get the value & datumtype
1621 for eachDec
in self
.PackageList
:
1622 for DecPcd
in eachDec
.Pcds
:
1623 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1624 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1625 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1626 # Print warning message to let the developer make a determine.
1627 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1628 File
=self
.MetaFile
, \
1629 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1630 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1632 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1633 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1634 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1635 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1636 # Only fix the value while no value provided in DSC file.
1637 if not Sku
.DefaultValue
:
1638 DscPcdEntry
.SkuInfoList
[list(DscPcdEntry
.SkuInfoList
.keys())[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1640 if DscPcdEntry
not in self
._DynamicPcdList
:
1641 self
._DynamicPcdList
.append(DscPcdEntry
)
1642 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1643 PcdValue
= Sku
.DefaultValue
1645 PcdValue
= DscPcdEntry
.DefaultValue
1646 if Sku
.VpdOffset
!= TAB_STAR
:
1647 if PcdValue
.startswith("{"):
1649 elif PcdValue
.startswith("L"):
1654 VpdOffset
= int(Sku
.VpdOffset
)
1657 VpdOffset
= int(Sku
.VpdOffset
, 16)
1659 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1660 if VpdOffset
% Alignment
!= 0:
1661 if PcdValue
.startswith("{"):
1662 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1664 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1665 if PcdValue
not in SkuValueMap
:
1666 SkuValueMap
[PcdValue
] = []
1667 VpdFile
.Add(DscPcdEntry
, SkuName
, Sku
.VpdOffset
)
1668 SkuValueMap
[PcdValue
].append(Sku
)
1669 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== TAB_STAR
:
1670 NeedProcessVpdMapFile
= True
1671 if DscPcdEntry
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
1672 UnicodePcdArray
.add(DscPcdEntry
)
1673 elif len(Sku
.VariableName
) > 0:
1674 HiiPcdArray
.add(DscPcdEntry
)
1676 OtherPcdArray
.add(DscPcdEntry
)
1678 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1679 VpdSkuMap
[DscPcd
] = SkuValueMap
1680 if (self
.Platform
.FlashDefinition
is None or self
.Platform
.FlashDefinition
== '') and \
1681 VpdFile
.GetCount() != 0:
1682 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1683 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1685 if VpdFile
.GetCount() != 0:
1687 self
.FixVpdOffset(VpdFile
)
1689 self
.FixVpdOffset(self
.UpdateNVStoreMaxSize(VpdFile
))
1690 PcdNvStoreDfBuffer
= [item
for item
in self
._DynamicPcdList
if item
.TokenCName
== "PcdNvStoreDefaultValueBuffer" and item
.TokenSpaceGuidCName
== "gEfiMdeModulePkgTokenSpaceGuid"]
1691 if PcdNvStoreDfBuffer
:
1692 PcdName
,PcdGuid
= PcdNvStoreDfBuffer
[0].TokenCName
, PcdNvStoreDfBuffer
[0].TokenSpaceGuidCName
1693 if (PcdName
,PcdGuid
) in VpdSkuMap
:
1694 DefaultSku
= PcdNvStoreDfBuffer
[0].SkuInfoList
.get(TAB_DEFAULT
)
1695 VpdSkuMap
[(PcdName
,PcdGuid
)] = {DefaultSku
.DefaultValue
:[SkuObj
for SkuObj
in PcdNvStoreDfBuffer
[0].SkuInfoList
.values() ]}
1697 # Process VPD map file generated by third party BPDG tool
1698 if NeedProcessVpdMapFile
:
1699 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
1700 if os
.path
.exists(VpdMapFilePath
):
1701 VpdFile
.Read(VpdMapFilePath
)
1703 # Fixup TAB_STAR offset
1704 for pcd
in VpdSkuMap
:
1705 vpdinfo
= VpdFile
.GetVpdInfo(pcd
)
1707 # just pick the a value to determine whether is unicode string type
1709 for pcdvalue
in VpdSkuMap
[pcd
]:
1710 for sku
in VpdSkuMap
[pcd
][pcdvalue
]:
1711 for item
in vpdinfo
:
1712 if item
[2] == pcdvalue
:
1713 sku
.VpdOffset
= item
[1]
1715 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1717 # Delete the DynamicPcdList At the last time enter into this function
1718 for Pcd
in self
._DynamicPcdList
:
1719 # just pick the a value to determine whether is unicode string type
1720 Sku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
1721 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1723 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1724 Pcd
.DatumType
= TAB_VOID
1726 PcdValue
= Sku
.DefaultValue
1727 if Pcd
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
1728 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1729 UnicodePcdArray
.add(Pcd
)
1730 elif len(Sku
.VariableName
) > 0:
1731 # if found HII type PCD then insert to right of UnicodeIndex
1732 HiiPcdArray
.add(Pcd
)
1734 OtherPcdArray
.add(Pcd
)
1735 del self
._DynamicPcdList
[:]
1736 self
._DynamicPcdList
.extend(list(UnicodePcdArray
))
1737 self
._DynamicPcdList
.extend(list(HiiPcdArray
))
1738 self
._DynamicPcdList
.extend(list(OtherPcdArray
))
1739 allskuset
= [(SkuName
, Sku
.SkuId
) for pcd
in self
._DynamicPcdList
for (SkuName
, Sku
) in pcd
.SkuInfoList
.items()]
1740 for pcd
in self
._DynamicPcdList
:
1741 if len(pcd
.SkuInfoList
) == 1:
1742 for (SkuName
, SkuId
) in allskuset
:
1743 if isinstance(SkuId
, str) and eval(SkuId
) == 0 or SkuId
== 0:
1745 pcd
.SkuInfoList
[SkuName
] = copy
.deepcopy(pcd
.SkuInfoList
[TAB_DEFAULT
])
1746 pcd
.SkuInfoList
[SkuName
].SkuId
= SkuId
1747 pcd
.SkuInfoList
[SkuName
].SkuIdName
= SkuName
1749 def FixVpdOffset(self
, VpdFile
):
1750 FvPath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
1751 if not os
.path
.exists(FvPath
):
1755 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1757 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1759 if VpdFile
.Write(VpdFilePath
):
1760 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1762 for ToolDef
in self
.ToolDefinition
.values():
1763 if TAB_GUID
in ToolDef
and ToolDef
[TAB_GUID
] == self
.Platform
.VpdToolGuid
:
1764 if "PATH" not in ToolDef
:
1765 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1766 BPDGToolName
= ToolDef
["PATH"]
1768 # Call third party GUID BPDG tool.
1769 if BPDGToolName
is not None:
1770 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1772 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.")
1774 ## Return the platform build data object
1777 return self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1779 ## Return platform name
1782 return self
.Platform
.PlatformName
1784 ## Return the meta file GUID
1787 return self
.Platform
.Guid
1789 ## Return the platform version
1792 return self
.Platform
.Version
1794 ## Return the FDF file name
1797 if self
.Workspace
.FdfFile
:
1798 RetVal
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1803 ## Return the build output directory platform specifies
1805 def OutputDir(self
):
1806 return self
.Platform
.OutputDirectory
1808 ## Return the directory to store all intermediate and final files built
1811 if os
.path
.isabs(self
.OutputDir
):
1812 GlobalData
.gBuildDirectory
= RetVal
= path
.join(
1813 path
.abspath(self
.OutputDir
),
1814 self
.BuildTarget
+ "_" + self
.ToolChain
,
1817 GlobalData
.gBuildDirectory
= RetVal
= path
.join(
1820 self
.BuildTarget
+ "_" + self
.ToolChain
,
1824 ## Return directory of platform makefile
1826 # @retval string Makefile directory
1829 def MakeFileDir(self
):
1830 return path
.join(self
.BuildDir
, self
.Arch
)
1832 ## Return build command string
1834 # @retval string Build command string
1837 def BuildCommand(self
):
1839 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1840 RetVal
+= _SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1841 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1842 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1844 RetVal
+= _SplitOption(NewOption
)
1845 if "MAKE" in self
.EdkIIBuildOption
:
1846 if "FLAGS" in self
.EdkIIBuildOption
["MAKE"]:
1847 Flags
= self
.EdkIIBuildOption
["MAKE"]["FLAGS"]
1848 if Flags
.startswith('='):
1849 RetVal
= [RetVal
[0]] + [Flags
[1:]]
1851 RetVal
.append(Flags
)
1854 ## Get tool chain definition
1856 # Get each tool definition for given tool chain from tools_def.txt and platform
1859 def ToolDefinition(self
):
1860 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1861 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1862 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1863 ExtraData
="[%s]" % self
.MetaFile
)
1866 for Def
in ToolDefinition
:
1867 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1868 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1871 Value
= ToolDefinition
[Def
]
1872 # don't record the DLL
1874 DllPathList
.add(Value
)
1877 if Tool
not in RetVal
:
1879 RetVal
[Tool
][Attr
] = Value
1882 if GlobalData
.gOptions
.SilentMode
and "MAKE" in RetVal
:
1883 if "FLAGS" not in RetVal
["MAKE"]:
1884 RetVal
["MAKE"]["FLAGS"] = ""
1885 RetVal
["MAKE"]["FLAGS"] += " -s"
1888 for Attr
in RetVal
[Tool
]:
1889 Value
= RetVal
[Tool
][Attr
]
1890 if Tool
in self
._BuildOptionWithToolDef
(RetVal
) and Attr
in self
._BuildOptionWithToolDef
(RetVal
)[Tool
]:
1891 # check if override is indicated
1892 if self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
].startswith('='):
1893 Value
= self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
][1:]
1896 Value
+= " " + self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
]
1898 Value
= self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
]
1901 # Don't put MAKE definition in the file
1903 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1905 # Don't put MAKE definition in the file
1910 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1913 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
, False)
1914 for DllPath
in DllPathList
:
1915 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1916 os
.environ
["MAKE_FLAGS"] = MakeFlags
1920 ## Return the paths of tools
1922 def ToolDefinitionFile(self
):
1923 return os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1925 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1927 def ToolChainFamily(self
):
1928 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1929 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1930 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1931 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1932 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1934 RetVal
= TAB_COMPILER_MSFT
1936 RetVal
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1940 def BuildRuleFamily(self
):
1941 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1942 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1943 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1944 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1945 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1947 return TAB_COMPILER_MSFT
1949 return ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1951 ## Return the build options specific for all modules in this platform
1953 def BuildOption(self
):
1954 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1956 def _BuildOptionWithToolDef(self
, ToolDef
):
1957 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, ToolDef
=ToolDef
)
1959 ## Return the build options specific for EDK modules in this platform
1961 def EdkBuildOption(self
):
1962 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1964 ## Return the build options specific for EDKII modules in this platform
1966 def EdkIIBuildOption(self
):
1967 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1969 ## Parse build_rule.txt in Conf Directory.
1971 # @retval BuildRule object
1974 def BuildRule(self
):
1975 BuildRuleFile
= None
1976 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1977 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1978 if not BuildRuleFile
:
1979 BuildRuleFile
= gDefaultBuildRuleFile
1980 RetVal
= BuildRule(BuildRuleFile
)
1981 if RetVal
._FileVersion
== "":
1982 RetVal
._FileVersion
= AutoGenReqBuildRuleVerNum
1984 if RetVal
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1985 # If Build Rule's version is less than the version number required by the tools, halting the build.
1986 EdkLogger
.error("build", AUTOGEN_ERROR
,
1987 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])"\
1988 % (RetVal
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1991 ## Summarize the packages used by modules in this platform
1993 def PackageList(self
):
1995 for La
in self
.LibraryAutoGenList
:
1996 RetVal
.update(La
.DependentPackageList
)
1997 for Ma
in self
.ModuleAutoGenList
:
1998 RetVal
.update(Ma
.DependentPackageList
)
1999 #Collect package set information from INF of FDF
2000 for ModuleFile
in self
._AsBuildModuleList
:
2001 if ModuleFile
in self
.Platform
.Modules
:
2003 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2004 RetVal
.update(ModuleData
.Packages
)
2008 def NonDynamicPcdDict(self
):
2009 return {(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
):Pcd
for Pcd
in self
.NonDynamicPcdList
}
2011 ## Get list of non-dynamic PCDs
2013 def NonDynamicPcdList(self
):
2014 if not self
._NonDynamicPcdList
:
2015 self
.CollectPlatformDynamicPcds()
2016 return self
._NonDynamicPcdList
2018 ## Get list of dynamic PCDs
2020 def DynamicPcdList(self
):
2021 if not self
._DynamicPcdList
:
2022 self
.CollectPlatformDynamicPcds()
2023 return self
._DynamicPcdList
2025 ## Generate Token Number for all PCD
2027 def PcdTokenNumber(self
):
2028 RetVal
= OrderedDict()
2031 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
2035 # TokenNumber 0 ~ 10
2037 # TokeNumber 11 ~ 20
2039 for Pcd
in self
.DynamicPcdList
:
2040 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
2041 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2042 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2045 for Pcd
in self
.DynamicPcdList
:
2046 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2047 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2048 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2051 for Pcd
in self
.DynamicPcdList
:
2052 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
2053 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2054 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2057 for Pcd
in self
.DynamicPcdList
:
2058 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2059 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2060 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2063 for Pcd
in self
.NonDynamicPcdList
:
2064 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2070 for ModuleFile
in self
.Platform
.Modules
:
2079 self
.Platform
.Modules
[ModuleFile
].M
= Ma
2080 return [x
.M
for x
in self
.Platform
.Modules
.values()]
2082 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
2084 def ModuleAutoGenList(self
):
2086 for Ma
in self
._MaList
:
2087 if Ma
not in RetVal
:
2091 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
2093 def LibraryAutoGenList(self
):
2095 for Ma
in self
._MaList
:
2096 for La
in Ma
.LibraryAutoGenList
:
2097 if La
not in RetVal
:
2099 if Ma
not in La
.ReferenceModules
:
2100 La
.ReferenceModules
.append(Ma
)
2103 ## Test if a module is supported by the platform
2105 # An error will be raised directly if the module or its arch is not supported
2106 # by the platform or current configuration
2108 def ValidModule(self
, Module
):
2109 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
2110 or Module
in self
._AsBuildModuleList
2112 ## Resolve the library classes in a module to library instances
2114 # This method will not only resolve library classes but also sort the library
2115 # instances according to the dependency-ship.
2117 # @param Module The module from which the library classes will be resolved
2119 # @retval library_list List of library instances sorted
2121 def ApplyLibraryInstance(self
, Module
):
2122 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
2123 if str(Module
) not in self
.Platform
.Modules
:
2126 return GetModuleLibInstances(Module
,
2135 ## Override PCD setting (type, value, ...)
2137 # @param ToPcd The PCD to be overridden
2138 # @param FromPcd The PCD overriding from
2140 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
="", Msg
="", Library
=""):
2142 # in case there's PCDs coming from FDF file, which have no type given.
2143 # at this point, ToPcd.Type has the type found from dependent
2146 TokenCName
= ToPcd
.TokenCName
2147 for PcdItem
in GlobalData
.MixedPcd
:
2148 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2149 TokenCName
= PcdItem
[0]
2151 if FromPcd
is not None:
2152 if ToPcd
.Pending
and FromPcd
.Type
:
2153 ToPcd
.Type
= FromPcd
.Type
2154 elif ToPcd
.Type
and FromPcd
.Type\
2155 and ToPcd
.Type
!= FromPcd
.Type
and ToPcd
.Type
in FromPcd
.Type
:
2156 if ToPcd
.Type
.strip() == TAB_PCDS_DYNAMIC_EX
:
2157 ToPcd
.Type
= FromPcd
.Type
2158 elif ToPcd
.Type
and FromPcd
.Type \
2159 and ToPcd
.Type
!= FromPcd
.Type
:
2161 Module
= str(Module
) + " 's library file (" + str(Library
) + ")"
2162 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2163 ExtraData
="%s.%s is used as [%s] in module %s, but as [%s] in %s."\
2164 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2165 ToPcd
.Type
, Module
, FromPcd
.Type
, Msg
),
2168 if FromPcd
.MaxDatumSize
:
2169 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2170 ToPcd
.MaxSizeUserSet
= FromPcd
.MaxDatumSize
2171 if FromPcd
.DefaultValue
:
2172 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2173 if FromPcd
.TokenValue
:
2174 ToPcd
.TokenValue
= FromPcd
.TokenValue
2175 if FromPcd
.DatumType
:
2176 ToPcd
.DatumType
= FromPcd
.DatumType
2177 if FromPcd
.SkuInfoList
:
2178 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2179 if FromPcd
.UserDefinedDefaultStoresFlag
:
2180 ToPcd
.UserDefinedDefaultStoresFlag
= FromPcd
.UserDefinedDefaultStoresFlag
2181 # Add Flexible PCD format parse
2182 if ToPcd
.DefaultValue
:
2184 ToPcd
.DefaultValue
= ValueExpressionEx(ToPcd
.DefaultValue
, ToPcd
.DatumType
, self
.Workspace
._GuidDict
)(True)
2185 except BadExpression
as Value
:
2186 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %(ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
, ToPcd
.DefaultValue
, Value
),
2189 # check the validation of datum
2190 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2192 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2193 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2194 ToPcd
.validateranges
= FromPcd
.validateranges
2195 ToPcd
.validlists
= FromPcd
.validlists
2196 ToPcd
.expressions
= FromPcd
.expressions
2197 ToPcd
.CustomAttribute
= FromPcd
.CustomAttribute
2199 if FromPcd
is not None and ToPcd
.DatumType
== TAB_VOID
and not ToPcd
.MaxDatumSize
:
2200 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2201 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2202 Value
= ToPcd
.DefaultValue
2204 ToPcd
.MaxDatumSize
= '1'
2205 elif Value
[0] == 'L':
2206 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2207 elif Value
[0] == '{':
2208 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2210 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2212 # apply default SKU for dynamic PCDS if specified one is not available
2213 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_SET
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
) \
2214 and not ToPcd
.SkuInfoList
:
2215 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2216 SkuName
= self
.Platform
.SkuName
2218 SkuName
= TAB_DEFAULT
2219 ToPcd
.SkuInfoList
= {
2220 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
][0], '', '', '', '', '', ToPcd
.DefaultValue
)
2223 ## Apply PCD setting defined platform to a module
2225 # @param Module The module from which the PCD setting will be overridden
2227 # @retval PCD_list The list PCDs with settings from platform
2229 def ApplyPcdSetting(self
, Module
, Pcds
, Library
=""):
2230 # for each PCD in module
2231 for Name
, Guid
in Pcds
:
2232 PcdInModule
= Pcds
[Name
, Guid
]
2233 # find out the PCD setting in platform
2234 if (Name
, Guid
) in self
.Platform
.Pcds
:
2235 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2237 PcdInPlatform
= None
2238 # then override the settings if any
2239 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
, Msg
="DSC PCD sections", Library
=Library
)
2240 # resolve the VariableGuid value
2241 for SkuId
in PcdInModule
.SkuInfoList
:
2242 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2243 if Sku
.VariableGuid
== '': continue
2244 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
2245 if Sku
.VariableGuidValue
is None:
2246 PackageList
= "\n\t".join(str(P
) for P
in self
.PackageList
)
2249 RESOURCE_NOT_AVAILABLE
,
2250 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2251 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2252 % (Guid
, Name
, str(Module
)),
2256 # override PCD settings with module specific setting
2257 if Module
in self
.Platform
.Modules
:
2258 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2259 for Key
in PlatformModule
.Pcds
:
2260 if GlobalData
.BuildOptionPcd
:
2261 for pcd
in GlobalData
.BuildOptionPcd
:
2262 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
2263 if (TokenCName
, TokenSpaceGuidCName
) == Key
and FieldName
=="":
2264 PlatformModule
.Pcds
[Key
].DefaultValue
= pcdvalue
2265 PlatformModule
.Pcds
[Key
].PcdValueFromComm
= pcdvalue
2271 elif Key
in GlobalData
.MixedPcd
:
2272 for PcdItem
in GlobalData
.MixedPcd
[Key
]:
2274 ToPcd
= Pcds
[PcdItem
]
2278 self
._OverridePcd
(ToPcd
, PlatformModule
.Pcds
[Key
], Module
, Msg
="DSC Components Module scoped PCD section", Library
=Library
)
2279 # use PCD value to calculate the MaxDatumSize when it is not specified
2280 for Name
, Guid
in Pcds
:
2281 Pcd
= Pcds
[Name
, Guid
]
2282 if Pcd
.DatumType
== TAB_VOID
and not Pcd
.MaxDatumSize
:
2283 Pcd
.MaxSizeUserSet
= None
2284 Value
= Pcd
.DefaultValue
2286 Pcd
.MaxDatumSize
= '1'
2287 elif Value
[0] == 'L':
2288 Pcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2289 elif Value
[0] == '{':
2290 Pcd
.MaxDatumSize
= str(len(Value
.split(',')))
2292 Pcd
.MaxDatumSize
= str(len(Value
) - 1)
2293 return list(Pcds
.values())
2297 ## Calculate the priority value of the build option
2299 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2301 # @retval Value Priority value based on the priority list.
2303 def CalculatePriorityValue(self
, Key
):
2304 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2305 PriorityValue
= 0x11111
2306 if Target
== TAB_STAR
:
2307 PriorityValue
&= 0x01111
2308 if ToolChain
== TAB_STAR
:
2309 PriorityValue
&= 0x10111
2310 if Arch
== TAB_STAR
:
2311 PriorityValue
&= 0x11011
2312 if CommandType
== TAB_STAR
:
2313 PriorityValue
&= 0x11101
2314 if Attr
== TAB_STAR
:
2315 PriorityValue
&= 0x11110
2317 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2320 ## Expand * in build option key
2322 # @param Options Options to be expanded
2323 # @param ToolDef Use specified ToolDef instead of full version.
2324 # This is needed during initialization to prevent
2325 # infinite recursion betweeh BuildOptions,
2326 # ToolDefinition, and this function.
2328 # @retval options Options expanded
2330 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None, ToolDef
=None):
2332 ToolDef
= self
.ToolDefinition
2339 # Construct a list contain the build options which need override.
2343 # Key[0] -- tool family
2344 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2346 if (Key
[0] == self
.BuildRuleFamily
and
2347 (ModuleStyle
is None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2348 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2349 if (Target
== self
.BuildTarget
or Target
== TAB_STAR
) and\
2350 (ToolChain
== self
.ToolChain
or ToolChain
== TAB_STAR
) and\
2351 (Arch
== self
.Arch
or Arch
== TAB_STAR
) and\
2352 Options
[Key
].startswith("="):
2354 if OverrideList
.get(Key
[1]) is not None:
2355 OverrideList
.pop(Key
[1])
2356 OverrideList
[Key
[1]] = Options
[Key
]
2359 # Use the highest priority value.
2361 if (len(OverrideList
) >= 2):
2362 KeyList
= list(OverrideList
.keys())
2363 for Index
in range(len(KeyList
)):
2364 NowKey
= KeyList
[Index
]
2365 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2366 for Index1
in range(len(KeyList
) - Index
- 1):
2367 NextKey
= KeyList
[Index1
+ Index
+ 1]
2369 # Compare two Key, if one is included by another, choose the higher priority one
2371 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2372 if (Target1
== Target2
or Target1
== TAB_STAR
or Target2
== TAB_STAR
) and\
2373 (ToolChain1
== ToolChain2
or ToolChain1
== TAB_STAR
or ToolChain2
== TAB_STAR
) and\
2374 (Arch1
== Arch2
or Arch1
== TAB_STAR
or Arch2
== TAB_STAR
) and\
2375 (CommandType1
== CommandType2
or CommandType1
== TAB_STAR
or CommandType2
== TAB_STAR
) and\
2376 (Attr1
== Attr2
or Attr1
== TAB_STAR
or Attr2
== TAB_STAR
):
2378 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2379 if Options
.get((self
.BuildRuleFamily
, NextKey
)) is not None:
2380 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2382 if Options
.get((self
.BuildRuleFamily
, NowKey
)) is not None:
2383 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2386 if ModuleStyle
is not None and len (Key
) > 2:
2387 # Check Module style is EDK or EDKII.
2388 # Only append build option for the matched style module.
2389 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2391 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2394 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2395 # if tool chain family doesn't match, skip it
2396 if Tool
in ToolDef
and Family
!= "":
2397 FamilyIsNull
= False
2398 if ToolDef
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2399 if Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2401 elif Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2404 # expand any wildcard
2405 if Target
== TAB_STAR
or Target
== self
.BuildTarget
:
2406 if Tag
== TAB_STAR
or Tag
== self
.ToolChain
:
2407 if Arch
== TAB_STAR
or Arch
== self
.Arch
:
2408 if Tool
not in BuildOptions
:
2409 BuildOptions
[Tool
] = {}
2410 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2411 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2413 # append options for the same tool except PATH
2415 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2417 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2418 # Build Option Family has been checked, which need't to be checked again for family.
2419 if FamilyMatch
or FamilyIsNull
:
2423 if ModuleStyle
is not None and len (Key
) > 2:
2424 # Check Module style is EDK or EDKII.
2425 # Only append build option for the matched style module.
2426 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2428 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2431 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2432 # if tool chain family doesn't match, skip it
2433 if Tool
not in ToolDef
or Family
== "":
2435 # option has been added before
2436 if Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2439 # expand any wildcard
2440 if Target
== TAB_STAR
or Target
== self
.BuildTarget
:
2441 if Tag
== TAB_STAR
or Tag
== self
.ToolChain
:
2442 if Arch
== TAB_STAR
or Arch
== self
.Arch
:
2443 if Tool
not in BuildOptions
:
2444 BuildOptions
[Tool
] = {}
2445 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2446 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2448 # append options for the same tool except PATH
2450 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2452 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2455 ## Append build options in platform to a module
2457 # @param Module The module to which the build options will be appended
2459 # @retval options The options appended with build options in platform
2461 def ApplyBuildOption(self
, Module
):
2462 # Get the different options for the different style module
2463 PlatformOptions
= self
.EdkIIBuildOption
2464 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2465 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2466 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2467 if Module
in self
.Platform
.Modules
:
2468 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2469 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2471 PlatformModuleOptions
= {}
2473 BuildRuleOrder
= None
2474 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2475 for Tool
in Options
:
2476 for Attr
in Options
[Tool
]:
2477 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2478 BuildRuleOrder
= Options
[Tool
][Attr
]
2480 AllTools
= set(list(ModuleOptions
.keys()) + list(PlatformOptions
.keys()) +
2481 list(PlatformModuleOptions
.keys()) + list(ModuleTypeOptions
.keys()) +
2482 list(self
.ToolDefinition
.keys()))
2483 BuildOptions
= defaultdict(lambda: defaultdict(str))
2484 for Tool
in AllTools
:
2485 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2486 if Tool
not in Options
:
2488 for Attr
in Options
[Tool
]:
2490 # Do not generate it in Makefile
2492 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2494 Value
= Options
[Tool
][Attr
]
2495 # check if override is indicated
2496 if Value
.startswith('='):
2497 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
[1:])
2500 BuildOptions
[Tool
][Attr
] += " " + mws
.handleWsMacro(Value
)
2502 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
)
2504 return BuildOptions
, BuildRuleOrder
2507 # extend lists contained in a dictionary with lists stored in another dictionary
2508 # if CopyToDict is not derived from DefaultDict(list) then this may raise exception
2510 def ExtendCopyDictionaryLists(CopyToDict
, CopyFromDict
):
2511 for Key
in CopyFromDict
:
2512 CopyToDict
[Key
].extend(CopyFromDict
[Key
])
2514 # Create a directory specified by a set of path elements and return the full path
2515 def _MakeDir(PathList
):
2516 RetVal
= path
.join(*PathList
)
2517 CreateDirectory(RetVal
)
2520 ## ModuleAutoGen class
2522 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2523 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2524 # to the [depex] section in module's inf file.
2526 class ModuleAutoGen(AutoGen
):
2527 # call super().__init__ then call the worker function with different parameter count
2528 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2529 if not hasattr(self
, "_Init"):
2530 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
)
2533 ## Cache the timestamps of metafiles of every module in a class attribute
2537 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2538 # check if this module is employed by active platform
2539 if not PlatformAutoGen(Workspace
, args
[0], Target
, Toolchain
, Arch
).ValidModule(MetaFile
):
2540 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2543 return super(ModuleAutoGen
, cls
).__new
__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2545 ## Initialize ModuleAutoGen
2547 # @param Workspace EdkIIWorkspaceBuild object
2548 # @param ModuleFile The path of module file
2549 # @param Target Build target (DEBUG, RELEASE)
2550 # @param Toolchain Name of tool chain
2551 # @param Arch The arch the module supports
2552 # @param PlatformFile Platform meta-file
2554 def _InitWorker(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2555 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2556 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2558 self
.Workspace
= Workspace
2559 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2560 self
.MetaFile
= ModuleFile
2561 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2563 self
.SourceDir
= self
.MetaFile
.SubDir
2564 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2566 self
.ToolChain
= Toolchain
2567 self
.BuildTarget
= Target
2569 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2570 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2572 self
.IsCodeFileCreated
= False
2573 self
.IsAsBuiltInfCreated
= False
2574 self
.DepexGenerated
= False
2576 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2577 self
.BuildRuleOrder
= None
2580 self
._PcdComments
= OrderedListDict()
2581 self
._GuidComments
= OrderedListDict()
2582 self
._ProtocolComments
= OrderedListDict()
2583 self
._PpiComments
= OrderedListDict()
2584 self
._BuildTargets
= None
2585 self
._IntroBuildTargetList
= None
2586 self
._FinalBuildTargetList
= None
2587 self
._FileTypes
= None
2589 self
.AutoGenDepSet
= set()
2590 self
.ReferenceModules
= []
2593 ## hash() operator of ModuleAutoGen
2595 # The module file path and arch string will be used to represent
2596 # hash value of this object
2598 # @retval int Hash value of the module file path and arch
2600 @cached_class_function
2602 return hash((self
.MetaFile
, self
.Arch
))
2605 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2607 # Get FixedAtBuild Pcds of this Module
2609 def FixedAtBuildPcds(self
):
2611 for Pcd
in self
.ModulePcdList
:
2612 if Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
2614 if Pcd
not in RetVal
:
2619 def FixedVoidTypePcds(self
):
2621 for Pcd
in self
.FixedAtBuildPcds
:
2622 if Pcd
.DatumType
== TAB_VOID
:
2623 if '{}.{}'.format(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) not in RetVal
:
2624 RetVal
['{}.{}'.format(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)] = Pcd
.DefaultValue
2628 def UniqueBaseName(self
):
2629 BaseName
= self
.Name
2630 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2631 if Module
.MetaFile
== self
.MetaFile
:
2633 if Module
.Name
== self
.Name
:
2634 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2635 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2636 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2637 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2640 # Macros could be used in build_rule.txt (also Makefile)
2643 return OrderedDict((
2644 ("WORKSPACE" ,self
.WorkspaceDir
),
2645 ("MODULE_NAME" ,self
.Name
),
2646 ("MODULE_NAME_GUID" ,self
.UniqueBaseName
),
2647 ("MODULE_GUID" ,self
.Guid
),
2648 ("MODULE_VERSION" ,self
.Version
),
2649 ("MODULE_TYPE" ,self
.ModuleType
),
2650 ("MODULE_FILE" ,str(self
.MetaFile
)),
2651 ("MODULE_FILE_BASE_NAME" ,self
.MetaFile
.BaseName
),
2652 ("MODULE_RELATIVE_DIR" ,self
.SourceDir
),
2653 ("MODULE_DIR" ,self
.SourceDir
),
2654 ("BASE_NAME" ,self
.Name
),
2655 ("ARCH" ,self
.Arch
),
2656 ("TOOLCHAIN" ,self
.ToolChain
),
2657 ("TOOLCHAIN_TAG" ,self
.ToolChain
),
2658 ("TOOL_CHAIN_TAG" ,self
.ToolChain
),
2659 ("TARGET" ,self
.BuildTarget
),
2660 ("BUILD_DIR" ,self
.PlatformInfo
.BuildDir
),
2661 ("BIN_DIR" ,os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)),
2662 ("LIB_DIR" ,os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)),
2663 ("MODULE_BUILD_DIR" ,self
.BuildDir
),
2664 ("OUTPUT_DIR" ,self
.OutputDir
),
2665 ("DEBUG_DIR" ,self
.DebugDir
),
2666 ("DEST_DIR_OUTPUT" ,self
.OutputDir
),
2667 ("DEST_DIR_DEBUG" ,self
.DebugDir
),
2668 ("PLATFORM_NAME" ,self
.PlatformInfo
.Name
),
2669 ("PLATFORM_GUID" ,self
.PlatformInfo
.Guid
),
2670 ("PLATFORM_VERSION" ,self
.PlatformInfo
.Version
),
2671 ("PLATFORM_RELATIVE_DIR" ,self
.PlatformInfo
.SourceDir
),
2672 ("PLATFORM_DIR" ,mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)),
2673 ("PLATFORM_OUTPUT_DIR" ,self
.PlatformInfo
.OutputDir
),
2674 ("FFS_OUTPUT_DIR" ,self
.FfsOutputDir
)
2677 ## Return the module build data object
2680 return self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2682 ## Return the module name
2685 return self
.Module
.BaseName
2687 ## Return the module DxsFile if exist
2690 return self
.Module
.DxsFile
2692 ## Return the module meta-file GUID
2696 # To build same module more than once, the module path with FILE_GUID overridden has
2697 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the real path
2698 # in DSC. The overridden GUID can be retrieved from file name
2700 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2702 # Length of GUID is 36
2704 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2705 return self
.Module
.Guid
2707 ## Return the module version
2710 return self
.Module
.Version
2712 ## Return the module type
2714 def ModuleType(self
):
2715 return self
.Module
.ModuleType
2717 ## Return the component type (for Edk.x style of module)
2719 def ComponentType(self
):
2720 return self
.Module
.ComponentType
2722 ## Return the build type
2724 def BuildType(self
):
2725 return self
.Module
.BuildType
2727 ## Return the PCD_IS_DRIVER setting
2729 def PcdIsDriver(self
):
2730 return self
.Module
.PcdIsDriver
2732 ## Return the autogen version, i.e. module meta-file version
2734 def AutoGenVersion(self
):
2735 return self
.Module
.AutoGenVersion
2737 ## Check if the module is library or not
2739 def IsLibrary(self
):
2740 return bool(self
.Module
.LibraryClass
)
2742 ## Check if the module is binary module or not
2744 def IsBinaryModule(self
):
2745 return self
.Module
.IsBinaryModule
2747 ## Return the directory to store intermediate files of the module
2751 self
.PlatformInfo
.BuildDir
,
2754 self
.MetaFile
.BaseName
2757 ## Return the directory to store the intermediate object files of the module
2759 def OutputDir(self
):
2760 return _MakeDir((self
.BuildDir
, "OUTPUT"))
2762 ## Return the directory path to store ffs file
2764 def FfsOutputDir(self
):
2765 if GlobalData
.gFdfParser
:
2766 return path
.join(self
.PlatformInfo
.BuildDir
, TAB_FV_DIRECTORY
, "Ffs", self
.Guid
+ self
.Name
)
2769 ## Return the directory to store auto-gened source files of the module
2772 return _MakeDir((self
.BuildDir
, "DEBUG"))
2774 ## Return the path of custom file
2776 def CustomMakefile(self
):
2778 for Type
in self
.Module
.CustomMakefile
:
2779 MakeType
= gMakeTypeMap
[Type
] if Type
in gMakeTypeMap
else 'nmake'
2780 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2781 RetVal
[MakeType
] = File
2784 ## Return the directory of the makefile
2786 # @retval string The directory string of module's makefile
2789 def MakeFileDir(self
):
2790 return self
.BuildDir
2792 ## Return build command string
2794 # @retval string Build command string
2797 def BuildCommand(self
):
2798 return self
.PlatformInfo
.BuildCommand
2800 ## Get object list of all packages the module and its dependent libraries belong to
2802 # @retval list The list of package object
2805 def DerivedPackageList(self
):
2807 for M
in [self
.Module
] + self
.DependentLibraryList
:
2808 for Package
in M
.Packages
:
2809 if Package
in PackageList
:
2811 PackageList
.append(Package
)
2814 ## Get the depex string
2816 # @return : a string contain all depex expression.
2817 def _GetDepexExpresionString(self
):
2820 ## DPX_SOURCE IN Define section.
2821 if self
.Module
.DxsFile
:
2823 for M
in [self
.Module
] + self
.DependentLibraryList
:
2824 Filename
= M
.MetaFile
.Path
2825 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2826 DepexExpressionList
= InfObj
.GetDepexExpresionList()
2827 for DepexExpression
in DepexExpressionList
:
2828 for key
in DepexExpression
:
2829 Arch
, ModuleType
= key
2830 DepexExpr
= [x
for x
in DepexExpression
[key
] if not str(x
).startswith('#')]
2831 # the type of build module is USER_DEFINED.
2832 # All different DEPEX section tags would be copied into the As Built INF file
2833 # and there would be separate DEPEX section tags
2834 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2835 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2836 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2838 if Arch
.upper() == TAB_ARCH_COMMON
or \
2839 (Arch
.upper() == self
.Arch
.upper() and \
2840 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2841 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2843 #the type of build module is USER_DEFINED.
2844 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2845 for Depex
in DepexList
:
2847 DepexStr
+= '[Depex.%s.%s]\n' % key
2848 DepexStr
+= '\n'.join('# '+ val
for val
in Depex
[key
])
2851 return '[Depex.%s]\n' % self
.Arch
2854 #the type of build module not is USER_DEFINED.
2856 for Depex
in DepexList
:
2861 for D
in Depex
.values():
2862 DepexStr
+= ' '.join(val
for val
in D
)
2863 Index
= DepexStr
.find('END')
2864 if Index
> -1 and Index
== len(DepexStr
) - 3:
2865 DepexStr
= DepexStr
[:-3]
2866 DepexStr
= DepexStr
.strip()
2869 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
2871 return '[Depex.%s]\n' % self
.Arch
2872 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
2874 ## Merge dependency expression
2876 # @retval list The token list of the dependency expression after parsed
2879 def DepexList(self
):
2880 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2885 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expression
2887 for M
in [self
.Module
] + self
.DependentLibraryList
:
2889 for D
in M
.Depex
[self
.Arch
, self
.ModuleType
]:
2891 DepexList
.append('AND')
2892 DepexList
.append('(')
2893 #replace D with value if D is FixedAtBuild PCD
2897 NewList
.append(item
)
2899 FixedVoidTypePcds
= {}
2900 if item
in self
.FixedVoidTypePcds
:
2901 FixedVoidTypePcds
= self
.FixedVoidTypePcds
2902 elif M
in self
.PlatformInfo
.LibraryAutoGenList
:
2903 Index
= self
.PlatformInfo
.LibraryAutoGenList
.index(M
)
2904 FixedVoidTypePcds
= self
.PlatformInfo
.LibraryAutoGenList
[Index
].FixedVoidTypePcds
2905 if item
not in FixedVoidTypePcds
:
2906 EdkLogger
.error("build", FORMAT_INVALID
, "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type in the module.".format(item
))
2908 Value
= FixedVoidTypePcds
[item
]
2909 if len(Value
.split(',')) != 16:
2910 EdkLogger
.error("build", FORMAT_INVALID
,
2911 "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type and 16 bytes in the module.".format(item
))
2912 NewList
.append(Value
)
2913 DepexList
.extend(NewList
)
2914 if DepexList
[-1] == 'END': # no need of a END at this time
2916 DepexList
.append(')')
2919 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
2920 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
2922 if len(DepexList
) > 0:
2923 EdkLogger
.verbose('')
2924 return {self
.ModuleType
:DepexList
}
2926 ## Merge dependency expression
2928 # @retval list The token list of the dependency expression after parsed
2931 def DepexExpressionDict(self
):
2932 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2935 DepexExpressionString
= ''
2937 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2939 for M
in [self
.Module
] + self
.DependentLibraryList
:
2941 for D
in M
.DepexExpression
[self
.Arch
, self
.ModuleType
]:
2942 if DepexExpressionString
!= '':
2943 DepexExpressionString
+= ' AND '
2944 DepexExpressionString
+= '('
2945 DepexExpressionString
+= D
2946 DepexExpressionString
= DepexExpressionString
.rstrip('END').strip()
2947 DepexExpressionString
+= ')'
2950 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionString
))
2951 if 'BEFORE' in DepexExpressionString
or 'AFTER' in DepexExpressionString
:
2953 if len(DepexExpressionString
) > 0:
2954 EdkLogger
.verbose('')
2956 return {self
.ModuleType
:DepexExpressionString
}
2958 # Get the tiano core user extension, it is contain dependent library.
2959 # @retval: a list contain tiano core userextension.
2961 def _GetTianoCoreUserExtensionList(self
):
2962 TianoCoreUserExtentionList
= []
2963 for M
in [self
.Module
] + self
.DependentLibraryList
:
2964 Filename
= M
.MetaFile
.Path
2965 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2966 TianoCoreUserExtenList
= InfObj
.GetUserExtensionTianoCore()
2967 for TianoCoreUserExtent
in TianoCoreUserExtenList
:
2968 for Section
in TianoCoreUserExtent
:
2969 ItemList
= Section
.split(TAB_SPLIT
)
2971 if len(ItemList
) == 4:
2973 if Arch
.upper() == TAB_ARCH_COMMON
or Arch
.upper() == self
.Arch
.upper():
2975 TianoCoreList
.extend([TAB_SECTION_START
+ Section
+ TAB_SECTION_END
])
2976 TianoCoreList
.extend(TianoCoreUserExtent
[Section
][:])
2977 TianoCoreList
.append('\n')
2978 TianoCoreUserExtentionList
.append(TianoCoreList
)
2980 return TianoCoreUserExtentionList
2982 ## Return the list of specification version required for the module
2984 # @retval list The list of specification defined in module file
2987 def Specification(self
):
2988 return self
.Module
.Specification
2990 ## Tool option for the module build
2992 # @param PlatformInfo The object of PlatformBuildInfo
2993 # @retval dict The dict containing valid options
2996 def BuildOption(self
):
2997 RetVal
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
2998 if self
.BuildRuleOrder
:
2999 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
3002 ## Get include path list from tool option for the module build
3004 # @retval list The include path list
3007 def BuildOptionIncPathList(self
):
3009 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3010 # is the former use /I , the Latter used -I to specify include directories
3012 if self
.PlatformInfo
.ToolChainFamily
in (TAB_COMPILER_MSFT
):
3013 BuildOptIncludeRegEx
= gBuildOptIncludePatternMsft
3014 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
3015 BuildOptIncludeRegEx
= gBuildOptIncludePatternOther
3018 # New ToolChainFamily, don't known whether there is option to specify include directories
3023 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3025 FlagOption
= self
.BuildOption
[Tool
]['FLAGS']
3029 if self
.ToolChainFamily
!= 'RVCT':
3030 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in BuildOptIncludeRegEx
.findall(FlagOption
)]
3033 # RVCT may specify a list of directory separated by commas
3036 for Path
in BuildOptIncludeRegEx
.findall(FlagOption
):
3037 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3038 IncPathList
.extend(NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
)
3041 # EDK II modules must not reference header files outside of the packages they depend on or
3042 # within the module's directory tree. Report error if violation.
3044 if GlobalData
.gDisableIncludePathCheck
== False:
3045 for Path
in IncPathList
:
3046 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3047 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3048 EdkLogger
.error("build",
3051 File
=str(self
.MetaFile
))
3052 RetVal
+= IncPathList
3055 ## Return a list of files which can be built from source
3057 # What kind of files can be built is determined by build rules in
3058 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3061 def SourceFileList(self
):
3063 ToolChainTagSet
= {"", TAB_STAR
, self
.ToolChain
}
3064 ToolChainFamilySet
= {"", TAB_STAR
, self
.ToolChainFamily
, self
.BuildRuleFamily
}
3065 for F
in self
.Module
.Sources
:
3067 if F
.TagName
not in ToolChainTagSet
:
3068 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3069 "but [%s] is currently used" % (F
.TagName
, str(F
), self
.ToolChain
))
3071 # match tool chain family or build rule family
3072 if F
.ToolChainFamily
not in ToolChainFamilySet
:
3075 "The file [%s] must be built by tools of [%s], " \
3076 "but current toolchain family is [%s], buildrule family is [%s]" \
3077 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
, self
.BuildRuleFamily
))
3080 # add the file path into search path list for file including
3081 if F
.Dir
not in self
.IncludePathList
:
3082 self
.IncludePathList
.insert(0, F
.Dir
)
3085 self
._MatchBuildRuleOrder
(RetVal
)
3088 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3091 def _MatchBuildRuleOrder(self
, FileList
):
3094 for SingleFile
in FileList
:
3095 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3096 key
= SingleFile
.Path
.rsplit(SingleFile
.Ext
,1)[0]
3097 if key
in Order_Dict
:
3098 Order_Dict
[key
].append(SingleFile
.Ext
)
3100 Order_Dict
[key
] = [SingleFile
.Ext
]
3103 for F
in Order_Dict
:
3104 if len(Order_Dict
[F
]) > 1:
3105 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3106 for Ext
in Order_Dict
[F
][1:]:
3107 RemoveList
.append(F
+ Ext
)
3109 for item
in RemoveList
:
3110 FileList
.remove(item
)
3114 ## Return the list of unicode files
3116 def UnicodeFileList(self
):
3117 return self
.FileTypes
.get(TAB_UNICODE_FILE
,[])
3119 ## Return the list of vfr files
3121 def VfrFileList(self
):
3122 return self
.FileTypes
.get(TAB_VFR_FILE
, [])
3124 ## Return the list of Image Definition files
3126 def IdfFileList(self
):
3127 return self
.FileTypes
.get(TAB_IMAGE_FILE
,[])
3129 ## Return a list of files which can be built from binary
3131 # "Build" binary files are just to copy them to build directory.
3133 # @retval list The list of files which can be built later
3136 def BinaryFileList(self
):
3138 for F
in self
.Module
.Binaries
:
3139 if F
.Target
not in [TAB_ARCH_COMMON
, TAB_STAR
] and F
.Target
!= self
.BuildTarget
:
3142 self
._ApplyBuildRule
(F
, F
.Type
, BinaryFileList
=RetVal
)
3146 def BuildRules(self
):
3148 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3149 for Type
in BuildRuleDatabase
.FileTypeList
:
3150 #first try getting build rule by BuildRuleFamily
3151 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3153 # build type is always module type, but ...
3154 if self
.ModuleType
!= self
.BuildType
:
3155 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3156 #second try getting build rule by ToolChainFamily
3158 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3160 # build type is always module type, but ...
3161 if self
.ModuleType
!= self
.BuildType
:
3162 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3165 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3166 RetVal
[Type
] = RuleObject
3167 for Ext
in RuleObject
.SourceFileExtList
:
3168 RetVal
[Ext
] = RuleObject
3171 def _ApplyBuildRule(self
, File
, FileType
, BinaryFileList
=None):
3172 if self
._BuildTargets
is None:
3173 self
._IntroBuildTargetList
= set()
3174 self
._FinalBuildTargetList
= set()
3175 self
._BuildTargets
= defaultdict(set)
3176 self
._FileTypes
= defaultdict(set)
3178 if not BinaryFileList
:
3179 BinaryFileList
= self
.BinaryFileList
3181 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3182 if not os
.path
.exists(SubDirectory
):
3183 CreateDirectory(SubDirectory
)
3189 # Make sure to get build rule order value
3193 while Index
< len(SourceList
):
3194 Source
= SourceList
[Index
]
3198 CreateDirectory(Source
.Dir
)
3200 if File
.IsBinary
and File
== Source
and File
in BinaryFileList
:
3201 # Skip all files that are not binary libraries
3202 if not self
.IsLibrary
:
3204 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3205 elif FileType
in self
.BuildRules
:
3206 RuleObject
= self
.BuildRules
[FileType
]
3207 elif Source
.Ext
in self
.BuildRules
:
3208 RuleObject
= self
.BuildRules
[Source
.Ext
]
3210 # stop at no more rules
3212 self
._FinalBuildTargetList
.add(LastTarget
)
3215 FileType
= RuleObject
.SourceFileType
3216 self
._FileTypes
[FileType
].add(Source
)
3218 # stop at STATIC_LIBRARY for library
3219 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3221 self
._FinalBuildTargetList
.add(LastTarget
)
3224 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3227 self
._FinalBuildTargetList
.add(LastTarget
)
3229 elif not Target
.Outputs
:
3230 # Only do build for target with outputs
3231 self
._FinalBuildTargetList
.add(Target
)
3233 self
._BuildTargets
[FileType
].add(Target
)
3235 if not Source
.IsBinary
and Source
== File
:
3236 self
._IntroBuildTargetList
.add(Target
)
3238 # to avoid cyclic rule
3239 if FileType
in RuleChain
:
3242 RuleChain
.add(FileType
)
3243 SourceList
.extend(Target
.Outputs
)
3245 FileType
= TAB_UNKNOWN_FILE
3249 if self
._BuildTargets
is None:
3250 self
._IntroBuildTargetList
= set()
3251 self
._FinalBuildTargetList
= set()
3252 self
._BuildTargets
= defaultdict(set)
3253 self
._FileTypes
= defaultdict(set)
3255 #TRICK: call SourceFileList property to apply build rule for source files
3258 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3261 return self
._BuildTargets
3264 def IntroTargetList(self
):
3266 return self
._IntroBuildTargetList
3269 def CodaTargetList(self
):
3271 return self
._FinalBuildTargetList
3274 def FileTypes(self
):
3276 return self
._FileTypes
3278 ## Get the list of package object the module depends on
3280 # @retval list The package object list
3283 def DependentPackageList(self
):
3284 return self
.Module
.Packages
3286 ## Return the list of auto-generated code file
3288 # @retval list The list of auto-generated file
3291 def AutoGenFileList(self
):
3292 AutoGenUniIdf
= self
.BuildType
!= 'UEFI_HII'
3293 UniStringBinBuffer
= BytesIO()
3294 IdfGenBinBuffer
= BytesIO()
3296 AutoGenC
= TemplateString()
3297 AutoGenH
= TemplateString()
3298 StringH
= TemplateString()
3299 StringIdf
= TemplateString()
3300 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, AutoGenUniIdf
, UniStringBinBuffer
, StringIdf
, AutoGenUniIdf
, IdfGenBinBuffer
)
3302 # AutoGen.c is generated if there are library classes in inf, or there are object files
3304 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3305 or TAB_OBJECT_FILE
in self
.FileTypes
):
3306 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3307 RetVal
[AutoFile
] = str(AutoGenC
)
3308 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3309 if str(AutoGenH
) != "":
3310 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3311 RetVal
[AutoFile
] = str(AutoGenH
)
3312 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3313 if str(StringH
) != "":
3314 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3315 RetVal
[AutoFile
] = str(StringH
)
3316 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3317 if UniStringBinBuffer
is not None and UniStringBinBuffer
.getvalue() != b
"":
3318 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3319 RetVal
[AutoFile
] = UniStringBinBuffer
.getvalue()
3320 AutoFile
.IsBinary
= True
3321 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3322 if UniStringBinBuffer
is not None:
3323 UniStringBinBuffer
.close()
3324 if str(StringIdf
) != "":
3325 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3326 RetVal
[AutoFile
] = str(StringIdf
)
3327 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3328 if IdfGenBinBuffer
is not None and IdfGenBinBuffer
.getvalue() != b
"":
3329 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3330 RetVal
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3331 AutoFile
.IsBinary
= True
3332 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3333 if IdfGenBinBuffer
is not None:
3334 IdfGenBinBuffer
.close()
3337 ## Return the list of library modules explicitly or implicitly used by this module
3339 def DependentLibraryList(self
):
3340 # only merge library classes and PCD for non-library module
3343 return self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3345 ## Get the list of PCDs from current module
3347 # @retval list The list of PCD
3350 def ModulePcdList(self
):
3351 # apply PCD settings from platform
3352 RetVal
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3353 ExtendCopyDictionaryLists(self
._PcdComments
, self
.Module
.PcdComments
)
3356 ## Get the list of PCDs from dependent libraries
3358 # @retval list The list of PCD
3361 def LibraryPcdList(self
):
3366 # get PCDs from dependent libraries
3367 for Library
in self
.DependentLibraryList
:
3368 PcdsInLibrary
= OrderedDict()
3369 ExtendCopyDictionaryLists(self
._PcdComments
, Library
.PcdComments
)
3370 for Key
in Library
.Pcds
:
3371 # skip duplicated PCDs
3372 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3375 PcdsInLibrary
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3376 RetVal
.extend(self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, PcdsInLibrary
, Library
=Library
))
3379 ## Get the GUID value mapping
3381 # @retval dict The mapping between GUID cname and its value
3385 RetVal
= OrderedDict(self
.Module
.Guids
)
3386 for Library
in self
.DependentLibraryList
:
3387 RetVal
.update(Library
.Guids
)
3388 ExtendCopyDictionaryLists(self
._GuidComments
, Library
.GuidComments
)
3389 ExtendCopyDictionaryLists(self
._GuidComments
, self
.Module
.GuidComments
)
3393 def GetGuidsUsedByPcd(self
):
3394 RetVal
= OrderedDict(self
.Module
.GetGuidsUsedByPcd())
3395 for Library
in self
.DependentLibraryList
:
3396 RetVal
.update(Library
.GetGuidsUsedByPcd())
3398 ## Get the protocol value mapping
3400 # @retval dict The mapping between protocol cname and its value
3403 def ProtocolList(self
):
3404 RetVal
= OrderedDict(self
.Module
.Protocols
)
3405 for Library
in self
.DependentLibraryList
:
3406 RetVal
.update(Library
.Protocols
)
3407 ExtendCopyDictionaryLists(self
._ProtocolComments
, Library
.ProtocolComments
)
3408 ExtendCopyDictionaryLists(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3411 ## Get the PPI value mapping
3413 # @retval dict The mapping between PPI cname and its value
3417 RetVal
= OrderedDict(self
.Module
.Ppis
)
3418 for Library
in self
.DependentLibraryList
:
3419 RetVal
.update(Library
.Ppis
)
3420 ExtendCopyDictionaryLists(self
._PpiComments
, Library
.PpiComments
)
3421 ExtendCopyDictionaryLists(self
._PpiComments
, self
.Module
.PpiComments
)
3424 ## Get the list of include search path
3426 # @retval list The list path
3429 def IncludePathList(self
):
3431 RetVal
.append(self
.MetaFile
.Dir
)
3432 RetVal
.append(self
.DebugDir
)
3434 for Package
in self
.Module
.Packages
:
3435 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3436 if PackageDir
not in RetVal
:
3437 RetVal
.append(PackageDir
)
3438 IncludesList
= Package
.Includes
3439 if Package
._PrivateIncludes
:
3440 if not self
.MetaFile
.OriginalPath
.Path
.startswith(PackageDir
):
3441 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3442 for Inc
in IncludesList
:
3443 if Inc
not in RetVal
:
3444 RetVal
.append(str(Inc
))
3448 def IncludePathLength(self
):
3449 return sum(len(inc
)+1 for inc
in self
.IncludePathList
)
3451 ## Get HII EX PCDs which maybe used by VFR
3453 # efivarstore used by VFR may relate with HII EX PCDs
3454 # Get the variable name and GUID from efivarstore and HII EX PCD
3455 # List the HII EX PCDs in As Built INF if both name and GUID match.
3457 # @retval list HII EX PCDs
3459 def _GetPcdsMaybeUsedByVfr(self
):
3460 if not self
.SourceFileList
:
3464 for SrcFile
in self
.SourceFileList
:
3465 if SrcFile
.Ext
.lower() != '.vfr':
3467 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3468 if not os
.path
.exists(Vfri
):
3470 VfriFile
= open(Vfri
, 'r')
3471 Content
= VfriFile
.read()
3473 Pos
= Content
.find('efivarstore')
3476 # Make sure 'efivarstore' is the start of efivarstore statement
3477 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3480 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3482 if Index
>= 0 and Content
[Index
] != ';':
3483 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3486 # 'efivarstore' must be followed by name and guid
3488 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3491 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3494 NameArray
= _ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3495 NameGuids
.add((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3496 Pos
= Content
.find('efivarstore', Name
.end())
3500 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3501 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3503 for SkuInfo
in Pcd
.SkuInfoList
.values():
3504 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3507 Name
= _ConvertStringToByteArray(SkuInfo
.VariableName
)
3508 Guid
= GuidStructureStringToGuidString(Value
)
3509 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3510 HiiExPcds
.append(Pcd
)
3515 def _GenOffsetBin(self
):
3517 for SourceFile
in self
.Module
.Sources
:
3518 if SourceFile
.Type
.upper() == ".VFR" :
3520 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3522 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3523 elif SourceFile
.Type
.upper() == ".UNI" :
3525 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3527 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3529 if not VfrUniBaseName
:
3531 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3532 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3533 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, list(VfrUniBaseName
.values()))
3534 if not VfrUniOffsetList
:
3537 OutputName
= '%sOffset.bin' % self
.Name
3538 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3541 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3543 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
, None)
3545 # Use a instance of BytesIO to cache data
3546 fStringIO
= BytesIO()
3548 for Item
in VfrUniOffsetList
:
3549 if (Item
[0].find("Strings") != -1):
3551 # UNI offset in image.
3553 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3555 UniGuid
= b
'\xe0\xc5\x13\x89\xf63\x86M\x9b\xf1C\xef\x89\xfc\x06f'
3556 fStringIO
.write(UniGuid
)
3557 UniValue
= pack ('Q', int (Item
[1], 16))
3558 fStringIO
.write (UniValue
)
3561 # VFR binary offset in image.
3563 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3565 VfrGuid
= b
'\xb4|\xbc\xd0Gj_I\xaa\x11q\x07F\xda\x06\xa2'
3566 fStringIO
.write(VfrGuid
)
3567 VfrValue
= pack ('Q', int (Item
[1], 16))
3568 fStringIO
.write (VfrValue
)
3570 # write data into file.
3573 fInputfile
.write (fStringIO
.getvalue())
3575 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3576 "file been locked or using by other applications." %UniVfrOffsetFileName
, None)
3583 def OutputFile(self
):
3585 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3586 DebugDir
= self
.DebugDir
.replace('\\', '/').strip('/')
3587 for Item
in self
.CodaTargetList
:
3588 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(DebugDir
, '').replace(OutputDir
, '').strip('/')
3590 if self
.DepexGenerated
:
3591 retVal
.add(self
.Name
+ '.depex')
3593 Bin
= self
._GenOffsetBin
()
3597 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3599 if File
.lower().endswith('.pdb'):
3604 ## Create AsBuilt INF file the module
3606 def CreateAsBuiltInf(self
):
3608 if self
.IsAsBuiltInfCreated
:
3611 # Skip INF file generation for libraries
3615 # Skip the following code for modules with no source files
3616 if not self
.SourceFileList
:
3619 # Skip the following code for modules without any binary files
3620 if self
.BinaryFileList
:
3623 ### TODO: How to handles mixed source and binary modules
3625 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3626 # Also find all packages that the DynamicEx PCDs depend on
3631 PcdTokenSpaceList
= []
3632 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3633 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3634 PatchablePcds
.append(Pcd
)
3635 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_PATCHABLE_IN_MODULE
))
3636 elif Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
3639 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC_EX
))
3640 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC
))
3641 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3642 GuidList
= OrderedDict(self
.GuidList
)
3643 for TokenSpace
in self
.GetGuidsUsedByPcd
:
3644 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3645 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3646 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3647 GuidList
.pop(TokenSpace
)
3648 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3649 for Package
in self
.DerivedPackageList
:
3650 if Package
in Packages
:
3652 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3654 for Index
in range(len(BeChecked
)):
3655 for Item
in CheckList
[Index
]:
3656 if Item
in BeChecked
[Index
]:
3657 Packages
.append(Package
)
3663 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3664 for Pkg
in self
.PlatformInfo
.PackageList
:
3667 for VfrPcd
in VfrPcds
:
3668 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC_EX
) in Pkg
.Pcds
or
3669 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC
) in Pkg
.Pcds
):
3670 Packages
.append(Pkg
)
3673 ModuleType
= SUP_MODULE_DXE_DRIVER
if self
.ModuleType
== SUP_MODULE_UEFI_DRIVER
and self
.DepexGenerated
else self
.ModuleType
3674 DriverType
= self
.PcdIsDriver
if self
.PcdIsDriver
else ''
3676 MDefs
= self
.Module
.Defines
3679 'module_name' : self
.Name
,
3680 'module_guid' : Guid
,
3681 'module_module_type' : ModuleType
,
3682 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3683 'pcd_is_driver_string' : [],
3684 'module_uefi_specification_version' : [],
3685 'module_pi_specification_version' : [],
3686 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3687 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3688 'module_constructor' : self
.Module
.ConstructorList
,
3689 'module_destructor' : self
.Module
.DestructorList
,
3690 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3691 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3692 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3693 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3694 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3695 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3696 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3697 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3698 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3699 'module_arch' : self
.Arch
,
3700 'package_item' : [Package
.MetaFile
.File
.replace('\\', '/') for Package
in Packages
],
3702 'patchablepcd_item' : [],
3704 'protocol_item' : [],
3708 'libraryclasses_item' : []
3711 if 'MODULE_UNI_FILE' in MDefs
:
3712 UNIFile
= os
.path
.join(self
.MetaFile
.Dir
, MDefs
['MODULE_UNI_FILE'])
3713 if os
.path
.isfile(UNIFile
):
3714 shutil
.copy2(UNIFile
, self
.OutputDir
)
3716 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3717 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3719 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3722 AsBuiltInfDict
['pcd_is_driver_string'].append(DriverType
)
3724 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3725 AsBuiltInfDict
['module_uefi_specification_version'].append(self
.Specification
['UEFI_SPECIFICATION_VERSION'])
3726 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3727 AsBuiltInfDict
['module_pi_specification_version'].append(self
.Specification
['PI_SPECIFICATION_VERSION'])
3729 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3730 DebugDir
= self
.DebugDir
.replace('\\', '/').strip('/')
3731 for Item
in self
.CodaTargetList
:
3732 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(DebugDir
, '').replace(OutputDir
, '').strip('/')
3733 if os
.path
.isabs(File
):
3734 File
= File
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3735 if Item
.Target
.Ext
.lower() == '.aml':
3736 AsBuiltInfDict
['binary_item'].append('ASL|' + File
)
3737 elif Item
.Target
.Ext
.lower() == '.acpi':
3738 AsBuiltInfDict
['binary_item'].append('ACPI|' + File
)
3739 elif Item
.Target
.Ext
.lower() == '.efi':
3740 AsBuiltInfDict
['binary_item'].append('PE32|' + self
.Name
+ '.efi')
3742 AsBuiltInfDict
['binary_item'].append('BIN|' + File
)
3743 if not self
.DepexGenerated
:
3744 DepexFile
= os
.path
.join(self
.OutputDir
, self
.Name
+ '.depex')
3745 if os
.path
.exists(DepexFile
):
3746 self
.DepexGenerated
= True
3747 if self
.DepexGenerated
:
3748 if self
.ModuleType
in [SUP_MODULE_PEIM
]:
3749 AsBuiltInfDict
['binary_item'].append('PEI_DEPEX|' + self
.Name
+ '.depex')
3750 elif self
.ModuleType
in [SUP_MODULE_DXE_DRIVER
, SUP_MODULE_DXE_RUNTIME_DRIVER
, SUP_MODULE_DXE_SAL_DRIVER
, SUP_MODULE_UEFI_DRIVER
]:
3751 AsBuiltInfDict
['binary_item'].append('DXE_DEPEX|' + self
.Name
+ '.depex')
3752 elif self
.ModuleType
in [SUP_MODULE_DXE_SMM_DRIVER
]:
3753 AsBuiltInfDict
['binary_item'].append('SMM_DEPEX|' + self
.Name
+ '.depex')
3755 Bin
= self
._GenOffsetBin
()
3757 AsBuiltInfDict
['binary_item'].append('BIN|%s' % Bin
)
3759 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3761 if File
.lower().endswith('.pdb'):
3762 AsBuiltInfDict
['binary_item'].append('DISPOSABLE|' + File
)
3763 HeaderComments
= self
.Module
.HeaderComments
3765 for Index
in range(len(HeaderComments
)):
3766 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3767 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3770 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3771 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3774 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3775 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3776 (GuidList
, self
._GuidComments
, 'guid_item')
3778 for Item
in GenList
:
3779 for CName
in Item
[0]:
3780 Comments
= '\n '.join(Item
[1][CName
]) if CName
in Item
[1] else ''
3781 Entry
= Comments
+ '\n ' + CName
if Comments
else CName
3782 AsBuiltInfDict
[Item
[2]].append(Entry
)
3783 PatchList
= parsePcdInfoFromMapFile(
3784 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3785 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3788 for Pcd
in PatchablePcds
:
3789 TokenCName
= Pcd
.TokenCName
3790 for PcdItem
in GlobalData
.MixedPcd
:
3791 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3792 TokenCName
= PcdItem
[0]
3794 for PatchPcd
in PatchList
:
3795 if TokenCName
== PatchPcd
[0]:
3800 if Pcd
.DatumType
== 'BOOLEAN':
3801 BoolValue
= Pcd
.DefaultValue
.upper()
3802 if BoolValue
== 'TRUE':
3803 Pcd
.DefaultValue
= '1'
3804 elif BoolValue
== 'FALSE':
3805 Pcd
.DefaultValue
= '0'
3807 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
3808 HexFormat
= '0x%02x'
3809 if Pcd
.DatumType
== TAB_UINT16
:
3810 HexFormat
= '0x%04x'
3811 elif Pcd
.DatumType
== TAB_UINT32
:
3812 HexFormat
= '0x%08x'
3813 elif Pcd
.DatumType
== TAB_UINT64
:
3814 HexFormat
= '0x%016x'
3815 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3817 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
3818 EdkLogger
.error("build", AUTOGEN_ERROR
,
3819 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3821 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3822 PcdValue
= Pcd
.DefaultValue
3823 if PcdValue
[0] != '{':
3825 if PcdValue
[0] == 'L':
3827 PcdValue
= PcdValue
.lstrip('L')
3828 PcdValue
= eval(PcdValue
)
3830 for Index
in range(0, len(PcdValue
)):
3832 CharVal
= ord(PcdValue
[Index
])
3833 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3834 + '0x%02x' % (CharVal
>> 8) + ', '
3836 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3839 Padding
= Padding
* 2
3840 ArraySize
= ArraySize
// 2
3841 if ArraySize
< (len(PcdValue
) + 1):
3842 if Pcd
.MaxSizeUserSet
:
3843 EdkLogger
.error("build", AUTOGEN_ERROR
,
3844 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3847 ArraySize
= len(PcdValue
) + 1
3848 if ArraySize
> len(PcdValue
) + 1:
3849 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3850 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3851 elif len(PcdValue
.split(',')) <= ArraySize
:
3852 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3855 if Pcd
.MaxSizeUserSet
:
3856 EdkLogger
.error("build", AUTOGEN_ERROR
,
3857 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3860 ArraySize
= len(PcdValue
) + 1
3861 PcdItem
= '%s.%s|%s|0x%X' % \
3862 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
3864 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3865 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
3867 PcdItem
= PcdComments
+ '\n ' + PcdItem
3868 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
3870 for Pcd
in Pcds
+ VfrPcds
:
3873 TokenCName
= Pcd
.TokenCName
3874 for PcdItem
in GlobalData
.MixedPcd
:
3875 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3876 TokenCName
= PcdItem
[0]
3878 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
3879 for SkuName
in Pcd
.SkuInfoList
:
3880 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3881 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
3883 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3884 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
3888 for Index
, Comment
in enumerate(PcdCommentList
):
3889 for Usage
in UsageList
:
3890 if Comment
.find(Usage
) != -1:
3894 if UsageIndex
!= -1:
3895 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
3897 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
3898 PcdComments
= '\n '.join(PcdCommentList
)
3899 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
3901 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
3902 AsBuiltInfDict
['pcd_item'].append(PcdEntry
)
3903 for Item
in self
.BuildOption
:
3904 if 'FLAGS' in self
.BuildOption
[Item
]:
3905 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()))
3907 # Generated LibraryClasses section in comments.
3908 for Library
in self
.LibraryAutoGenList
:
3909 AsBuiltInfDict
['libraryclasses_item'].append(Library
.MetaFile
.File
.replace('\\', '/'))
3911 # Generated UserExtensions TianoCore section.
3912 # All tianocore user extensions are copied.
3914 for TianoCore
in self
._GetTianoCoreUserExtensionList
():
3915 UserExtStr
+= '\n'.join(TianoCore
)
3916 ExtensionFile
= os
.path
.join(self
.MetaFile
.Dir
, TianoCore
[1])
3917 if os
.path
.isfile(ExtensionFile
):
3918 shutil
.copy2(ExtensionFile
, self
.OutputDir
)
3919 AsBuiltInfDict
['userextension_tianocore_item'] = UserExtStr
3921 # Generated depex expression section in comments.
3922 DepexExpression
= self
._GetDepexExpresionString
()
3923 AsBuiltInfDict
['depexsection_item'] = DepexExpression
if DepexExpression
else ''
3925 AsBuiltInf
= TemplateString()
3926 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
3928 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
3930 self
.IsAsBuiltInfCreated
= True
3932 def CopyModuleToCache(self
):
3933 FileDir
= path
.join(GlobalData
.gBinCacheDest
, self
.PlatformInfo
.OutputDir
, self
.BuildTarget
+ "_" + self
.ToolChain
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
3934 CreateDirectory (FileDir
)
3935 HashFile
= path
.join(self
.BuildDir
, self
.Name
+ '.hash')
3936 if os
.path
.exists(HashFile
):
3937 CopyFileOnChange(HashFile
, FileDir
)
3938 ModuleFile
= path
.join(self
.OutputDir
, self
.Name
+ '.inf')
3939 if os
.path
.exists(ModuleFile
):
3940 CopyFileOnChange(ModuleFile
, FileDir
)
3942 if not self
.OutputFile
:
3943 Ma
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
3944 self
.OutputFile
= Ma
.Binaries
3946 for File
in self
.OutputFile
:
3948 if not os
.path
.isabs(File
):
3949 File
= os
.path
.join(self
.OutputDir
, File
)
3950 if os
.path
.exists(File
):
3951 sub_dir
= os
.path
.relpath(File
, self
.OutputDir
)
3952 destination_file
= os
.path
.join(FileDir
, sub_dir
)
3953 destination_dir
= os
.path
.dirname(destination_file
)
3954 CreateDirectory(destination_dir
)
3955 CopyFileOnChange(File
, destination_dir
)
3957 def AttemptModuleCacheCopy(self
):
3958 # If library or Module is binary do not skip by hash
3959 if self
.IsBinaryModule
:
3961 # .inc is contains binary information so do not skip by hash as well
3962 for f_ext
in self
.SourceFileList
:
3963 if '.inc' in str(f_ext
):
3965 FileDir
= path
.join(GlobalData
.gBinCacheSource
, self
.PlatformInfo
.OutputDir
, self
.BuildTarget
+ "_" + self
.ToolChain
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
3966 HashFile
= path
.join(FileDir
, self
.Name
+ '.hash')
3967 if os
.path
.exists(HashFile
):
3968 f
= open(HashFile
, 'r')
3969 CacheHash
= f
.read()
3971 self
.GenModuleHash()
3972 if GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
3973 if CacheHash
== GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
3974 for root
, dir, files
in os
.walk(FileDir
):
3976 if self
.Name
+ '.hash' in f
:
3977 CopyFileOnChange(HashFile
, self
.BuildDir
)
3979 File
= path
.join(root
, f
)
3980 sub_dir
= os
.path
.relpath(File
, FileDir
)
3981 destination_file
= os
.path
.join(self
.OutputDir
, sub_dir
)
3982 destination_dir
= os
.path
.dirname(destination_file
)
3983 CreateDirectory(destination_dir
)
3984 CopyFileOnChange(File
, destination_dir
)
3985 if self
.Name
== "PcdPeim" or self
.Name
== "PcdDxe":
3986 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
3990 ## Create makefile for the module and its dependent libraries
3992 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
3993 # dependent libraries will be created
3995 @cached_class_function
3996 def CreateMakeFile(self
, CreateLibraryMakeFile
=True, GenFfsList
= []):
3997 # nest this function inside its only caller.
3998 def CreateTimeStamp():
3999 FileSet
= {self
.MetaFile
.Path
}
4001 for SourceFile
in self
.Module
.Sources
:
4002 FileSet
.add (SourceFile
.Path
)
4004 for Lib
in self
.DependentLibraryList
:
4005 FileSet
.add (Lib
.MetaFile
.Path
)
4007 for f
in self
.AutoGenDepSet
:
4008 FileSet
.add (f
.Path
)
4010 if os
.path
.exists (self
.TimeStampPath
):
4011 os
.remove (self
.TimeStampPath
)
4012 with
open(self
.TimeStampPath
, 'w+') as file:
4016 # Ignore generating makefile when it is a binary module
4017 if self
.IsBinaryModule
:
4020 self
.GenFfsList
= GenFfsList
4021 if not self
.IsLibrary
and CreateLibraryMakeFile
:
4022 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4023 LibraryAutoGen
.CreateMakeFile()
4025 # Don't enable if hash feature enabled, CanSkip uses timestamps to determine build skipping
4026 if not GlobalData
.gUseHashCache
and self
.CanSkip():
4029 if len(self
.CustomMakefile
) == 0:
4030 Makefile
= GenMake
.ModuleMakefile(self
)
4032 Makefile
= GenMake
.CustomMakefile(self
)
4033 if Makefile
.Generate():
4034 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
4035 (self
.Name
, self
.Arch
))
4037 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
4038 (self
.Name
, self
.Arch
))
4042 def CopyBinaryFiles(self
):
4043 for File
in self
.Module
.Binaries
:
4045 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4046 CopyLongFilePath(SrcPath
, DstPath
)
4047 ## Create autogen code for the module and its dependent libraries
4049 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4050 # dependent libraries will be created
4052 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4053 if self
.IsCodeFileCreated
:
4056 # Need to generate PcdDatabase even PcdDriver is binarymodule
4057 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4058 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4060 if self
.IsBinaryModule
:
4062 self
.CopyBinaryFiles()
4065 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4066 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4067 LibraryAutoGen
.CreateCodeFile()
4069 # Don't enable if hash feature enabled, CanSkip uses timestamps to determine build skipping
4070 if not GlobalData
.gUseHashCache
and self
.CanSkip():
4074 IgoredAutoGenList
= []
4076 for File
in self
.AutoGenFileList
:
4077 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4078 AutoGenList
.append(str(File
))
4080 IgoredAutoGenList
.append(str(File
))
4083 for ModuleType
in self
.DepexList
:
4084 # Ignore empty [depex] section or [depex] section for SUP_MODULE_USER_DEFINED module
4085 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== SUP_MODULE_USER_DEFINED
:
4088 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4089 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4091 if len(Dpx
.PostfixNotation
) != 0:
4092 self
.DepexGenerated
= True
4094 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4095 AutoGenList
.append(str(DpxFile
))
4097 IgoredAutoGenList
.append(str(DpxFile
))
4099 if IgoredAutoGenList
== []:
4100 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4101 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4102 elif AutoGenList
== []:
4103 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4104 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4106 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4107 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4109 self
.IsCodeFileCreated
= True
4112 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4114 def LibraryAutoGenList(self
):
4116 for Library
in self
.DependentLibraryList
:
4123 self
.PlatformInfo
.MetaFile
4125 if La
not in RetVal
:
4127 for Lib
in La
.CodaTargetList
:
4128 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4131 def GenModuleHash(self
):
4132 # Initialize a dictionary for each arch type
4133 if self
.Arch
not in GlobalData
.gModuleHash
:
4134 GlobalData
.gModuleHash
[self
.Arch
] = {}
4136 # Early exit if module or library has been hashed and is in memory
4137 if self
.Name
in GlobalData
.gModuleHash
[self
.Arch
]:
4138 return GlobalData
.gModuleHash
[self
.Arch
][self
.Name
].encode('utf-8')
4140 # Initialze hash object
4143 # Add Platform level hash
4144 m
.update(GlobalData
.gPlatformHash
.encode('utf-8'))
4146 # Add Package level hash
4147 if self
.DependentPackageList
:
4148 for Pkg
in sorted(self
.DependentPackageList
, key
=lambda x
: x
.PackageName
):
4149 if Pkg
.PackageName
in GlobalData
.gPackageHash
:
4150 m
.update(GlobalData
.gPackageHash
[Pkg
.PackageName
].encode('utf-8'))
4153 if self
.LibraryAutoGenList
:
4154 for Lib
in sorted(self
.LibraryAutoGenList
, key
=lambda x
: x
.Name
):
4155 if Lib
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4157 m
.update(GlobalData
.gModuleHash
[self
.Arch
][Lib
.Name
].encode('utf-8'))
4160 f
= open(str(self
.MetaFile
), 'rb')
4165 # Add Module's source files
4166 if self
.SourceFileList
:
4167 for File
in sorted(self
.SourceFileList
, key
=lambda x
: str(x
)):
4168 f
= open(str(File
), 'rb')
4173 GlobalData
.gModuleHash
[self
.Arch
][self
.Name
] = m
.hexdigest()
4175 return GlobalData
.gModuleHash
[self
.Arch
][self
.Name
].encode('utf-8')
4177 ## Decide whether we can skip the ModuleAutoGen process
4178 def CanSkipbyHash(self
):
4179 # Hashing feature is off
4180 if not GlobalData
.gUseHashCache
:
4183 # Initialize a dictionary for each arch type
4184 if self
.Arch
not in GlobalData
.gBuildHashSkipTracking
:
4185 GlobalData
.gBuildHashSkipTracking
[self
.Arch
] = dict()
4187 # If library or Module is binary do not skip by hash
4188 if self
.IsBinaryModule
:
4191 # .inc is contains binary information so do not skip by hash as well
4192 for f_ext
in self
.SourceFileList
:
4193 if '.inc' in str(f_ext
):
4196 # Use Cache, if exists and if Module has a copy in cache
4197 if GlobalData
.gBinCacheSource
and self
.AttemptModuleCacheCopy():
4200 # Early exit for libraries that haven't yet finished building
4201 HashFile
= path
.join(self
.BuildDir
, self
.Name
+ ".hash")
4202 if self
.IsLibrary
and not os
.path
.exists(HashFile
):
4205 # Return a Boolean based on if can skip by hash, either from memory or from IO.
4206 if self
.Name
not in GlobalData
.gBuildHashSkipTracking
[self
.Arch
]:
4207 # If hashes are the same, SaveFileOnChange() will return False.
4208 GlobalData
.gBuildHashSkipTracking
[self
.Arch
][self
.Name
] = not SaveFileOnChange(HashFile
, self
.GenModuleHash(), True)
4209 return GlobalData
.gBuildHashSkipTracking
[self
.Arch
][self
.Name
]
4211 return GlobalData
.gBuildHashSkipTracking
[self
.Arch
][self
.Name
]
4213 ## Decide whether we can skip the ModuleAutoGen process
4214 # If any source file is newer than the module than we cannot skip
4217 if self
.MakeFileDir
in GlobalData
.gSikpAutoGenCache
:
4219 if not os
.path
.exists(self
.TimeStampPath
):
4221 #last creation time of the module
4222 DstTimeStamp
= os
.stat(self
.TimeStampPath
)[8]
4224 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4225 if SrcTimeStamp
> DstTimeStamp
:
4228 with
open(self
.TimeStampPath
,'r') as f
:
4230 source
= source
.rstrip('\n')
4231 if not os
.path
.exists(source
):
4233 if source
not in ModuleAutoGen
.TimeDict
:
4234 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4235 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4237 GlobalData
.gSikpAutoGenCache
.add(self
.MakeFileDir
)
4241 def TimeStampPath(self
):
4242 return os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')