2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
7 # This program and the accompanying materials
8 # are licensed and made available under the terms and conditions of the BSD License
9 # which accompanies this distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 import Common
.LongFilePathOs
as os
20 import os
.path
as path
27 from StringIO
import StringIO
29 from StrGather
import *
30 from BuildEngine
import BuildRule
32 from Common
.LongFilePathSupport
import CopyLongFilePath
33 from Common
.BuildToolError
import *
34 from Common
.DataType
import *
35 from Common
.Misc
import *
36 from Common
.StringUtils
import *
37 import Common
.GlobalData
as GlobalData
38 from GenFds
.FdfParser
import *
39 from CommonDataClass
.CommonClass
import SkuInfoClass
40 from Workspace
.BuildClassObject
import *
41 from GenPatchPcdTable
.GenPatchPcdTable
import parsePcdInfoFromMapFile
42 import Common
.VpdInfoFile
as VpdInfoFile
43 from GenPcdDb
import CreatePcdDatabaseCode
44 from Workspace
.MetaFileCommentParser
import UsageList
45 from Workspace
.WorkspaceCommon
import GetModuleLibInstances
46 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
47 import InfSectionParser
50 from GenVar
import VariableMgr
,var_info
51 from collections
import OrderedDict
52 from collections
import defaultdict
53 from Workspace
.WorkspaceCommon
import OrderedListDict
55 ## Regular expression for splitting Dependency Expression string into tokens
56 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
58 ## Regular expression for match: PCD(xxxx.yyy)
59 gPCDAsGuidPattern
= re
.compile(r
"^PCD\(.+\..+\)$")
62 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
63 # is the former use /I , the Latter used -I to specify include directories
65 gBuildOptIncludePatternMsft
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
66 gBuildOptIncludePatternOther
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
69 # Match name = variable
71 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
73 # The format of guid in efivarstore statement likes following and must be correct:
74 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
76 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
78 ## Mapping Makefile type
79 gMakeTypeMap
= {"MSFT":"nmake", "GCC":"gmake"}
82 ## Build rule configuration file
83 gDefaultBuildRuleFile
= 'build_rule.txt'
85 ## Tools definition configuration file
86 gDefaultToolsDefFile
= 'tools_def.txt'
88 ## Build rule default version
89 AutoGenReqBuildRuleVerNum
= "0.1"
91 ## default file name for AutoGen
92 gAutoGenCodeFileName
= "AutoGen.c"
93 gAutoGenHeaderFileName
= "AutoGen.h"
94 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
95 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
96 gAutoGenDepexFileName
= "%(module_name)s.depex"
97 gAutoGenImageDefFileName
= "%(module_name)sImgDefs.h"
98 gAutoGenIdfFileName
= "%(module_name)sIdf.hpk"
99 gInfSpecVersion
= "0x00010017"
102 # Template string to generic AsBuilt INF
104 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
107 # FILE auto-generated
110 INF_VERSION = ${module_inf_version}
111 BASE_NAME = ${module_name}
112 FILE_GUID = ${module_guid}
113 MODULE_TYPE = ${module_module_type}${BEGIN}
114 VERSION_STRING = ${module_version_string}${END}${BEGIN}
115 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
116 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
117 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
118 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
119 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
120 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
121 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
122 SHADOW = ${module_shadow}${END}${BEGIN}
123 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
124 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
125 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
126 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
127 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
128 SPEC = ${module_spec}${END}${BEGIN}
129 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
130 MODULE_UNI_FILE = ${module_uni_file}${END}
132 [Packages.${module_arch}]${BEGIN}
133 ${package_item}${END}
135 [Binaries.${module_arch}]${BEGIN}
138 [PatchPcd.${module_arch}]${BEGIN}
142 [Protocols.${module_arch}]${BEGIN}
146 [Ppis.${module_arch}]${BEGIN}
150 [Guids.${module_arch}]${BEGIN}
154 [PcdEx.${module_arch}]${BEGIN}
158 [LibraryClasses.${module_arch}]
159 ## @LIB_INSTANCES${BEGIN}
160 # ${libraryclasses_item}${END}
164 ${userextension_tianocore_item}
168 [BuildOptions.${module_arch}]
170 ## ${flags_item}${END}
173 ## Base class for AutoGen
175 # This class just implements the cache mechanism of AutoGen objects.
177 class AutoGen(object):
178 # database to maintain the objects in each child class
179 __ObjectCache
= {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object
183 # @param Class class object of real AutoGen class
184 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
185 # @param Workspace Workspace directory or WorkspaceAutoGen object
186 # @param MetaFile The path of meta file
187 # @param Target Build target
188 # @param Toolchain Tool chain name
189 # @param Arch Target arch
190 # @param *args The specific class related parameters
191 # @param **kwargs The specific class related dict parameters
193 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
194 # check if the object has been created
195 Key
= (Target
, Toolchain
, Arch
, MetaFile
)
197 # if it exists, just return it directly
198 return cls
.__ObjectCache
[Key
]
200 # it didnt exist. create it, cache it, then return it
201 cls
.__ObjectCache
[Key
] = super(AutoGen
, cls
).__new
__(cls
)
202 return cls
.__ObjectCache
[Key
]
204 def __init__ (self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
205 super(AutoGen
, self
).__init
__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
209 # The file path of platform file will be used to represent hash value of this object
211 # @retval int Hash value of the file path of platform file
214 return hash(self
.MetaFile
)
218 # The file path of platform file will be used to represent this object
220 # @retval string String of platform file path
223 return str(self
.MetaFile
)
226 def __eq__(self
, Other
):
227 return Other
and self
.MetaFile
== Other
229 ## Workspace AutoGen class
231 # This class is used mainly to control the whole platform build for different
232 # architecture. This class will generate top level makefile.
234 class WorkspaceAutoGen(AutoGen
):
235 # call super().__init__ then call the worker function with different parameter count
236 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
240 super(WorkspaceAutoGen
, self
).__init
__(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
241 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
244 ## Initialize WorkspaceAutoGen
246 # @param WorkspaceDir Root directory of workspace
247 # @param ActivePlatform Meta-file of active platform
248 # @param Target Build target
249 # @param Toolchain Tool chain name
250 # @param ArchList List of architecture of current build
251 # @param MetaFileDb Database containing meta-files
252 # @param BuildConfig Configuration of build
253 # @param ToolDefinition Tool chain definitions
254 # @param FlashDefinitionFile File of flash definition
255 # @param Fds FD list to be generated
256 # @param Fvs FV list to be generated
257 # @param Caps Capsule list to be generated
258 # @param SkuId SKU id from command line
260 def _InitWorker(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
261 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
262 Progress
=None, BuildModule
=None):
263 self
.BuildDatabase
= MetaFileDb
264 self
.MetaFile
= ActivePlatform
265 self
.WorkspaceDir
= WorkspaceDir
266 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, TAB_ARCH_COMMON
, Target
, Toolchain
]
267 GlobalData
.gActivePlatform
= self
.Platform
268 self
.BuildTarget
= Target
269 self
.ToolChain
= Toolchain
270 self
.ArchList
= ArchList
272 self
.UniFlag
= UniFlag
274 self
.TargetTxt
= BuildConfig
275 self
.ToolDef
= ToolDefinition
276 self
.FdfFile
= FlashDefinitionFile
277 self
.FdTargetList
= Fds
if Fds
else []
278 self
.FvTargetList
= Fvs
if Fvs
else []
279 self
.CapTargetList
= Caps
if Caps
else []
280 self
.AutoGenObjectList
= []
281 self
._BuildDir
= None
283 self
._MakeFileDir
= None
284 self
._BuildCommand
= None
287 # there's many relative directory operations, so ...
288 os
.chdir(self
.WorkspaceDir
)
293 if not self
.ArchList
:
294 ArchList
= set(self
.Platform
.SupArchList
)
296 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
298 EdkLogger
.error("build", PARAMETER_INVALID
,
299 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
300 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
301 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
302 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
303 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
304 self
.ArchList
= tuple(ArchList
)
306 # Validate build target
307 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
308 EdkLogger
.error("build", PARAMETER_INVALID
,
309 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
310 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
313 # parse FDF file to get PCDs in it, if any
315 self
.FdfFile
= self
.Platform
.FlashDefinition
319 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
320 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
321 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
323 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
325 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
328 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
330 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
333 Progress
.Start("\nProcessing meta-data")
337 # Mark now build in AutoGen Phase
339 GlobalData
.gAutoGenPhase
= True
340 Fdf
= FdfParser(self
.FdfFile
.Path
)
342 GlobalData
.gFdfParser
= Fdf
343 GlobalData
.gAutoGenPhase
= False
344 PcdSet
= Fdf
.Profile
.PcdDict
345 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
346 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
347 for FdRegion
in FdDict
.RegionList
:
348 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
349 if int(FdRegion
.Offset
) % 8 != 0:
350 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
351 ModuleList
= Fdf
.Profile
.InfList
352 self
.FdfProfile
= Fdf
.Profile
353 for fvname
in self
.FvTargetList
:
354 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
355 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
356 "No such an FV in FDF file: %s" % fvname
)
358 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
359 # but the path (self.MetaFile.Path) is the real path
360 for key
in self
.FdfProfile
.InfDict
:
362 MetaFile_cache
= defaultdict(set)
363 for Arch
in self
.ArchList
:
364 Current_Platform_cache
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
365 for Pkey
in Current_Platform_cache
.Modules
:
366 MetaFile_cache
[Arch
].add(Current_Platform_cache
.Modules
[Pkey
].MetaFile
)
367 for Inf
in self
.FdfProfile
.InfDict
[key
]:
368 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
369 for Arch
in self
.ArchList
:
370 if ModuleFile
in MetaFile_cache
[Arch
]:
373 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
374 if not ModuleData
.IsBinaryModule
:
375 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
378 for Arch
in self
.ArchList
:
380 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
382 for Pkey
in Platform
.Modules
:
383 MetaFileList
.add(Platform
.Modules
[Pkey
].MetaFile
)
384 for Inf
in self
.FdfProfile
.InfDict
[key
]:
385 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
386 if ModuleFile
in MetaFileList
:
388 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
389 if not ModuleData
.IsBinaryModule
:
390 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
395 self
.FdfProfile
= None
396 if self
.FdTargetList
:
397 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
398 self
.FdTargetList
= []
399 if self
.FvTargetList
:
400 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
401 self
.FvTargetList
= []
402 if self
.CapTargetList
:
403 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
404 self
.CapTargetList
= []
406 # apply SKU and inject PCDs from Flash Definition file
407 for Arch
in self
.ArchList
:
408 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
409 PlatformPcds
= Platform
.Pcds
410 self
._GuidDict
= Platform
._GuidDict
411 SourcePcdDict
= {TAB_PCDS_DYNAMIC_EX
:set(), TAB_PCDS_PATCHABLE_IN_MODULE
:set(),TAB_PCDS_DYNAMIC
:set(),TAB_PCDS_FIXED_AT_BUILD
:set()}
412 BinaryPcdDict
= {TAB_PCDS_DYNAMIC_EX
:set(), TAB_PCDS_PATCHABLE_IN_MODULE
:set()}
413 SourcePcdDict_Keys
= SourcePcdDict
.keys()
414 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
416 # generate the SourcePcdDict and BinaryPcdDict
417 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
418 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
419 if BuildData
.Arch
!= Arch
:
421 if BuildData
.MetaFile
.Ext
== '.inf':
422 for key
in BuildData
.Pcds
:
423 if BuildData
.Pcds
[key
].Pending
:
424 if key
in Platform
.Pcds
:
425 PcdInPlatform
= Platform
.Pcds
[key
]
426 if PcdInPlatform
.Type
:
427 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
428 BuildData
.Pcds
[key
].Pending
= False
430 if BuildData
.MetaFile
in Platform
.Modules
:
431 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
432 if key
in PlatformModule
.Pcds
:
433 PcdInPlatform
= PlatformModule
.Pcds
[key
]
434 if PcdInPlatform
.Type
:
435 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
436 BuildData
.Pcds
[key
].Pending
= False
438 #Pcd used in Library, Pcd Type from reference module if Pcd Type is Pending
439 if BuildData
.Pcds
[key
].Pending
:
440 MGen
= ModuleAutoGen(self
, BuildData
.MetaFile
, Target
, Toolchain
, Arch
, self
.MetaFile
)
441 if MGen
and MGen
.IsLibrary
:
442 if MGen
in PGen
.LibraryAutoGenList
:
443 ReferenceModules
= MGen
._ReferenceModules
444 for ReferenceModule
in ReferenceModules
:
445 if ReferenceModule
.MetaFile
in Platform
.Modules
:
446 RefPlatformModule
= Platform
.Modules
[str(ReferenceModule
.MetaFile
)]
447 if key
in RefPlatformModule
.Pcds
:
448 PcdInReferenceModule
= RefPlatformModule
.Pcds
[key
]
449 if PcdInReferenceModule
.Type
:
450 BuildData
.Pcds
[key
].Type
= PcdInReferenceModule
.Type
451 BuildData
.Pcds
[key
].Pending
= False
454 if TAB_PCDS_DYNAMIC_EX
in BuildData
.Pcds
[key
].Type
:
455 if BuildData
.IsBinaryModule
:
456 BinaryPcdDict
[TAB_PCDS_DYNAMIC_EX
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
458 SourcePcdDict
[TAB_PCDS_DYNAMIC_EX
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
460 elif TAB_PCDS_PATCHABLE_IN_MODULE
in BuildData
.Pcds
[key
].Type
:
461 if BuildData
.MetaFile
.Ext
== '.inf':
462 if BuildData
.IsBinaryModule
:
463 BinaryPcdDict
[TAB_PCDS_PATCHABLE_IN_MODULE
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
465 SourcePcdDict
[TAB_PCDS_PATCHABLE_IN_MODULE
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
467 elif TAB_PCDS_DYNAMIC
in BuildData
.Pcds
[key
].Type
:
468 SourcePcdDict
[TAB_PCDS_DYNAMIC
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
469 elif TAB_PCDS_FIXED_AT_BUILD
in BuildData
.Pcds
[key
].Type
:
470 SourcePcdDict
[TAB_PCDS_FIXED_AT_BUILD
].add((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
474 # A PCD can only use one type for all source modules
476 for i
in SourcePcdDict_Keys
:
477 for j
in SourcePcdDict_Keys
:
479 Intersections
= SourcePcdDict
[i
].intersection(SourcePcdDict
[j
])
480 if len(Intersections
) > 0:
484 "Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i
, j
),
485 ExtraData
='\n\t'.join(str(P
[1]+'.'+P
[0]) for P
in Intersections
)
489 # intersection the BinaryPCD for Mixed PCD
491 for i
in BinaryPcdDict_Keys
:
492 for j
in BinaryPcdDict_Keys
:
494 Intersections
= BinaryPcdDict
[i
].intersection(BinaryPcdDict
[j
])
495 for item
in Intersections
:
496 NewPcd1
= (item
[0] + '_' + i
, item
[1])
497 NewPcd2
= (item
[0] + '_' + j
, item
[1])
498 if item
not in GlobalData
.MixedPcd
:
499 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
501 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
502 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
503 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
504 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
507 # intersection the SourcePCD and BinaryPCD for Mixed PCD
509 for i
in SourcePcdDict_Keys
:
510 for j
in BinaryPcdDict_Keys
:
512 Intersections
= SourcePcdDict
[i
].intersection(BinaryPcdDict
[j
])
513 for item
in Intersections
:
514 NewPcd1
= (item
[0] + '_' + i
, item
[1])
515 NewPcd2
= (item
[0] + '_' + j
, item
[1])
516 if item
not in GlobalData
.MixedPcd
:
517 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
519 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
520 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
521 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
522 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
524 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
525 if BuildData
.Arch
!= Arch
:
527 for key
in BuildData
.Pcds
:
528 for SinglePcd
in GlobalData
.MixedPcd
:
529 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
530 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
531 Pcd_Type
= item
[0].split('_')[-1]
532 if (Pcd_Type
== BuildData
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and BuildData
.Pcds
[key
].Type
in PCD_DYNAMIC_EX_TYPE_SET
) or \
533 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in PCD_DYNAMIC_TYPE_SET
):
534 Value
= BuildData
.Pcds
[key
]
535 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
537 newkey
= (Value
.TokenCName
, key
[1])
539 newkey
= (Value
.TokenCName
, key
[1], key
[2])
540 del BuildData
.Pcds
[key
]
541 BuildData
.Pcds
[newkey
] = Value
545 # handle the mixed pcd in FDF file
547 if key
in GlobalData
.MixedPcd
:
550 for item
in GlobalData
.MixedPcd
[key
]:
553 #Collect package set information from INF of FDF
555 for Inf
in ModuleList
:
556 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
557 if ModuleFile
in Platform
.Modules
:
559 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
560 PkgSet
.update(ModuleData
.Packages
)
561 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
566 DecPcds
.add((Pcd
[0], Pcd
[1]))
567 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
569 Platform
.SkuName
= self
.SkuId
570 for Name
, Guid
in PcdSet
:
571 if (Name
, Guid
) not in DecPcds
:
575 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
576 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
577 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
580 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
581 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
582 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
583 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
584 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
586 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
590 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
591 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
592 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
595 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
597 # Explicitly collect platform's dynamic PCDs
599 Pa
.CollectPlatformDynamicPcds()
600 Pa
.CollectFixedAtBuildPcds()
601 self
.AutoGenObjectList
.append(Pa
)
604 # Generate Package level hash value
606 GlobalData
.gPackageHash
[Arch
] = {}
607 if GlobalData
.gUseHashCache
:
609 self
._GenPkgLevelHash
(Pkg
)
612 # Check PCDs token value conflict in each DEC file.
614 self
._CheckAllPcdsTokenValueConflict
()
617 # Check PCD type and definition between DSC and DEC
619 self
._CheckPcdDefineAndType
()
622 # self._CheckDuplicateInFV(Fdf)
625 # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.
627 content
= 'gCommandLineDefines: '
628 content
+= str(GlobalData
.gCommandLineDefines
)
629 content
+= os
.linesep
630 content
+= 'BuildOptionPcd: '
631 content
+= str(GlobalData
.BuildOptionPcd
)
632 content
+= os
.linesep
633 content
+= 'Active Platform: '
634 content
+= str(self
.Platform
)
635 content
+= os
.linesep
637 content
+= 'Flash Image Definition: '
638 content
+= str(self
.FdfFile
)
639 content
+= os
.linesep
640 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'BuildOptions'), content
, False)
643 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.
645 PcdTokenNumber
= 'PcdTokenNumber: '
646 if Pa
.PcdTokenNumber
:
647 if Pa
.DynamicPcdList
:
648 for Pcd
in Pa
.DynamicPcdList
:
649 PcdTokenNumber
+= os
.linesep
650 PcdTokenNumber
+= str((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
))
651 PcdTokenNumber
+= ' : '
652 PcdTokenNumber
+= str(Pa
.PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
])
653 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'), PcdTokenNumber
, False)
656 # Get set of workspace metafiles
658 AllWorkSpaceMetaFiles
= self
._GetMetaFiles
(Target
, Toolchain
, Arch
)
661 # Retrieve latest modified time of all metafiles
664 for f
in AllWorkSpaceMetaFiles
:
665 if os
.stat(f
)[8] > SrcTimeStamp
:
666 SrcTimeStamp
= os
.stat(f
)[8]
667 self
._SrcTimeStamp
= SrcTimeStamp
669 if GlobalData
.gUseHashCache
:
671 for files
in AllWorkSpaceMetaFiles
:
672 if files
.endswith('.dec'):
678 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'AutoGen.hash'), m
.hexdigest(), True)
679 GlobalData
.gPlatformHash
= m
.hexdigest()
682 # Write metafile list to build directory
684 AutoGenFilePath
= os
.path
.join(self
.BuildDir
, 'AutoGen')
685 if os
.path
.exists (AutoGenFilePath
):
686 os
.remove(AutoGenFilePath
)
687 if not os
.path
.exists(self
.BuildDir
):
688 os
.makedirs(self
.BuildDir
)
689 with
open(os
.path
.join(self
.BuildDir
, 'AutoGen'), 'w+') as file:
690 for f
in AllWorkSpaceMetaFiles
:
694 def _GenPkgLevelHash(self
, Pkg
):
695 if Pkg
.PackageName
in GlobalData
.gPackageHash
[Pkg
.Arch
]:
698 PkgDir
= os
.path
.join(self
.BuildDir
, Pkg
.Arch
, Pkg
.PackageName
)
699 CreateDirectory(PkgDir
)
700 HashFile
= os
.path
.join(PkgDir
, Pkg
.PackageName
+ '.hash')
702 # Get .dec file's hash value
703 f
= open(Pkg
.MetaFile
.Path
, 'r')
707 # Get include files hash value
709 for inc
in sorted(Pkg
.Includes
, key
=lambda x
: str(x
)):
710 for Root
, Dirs
, Files
in os
.walk(str(inc
)):
711 for File
in sorted(Files
):
712 File_Path
= os
.path
.join(Root
, File
)
713 f
= open(File_Path
, 'r')
717 SaveFileOnChange(HashFile
, m
.hexdigest(), True)
718 GlobalData
.gPackageHash
[Pkg
.Arch
][Pkg
.PackageName
] = m
.hexdigest()
720 def _GetMetaFiles(self
, Target
, Toolchain
, Arch
):
721 AllWorkSpaceMetaFiles
= set()
726 AllWorkSpaceMetaFiles
.add (self
.FdfFile
.Path
)
727 for f
in GlobalData
.gFdfParser
.GetAllIncludedFile():
728 AllWorkSpaceMetaFiles
.add (f
.FileName
)
732 AllWorkSpaceMetaFiles
.add(self
.MetaFile
.Path
)
735 # add build_rule.txt & tools_def.txt
737 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultBuildRuleFile
))
738 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultToolsDefFile
))
740 # add BuildOption metafile
742 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'BuildOptions'))
744 # add PcdToken Number file for Dynamic/DynamicEx Pcd
746 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'))
748 for Arch
in self
.ArchList
:
752 for Package
in PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
).PackageList
:
753 AllWorkSpaceMetaFiles
.add(Package
.MetaFile
.Path
)
758 for filePath
in self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]._RawData
.IncludedFiles
:
759 AllWorkSpaceMetaFiles
.add(filePath
.Path
)
761 return AllWorkSpaceMetaFiles
763 ## _CheckDuplicateInFV() method
765 # Check whether there is duplicate modules/files exist in FV section.
766 # The check base on the file GUID;
768 def _CheckDuplicateInFV(self
, Fdf
):
769 for Fv
in Fdf
.Profile
.FvDict
:
771 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
772 if FfsFile
.InfFileName
and FfsFile
.NameGuid
is None:
777 for Pa
in self
.AutoGenObjectList
:
780 for Module
in Pa
.ModuleAutoGenList
:
781 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
783 if Module
.Guid
.upper() not in _GuidDict
:
784 _GuidDict
[Module
.Guid
.upper()] = FfsFile
787 EdkLogger
.error("build",
789 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
790 FfsFile
.CurrentLineContent
,
791 _GuidDict
[Module
.Guid
.upper()].CurrentLineNum
,
792 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
793 Module
.Guid
.upper()),
794 ExtraData
=self
.FdfFile
)
796 # Some INF files not have entity in DSC file.
799 if FfsFile
.InfFileName
.find('$') == -1:
800 InfPath
= NormPath(FfsFile
.InfFileName
)
801 if not os
.path
.exists(InfPath
):
802 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
804 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
806 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
807 # BuildObject from one of AutoGenObjectList is enough.
809 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, TAB_ARCH_COMMON
, self
.BuildTarget
, self
.ToolChain
]
810 if InfObj
.Guid
.upper() not in _GuidDict
:
811 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
813 EdkLogger
.error("build",
815 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
816 FfsFile
.CurrentLineContent
,
817 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
818 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
819 InfObj
.Guid
.upper()),
820 ExtraData
=self
.FdfFile
)
823 if FfsFile
.NameGuid
is not None:
825 # If the NameGuid reference a PCD name.
826 # The style must match: PCD(xxxx.yyy)
828 if gPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
830 # Replace the PCD value.
832 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
834 for Pa
in self
.AutoGenObjectList
:
836 for PcdItem
in Pa
.AllPcdList
:
837 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
839 # First convert from CFormatGuid to GUID string
841 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
843 if not _PcdGuidString
:
845 # Then try Byte array.
847 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
849 if not _PcdGuidString
:
851 # Not Byte array or CFormat GUID, raise error.
853 EdkLogger
.error("build",
855 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
856 ExtraData
=self
.FdfFile
)
858 if _PcdGuidString
.upper() not in _GuidDict
:
859 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
863 EdkLogger
.error("build",
865 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
866 FfsFile
.CurrentLineContent
,
867 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
868 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
869 FfsFile
.NameGuid
.upper()),
870 ExtraData
=self
.FdfFile
)
872 if FfsFile
.NameGuid
.upper() not in _GuidDict
:
873 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
876 # Two raw file GUID conflict.
878 EdkLogger
.error("build",
880 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
881 FfsFile
.CurrentLineContent
,
882 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
883 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
884 FfsFile
.NameGuid
.upper()),
885 ExtraData
=self
.FdfFile
)
888 def _CheckPcdDefineAndType(self
):
889 PcdTypeSet
= {TAB_PCDS_FIXED_AT_BUILD
,
890 TAB_PCDS_PATCHABLE_IN_MODULE
,
891 TAB_PCDS_FEATURE_FLAG
,
895 # This dict store PCDs which are not used by any modules with specified arches
896 UnusedPcd
= OrderedDict()
897 for Pa
in self
.AutoGenObjectList
:
898 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
899 for Pcd
in Pa
.Platform
.Pcds
:
900 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
902 # If no PCD type, this PCD comes from FDF
906 # Try to remove Hii and Vpd suffix
907 if PcdType
.startswith(TAB_PCDS_DYNAMIC_EX
):
908 PcdType
= TAB_PCDS_DYNAMIC_EX
909 elif PcdType
.startswith(TAB_PCDS_DYNAMIC
):
910 PcdType
= TAB_PCDS_DYNAMIC
912 for Package
in Pa
.PackageList
:
913 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
914 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
916 for Type
in PcdTypeSet
:
917 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
921 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
922 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
927 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
929 for Pcd
in UnusedPcd
:
932 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
933 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
934 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
939 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
941 ## Return the directory to store FV files
943 if self
._FvDir
is None:
944 self
._FvDir
= path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
947 ## Return the directory to store all intermediate and final files built
948 def _GetBuildDir(self
):
949 if self
._BuildDir
is None:
950 return self
.AutoGenObjectList
[0].BuildDir
952 ## Return the build output directory platform specifies
953 def _GetOutputDir(self
):
954 return self
.Platform
.OutputDirectory
956 ## Return platform name
958 return self
.Platform
.PlatformName
960 ## Return meta-file GUID
962 return self
.Platform
.Guid
964 ## Return platform version
965 def _GetVersion(self
):
966 return self
.Platform
.Version
968 ## Return paths of tools
969 def _GetToolDefinition(self
):
970 return self
.AutoGenObjectList
[0].ToolDefinition
972 ## Return directory of platform makefile
974 # @retval string Makefile directory
976 def _GetMakeFileDir(self
):
977 if self
._MakeFileDir
is None:
978 self
._MakeFileDir
= self
.BuildDir
979 return self
._MakeFileDir
981 ## Return build command string
983 # @retval string Build command string
985 def _GetBuildCommand(self
):
986 if self
._BuildCommand
is None:
987 # BuildCommand should be all the same. So just get one from platform AutoGen
988 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
989 return self
._BuildCommand
991 ## Check the PCDs token value conflict in each DEC file.
993 # Will cause build break and raise error message while two PCDs conflict.
997 def _CheckAllPcdsTokenValueConflict(self
):
998 for Pa
in self
.AutoGenObjectList
:
999 for Package
in Pa
.PackageList
:
1000 PcdList
= Package
.Pcds
.values()
1001 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
1003 while (Count
< len(PcdList
) - 1) :
1004 Item
= PcdList
[Count
]
1005 ItemNext
= PcdList
[Count
+ 1]
1007 # Make sure in the same token space the TokenValue should be unique
1009 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
1010 SameTokenValuePcdList
= []
1011 SameTokenValuePcdList
.append(Item
)
1012 SameTokenValuePcdList
.append(ItemNext
)
1013 RemainPcdListLength
= len(PcdList
) - Count
- 2
1014 for ValueSameCount
in range(RemainPcdListLength
):
1015 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
1016 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
1020 # Sort same token value PCD list with TokenGuid and TokenCName
1022 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1023 SameTokenValuePcdListCount
= 0
1024 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
1026 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
1027 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
1029 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
1030 for PcdItem
in GlobalData
.MixedPcd
:
1031 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
1032 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1038 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
1039 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
1042 SameTokenValuePcdListCount
+= 1
1043 Count
+= SameTokenValuePcdListCount
1046 PcdList
= Package
.Pcds
.values()
1047 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1049 while (Count
< len(PcdList
) - 1) :
1050 Item
= PcdList
[Count
]
1051 ItemNext
= PcdList
[Count
+ 1]
1053 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
1055 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
1059 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
1060 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
1064 ## Generate fds command
1065 def _GenFdsCommand(self
):
1066 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
1068 ## Create makefile for the platform and modules in it
1070 # @param CreateDepsMakeFile Flag indicating if the makefile for
1071 # modules will be created as well
1073 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
1074 if not CreateDepsMakeFile
:
1076 for Pa
in self
.AutoGenObjectList
:
1077 Pa
.CreateMakeFile(True)
1079 ## Create autogen code for platform and modules
1081 # Since there's no autogen code for platform, this method will do nothing
1082 # if CreateModuleCodeFile is set to False.
1084 # @param CreateDepsCodeFile Flag indicating if creating module's
1085 # autogen code file or not
1087 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
1088 if not CreateDepsCodeFile
:
1090 for Pa
in self
.AutoGenObjectList
:
1091 Pa
.CreateCodeFile(True)
1093 ## Create AsBuilt INF file the platform
1095 def CreateAsBuiltInf(self
):
1098 Name
= property(_GetName
)
1099 Guid
= property(_GetGuid
)
1100 Version
= property(_GetVersion
)
1101 OutputDir
= property(_GetOutputDir
)
1103 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
1105 BuildDir
= property(_GetBuildDir
)
1106 FvDir
= property(_GetFvDir
)
1107 MakeFileDir
= property(_GetMakeFileDir
)
1108 BuildCommand
= property(_GetBuildCommand
)
1109 GenFdsCommand
= property(_GenFdsCommand
)
1111 ## AutoGen class for platform
1113 # PlatformAutoGen class will process the original information in platform
1114 # file in order to generate makefile for platform.
1116 class PlatformAutoGen(AutoGen
):
1117 # call super().__init__ then call the worker function with different parameter count
1118 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
1122 super(PlatformAutoGen
, self
).__init
__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
1123 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
)
1126 # Used to store all PCDs for both PEI and DXE phase, in order to generate
1127 # correct PCD database
1130 _NonDynaPcdList_
= []
1134 # The priority list while override build option
1136 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
1137 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1138 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1139 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1140 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1141 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1142 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1143 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1144 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1145 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1146 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1147 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1148 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1149 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1150 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1151 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1153 ## Initialize PlatformAutoGen
1156 # @param Workspace WorkspaceAutoGen object
1157 # @param PlatformFile Platform file (DSC file)
1158 # @param Target Build target (DEBUG, RELEASE)
1159 # @param Toolchain Name of tool chain
1160 # @param Arch arch of the platform supports
1162 def _InitWorker(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1163 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1164 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1166 self
.MetaFile
= PlatformFile
1167 self
.Workspace
= Workspace
1168 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1169 self
.ToolChain
= Toolchain
1170 self
.BuildTarget
= Target
1172 self
.SourceDir
= PlatformFile
.SubDir
1173 self
.SourceOverrideDir
= None
1174 self
.FdTargetList
= self
.Workspace
.FdTargetList
1175 self
.FvTargetList
= self
.Workspace
.FvTargetList
1176 self
.AllPcdList
= []
1177 # get the original module/package/platform objects
1178 self
.BuildDatabase
= Workspace
.BuildDatabase
1179 self
.DscBuildDataObj
= Workspace
.Platform
1180 self
._GuidDict
= Workspace
._GuidDict
1182 # flag indicating if the makefile/C-code file has been created or not
1183 self
.IsMakeFileCreated
= False
1184 self
.IsCodeFileCreated
= False
1186 self
._Platform
= None
1189 self
._Version
= None
1191 self
._BuildRule
= None
1192 self
._SourceDir
= None
1193 self
._BuildDir
= None
1194 self
._OutputDir
= None
1196 self
._MakeFileDir
= None
1197 self
._FdfFile
= None
1199 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
1200 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1201 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1202 self
._NonDynamicPcdDict
= {}
1204 self
._ToolDefinitions
= None
1205 self
._ToolDefFile
= None # toolcode : tool path
1206 self
._ToolChainFamily
= None
1207 self
._BuildRuleFamily
= None
1208 self
._BuildOption
= None # toolcode : option
1209 self
._EdkBuildOption
= None # edktoolcode : option
1210 self
._EdkIIBuildOption
= None # edkiitoolcode : option
1211 self
._PackageList
= None
1212 self
._ModuleAutoGenList
= None
1213 self
._LibraryAutoGenList
= None
1214 self
._BuildCommand
= None
1215 self
._AsBuildInfList
= []
1216 self
._AsBuildModuleList
= []
1218 self
.VariableInfo
= None
1220 if GlobalData
.gFdfParser
is not None:
1221 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1222 for Inf
in self
._AsBuildInfList
:
1223 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1224 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1225 if not M
.IsSupportedArch
:
1227 self
._AsBuildModuleList
.append(InfClass
)
1228 # get library/modules for build
1229 self
.LibraryBuildDirectoryList
= []
1230 self
.ModuleBuildDirectoryList
= []
1235 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1237 ## Create autogen code for platform and modules
1239 # Since there's no autogen code for platform, this method will do nothing
1240 # if CreateModuleCodeFile is set to False.
1242 # @param CreateModuleCodeFile Flag indicating if creating module's
1243 # autogen code file or not
1245 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1246 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1247 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
1250 for Ma
in self
.ModuleAutoGenList
:
1251 Ma
.CreateCodeFile(True)
1253 # don't do this twice
1254 self
.IsCodeFileCreated
= True
1256 ## Generate Fds Command
1257 def _GenFdsCommand(self
):
1258 return self
.Workspace
.GenFdsCommand
1260 ## Create makefile for the platform and mdoules in it
1262 # @param CreateModuleMakeFile Flag indicating if the makefile for
1263 # modules will be created as well
1265 def CreateMakeFile(self
, CreateModuleMakeFile
=False, FfsCommand
= {}):
1266 if CreateModuleMakeFile
:
1267 for ModuleFile
in self
.Platform
.Modules
:
1268 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
1269 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1270 if (ModuleFile
.File
, self
.Arch
) in FfsCommand
:
1271 Ma
.CreateMakeFile(True, FfsCommand
[ModuleFile
.File
, self
.Arch
])
1273 Ma
.CreateMakeFile(True)
1274 #Ma.CreateAsBuiltInf()
1276 # no need to create makefile for the platform more than once
1277 if self
.IsMakeFileCreated
:
1280 # create library/module build dirs for platform
1281 Makefile
= GenMake
.PlatformMakefile(self
)
1282 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1283 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1285 self
.IsMakeFileCreated
= True
1287 ## Deal with Shared FixedAtBuild Pcds
1289 def CollectFixedAtBuildPcds(self
):
1290 for LibAuto
in self
.LibraryAutoGenList
:
1291 FixedAtBuildPcds
= {}
1292 ShareFixedAtBuildPcdsSameValue
= {}
1293 for Module
in LibAuto
._ReferenceModules
:
1294 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
1295 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1296 if key
not in FixedAtBuildPcds
:
1297 ShareFixedAtBuildPcdsSameValue
[key
] = True
1298 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
1300 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
1301 ShareFixedAtBuildPcdsSameValue
[key
] = False
1302 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1303 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1304 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1307 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
1308 if DscPcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
1310 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1311 LibAuto
.ConstPcd
[key
] = FixedAtBuildPcds
[key
]
1313 def CollectVariables(self
, DynamicPcdSet
):
1317 if self
.Workspace
.FdfFile
:
1318 FdDict
= self
.Workspace
.FdfProfile
.FdDict
[GlobalData
.gFdfParser
.CurrentFdName
]
1319 for FdRegion
in FdDict
.RegionList
:
1320 for item
in FdRegion
.RegionDataList
:
1321 if self
.Platform
.VpdToolGuid
.strip() and self
.Platform
.VpdToolGuid
in item
:
1322 VpdRegionSize
= FdRegion
.Size
1323 VpdRegionBase
= FdRegion
.Offset
1327 VariableInfo
= VariableMgr(self
.DscBuildDataObj
._GetDefaultStores
(),self
.DscBuildDataObj
._GetSkuIds
())
1328 VariableInfo
.SetVpdRegionMaxSize(VpdRegionSize
)
1329 VariableInfo
.SetVpdRegionOffset(VpdRegionBase
)
1331 for Pcd
in DynamicPcdSet
:
1332 pcdname
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1333 for SkuName
in Pcd
.SkuInfoList
:
1334 Sku
= Pcd
.SkuInfoList
[SkuName
]
1336 if SkuId
is None or SkuId
== '':
1338 if len(Sku
.VariableName
) > 0:
1339 VariableGuidStructure
= Sku
.VariableGuidValue
1340 VariableGuid
= GuidStructureStringToGuidString(VariableGuidStructure
)
1341 for StorageName
in Sku
.DefaultStoreDict
:
1342 VariableInfo
.append_variable(var_info(Index
,pcdname
,StorageName
,SkuName
, StringToArray(Sku
.VariableName
),VariableGuid
, Sku
.VariableOffset
, Sku
.VariableAttribute
, Sku
.HiiDefaultValue
,Sku
.DefaultStoreDict
[StorageName
],Pcd
.DatumType
))
1346 def UpdateNVStoreMaxSize(self
,OrgVpdFile
):
1347 if self
.VariableInfo
:
1348 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
1349 PcdNvStoreDfBuffer
= [item
for item
in self
._DynamicPcdList
if item
.TokenCName
== "PcdNvStoreDefaultValueBuffer" and item
.TokenSpaceGuidCName
== "gEfiMdeModulePkgTokenSpaceGuid"]
1351 if PcdNvStoreDfBuffer
:
1352 if os
.path
.exists(VpdMapFilePath
):
1353 OrgVpdFile
.Read(VpdMapFilePath
)
1354 PcdItems
= OrgVpdFile
.GetOffset(PcdNvStoreDfBuffer
[0])
1355 NvStoreOffset
= PcdItems
.values()[0].strip() if PcdItems
else '0'
1357 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1359 NvStoreOffset
= int(NvStoreOffset
,16) if NvStoreOffset
.upper().startswith("0X") else int(NvStoreOffset
)
1360 default_skuobj
= PcdNvStoreDfBuffer
[0].SkuInfoList
.get(TAB_DEFAULT
)
1361 maxsize
= self
.VariableInfo
.VpdRegionSize
- NvStoreOffset
if self
.VariableInfo
.VpdRegionSize
else len(default_skuobj
.DefaultValue
.split(","))
1362 var_data
= self
.VariableInfo
.PatchNVStoreDefaultMaxSize(maxsize
)
1364 if var_data
and default_skuobj
:
1365 default_skuobj
.DefaultValue
= var_data
1366 PcdNvStoreDfBuffer
[0].DefaultValue
= var_data
1367 PcdNvStoreDfBuffer
[0].SkuInfoList
.clear()
1368 PcdNvStoreDfBuffer
[0].SkuInfoList
[TAB_DEFAULT
] = default_skuobj
1369 PcdNvStoreDfBuffer
[0].MaxDatumSize
= str(len(default_skuobj
.DefaultValue
.split(",")))
1373 ## Collect dynamic PCDs
1375 # Gather dynamic PCDs list from each module and their settings from platform
1376 # This interface should be invoked explicitly when platform action is created.
1378 def CollectPlatformDynamicPcds(self
):
1380 for key
in self
.Platform
.Pcds
:
1381 for SinglePcd
in GlobalData
.MixedPcd
:
1382 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1383 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1384 Pcd_Type
= item
[0].split('_')[-1]
1385 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 \
1386 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in PCD_DYNAMIC_TYPE_SET
):
1387 Value
= self
.Platform
.Pcds
[key
]
1388 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1390 newkey
= (Value
.TokenCName
, key
[1])
1392 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1393 del self
.Platform
.Pcds
[key
]
1394 self
.Platform
.Pcds
[newkey
] = Value
1398 # for gathering error information
1399 NoDatumTypePcdList
= set()
1401 for InfName
in self
._AsBuildInfList
:
1402 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1403 FdfModuleList
.append(os
.path
.normpath(InfName
))
1404 for F
in self
.Platform
.Modules
.keys():
1405 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1406 #GuidValue.update(M.Guids)
1408 self
.Platform
.Modules
[F
].M
= M
1410 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1411 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1412 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
1413 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1415 # Check the PCD from Binary INF or Source INF
1416 if M
.IsBinaryModule
== True:
1417 PcdFromModule
.IsFromBinaryInf
= True
1419 # Check the PCD from DSC or not
1420 PcdFromModule
.IsFromDsc
= (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
1422 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
or PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1423 if F
.Path
not in FdfModuleList
:
1424 # If one of the Source built modules listed in the DSC is not listed
1425 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1426 # access method (it is only listed in the DEC file that declares the
1427 # PCD as PcdsDynamic), then build tool will report warning message
1428 # notify the PI that they are attempting to build a module that must
1429 # be included in a flash image in order to be functional. These Dynamic
1430 # PCD will not be added into the Database unless it is used by other
1431 # modules that are included in the FDF file.
1432 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
and \
1433 PcdFromModule
.IsFromBinaryInf
== False:
1434 # Print warning message to let the developer make a determine.
1436 # If one of the Source built modules listed in the DSC is not listed in
1437 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1438 # access method (it is only listed in the DEC file that declares the
1439 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1440 # PCD to the Platform's PCD Database.
1441 if PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1444 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1445 # it should be stored in Pcd PEI database, If a dynamic only
1446 # used by DXE module, it should be stored in DXE PCD database.
1447 # The default Phase is DXE
1449 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
1450 PcdFromModule
.Phase
= "PEI"
1451 if PcdFromModule
not in self
._DynaPcdList
_:
1452 self
._DynaPcdList
_.append(PcdFromModule
)
1453 elif PcdFromModule
.Phase
== 'PEI':
1454 # overwrite any the same PCD existing, if Phase is PEI
1455 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1456 self
._DynaPcdList
_[Index
] = PcdFromModule
1457 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1458 self
._NonDynaPcdList
_.append(PcdFromModule
)
1459 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1460 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1461 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1462 #The PCD from Binary INF will override the same one from source INF
1463 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1464 PcdFromModule
.Pending
= False
1465 self
._NonDynaPcdList
_.append (PcdFromModule
)
1466 DscModuleSet
= {os
.path
.normpath(ModuleInf
.Path
) for ModuleInf
in self
.Platform
.Modules
}
1467 # add the PCD from modules that listed in FDF but not in DSC to Database
1468 for InfName
in FdfModuleList
:
1469 if InfName
not in DscModuleSet
:
1470 InfClass
= PathClass(InfName
)
1471 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1472 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1473 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1474 # For binary module, if in current arch, we need to list the PCDs into database.
1475 if not M
.IsSupportedArch
:
1477 # Override the module PCD setting by platform setting
1478 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1479 for PcdFromModule
in ModulePcdList
:
1480 PcdFromModule
.IsFromBinaryInf
= True
1481 PcdFromModule
.IsFromDsc
= False
1482 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1483 if PcdFromModule
.Type
not in PCD_DYNAMIC_EX_TYPE_SET
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1484 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1486 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1487 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1488 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1489 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
1490 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1491 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
1492 PcdFromModule
.Phase
= "PEI"
1493 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1494 self
._DynaPcdList
_.append(PcdFromModule
)
1495 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1496 self
._NonDynaPcdList
_.append(PcdFromModule
)
1497 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1498 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1499 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1500 # module & DXE module at a same time.
1501 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1502 # INF file as DynamicEx.
1503 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1504 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1505 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1506 for PcdFromModule
in self
._NonDynaPcdList
_:
1507 # If a PCD is not listed in the DSC file, but binary INF files used by
1508 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1509 # section, AND all source INF files used by this platform the build
1510 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1511 # section, then the tools must NOT add the PCD to the Platform's PCD
1512 # Database; the build must assign the access method for this PCD as
1513 # PcdsPatchableInModule.
1514 if PcdFromModule
not in self
._DynaPcdList
_:
1516 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1517 if PcdFromModule
.IsFromDsc
== False and \
1518 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1519 PcdFromModule
.IsFromBinaryInf
== True and \
1520 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1521 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1522 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1524 # print out error information and break the build, if error found
1525 if len(NoDatumTypePcdList
) > 0:
1526 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1527 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1529 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1530 % NoDatumTypePcdListString
)
1531 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1532 self
._DynamicPcdList
= self
._DynaPcdList
_
1534 # Sort dynamic PCD list to:
1535 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1536 # try to be put header of dynamicd List
1537 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1539 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1541 UnicodePcdArray
= set()
1543 OtherPcdArray
= set()
1545 VpdFile
= VpdInfoFile
.VpdInfoFile()
1546 NeedProcessVpdMapFile
= False
1548 for pcd
in self
.Platform
.Pcds
:
1549 if pcd
not in self
._PlatformPcds
:
1550 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1552 for item
in self
._PlatformPcds
:
1553 if self
._PlatformPcds
[item
].DatumType
and self
._PlatformPcds
[item
].DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1554 self
._PlatformPcds
[item
].DatumType
= TAB_VOID
1556 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1557 for Pcd
in self
._DynamicPcdList
:
1558 # just pick the a value to determine whether is unicode string type
1559 Sku
= Pcd
.SkuInfoList
.values()[0]
1560 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1562 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1563 Pcd
.DatumType
= TAB_VOID
1565 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1566 # if found HII type PCD then insert to right of UnicodeIndex
1567 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1568 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1570 #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer
1571 PcdNvStoreDfBuffer
= VpdPcdDict
.get(("PcdNvStoreDefaultValueBuffer","gEfiMdeModulePkgTokenSpaceGuid"))
1572 if PcdNvStoreDfBuffer
:
1573 self
.VariableInfo
= self
.CollectVariables(self
._DynamicPcdList
)
1574 vardump
= self
.VariableInfo
.dump()
1576 PcdNvStoreDfBuffer
.DefaultValue
= vardump
1577 for skuname
in PcdNvStoreDfBuffer
.SkuInfoList
:
1578 PcdNvStoreDfBuffer
.SkuInfoList
[skuname
].DefaultValue
= vardump
1579 PcdNvStoreDfBuffer
.MaxDatumSize
= str(len(vardump
.split(",")))
1581 PlatformPcds
= sorted(self
._PlatformPcds
.keys())
1583 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1586 for PcdKey
in PlatformPcds
:
1587 Pcd
= self
._PlatformPcds
[PcdKey
]
1588 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1589 PcdKey
in VpdPcdDict
:
1590 Pcd
= VpdPcdDict
[PcdKey
]
1592 DefaultSku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
1594 PcdValue
= DefaultSku
.DefaultValue
1595 if PcdValue
not in SkuValueMap
:
1596 SkuValueMap
[PcdValue
] = []
1597 VpdFile
.Add(Pcd
, TAB_DEFAULT
,DefaultSku
.VpdOffset
)
1598 SkuValueMap
[PcdValue
].append(DefaultSku
)
1600 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1601 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1602 PcdValue
= Sku
.DefaultValue
1604 PcdValue
= Pcd
.DefaultValue
1605 if Sku
.VpdOffset
!= '*':
1606 if PcdValue
.startswith("{"):
1608 elif PcdValue
.startswith("L"):
1613 VpdOffset
= int(Sku
.VpdOffset
)
1616 VpdOffset
= int(Sku
.VpdOffset
, 16)
1618 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1619 if VpdOffset
% Alignment
!= 0:
1620 if PcdValue
.startswith("{"):
1621 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1623 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1624 if PcdValue
not in SkuValueMap
:
1625 SkuValueMap
[PcdValue
] = []
1626 VpdFile
.Add(Pcd
, SkuName
,Sku
.VpdOffset
)
1627 SkuValueMap
[PcdValue
].append(Sku
)
1628 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1629 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1630 NeedProcessVpdMapFile
= True
1631 if self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== '':
1632 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1633 "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.")
1635 VpdSkuMap
[PcdKey
] = SkuValueMap
1637 # Fix the PCDs define in VPD PCD section that never referenced by module.
1638 # An example is PCD for signature usage.
1640 for DscPcd
in PlatformPcds
:
1641 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1642 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1643 if not (self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== ''):
1645 for VpdPcd
in VpdFile
._VpdArray
:
1646 # This PCD has been referenced by module
1647 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1648 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1651 # Not found, it should be signature
1653 # just pick the a value to determine whether is unicode string type
1655 SkuObjList
= DscPcdEntry
.SkuInfoList
.items()
1656 DefaultSku
= DscPcdEntry
.SkuInfoList
.get(TAB_DEFAULT
)
1658 defaultindex
= SkuObjList
.index((TAB_DEFAULT
,DefaultSku
))
1659 SkuObjList
[0],SkuObjList
[defaultindex
] = SkuObjList
[defaultindex
],SkuObjList
[0]
1660 for (SkuName
,Sku
) in SkuObjList
:
1661 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1663 # Need to iterate DEC pcd information to get the value & datumtype
1664 for eachDec
in self
.PackageList
:
1665 for DecPcd
in eachDec
.Pcds
:
1666 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1667 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1668 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1669 # Print warning message to let the developer make a determine.
1670 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1671 File
=self
.MetaFile
, \
1672 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1673 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1675 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1676 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1677 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1678 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1679 # Only fix the value while no value provided in DSC file.
1680 if not Sku
.DefaultValue
:
1681 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1683 if DscPcdEntry
not in self
._DynamicPcdList
:
1684 self
._DynamicPcdList
.append(DscPcdEntry
)
1685 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1686 PcdValue
= Sku
.DefaultValue
1688 PcdValue
= DscPcdEntry
.DefaultValue
1689 if Sku
.VpdOffset
!= '*':
1690 if PcdValue
.startswith("{"):
1692 elif PcdValue
.startswith("L"):
1697 VpdOffset
= int(Sku
.VpdOffset
)
1700 VpdOffset
= int(Sku
.VpdOffset
, 16)
1702 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1703 if VpdOffset
% Alignment
!= 0:
1704 if PcdValue
.startswith("{"):
1705 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1707 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1708 if PcdValue
not in SkuValueMap
:
1709 SkuValueMap
[PcdValue
] = []
1710 VpdFile
.Add(DscPcdEntry
, SkuName
,Sku
.VpdOffset
)
1711 SkuValueMap
[PcdValue
].append(Sku
)
1712 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1713 NeedProcessVpdMapFile
= True
1714 if DscPcdEntry
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
1715 UnicodePcdArray
.add(DscPcdEntry
)
1716 elif len(Sku
.VariableName
) > 0:
1717 HiiPcdArray
.add(DscPcdEntry
)
1719 OtherPcdArray
.add(DscPcdEntry
)
1721 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1722 VpdSkuMap
[DscPcd
] = SkuValueMap
1723 if (self
.Platform
.FlashDefinition
is None or self
.Platform
.FlashDefinition
== '') and \
1724 VpdFile
.GetCount() != 0:
1725 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1726 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1728 if VpdFile
.GetCount() != 0:
1730 self
.FixVpdOffset(VpdFile
)
1732 self
.FixVpdOffset(self
.UpdateNVStoreMaxSize(VpdFile
))
1734 # Process VPD map file generated by third party BPDG tool
1735 if NeedProcessVpdMapFile
:
1736 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
1737 if os
.path
.exists(VpdMapFilePath
):
1738 VpdFile
.Read(VpdMapFilePath
)
1741 for pcd
in VpdSkuMap
:
1742 vpdinfo
= VpdFile
.GetVpdInfo(pcd
)
1744 # just pick the a value to determine whether is unicode string type
1746 for pcdvalue
in VpdSkuMap
[pcd
]:
1747 for sku
in VpdSkuMap
[pcd
][pcdvalue
]:
1748 for item
in vpdinfo
:
1749 if item
[2] == pcdvalue
:
1750 sku
.VpdOffset
= item
[1]
1752 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1754 # Delete the DynamicPcdList At the last time enter into this function
1755 for Pcd
in self
._DynamicPcdList
:
1756 # just pick the a value to determine whether is unicode string type
1757 Sku
= Pcd
.SkuInfoList
.values()[0]
1758 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1760 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
1761 Pcd
.DatumType
= TAB_VOID
1763 PcdValue
= Sku
.DefaultValue
1764 if Pcd
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
1765 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1766 UnicodePcdArray
.add(Pcd
)
1767 elif len(Sku
.VariableName
) > 0:
1768 # if found HII type PCD then insert to right of UnicodeIndex
1769 HiiPcdArray
.add(Pcd
)
1771 OtherPcdArray
.add(Pcd
)
1772 del self
._DynamicPcdList
[:]
1773 self
._DynamicPcdList
.extend(list(UnicodePcdArray
))
1774 self
._DynamicPcdList
.extend(list(HiiPcdArray
))
1775 self
._DynamicPcdList
.extend(list(OtherPcdArray
))
1776 allskuset
= [(SkuName
,Sku
.SkuId
) for pcd
in self
._DynamicPcdList
for (SkuName
,Sku
) in pcd
.SkuInfoList
.items()]
1777 for pcd
in self
._DynamicPcdList
:
1778 if len(pcd
.SkuInfoList
) == 1:
1779 for (SkuName
,SkuId
) in allskuset
:
1780 if type(SkuId
) in (str,unicode) and eval(SkuId
) == 0 or SkuId
== 0:
1782 pcd
.SkuInfoList
[SkuName
] = copy
.deepcopy(pcd
.SkuInfoList
[TAB_DEFAULT
])
1783 pcd
.SkuInfoList
[SkuName
].SkuId
= SkuId
1784 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1786 def FixVpdOffset(self
,VpdFile
):
1787 FvPath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
1788 if not os
.path
.exists(FvPath
):
1792 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1794 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1796 if VpdFile
.Write(VpdFilePath
):
1797 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1799 for ToolDef
in self
.ToolDefinition
.values():
1800 if ToolDef
.has_key(TAB_GUID
) and ToolDef
[TAB_GUID
] == self
.Platform
.VpdToolGuid
:
1801 if not ToolDef
.has_key("PATH"):
1802 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1803 BPDGToolName
= ToolDef
["PATH"]
1805 # Call third party GUID BPDG tool.
1806 if BPDGToolName
is not None:
1807 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1809 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.")
1811 ## Return the platform build data object
1812 def _GetPlatform(self
):
1813 if self
._Platform
is None:
1814 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1815 return self
._Platform
1817 ## Return platform name
1819 return self
.Platform
.PlatformName
1821 ## Return the meta file GUID
1823 return self
.Platform
.Guid
1825 ## Return the platform version
1826 def _GetVersion(self
):
1827 return self
.Platform
.Version
1829 ## Return the FDF file name
1830 def _GetFdfFile(self
):
1831 if self
._FdfFile
is None:
1832 if self
.Workspace
.FdfFile
!= "":
1833 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1836 return self
._FdfFile
1838 ## Return the build output directory platform specifies
1839 def _GetOutputDir(self
):
1840 return self
.Platform
.OutputDirectory
1842 ## Return the directory to store all intermediate and final files built
1843 def _GetBuildDir(self
):
1844 if self
._BuildDir
is None:
1845 if os
.path
.isabs(self
.OutputDir
):
1846 self
._BuildDir
= path
.join(
1847 path
.abspath(self
.OutputDir
),
1848 self
.BuildTarget
+ "_" + self
.ToolChain
,
1851 self
._BuildDir
= path
.join(
1854 self
.BuildTarget
+ "_" + self
.ToolChain
,
1856 GlobalData
.gBuildDirectory
= self
._BuildDir
1857 return self
._BuildDir
1859 ## Return directory of platform makefile
1861 # @retval string Makefile directory
1863 def _GetMakeFileDir(self
):
1864 if self
._MakeFileDir
is None:
1865 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1866 return self
._MakeFileDir
1868 ## Return build command string
1870 # @retval string Build command string
1872 def _GetBuildCommand(self
):
1873 if self
._BuildCommand
is None:
1874 self
._BuildCommand
= []
1875 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1876 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1877 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1878 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1880 self
._BuildCommand
+= SplitOption(NewOption
)
1881 if "MAKE" in self
.EdkIIBuildOption
:
1882 if "FLAGS" in self
.EdkIIBuildOption
["MAKE"]:
1883 Flags
= self
.EdkIIBuildOption
["MAKE"]["FLAGS"]
1884 if Flags
.startswith('='):
1885 self
._BuildCommand
= [self
._BuildCommand
[0]] + [Flags
[1:]]
1887 self
._BuildCommand
.append(Flags
)
1888 return self
._BuildCommand
1890 ## Get tool chain definition
1892 # Get each tool defition for given tool chain from tools_def.txt and platform
1894 def _GetToolDefinition(self
):
1895 if self
._ToolDefinitions
is None:
1896 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1897 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1898 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1899 ExtraData
="[%s]" % self
.MetaFile
)
1900 self
._ToolDefinitions
= {}
1902 for Def
in ToolDefinition
:
1903 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1904 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1907 Value
= ToolDefinition
[Def
]
1908 # don't record the DLL
1910 DllPathList
.add(Value
)
1913 if Tool
not in self
._ToolDefinitions
:
1914 self
._ToolDefinitions
[Tool
] = {}
1915 self
._ToolDefinitions
[Tool
][Attr
] = Value
1918 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1919 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1920 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1921 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1923 for Tool
in self
._ToolDefinitions
:
1924 for Attr
in self
._ToolDefinitions
[Tool
]:
1925 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1926 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1927 # check if override is indicated
1928 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1929 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1932 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1934 Value
= self
.BuildOption
[Tool
][Attr
]
1937 # Don't put MAKE definition in the file
1939 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1941 # Don't put MAKE definition in the file
1946 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1949 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1950 for DllPath
in DllPathList
:
1951 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1952 os
.environ
["MAKE_FLAGS"] = MakeFlags
1954 return self
._ToolDefinitions
1956 ## Return the paths of tools
1957 def _GetToolDefFile(self
):
1958 if self
._ToolDefFile
is None:
1959 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1960 return self
._ToolDefFile
1962 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1963 def _GetToolChainFamily(self
):
1964 if self
._ToolChainFamily
is None:
1965 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1966 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1967 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1968 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1969 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1971 self
._ToolChainFamily
= "MSFT"
1973 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1974 return self
._ToolChainFamily
1976 def _GetBuildRuleFamily(self
):
1977 if self
._BuildRuleFamily
is None:
1978 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1979 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1980 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1981 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1982 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1984 self
._BuildRuleFamily
= "MSFT"
1986 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1987 return self
._BuildRuleFamily
1989 ## Return the build options specific for all modules in this platform
1990 def _GetBuildOptions(self
):
1991 if self
._BuildOption
is None:
1992 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1993 return self
._BuildOption
1995 ## Return the build options specific for EDK modules in this platform
1996 def _GetEdkBuildOptions(self
):
1997 if self
._EdkBuildOption
is None:
1998 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1999 return self
._EdkBuildOption
2001 ## Return the build options specific for EDKII modules in this platform
2002 def _GetEdkIIBuildOptions(self
):
2003 if self
._EdkIIBuildOption
is None:
2004 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
2005 return self
._EdkIIBuildOption
2007 ## Parse build_rule.txt in Conf Directory.
2009 # @retval BuildRule object
2011 def _GetBuildRule(self
):
2012 if self
._BuildRule
is None:
2013 BuildRuleFile
= None
2014 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
2015 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
2016 if not BuildRuleFile
:
2017 BuildRuleFile
= gDefaultBuildRuleFile
2018 self
._BuildRule
= BuildRule(BuildRuleFile
)
2019 if self
._BuildRule
._FileVersion
== "":
2020 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
2022 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
2023 # If Build Rule's version is less than the version number required by the tools, halting the build.
2024 EdkLogger
.error("build", AUTOGEN_ERROR
,
2025 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])"\
2026 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
2028 return self
._BuildRule
2030 ## Summarize the packages used by modules in this platform
2031 def _GetPackageList(self
):
2032 if self
._PackageList
is None:
2033 self
._PackageList
= set()
2034 for La
in self
.LibraryAutoGenList
:
2035 self
._PackageList
.update(La
.DependentPackageList
)
2036 for Ma
in self
.ModuleAutoGenList
:
2037 self
._PackageList
.update(Ma
.DependentPackageList
)
2038 #Collect package set information from INF of FDF
2040 for ModuleFile
in self
._AsBuildModuleList
:
2041 if ModuleFile
in self
.Platform
.Modules
:
2043 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2044 PkgSet
.update(ModuleData
.Packages
)
2045 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
2046 return self
._PackageList
2048 def _GetNonDynamicPcdDict(self
):
2049 if self
._NonDynamicPcdDict
:
2050 return self
._NonDynamicPcdDict
2051 for Pcd
in self
.NonDynamicPcdList
:
2052 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
2053 return self
._NonDynamicPcdDict
2055 ## Get list of non-dynamic PCDs
2056 def _GetNonDynamicPcdList(self
):
2057 if self
._NonDynamicPcdList
is None:
2058 self
.CollectPlatformDynamicPcds()
2059 return self
._NonDynamicPcdList
2061 ## Get list of dynamic PCDs
2062 def _GetDynamicPcdList(self
):
2063 if self
._DynamicPcdList
is None:
2064 self
.CollectPlatformDynamicPcds()
2065 return self
._DynamicPcdList
2067 ## Generate Token Number for all PCD
2068 def _GetPcdTokenNumbers(self
):
2069 if self
._PcdTokenNumber
is None:
2070 self
._PcdTokenNumber
= OrderedDict()
2073 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
2077 # TokenNumber 0 ~ 10
2079 # TokeNumber 11 ~ 20
2081 for Pcd
in self
.DynamicPcdList
:
2082 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
2083 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2084 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2087 for Pcd
in self
.DynamicPcdList
:
2088 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2089 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2090 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2093 for Pcd
in self
.DynamicPcdList
:
2094 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
2095 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2096 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2099 for Pcd
in self
.DynamicPcdList
:
2100 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
2101 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
2102 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2105 for Pcd
in self
.NonDynamicPcdList
:
2106 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2108 return self
._PcdTokenNumber
2110 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
2111 def _GetAutoGenObjectList(self
):
2112 self
._ModuleAutoGenList
= []
2113 self
._LibraryAutoGenList
= []
2114 for ModuleFile
in self
.Platform
.Modules
:
2123 if Ma
not in self
._ModuleAutoGenList
:
2124 self
._ModuleAutoGenList
.append(Ma
)
2125 for La
in Ma
.LibraryAutoGenList
:
2126 if La
not in self
._LibraryAutoGenList
:
2127 self
._LibraryAutoGenList
.append(La
)
2128 if Ma
not in La
._ReferenceModules
:
2129 La
._ReferenceModules
.append(Ma
)
2131 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
2132 def _GetModuleAutoGenList(self
):
2133 if self
._ModuleAutoGenList
is None:
2134 self
._GetAutoGenObjectList
()
2135 return self
._ModuleAutoGenList
2137 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
2138 def _GetLibraryAutoGenList(self
):
2139 if self
._LibraryAutoGenList
is None:
2140 self
._GetAutoGenObjectList
()
2141 return self
._LibraryAutoGenList
2143 ## Test if a module is supported by the platform
2145 # An error will be raised directly if the module or its arch is not supported
2146 # by the platform or current configuration
2148 def ValidModule(self
, Module
):
2149 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
2150 or Module
in self
._AsBuildModuleList
2152 ## Resolve the library classes in a module to library instances
2154 # This method will not only resolve library classes but also sort the library
2155 # instances according to the dependency-ship.
2157 # @param Module The module from which the library classes will be resolved
2159 # @retval library_list List of library instances sorted
2161 def ApplyLibraryInstance(self
, Module
):
2162 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
2163 if str(Module
) not in self
.Platform
.Modules
:
2166 return GetModuleLibInstances(Module
,
2175 ## Override PCD setting (type, value, ...)
2177 # @param ToPcd The PCD to be overrided
2178 # @param FromPcd The PCD overrideing from
2180 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
="", Msg
="", Library
=""):
2182 # in case there's PCDs coming from FDF file, which have no type given.
2183 # at this point, ToPcd.Type has the type found from dependent
2186 TokenCName
= ToPcd
.TokenCName
2187 for PcdItem
in GlobalData
.MixedPcd
:
2188 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2189 TokenCName
= PcdItem
[0]
2191 if FromPcd
is not None:
2192 if ToPcd
.Pending
and FromPcd
.Type
:
2193 ToPcd
.Type
= FromPcd
.Type
2194 elif ToPcd
.Type
and FromPcd
.Type\
2195 and ToPcd
.Type
!= FromPcd
.Type
and ToPcd
.Type
in FromPcd
.Type
:
2196 if ToPcd
.Type
.strip() == TAB_PCDS_DYNAMIC_EX
:
2197 ToPcd
.Type
= FromPcd
.Type
2198 elif ToPcd
.Type
and FromPcd
.Type \
2199 and ToPcd
.Type
!= FromPcd
.Type
:
2201 Module
= str(Module
) + " 's library file (" + str(Library
) + ")"
2202 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2203 ExtraData
="%s.%s is used as [%s] in module %s, but as [%s] in %s."\
2204 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2205 ToPcd
.Type
, Module
, FromPcd
.Type
, Msg
),
2208 if FromPcd
.MaxDatumSize
:
2209 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2210 ToPcd
.MaxSizeUserSet
= FromPcd
.MaxDatumSize
2211 if FromPcd
.DefaultValue
:
2212 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2213 if FromPcd
.TokenValue
:
2214 ToPcd
.TokenValue
= FromPcd
.TokenValue
2215 if FromPcd
.DatumType
:
2216 ToPcd
.DatumType
= FromPcd
.DatumType
2217 if FromPcd
.SkuInfoList
:
2218 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2219 # Add Flexible PCD format parse
2220 if ToPcd
.DefaultValue
:
2222 ToPcd
.DefaultValue
= ValueExpressionEx(ToPcd
.DefaultValue
, ToPcd
.DatumType
, self
._GuidDict
)(True)
2223 except BadExpression
, Value
:
2224 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %(ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
, ToPcd
.DefaultValue
, Value
),
2227 # check the validation of datum
2228 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2230 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2231 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2232 ToPcd
.validateranges
= FromPcd
.validateranges
2233 ToPcd
.validlists
= FromPcd
.validlists
2234 ToPcd
.expressions
= FromPcd
.expressions
2236 if FromPcd
is not None and ToPcd
.DatumType
== TAB_VOID
and not ToPcd
.MaxDatumSize
:
2237 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2238 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2239 Value
= ToPcd
.DefaultValue
2241 ToPcd
.MaxDatumSize
= '1'
2242 elif Value
[0] == 'L':
2243 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2244 elif Value
[0] == '{':
2245 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2247 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2249 # apply default SKU for dynamic PCDS if specified one is not available
2250 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_SET
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
) \
2251 and not ToPcd
.SkuInfoList
:
2252 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2253 SkuName
= self
.Platform
.SkuName
2255 SkuName
= TAB_DEFAULT
2256 ToPcd
.SkuInfoList
= {
2257 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
][0], '', '', '', '', '', ToPcd
.DefaultValue
)
2260 ## Apply PCD setting defined platform to a module
2262 # @param Module The module from which the PCD setting will be overrided
2264 # @retval PCD_list The list PCDs with settings from platform
2266 def ApplyPcdSetting(self
, Module
, Pcds
, Library
=""):
2267 # for each PCD in module
2268 for Name
, Guid
in Pcds
:
2269 PcdInModule
= Pcds
[Name
, Guid
]
2270 # find out the PCD setting in platform
2271 if (Name
, Guid
) in self
.Platform
.Pcds
:
2272 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2274 PcdInPlatform
= None
2275 # then override the settings if any
2276 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
, Msg
="DSC PCD sections", Library
=Library
)
2277 # resolve the VariableGuid value
2278 for SkuId
in PcdInModule
.SkuInfoList
:
2279 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2280 if Sku
.VariableGuid
== '': continue
2281 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
2282 if Sku
.VariableGuidValue
is None:
2283 PackageList
= "\n\t".join(str(P
) for P
in self
.PackageList
)
2286 RESOURCE_NOT_AVAILABLE
,
2287 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2288 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2289 % (Guid
, Name
, str(Module
)),
2293 # override PCD settings with module specific setting
2294 if Module
in self
.Platform
.Modules
:
2295 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2296 for Key
in PlatformModule
.Pcds
:
2301 elif Key
in GlobalData
.MixedPcd
:
2302 for PcdItem
in GlobalData
.MixedPcd
[Key
]:
2304 ToPcd
= Pcds
[PcdItem
]
2308 self
._OverridePcd
(ToPcd
, PlatformModule
.Pcds
[Key
], Module
, Msg
="DSC Components Module scoped PCD section", Library
=Library
)
2309 # use PCD value to calculate the MaxDatumSize when it is not specified
2310 for Name
, Guid
in Pcds
:
2311 Pcd
= Pcds
[Name
, Guid
]
2312 if Pcd
.DatumType
== TAB_VOID
and not Pcd
.MaxDatumSize
:
2313 Pcd
.MaxSizeUserSet
= None
2314 Value
= Pcd
.DefaultValue
2316 Pcd
.MaxDatumSize
= '1'
2317 elif Value
[0] == 'L':
2318 Pcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2319 elif Value
[0] == '{':
2320 Pcd
.MaxDatumSize
= str(len(Value
.split(',')))
2322 Pcd
.MaxDatumSize
= str(len(Value
) - 1)
2323 return Pcds
.values()
2325 ## Resolve library names to library modules
2327 # (for Edk.x modules)
2329 # @param Module The module from which the library names will be resolved
2331 # @retval library_list The list of library modules
2333 def ResolveLibraryReference(self
, Module
):
2334 EdkLogger
.verbose("")
2335 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2336 LibraryConsumerList
= [Module
]
2338 # "CompilerStub" is a must for Edk modules
2339 if Module
.Libraries
:
2340 Module
.Libraries
.append("CompilerStub")
2342 while len(LibraryConsumerList
) > 0:
2343 M
= LibraryConsumerList
.pop()
2344 for LibraryName
in M
.Libraries
:
2345 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2347 for Key
in self
.Platform
.LibraryClasses
.data
:
2348 if LibraryName
.upper() == Key
.upper():
2349 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2352 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2353 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2356 if Library
not in LibraryList
:
2357 LibraryList
.append(Library
)
2358 LibraryConsumerList
.append(Library
)
2359 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2362 ## Calculate the priority value of the build option
2364 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2366 # @retval Value Priority value based on the priority list.
2368 def CalculatePriorityValue(self
, Key
):
2369 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2370 PriorityValue
= 0x11111
2372 PriorityValue
&= 0x01111
2373 if ToolChain
== "*":
2374 PriorityValue
&= 0x10111
2376 PriorityValue
&= 0x11011
2377 if CommandType
== "*":
2378 PriorityValue
&= 0x11101
2380 PriorityValue
&= 0x11110
2382 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2385 ## Expand * in build option key
2387 # @param Options Options to be expanded
2389 # @retval options Options expanded
2391 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2398 # Construct a list contain the build options which need override.
2402 # Key[0] -- tool family
2403 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2405 if (Key
[0] == self
.BuildRuleFamily
and
2406 (ModuleStyle
is None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2407 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2408 if (Target
== self
.BuildTarget
or Target
== "*") and\
2409 (ToolChain
== self
.ToolChain
or ToolChain
== "*") and\
2410 (Arch
== self
.Arch
or Arch
== "*") and\
2411 Options
[Key
].startswith("="):
2413 if OverrideList
.get(Key
[1]) is not None:
2414 OverrideList
.pop(Key
[1])
2415 OverrideList
[Key
[1]] = Options
[Key
]
2418 # Use the highest priority value.
2420 if (len(OverrideList
) >= 2):
2421 KeyList
= OverrideList
.keys()
2422 for Index
in range(len(KeyList
)):
2423 NowKey
= KeyList
[Index
]
2424 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2425 for Index1
in range(len(KeyList
) - Index
- 1):
2426 NextKey
= KeyList
[Index1
+ Index
+ 1]
2428 # Compare two Key, if one is included by another, choose the higher priority one
2430 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2431 if (Target1
== Target2
or Target1
== "*" or Target2
== "*") and\
2432 (ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*") and\
2433 (Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*") and\
2434 (CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*") and\
2435 (Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*"):
2437 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2438 if Options
.get((self
.BuildRuleFamily
, NextKey
)) is not None:
2439 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2441 if Options
.get((self
.BuildRuleFamily
, NowKey
)) is not None:
2442 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2445 if ModuleStyle
is not None and len (Key
) > 2:
2446 # Check Module style is EDK or EDKII.
2447 # Only append build option for the matched style module.
2448 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2450 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2453 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2454 # if tool chain family doesn't match, skip it
2455 if Tool
in self
.ToolDefinition
and Family
!= "":
2456 FamilyIsNull
= False
2457 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2458 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2460 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2463 # expand any wildcard
2464 if Target
== "*" or Target
== self
.BuildTarget
:
2465 if Tag
== "*" or Tag
== self
.ToolChain
:
2466 if Arch
== "*" or Arch
== self
.Arch
:
2467 if Tool
not in BuildOptions
:
2468 BuildOptions
[Tool
] = {}
2469 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2470 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2472 # append options for the same tool except PATH
2474 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2476 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2477 # Build Option Family has been checked, which need't to be checked again for family.
2478 if FamilyMatch
or FamilyIsNull
:
2482 if ModuleStyle
is not None and len (Key
) > 2:
2483 # Check Module style is EDK or EDKII.
2484 # Only append build option for the matched style module.
2485 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2487 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2490 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2491 # if tool chain family doesn't match, skip it
2492 if Tool
not in self
.ToolDefinition
or Family
== "":
2494 # option has been added before
2495 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2498 # expand any wildcard
2499 if Target
== "*" or Target
== self
.BuildTarget
:
2500 if Tag
== "*" or Tag
== self
.ToolChain
:
2501 if Arch
== "*" or Arch
== self
.Arch
:
2502 if Tool
not in BuildOptions
:
2503 BuildOptions
[Tool
] = {}
2504 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2505 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2507 # append options for the same tool except PATH
2509 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2511 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2514 ## Append build options in platform to a module
2516 # @param Module The module to which the build options will be appened
2518 # @retval options The options appended with build options in platform
2520 def ApplyBuildOption(self
, Module
):
2521 # Get the different options for the different style module
2522 if Module
.AutoGenVersion
< 0x00010005:
2523 PlatformOptions
= self
.EdkBuildOption
2524 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2526 PlatformOptions
= self
.EdkIIBuildOption
2527 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2528 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2529 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2530 if Module
in self
.Platform
.Modules
:
2531 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2532 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2534 PlatformModuleOptions
= {}
2536 BuildRuleOrder
= None
2537 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2538 for Tool
in Options
:
2539 for Attr
in Options
[Tool
]:
2540 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2541 BuildRuleOrder
= Options
[Tool
][Attr
]
2543 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2544 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2545 self
.ToolDefinition
.keys())
2546 BuildOptions
= defaultdict(lambda: defaultdict(str))
2547 for Tool
in AllTools
:
2548 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2549 if Tool
not in Options
:
2551 for Attr
in Options
[Tool
]:
2553 # Do not generate it in Makefile
2555 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2557 Value
= Options
[Tool
][Attr
]
2558 # check if override is indicated
2559 if Value
.startswith('='):
2560 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
[1:])
2563 BuildOptions
[Tool
][Attr
] += " " + mws
.handleWsMacro(Value
)
2565 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
)
2567 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
is not None:
2569 # Override UNI flag only for EDK module.
2571 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2572 return BuildOptions
, BuildRuleOrder
2574 Platform
= property(_GetPlatform
)
2575 Name
= property(_GetName
)
2576 Guid
= property(_GetGuid
)
2577 Version
= property(_GetVersion
)
2579 OutputDir
= property(_GetOutputDir
)
2580 BuildDir
= property(_GetBuildDir
)
2581 MakeFileDir
= property(_GetMakeFileDir
)
2582 FdfFile
= property(_GetFdfFile
)
2584 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2585 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2586 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2587 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2588 PackageList
= property(_GetPackageList
)
2590 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2591 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2592 ToolChainFamily
= property(_GetToolChainFamily
)
2593 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2594 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2595 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2596 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2598 BuildCommand
= property(_GetBuildCommand
)
2599 BuildRule
= property(_GetBuildRule
)
2600 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2601 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2602 GenFdsCommand
= property(_GenFdsCommand
)
2605 # extend lists contained in a dictionary with lists stored in another dictionary
2606 # if CopyToDict is not derived from DefaultDict(list) then this may raise exception
2608 def ExtendCopyDictionaryLists(CopyToDict
, CopyFromDict
):
2609 for Key
in CopyFromDict
:
2610 CopyToDict
[Key
].extend(CopyFromDict
[Key
])
2613 ## ModuleAutoGen class
2615 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2616 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2617 # to the [depex] section in module's inf file.
2619 class ModuleAutoGen(AutoGen
):
2620 # call super().__init__ then call the worker function with different parameter count
2621 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2625 super(ModuleAutoGen
, self
).__init
__(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2626 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
)
2629 ## Cache the timestamps of metafiles of every module in a class variable
2633 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
2634 obj
= super(ModuleAutoGen
, cls
).__new
__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
)
2635 # check if this module is employed by active platform
2636 if not PlatformAutoGen(Workspace
, args
[0], Target
, Toolchain
, Arch
).ValidModule(MetaFile
):
2637 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2642 ## Initialize ModuleAutoGen
2644 # @param Workspace EdkIIWorkspaceBuild object
2645 # @param ModuleFile The path of module file
2646 # @param Target Build target (DEBUG, RELEASE)
2647 # @param Toolchain Name of tool chain
2648 # @param Arch The arch the module supports
2649 # @param PlatformFile Platform meta-file
2651 def _InitWorker(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2652 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2653 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2655 self
.Workspace
= Workspace
2656 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2657 self
._GuidDict
= Workspace
._GuidDict
2658 self
.MetaFile
= ModuleFile
2659 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2661 self
.SourceDir
= self
.MetaFile
.SubDir
2662 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2664 self
.SourceOverrideDir
= None
2665 # use overrided path defined in DSC file
2666 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2667 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2669 self
.ToolChain
= Toolchain
2670 self
.BuildTarget
= Target
2672 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2673 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2675 self
.IsMakeFileCreated
= False
2676 self
.IsCodeFileCreated
= False
2677 self
.IsAsBuiltInfCreated
= False
2678 self
.DepexGenerated
= False
2680 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2681 self
.BuildRuleOrder
= None
2687 self
._Version
= None
2688 self
._ModuleType
= None
2689 self
._ComponentType
= None
2690 self
._PcdIsDriver
= None
2691 self
._AutoGenVersion
= None
2692 self
._LibraryFlag
= None
2693 self
._CustomMakefile
= None
2696 self
._BuildDir
= None
2697 self
._OutputDir
= None
2698 self
._FfsOutputDir
= None
2699 self
._DebugDir
= None
2700 self
._MakeFileDir
= None
2702 self
._IncludePathList
= None
2703 self
._AutoGenFileList
= None
2704 self
._UnicodeFileList
= None
2705 self
._VfrFileList
= None
2706 self
._IdfFileList
= None
2707 self
._SourceFileList
= None
2708 self
._ObjectFileList
= None
2709 self
._BinaryFileList
= None
2711 self
._DependentPackageList
= None
2712 self
._DependentLibraryList
= None
2713 self
._LibraryAutoGenList
= None
2714 self
._DerivedPackageList
= None
2715 self
._ModulePcdList
= None
2716 self
._LibraryPcdList
= None
2717 self
._PcdComments
= OrderedListDict()
2718 self
._GuidList
= None
2719 self
._GuidsUsedByPcd
= None
2720 self
._GuidComments
= OrderedListDict()
2721 self
._ProtocolList
= None
2722 self
._ProtocolComments
= OrderedListDict()
2723 self
._PpiList
= None
2724 self
._PpiComments
= OrderedListDict()
2725 self
._DepexDict
= None
2726 self
._DepexExpressionDict
= None
2727 self
._BuildOption
= None
2728 self
._BuildOptionIncPathList
= None
2729 self
._BuildTargets
= None
2730 self
._IntroBuildTargetList
= None
2731 self
._FinalBuildTargetList
= None
2732 self
._FileTypes
= None
2733 self
._BuildRules
= None
2735 self
._TimeStampPath
= None
2737 self
.AutoGenDepSet
= set()
2740 ## The Modules referenced to this Library
2741 # Only Library has this attribute
2742 self
._ReferenceModules
= []
2744 ## Store the FixedAtBuild Pcds
2746 self
._FixedAtBuildPcds
= []
2750 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2752 # Get FixedAtBuild Pcds of this Module
2753 def _GetFixedAtBuildPcds(self
):
2754 if self
._FixedAtBuildPcds
:
2755 return self
._FixedAtBuildPcds
2756 for Pcd
in self
.ModulePcdList
:
2757 if Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
2759 if Pcd
not in self
._FixedAtBuildPcds
:
2760 self
._FixedAtBuildPcds
.append(Pcd
)
2762 return self
._FixedAtBuildPcds
2764 def _GetUniqueBaseName(self
):
2765 BaseName
= self
.Name
2766 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2767 if Module
.MetaFile
== self
.MetaFile
:
2769 if Module
.Name
== self
.Name
:
2770 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2771 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2772 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2773 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2776 # Macros could be used in build_rule.txt (also Makefile)
2777 def _GetMacros(self
):
2778 if self
._Macro
is None:
2779 self
._Macro
= OrderedDict()
2780 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2781 self
._Macro
["MODULE_NAME" ] = self
.Name
2782 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2783 self
._Macro
["MODULE_GUID" ] = self
.Guid
2784 self
._Macro
["MODULE_VERSION" ] = self
.Version
2785 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2786 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2787 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2788 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2789 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2791 self
._Macro
["BASE_NAME" ] = self
.Name
2793 self
._Macro
["ARCH" ] = self
.Arch
2794 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2795 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2796 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2797 self
._Macro
["TARGET" ] = self
.BuildTarget
2799 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2800 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2801 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2802 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2803 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2804 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2805 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2806 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2807 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2808 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2809 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2810 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2811 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2812 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2813 self
._Macro
["FFS_OUTPUT_DIR" ] = self
.FfsOutputDir
2816 ## Return the module build data object
2817 def _GetModule(self
):
2818 if self
._Module
is None:
2819 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2822 ## Return the module name
2823 def _GetBaseName(self
):
2824 return self
.Module
.BaseName
2826 ## Return the module DxsFile if exist
2827 def _GetDxsFile(self
):
2828 return self
.Module
.DxsFile
2830 ## Return the module SourceOverridePath
2831 def _GetSourceOverridePath(self
):
2832 return self
.Module
.SourceOverridePath
2834 ## Return the module meta-file GUID
2837 # To build same module more than once, the module path with FILE_GUID overridden has
2838 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2839 # in DSC. The overridden GUID can be retrieved from file name
2841 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2843 # Length of GUID is 36
2845 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2846 return self
.Module
.Guid
2848 ## Return the module version
2849 def _GetVersion(self
):
2850 return self
.Module
.Version
2852 ## Return the module type
2853 def _GetModuleType(self
):
2854 return self
.Module
.ModuleType
2856 ## Return the component type (for Edk.x style of module)
2857 def _GetComponentType(self
):
2858 return self
.Module
.ComponentType
2860 ## Return the build type
2861 def _GetBuildType(self
):
2862 return self
.Module
.BuildType
2864 ## Return the PCD_IS_DRIVER setting
2865 def _GetPcdIsDriver(self
):
2866 return self
.Module
.PcdIsDriver
2868 ## Return the autogen version, i.e. module meta-file version
2869 def _GetAutoGenVersion(self
):
2870 return self
.Module
.AutoGenVersion
2872 ## Check if the module is library or not
2873 def _IsLibrary(self
):
2874 if self
._LibraryFlag
is None:
2875 self
._LibraryFlag
= True if self
.Module
.LibraryClass
else False
2876 return self
._LibraryFlag
2878 ## Check if the module is binary module or not
2879 def _IsBinaryModule(self
):
2880 return self
.Module
.IsBinaryModule
2882 ## Return the directory to store intermediate files of the module
2883 def _GetBuildDir(self
):
2884 if self
._BuildDir
is None:
2885 self
._BuildDir
= path
.join(
2886 self
.PlatformInfo
.BuildDir
,
2889 self
.MetaFile
.BaseName
2891 CreateDirectory(self
._BuildDir
)
2892 return self
._BuildDir
2894 ## Return the directory to store the intermediate object files of the mdoule
2895 def _GetOutputDir(self
):
2896 if self
._OutputDir
is None:
2897 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2898 CreateDirectory(self
._OutputDir
)
2899 return self
._OutputDir
2901 ## Return the directory to store ffs file
2902 def _GetFfsOutputDir(self
):
2903 if self
._FfsOutputDir
is None:
2904 if GlobalData
.gFdfParser
is not None:
2905 self
._FfsOutputDir
= path
.join(self
.PlatformInfo
.BuildDir
, TAB_FV_DIRECTORY
, "Ffs", self
.Guid
+ self
.Name
)
2907 self
._FfsOutputDir
= ''
2908 return self
._FfsOutputDir
2910 ## Return the directory to store auto-gened source files of the mdoule
2911 def _GetDebugDir(self
):
2912 if self
._DebugDir
is None:
2913 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2914 CreateDirectory(self
._DebugDir
)
2915 return self
._DebugDir
2917 ## Return the path of custom file
2918 def _GetCustomMakefile(self
):
2919 if self
._CustomMakefile
is None:
2920 self
._CustomMakefile
= {}
2921 for Type
in self
.Module
.CustomMakefile
:
2922 if Type
in gMakeTypeMap
:
2923 MakeType
= gMakeTypeMap
[Type
]
2926 if self
.SourceOverrideDir
is not None:
2927 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2928 if not os
.path
.exists(File
):
2929 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2931 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2932 self
._CustomMakefile
[MakeType
] = File
2933 return self
._CustomMakefile
2935 ## Return the directory of the makefile
2937 # @retval string The directory string of module's makefile
2939 def _GetMakeFileDir(self
):
2940 return self
.BuildDir
2942 ## Return build command string
2944 # @retval string Build command string
2946 def _GetBuildCommand(self
):
2947 return self
.PlatformInfo
.BuildCommand
2949 ## Get object list of all packages the module and its dependent libraries belong to
2951 # @retval list The list of package object
2953 def _GetDerivedPackageList(self
):
2955 for M
in [self
.Module
] + self
.DependentLibraryList
:
2956 for Package
in M
.Packages
:
2957 if Package
in PackageList
:
2959 PackageList
.append(Package
)
2962 ## Get the depex string
2964 # @return : a string contain all depex expresion.
2965 def _GetDepexExpresionString(self
):
2968 ## DPX_SOURCE IN Define section.
2969 if self
.Module
.DxsFile
:
2971 for M
in [self
.Module
] + self
.DependentLibraryList
:
2972 Filename
= M
.MetaFile
.Path
2973 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2974 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2975 for DepexExpresion
in DepexExpresionList
:
2976 for key
in DepexExpresion
:
2977 Arch
, ModuleType
= key
2978 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
2979 # the type of build module is USER_DEFINED.
2980 # All different DEPEX section tags would be copied into the As Built INF file
2981 # and there would be separate DEPEX section tags
2982 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2983 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2984 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2986 if Arch
.upper() == TAB_ARCH_COMMON
or \
2987 (Arch
.upper() == self
.Arch
.upper() and \
2988 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2989 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2991 #the type of build module is USER_DEFINED.
2992 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2993 for Depex
in DepexList
:
2995 DepexStr
+= '[Depex.%s.%s]\n' % key
2996 DepexStr
+= '\n'.join('# '+ val
for val
in Depex
[key
])
2999 return '[Depex.%s]\n' % self
.Arch
3002 #the type of build module not is USER_DEFINED.
3004 for Depex
in DepexList
:
3009 for D
in Depex
.values():
3010 DepexStr
+= ' '.join(val
for val
in D
)
3011 Index
= DepexStr
.find('END')
3012 if Index
> -1 and Index
== len(DepexStr
) - 3:
3013 DepexStr
= DepexStr
[:-3]
3014 DepexStr
= DepexStr
.strip()
3017 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
3019 return '[Depex.%s]\n' % self
.Arch
3020 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
3022 ## Merge dependency expression
3024 # @retval list The token list of the dependency expression after parsed
3026 def _GetDepexTokenList(self
):
3027 if self
._DepexDict
is None:
3028 self
._DepexDict
= {}
3029 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3030 return self
._DepexDict
3032 self
._DepexDict
[self
.ModuleType
] = []
3034 for ModuleType
in self
._DepexDict
:
3035 DepexList
= self
._DepexDict
[ModuleType
]
3037 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3039 for M
in [self
.Module
] + self
.DependentLibraryList
:
3041 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
3043 DepexList
.append('AND')
3044 DepexList
.append('(')
3046 if DepexList
[-1] == 'END': # no need of a END at this time
3048 DepexList
.append(')')
3051 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
3052 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
3054 if len(DepexList
) > 0:
3055 EdkLogger
.verbose('')
3056 return self
._DepexDict
3058 ## Merge dependency expression
3060 # @retval list The token list of the dependency expression after parsed
3062 def _GetDepexExpressionTokenList(self
):
3063 if self
._DepexExpressionDict
is None:
3064 self
._DepexExpressionDict
= {}
3065 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3066 return self
._DepexExpressionDict
3068 self
._DepexExpressionDict
[self
.ModuleType
] = ''
3070 for ModuleType
in self
._DepexExpressionDict
:
3071 DepexExpressionString
= self
._DepexExpressionDict
[ModuleType
]
3073 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3075 for M
in [self
.Module
] + self
.DependentLibraryList
:
3077 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
3078 if DepexExpressionString
!= '':
3079 DepexExpressionString
+= ' AND '
3080 DepexExpressionString
+= '('
3081 DepexExpressionString
+= D
3082 DepexExpressionString
= DepexExpressionString
.rstrip('END').strip()
3083 DepexExpressionString
+= ')'
3086 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionString
))
3087 if 'BEFORE' in DepexExpressionString
or 'AFTER' in DepexExpressionString
:
3089 if len(DepexExpressionString
) > 0:
3090 EdkLogger
.verbose('')
3091 self
._DepexExpressionDict
[ModuleType
] = DepexExpressionString
3092 return self
._DepexExpressionDict
3094 # Get the tiano core user extension, it is contain dependent library.
3095 # @retval: a list contain tiano core userextension.
3097 def _GetTianoCoreUserExtensionList(self
):
3098 TianoCoreUserExtentionList
= []
3099 for M
in [self
.Module
] + self
.DependentLibraryList
:
3100 Filename
= M
.MetaFile
.Path
3101 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
3102 TianoCoreUserExtenList
= InfObj
.GetUserExtensionTianoCore()
3103 for TianoCoreUserExtent
in TianoCoreUserExtenList
:
3104 for Section
in TianoCoreUserExtent
:
3105 ItemList
= Section
.split(TAB_SPLIT
)
3107 if len(ItemList
) == 4:
3109 if Arch
.upper() == TAB_ARCH_COMMON
or Arch
.upper() == self
.Arch
.upper():
3111 TianoCoreList
.extend([TAB_SECTION_START
+ Section
+ TAB_SECTION_END
])
3112 TianoCoreList
.extend(TianoCoreUserExtent
[Section
][:])
3113 TianoCoreList
.append('\n')
3114 TianoCoreUserExtentionList
.append(TianoCoreList
)
3116 return TianoCoreUserExtentionList
3118 ## Return the list of specification version required for the module
3120 # @retval list The list of specification defined in module file
3122 def _GetSpecification(self
):
3123 return self
.Module
.Specification
3125 ## Tool option for the module build
3127 # @param PlatformInfo The object of PlatformBuildInfo
3128 # @retval dict The dict containing valid options
3130 def _GetModuleBuildOption(self
):
3131 if self
._BuildOption
is None:
3132 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
3133 if self
.BuildRuleOrder
:
3134 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
3135 return self
._BuildOption
3137 ## Get include path list from tool option for the module build
3139 # @retval list The include path list
3141 def _GetBuildOptionIncPathList(self
):
3142 if self
._BuildOptionIncPathList
is None:
3144 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3145 # is the former use /I , the Latter used -I to specify include directories
3147 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
3148 BuildOptIncludeRegEx
= gBuildOptIncludePatternMsft
3149 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
3150 BuildOptIncludeRegEx
= gBuildOptIncludePatternOther
3153 # New ToolChainFamily, don't known whether there is option to specify include directories
3155 self
._BuildOptionIncPathList
= []
3156 return self
._BuildOptionIncPathList
3158 BuildOptionIncPathList
= []
3159 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3161 FlagOption
= self
.BuildOption
[Tool
]['FLAGS']
3165 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
3166 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in BuildOptIncludeRegEx
.findall(FlagOption
)]
3169 # RVCT may specify a list of directory seperated by commas
3172 for Path
in BuildOptIncludeRegEx
.findall(FlagOption
):
3173 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3174 IncPathList
.extend(NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
)
3177 # EDK II modules must not reference header files outside of the packages they depend on or
3178 # within the module's directory tree. Report error if violation.
3180 if self
.AutoGenVersion
>= 0x00010005:
3181 for Path
in IncPathList
:
3182 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3183 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3184 EdkLogger
.error("build",
3187 File
=str(self
.MetaFile
))
3190 BuildOptionIncPathList
+= IncPathList
3192 self
._BuildOptionIncPathList
= BuildOptionIncPathList
3194 return self
._BuildOptionIncPathList
3196 ## Return a list of files which can be built from source
3198 # What kind of files can be built is determined by build rules in
3199 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3201 def _GetSourceFileList(self
):
3202 if self
._SourceFileList
is None:
3203 self
._SourceFileList
= []
3204 for F
in self
.Module
.Sources
:
3206 if F
.TagName
not in ("", "*", self
.ToolChain
):
3207 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3208 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
3210 # match tool chain family or build rule family
3211 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
, self
.BuildRuleFamily
):
3214 "The file [%s] must be built by tools of [%s], " \
3215 "but current toolchain family is [%s], buildrule family is [%s]" \
3216 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
, self
.BuildRuleFamily
))
3219 # add the file path into search path list for file including
3220 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3221 self
.IncludePathList
.insert(0, F
.Dir
)
3222 self
._SourceFileList
.append(F
)
3224 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
3226 for F
in self
._SourceFileList
:
3227 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3228 return self
._SourceFileList
3230 def _MatchBuildRuleOrder(self
, FileList
):
3232 self
._GetModuleBuildOption
()
3233 for SingleFile
in FileList
:
3234 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3235 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3236 if key
in Order_Dict
:
3237 Order_Dict
[key
].append(SingleFile
.Ext
)
3239 Order_Dict
[key
] = [SingleFile
.Ext
]
3242 for F
in Order_Dict
:
3243 if len(Order_Dict
[F
]) > 1:
3244 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3245 for Ext
in Order_Dict
[F
][1:]:
3246 RemoveList
.append(F
+ Ext
)
3248 for item
in RemoveList
:
3249 FileList
.remove(item
)
3253 ## Return the list of unicode files
3254 def _GetUnicodeFileList(self
):
3255 if self
._UnicodeFileList
is None:
3256 if TAB_UNICODE_FILE
in self
.FileTypes
:
3257 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
3259 self
._UnicodeFileList
= []
3260 return self
._UnicodeFileList
3262 ## Return the list of vfr files
3263 def _GetVfrFileList(self
):
3264 if self
._VfrFileList
is None:
3265 if TAB_VFR_FILE
in self
.FileTypes
:
3266 self
._VfrFileList
= self
.FileTypes
[TAB_VFR_FILE
]
3268 self
._VfrFileList
= []
3269 return self
._VfrFileList
3271 ## Return the list of Image Definition files
3272 def _GetIdfFileList(self
):
3273 if self
._IdfFileList
is None:
3274 if TAB_IMAGE_FILE
in self
.FileTypes
:
3275 self
._IdfFileList
= self
.FileTypes
[TAB_IMAGE_FILE
]
3277 self
._IdfFileList
= []
3278 return self
._IdfFileList
3280 ## Return a list of files which can be built from binary
3282 # "Build" binary files are just to copy them to build directory.
3284 # @retval list The list of files which can be built later
3286 def _GetBinaryFiles(self
):
3287 if self
._BinaryFileList
is None:
3288 self
._BinaryFileList
= []
3289 for F
in self
.Module
.Binaries
:
3290 if F
.Target
not in [TAB_ARCH_COMMON
, '*'] and F
.Target
!= self
.BuildTarget
:
3292 self
._BinaryFileList
.append(F
)
3293 self
._ApplyBuildRule
(F
, F
.Type
)
3294 return self
._BinaryFileList
3296 def _GetBuildRules(self
):
3297 if self
._BuildRules
is None:
3299 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3300 for Type
in BuildRuleDatabase
.FileTypeList
:
3301 #first try getting build rule by BuildRuleFamily
3302 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3304 # build type is always module type, but ...
3305 if self
.ModuleType
!= self
.BuildType
:
3306 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3307 #second try getting build rule by ToolChainFamily
3309 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3311 # build type is always module type, but ...
3312 if self
.ModuleType
!= self
.BuildType
:
3313 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3316 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3317 BuildRules
[Type
] = RuleObject
3318 for Ext
in RuleObject
.SourceFileExtList
:
3319 BuildRules
[Ext
] = RuleObject
3320 self
._BuildRules
= BuildRules
3321 return self
._BuildRules
3323 def _ApplyBuildRule(self
, File
, FileType
):
3324 if self
._BuildTargets
is None:
3325 self
._IntroBuildTargetList
= set()
3326 self
._FinalBuildTargetList
= set()
3327 self
._BuildTargets
= defaultdict(set)
3328 self
._FileTypes
= defaultdict(set)
3330 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3331 if not os
.path
.exists(SubDirectory
):
3332 CreateDirectory(SubDirectory
)
3338 # Make sure to get build rule order value
3340 self
._GetModuleBuildOption
()
3342 while Index
< len(SourceList
):
3343 Source
= SourceList
[Index
]
3347 CreateDirectory(Source
.Dir
)
3349 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
is not None and File
in self
._BinaryFileList
:
3350 # Skip all files that are not binary libraries
3351 if not self
.IsLibrary
:
3353 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3354 elif FileType
in self
.BuildRules
:
3355 RuleObject
= self
.BuildRules
[FileType
]
3356 elif Source
.Ext
in self
.BuildRules
:
3357 RuleObject
= self
.BuildRules
[Source
.Ext
]
3359 # stop at no more rules
3361 self
._FinalBuildTargetList
.add(LastTarget
)
3364 FileType
= RuleObject
.SourceFileType
3365 self
._FileTypes
[FileType
].add(Source
)
3367 # stop at STATIC_LIBRARY for library
3368 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3370 self
._FinalBuildTargetList
.add(LastTarget
)
3373 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3376 self
._FinalBuildTargetList
.add(LastTarget
)
3378 elif not Target
.Outputs
:
3379 # Only do build for target with outputs
3380 self
._FinalBuildTargetList
.add(Target
)
3382 self
._BuildTargets
[FileType
].add(Target
)
3384 if not Source
.IsBinary
and Source
== File
:
3385 self
._IntroBuildTargetList
.add(Target
)
3387 # to avoid cyclic rule
3388 if FileType
in RuleChain
:
3391 RuleChain
.add(FileType
)
3392 SourceList
.extend(Target
.Outputs
)
3394 FileType
= TAB_UNKNOWN_FILE
3396 def _GetTargets(self
):
3397 if self
._BuildTargets
is None:
3398 self
._IntroBuildTargetList
= set()
3399 self
._FinalBuildTargetList
= set()
3400 self
._BuildTargets
= defaultdict(set)
3401 self
._FileTypes
= defaultdict(set)
3403 #TRICK: call _GetSourceFileList to apply build rule for source files
3404 if self
.SourceFileList
:
3407 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3408 if self
.BinaryFileList
:
3411 return self
._BuildTargets
3413 def _GetIntroTargetList(self
):
3415 return self
._IntroBuildTargetList
3417 def _GetFinalTargetList(self
):
3419 return self
._FinalBuildTargetList
3421 def _GetFileTypes(self
):
3423 return self
._FileTypes
3425 ## Get the list of package object the module depends on
3427 # @retval list The package object list
3429 def _GetDependentPackageList(self
):
3430 return self
.Module
.Packages
3432 ## Return the list of auto-generated code file
3434 # @retval list The list of auto-generated file
3436 def _GetAutoGenFileList(self
):
3437 UniStringAutoGenC
= True
3438 IdfStringAutoGenC
= True
3439 UniStringBinBuffer
= StringIO()
3440 IdfGenBinBuffer
= StringIO()
3441 if self
.BuildType
== 'UEFI_HII':
3442 UniStringAutoGenC
= False
3443 IdfStringAutoGenC
= False
3444 if self
._AutoGenFileList
is None:
3445 self
._AutoGenFileList
= {}
3446 AutoGenC
= TemplateString()
3447 AutoGenH
= TemplateString()
3448 StringH
= TemplateString()
3449 StringIdf
= TemplateString()
3450 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
, StringIdf
, IdfStringAutoGenC
, IdfGenBinBuffer
)
3452 # AutoGen.c is generated if there are library classes in inf, or there are object files
3454 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3455 or TAB_OBJECT_FILE
in self
.FileTypes
):
3456 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3457 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3458 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3459 if str(AutoGenH
) != "":
3460 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3461 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3462 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3463 if str(StringH
) != "":
3464 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3465 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3466 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3467 if UniStringBinBuffer
is not None and UniStringBinBuffer
.getvalue() != "":
3468 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3469 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3470 AutoFile
.IsBinary
= True
3471 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3472 if UniStringBinBuffer
is not None:
3473 UniStringBinBuffer
.close()
3474 if str(StringIdf
) != "":
3475 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3476 self
._AutoGenFileList
[AutoFile
] = str(StringIdf
)
3477 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3478 if IdfGenBinBuffer
is not None and IdfGenBinBuffer
.getvalue() != "":
3479 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3480 self
._AutoGenFileList
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3481 AutoFile
.IsBinary
= True
3482 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3483 if IdfGenBinBuffer
is not None:
3484 IdfGenBinBuffer
.close()
3485 return self
._AutoGenFileList
3487 ## Return the list of library modules explicitly or implicityly used by this module
3488 def _GetLibraryList(self
):
3489 if self
._DependentLibraryList
is None:
3490 # only merge library classes and PCD for non-library module
3492 self
._DependentLibraryList
= []
3494 if self
.AutoGenVersion
< 0x00010005:
3495 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3497 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3498 return self
._DependentLibraryList
3500 ## Get the list of PCDs from current module
3502 # @retval list The list of PCD
3504 def _GetModulePcdList(self
):
3505 if self
._ModulePcdList
is None:
3506 # apply PCD settings from platform
3507 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3508 ExtendCopyDictionaryLists(self
._PcdComments
, self
.Module
.PcdComments
)
3509 return self
._ModulePcdList
3511 ## Get the list of PCDs from dependent libraries
3513 # @retval list The list of PCD
3515 def _GetLibraryPcdList(self
):
3516 if self
._LibraryPcdList
is None:
3517 Pcds
= OrderedDict()
3518 if not self
.IsLibrary
:
3519 # get PCDs from dependent libraries
3520 self
._LibraryPcdList
= []
3521 for Library
in self
.DependentLibraryList
:
3522 PcdsInLibrary
= OrderedDict()
3523 ExtendCopyDictionaryLists(self
._PcdComments
, Library
.PcdComments
)
3524 for Key
in Library
.Pcds
:
3525 # skip duplicated PCDs
3526 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3528 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3529 PcdsInLibrary
[Key
] = Pcds
[Key
]
3530 self
._LibraryPcdList
.extend(self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, PcdsInLibrary
, Library
=Library
))
3532 self
._LibraryPcdList
= []
3533 return self
._LibraryPcdList
3535 ## Get the GUID value mapping
3537 # @retval dict The mapping between GUID cname and its value
3539 def _GetGuidList(self
):
3540 if self
._GuidList
is None:
3541 self
._GuidList
= OrderedDict()
3542 self
._GuidList
.update(self
.Module
.Guids
)
3543 for Library
in self
.DependentLibraryList
:
3544 self
._GuidList
.update(Library
.Guids
)
3545 ExtendCopyDictionaryLists(self
._GuidComments
, Library
.GuidComments
)
3546 ExtendCopyDictionaryLists(self
._GuidComments
, self
.Module
.GuidComments
)
3547 return self
._GuidList
3549 def GetGuidsUsedByPcd(self
):
3550 if self
._GuidsUsedByPcd
is None:
3551 self
._GuidsUsedByPcd
= OrderedDict()
3552 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3553 for Library
in self
.DependentLibraryList
:
3554 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3555 return self
._GuidsUsedByPcd
3556 ## Get the protocol value mapping
3558 # @retval dict The mapping between protocol cname and its value
3560 def _GetProtocolList(self
):
3561 if self
._ProtocolList
is None:
3562 self
._ProtocolList
= OrderedDict()
3563 self
._ProtocolList
.update(self
.Module
.Protocols
)
3564 for Library
in self
.DependentLibraryList
:
3565 self
._ProtocolList
.update(Library
.Protocols
)
3566 ExtendCopyDictionaryLists(self
._ProtocolComments
, Library
.ProtocolComments
)
3567 ExtendCopyDictionaryLists(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3568 return self
._ProtocolList
3570 ## Get the PPI value mapping
3572 # @retval dict The mapping between PPI cname and its value
3574 def _GetPpiList(self
):
3575 if self
._PpiList
is None:
3576 self
._PpiList
= OrderedDict()
3577 self
._PpiList
.update(self
.Module
.Ppis
)
3578 for Library
in self
.DependentLibraryList
:
3579 self
._PpiList
.update(Library
.Ppis
)
3580 ExtendCopyDictionaryLists(self
._PpiComments
, Library
.PpiComments
)
3581 ExtendCopyDictionaryLists(self
._PpiComments
, self
.Module
.PpiComments
)
3582 return self
._PpiList
3584 ## Get the list of include search path
3586 # @retval list The list path
3588 def _GetIncludePathList(self
):
3589 if self
._IncludePathList
is None:
3590 self
._IncludePathList
= []
3591 if self
.AutoGenVersion
< 0x00010005:
3592 for Inc
in self
.Module
.Includes
:
3593 if Inc
not in self
._IncludePathList
:
3594 self
._IncludePathList
.append(Inc
)
3596 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3597 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3598 self
._IncludePathList
.append(Inc
)
3599 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3600 self
._IncludePathList
.append(self
.DebugDir
)
3602 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3603 self
._IncludePathList
.append(self
.DebugDir
)
3605 for Package
in self
.Module
.Packages
:
3606 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3607 if PackageDir
not in self
._IncludePathList
:
3608 self
._IncludePathList
.append(PackageDir
)
3609 IncludesList
= Package
.Includes
3610 if Package
._PrivateIncludes
:
3611 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3612 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3613 for Inc
in IncludesList
:
3614 if Inc
not in self
._IncludePathList
:
3615 self
._IncludePathList
.append(str(Inc
))
3616 return self
._IncludePathList
3618 def _GetIncludePathLength(self
):
3619 return sum(len(inc
)+1 for inc
in self
._IncludePathList
)
3621 ## Get HII EX PCDs which maybe used by VFR
3623 # efivarstore used by VFR may relate with HII EX PCDs
3624 # Get the variable name and GUID from efivarstore and HII EX PCD
3625 # List the HII EX PCDs in As Built INF if both name and GUID match.
3627 # @retval list HII EX PCDs
3629 def _GetPcdsMaybeUsedByVfr(self
):
3630 if not self
.SourceFileList
:
3634 for SrcFile
in self
.SourceFileList
:
3635 if SrcFile
.Ext
.lower() != '.vfr':
3637 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3638 if not os
.path
.exists(Vfri
):
3640 VfriFile
= open(Vfri
, 'r')
3641 Content
= VfriFile
.read()
3643 Pos
= Content
.find('efivarstore')
3646 # Make sure 'efivarstore' is the start of efivarstore statement
3647 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3650 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3652 if Index
>= 0 and Content
[Index
] != ';':
3653 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3656 # 'efivarstore' must be followed by name and guid
3658 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3661 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3664 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3665 NameGuids
.add((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3666 Pos
= Content
.find('efivarstore', Name
.end())
3670 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3671 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3673 for SkuInfo
in Pcd
.SkuInfoList
.values():
3674 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3677 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3678 Guid
= GuidStructureStringToGuidString(Value
)
3679 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3680 HiiExPcds
.append(Pcd
)
3685 def _GenOffsetBin(self
):
3687 for SourceFile
in self
.Module
.Sources
:
3688 if SourceFile
.Type
.upper() == ".VFR" :
3690 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3692 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3693 elif SourceFile
.Type
.upper() == ".UNI" :
3695 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3697 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3699 if not VfrUniBaseName
:
3701 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3702 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3703 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3704 if not VfrUniOffsetList
:
3707 OutputName
= '%sOffset.bin' % self
.Name
3708 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3711 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3713 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3715 # Use a instance of StringIO to cache data
3716 fStringIO
= StringIO('')
3718 for Item
in VfrUniOffsetList
:
3719 if (Item
[0].find("Strings") != -1):
3721 # UNI offset in image.
3723 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3725 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3726 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3727 fStringIO
.write(''.join(UniGuid
))
3728 UniValue
= pack ('Q', int (Item
[1], 16))
3729 fStringIO
.write (UniValue
)
3732 # VFR binary offset in image.
3734 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3736 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3737 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3738 fStringIO
.write(''.join(VfrGuid
))
3739 VfrValue
= pack ('Q', int (Item
[1], 16))
3740 fStringIO
.write (VfrValue
)
3742 # write data into file.
3745 fInputfile
.write (fStringIO
.getvalue())
3747 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3748 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3754 ## Create AsBuilt INF file the module
3756 def CreateAsBuiltInf(self
, IsOnlyCopy
= False):
3757 self
.OutputFile
= set()
3758 if IsOnlyCopy
and GlobalData
.gBinCacheDest
:
3759 self
.CopyModuleToCache()
3762 if self
.IsAsBuiltInfCreated
:
3765 # Skip the following code for EDK I inf
3766 if self
.AutoGenVersion
< 0x00010005:
3769 # Skip the following code for libraries
3773 # Skip the following code for modules with no source files
3774 if not self
.SourceFileList
:
3777 # Skip the following code for modules without any binary files
3778 if self
.BinaryFileList
:
3781 ### TODO: How to handles mixed source and binary modules
3783 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3784 # Also find all packages that the DynamicEx PCDs depend on
3789 PcdTokenSpaceList
= []
3790 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3791 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3792 PatchablePcds
.append(Pcd
)
3793 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_PATCHABLE_IN_MODULE
))
3794 elif Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
3797 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC_EX
))
3798 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC
))
3799 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3800 GuidList
= OrderedDict()
3801 GuidList
.update(self
.GuidList
)
3802 for TokenSpace
in self
.GetGuidsUsedByPcd():
3803 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3804 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3805 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3806 GuidList
.pop(TokenSpace
)
3807 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3808 for Package
in self
.DerivedPackageList
:
3809 if Package
in Packages
:
3811 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3813 for Index
in range(len(BeChecked
)):
3814 for Item
in CheckList
[Index
]:
3815 if Item
in BeChecked
[Index
]:
3816 Packages
.append(Package
)
3822 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3823 for Pkg
in self
.PlatformInfo
.PackageList
:
3826 for VfrPcd
in VfrPcds
:
3827 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC_EX
) in Pkg
.Pcds
or
3828 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, TAB_PCDS_DYNAMIC
) in Pkg
.Pcds
):
3829 Packages
.append(Pkg
)
3832 ModuleType
= SUP_MODULE_DXE_DRIVER
if self
.ModuleType
== SUP_MODULE_UEFI_DRIVER
and self
.DepexGenerated
else self
.ModuleType
3833 DriverType
= self
.PcdIsDriver
if self
.PcdIsDriver
else ''
3835 MDefs
= self
.Module
.Defines
3838 'module_name' : self
.Name
,
3839 'module_guid' : Guid
,
3840 'module_module_type' : ModuleType
,
3841 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3842 'pcd_is_driver_string' : [],
3843 'module_uefi_specification_version' : [],
3844 'module_pi_specification_version' : [],
3845 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3846 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3847 'module_constructor' : self
.Module
.ConstructorList
,
3848 'module_destructor' : self
.Module
.DestructorList
,
3849 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3850 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3851 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3852 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3853 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3854 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3855 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3856 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3857 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3858 'module_arch' : self
.Arch
,
3859 'package_item' : [Package
.MetaFile
.File
.replace('\\', '/') for Package
in Packages
],
3861 'patchablepcd_item' : [],
3863 'protocol_item' : [],
3867 'libraryclasses_item' : []
3870 if 'MODULE_UNI_FILE' in MDefs
:
3871 UNIFile
= os
.path
.join(self
.MetaFile
.Dir
, MDefs
['MODULE_UNI_FILE'])
3872 if os
.path
.isfile(UNIFile
):
3873 shutil
.copy2(UNIFile
, self
.OutputDir
)
3875 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3876 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3878 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3881 AsBuiltInfDict
['pcd_is_driver_string'].append(DriverType
)
3883 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3884 AsBuiltInfDict
['module_uefi_specification_version'].append(self
.Specification
['UEFI_SPECIFICATION_VERSION'])
3885 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3886 AsBuiltInfDict
['module_pi_specification_version'].append(self
.Specification
['PI_SPECIFICATION_VERSION'])
3888 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3889 DebugDir
= self
.DebugDir
.replace('\\', '/').strip('/')
3890 for Item
in self
.CodaTargetList
:
3891 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(DebugDir
, '').replace(OutputDir
, '').strip('/')
3892 self
.OutputFile
.add(File
)
3893 if os
.path
.isabs(File
):
3894 File
= File
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3895 if Item
.Target
.Ext
.lower() == '.aml':
3896 AsBuiltInfDict
['binary_item'].append('ASL|' + File
)
3897 elif Item
.Target
.Ext
.lower() == '.acpi':
3898 AsBuiltInfDict
['binary_item'].append('ACPI|' + File
)
3899 elif Item
.Target
.Ext
.lower() == '.efi':
3900 AsBuiltInfDict
['binary_item'].append('PE32|' + self
.Name
+ '.efi')
3902 AsBuiltInfDict
['binary_item'].append('BIN|' + File
)
3903 if self
.DepexGenerated
:
3904 self
.OutputFile
.add(self
.Name
+ '.depex')
3905 if self
.ModuleType
in [SUP_MODULE_PEIM
]:
3906 AsBuiltInfDict
['binary_item'].append('PEI_DEPEX|' + self
.Name
+ '.depex')
3907 elif self
.ModuleType
in [SUP_MODULE_DXE_DRIVER
, SUP_MODULE_DXE_RUNTIME_DRIVER
, SUP_MODULE_DXE_SAL_DRIVER
, SUP_MODULE_UEFI_DRIVER
]:
3908 AsBuiltInfDict
['binary_item'].append('DXE_DEPEX|' + self
.Name
+ '.depex')
3909 elif self
.ModuleType
in [SUP_MODULE_DXE_SMM_DRIVER
]:
3910 AsBuiltInfDict
['binary_item'].append('SMM_DEPEX|' + self
.Name
+ '.depex')
3912 Bin
= self
._GenOffsetBin
()
3914 AsBuiltInfDict
['binary_item'].append('BIN|%s' % Bin
)
3915 self
.OutputFile
.add(Bin
)
3917 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3919 if File
.lower().endswith('.pdb'):
3920 AsBuiltInfDict
['binary_item'].append('DISPOSABLE|' + File
)
3921 self
.OutputFile
.add(File
)
3922 HeaderComments
= self
.Module
.HeaderComments
3924 for Index
in range(len(HeaderComments
)):
3925 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3926 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3929 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3930 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3933 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3934 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3935 (GuidList
, self
._GuidComments
, 'guid_item')
3937 for Item
in GenList
:
3938 for CName
in Item
[0]:
3939 Comments
= '\n '.join(Item
[1][CName
]) if CName
in Item
[1] else ''
3940 Entry
= Comments
+ '\n ' + CName
if Comments
else CName
3941 AsBuiltInfDict
[Item
[2]].append(Entry
)
3942 PatchList
= parsePcdInfoFromMapFile(
3943 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3944 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3947 for Pcd
in PatchablePcds
:
3948 TokenCName
= Pcd
.TokenCName
3949 for PcdItem
in GlobalData
.MixedPcd
:
3950 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3951 TokenCName
= PcdItem
[0]
3953 for PatchPcd
in PatchList
:
3954 if TokenCName
== PatchPcd
[0]:
3959 if Pcd
.DatumType
== 'BOOLEAN':
3960 BoolValue
= Pcd
.DefaultValue
.upper()
3961 if BoolValue
== 'TRUE':
3962 Pcd
.DefaultValue
= '1'
3963 elif BoolValue
== 'FALSE':
3964 Pcd
.DefaultValue
= '0'
3966 if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
:
3967 HexFormat
= '0x%02x'
3968 if Pcd
.DatumType
== TAB_UINT16
:
3969 HexFormat
= '0x%04x'
3970 elif Pcd
.DatumType
== TAB_UINT32
:
3971 HexFormat
= '0x%08x'
3972 elif Pcd
.DatumType
== TAB_UINT64
:
3973 HexFormat
= '0x%016x'
3974 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3976 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
3977 EdkLogger
.error("build", AUTOGEN_ERROR
,
3978 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3980 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3981 PcdValue
= Pcd
.DefaultValue
3982 if PcdValue
[0] != '{':
3984 if PcdValue
[0] == 'L':
3986 PcdValue
= PcdValue
.lstrip('L')
3987 PcdValue
= eval(PcdValue
)
3989 for Index
in range(0, len(PcdValue
)):
3991 CharVal
= ord(PcdValue
[Index
])
3992 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3993 + '0x%02x' % (CharVal
>> 8) + ', '
3995 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3998 Padding
= Padding
* 2
3999 ArraySize
= ArraySize
/ 2
4000 if ArraySize
< (len(PcdValue
) + 1):
4001 if Pcd
.MaxSizeUserSet
:
4002 EdkLogger
.error("build", AUTOGEN_ERROR
,
4003 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4006 ArraySize
= len(PcdValue
) + 1
4007 if ArraySize
> len(PcdValue
) + 1:
4008 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
4009 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
4010 elif len(PcdValue
.split(',')) <= ArraySize
:
4011 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
4014 if Pcd
.MaxSizeUserSet
:
4015 EdkLogger
.error("build", AUTOGEN_ERROR
,
4016 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4019 ArraySize
= len(PcdValue
) + 1
4020 PcdItem
= '%s.%s|%s|0x%X' % \
4021 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
4023 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4024 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
4026 PcdItem
= PcdComments
+ '\n ' + PcdItem
4027 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
4030 for Pcd
in Pcds
+ VfrPcds
:
4034 TokenCName
= Pcd
.TokenCName
4035 for PcdItem
in GlobalData
.MixedPcd
:
4036 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
4037 TokenCName
= PcdItem
[0]
4039 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
4040 for SkuName
in Pcd
.SkuInfoList
:
4041 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
4042 SkuId
= SkuInfo
.SkuId
4043 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
4047 # Don't generate duplicated HII PCD
4049 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
4051 HiiPcds
.add((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
4052 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4053 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
4057 for Index
, Comment
in enumerate(PcdCommentList
):
4058 for Usage
in UsageList
:
4059 if Comment
.find(Usage
) != -1:
4063 if UsageIndex
!= -1:
4064 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
4066 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
4067 PcdComments
= '\n '.join(PcdCommentList
)
4068 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
4070 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
4071 AsBuiltInfDict
['pcd_item'].append(PcdEntry
)
4072 for Item
in self
.BuildOption
:
4073 if 'FLAGS' in self
.BuildOption
[Item
]:
4074 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()))
4076 # Generated LibraryClasses section in comments.
4077 for Library
in self
.LibraryAutoGenList
:
4078 AsBuiltInfDict
['libraryclasses_item'].append(Library
.MetaFile
.File
.replace('\\', '/'))
4080 # Generated UserExtensions TianoCore section.
4081 # All tianocore user extensions are copied.
4083 for TianoCore
in self
._GetTianoCoreUserExtensionList
():
4084 UserExtStr
+= '\n'.join(TianoCore
)
4085 ExtensionFile
= os
.path
.join(self
.MetaFile
.Dir
, TianoCore
[1])
4086 if os
.path
.isfile(ExtensionFile
):
4087 shutil
.copy2(ExtensionFile
, self
.OutputDir
)
4088 AsBuiltInfDict
['userextension_tianocore_item'] = UserExtStr
4090 # Generated depex expression section in comments.
4091 DepexExpresion
= self
._GetDepexExpresionString
()
4092 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
if DepexExpresion
else ''
4094 AsBuiltInf
= TemplateString()
4095 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
4097 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
4099 self
.IsAsBuiltInfCreated
= True
4100 if GlobalData
.gBinCacheDest
:
4101 self
.CopyModuleToCache()
4103 def CopyModuleToCache(self
):
4104 FileDir
= path
.join(GlobalData
.gBinCacheDest
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
4105 CreateDirectory (FileDir
)
4106 HashFile
= path
.join(self
.BuildDir
, self
.Name
+ '.hash')
4107 ModuleFile
= path
.join(self
.OutputDir
, self
.Name
+ '.inf')
4108 if os
.path
.exists(HashFile
):
4109 shutil
.copy2(HashFile
, FileDir
)
4110 if os
.path
.exists(ModuleFile
):
4111 shutil
.copy2(ModuleFile
, FileDir
)
4112 if not self
.OutputFile
:
4113 Ma
= self
.Workspace
.BuildDatabase
[PathClass(ModuleFile
), self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
4114 self
.OutputFile
= Ma
.Binaries
4116 for File
in self
.OutputFile
:
4118 if not os
.path
.isabs(File
):
4119 File
= os
.path
.join(self
.OutputDir
, File
)
4120 if os
.path
.exists(File
):
4121 shutil
.copy2(File
, FileDir
)
4123 def AttemptModuleCacheCopy(self
):
4124 if self
.IsBinaryModule
:
4126 FileDir
= path
.join(GlobalData
.gBinCacheSource
, self
.Arch
, self
.SourceDir
, self
.MetaFile
.BaseName
)
4127 HashFile
= path
.join(FileDir
, self
.Name
+ '.hash')
4128 if os
.path
.exists(HashFile
):
4129 f
= open(HashFile
, 'r')
4130 CacheHash
= f
.read()
4132 if GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
4133 if CacheHash
== GlobalData
.gModuleHash
[self
.Arch
][self
.Name
]:
4134 for root
, dir, files
in os
.walk(FileDir
):
4136 if self
.Name
+ '.hash' in f
:
4137 shutil
.copy2(HashFile
, self
.BuildDir
)
4139 File
= path
.join(root
, f
)
4140 shutil
.copy2(File
, self
.OutputDir
)
4141 if self
.Name
== "PcdPeim" or self
.Name
== "PcdDxe":
4142 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4146 ## Create makefile for the module and its dependent libraries
4148 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
4149 # dependent libraries will be created
4151 def CreateMakeFile(self
, CreateLibraryMakeFile
=True, GenFfsList
= []):
4152 # Ignore generating makefile when it is a binary module
4153 if self
.IsBinaryModule
:
4156 if self
.IsMakeFileCreated
:
4158 self
.GenFfsList
= GenFfsList
4159 if not self
.IsLibrary
and CreateLibraryMakeFile
:
4160 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4161 LibraryAutoGen
.CreateMakeFile()
4166 if len(self
.CustomMakefile
) == 0:
4167 Makefile
= GenMake
.ModuleMakefile(self
)
4169 Makefile
= GenMake
.CustomMakefile(self
)
4170 if Makefile
.Generate():
4171 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
4172 (self
.Name
, self
.Arch
))
4174 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
4175 (self
.Name
, self
.Arch
))
4177 self
.CreateTimeStamp(Makefile
)
4178 self
.IsMakeFileCreated
= True
4180 def CopyBinaryFiles(self
):
4181 for File
in self
.Module
.Binaries
:
4183 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4184 CopyLongFilePath(SrcPath
, DstPath
)
4185 ## Create autogen code for the module and its dependent libraries
4187 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4188 # dependent libraries will be created
4190 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4191 if self
.IsCodeFileCreated
:
4194 # Need to generate PcdDatabase even PcdDriver is binarymodule
4195 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4196 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4198 if self
.IsBinaryModule
:
4200 self
.CopyBinaryFiles()
4203 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4204 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4205 LibraryAutoGen
.CreateCodeFile()
4211 IgoredAutoGenList
= []
4213 for File
in self
.AutoGenFileList
:
4214 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4215 #Ignore Edk AutoGen.c
4216 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
4219 AutoGenList
.append(str(File
))
4221 IgoredAutoGenList
.append(str(File
))
4223 # Skip the following code for EDK I inf
4224 if self
.AutoGenVersion
< 0x00010005:
4227 for ModuleType
in self
.DepexList
:
4228 # Ignore empty [depex] section or [depex] section for SUP_MODULE_USER_DEFINED module
4229 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== SUP_MODULE_USER_DEFINED
:
4232 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4233 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4235 if len(Dpx
.PostfixNotation
) <> 0:
4236 self
.DepexGenerated
= True
4238 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4239 AutoGenList
.append(str(DpxFile
))
4241 IgoredAutoGenList
.append(str(DpxFile
))
4243 if IgoredAutoGenList
== []:
4244 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4245 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4246 elif AutoGenList
== []:
4247 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4248 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4250 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4251 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4253 self
.IsCodeFileCreated
= True
4256 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4257 def _GetLibraryAutoGenList(self
):
4258 if self
._LibraryAutoGenList
is None:
4259 self
._LibraryAutoGenList
= []
4260 for Library
in self
.DependentLibraryList
:
4267 self
.PlatformInfo
.MetaFile
4269 if La
not in self
._LibraryAutoGenList
:
4270 self
._LibraryAutoGenList
.append(La
)
4271 for Lib
in La
.CodaTargetList
:
4272 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4273 return self
._LibraryAutoGenList
4275 def GenModuleHash(self
):
4276 if self
.Arch
not in GlobalData
.gModuleHash
:
4277 GlobalData
.gModuleHash
[self
.Arch
] = {}
4279 # Add Platform level hash
4280 m
.update(GlobalData
.gPlatformHash
)
4281 # Add Package level hash
4282 if self
.DependentPackageList
:
4283 for Pkg
in sorted(self
.DependentPackageList
, key
=lambda x
: x
.PackageName
):
4284 if Pkg
.PackageName
in GlobalData
.gPackageHash
[self
.Arch
]:
4285 m
.update(GlobalData
.gPackageHash
[self
.Arch
][Pkg
.PackageName
])
4288 if self
.LibraryAutoGenList
:
4289 for Lib
in sorted(self
.LibraryAutoGenList
, key
=lambda x
: x
.Name
):
4290 if Lib
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4292 m
.update(GlobalData
.gModuleHash
[self
.Arch
][Lib
.Name
])
4295 f
= open(str(self
.MetaFile
), 'r')
4299 # Add Module's source files
4300 if self
.SourceFileList
:
4301 for File
in sorted(self
.SourceFileList
, key
=lambda x
: str(x
)):
4302 f
= open(str(File
), 'r')
4307 ModuleHashFile
= path
.join(self
.BuildDir
, self
.Name
+ ".hash")
4308 if self
.Name
not in GlobalData
.gModuleHash
[self
.Arch
]:
4309 GlobalData
.gModuleHash
[self
.Arch
][self
.Name
] = m
.hexdigest()
4310 if GlobalData
.gBinCacheSource
:
4311 if self
.AttemptModuleCacheCopy():
4313 return SaveFileOnChange(ModuleHashFile
, m
.hexdigest(), True)
4315 ## Decide whether we can skip the ModuleAutoGen process
4316 def CanSkipbyHash(self
):
4317 if GlobalData
.gUseHashCache
:
4318 return not self
.GenModuleHash()
4320 ## Decide whether we can skip the ModuleAutoGen process
4321 # If any source file is newer than the module than we cannot skip
4324 if not os
.path
.exists(self
.GetTimeStampPath()):
4326 #last creation time of the module
4327 DstTimeStamp
= os
.stat(self
.GetTimeStampPath())[8]
4329 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4330 if SrcTimeStamp
> DstTimeStamp
:
4333 with
open(self
.GetTimeStampPath(),'r') as f
:
4335 source
= source
.rstrip('\n')
4336 if not os
.path
.exists(source
):
4338 if source
not in ModuleAutoGen
.TimeDict
:
4339 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4340 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4344 def GetTimeStampPath(self
):
4345 if self
._TimeStampPath
is None:
4346 self
._TimeStampPath
= os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')
4347 return self
._TimeStampPath
4348 def CreateTimeStamp(self
, Makefile
):
4350 FileSet
= {self
.MetaFile
.Path
}
4352 for SourceFile
in self
.Module
.Sources
:
4353 FileSet
.add (SourceFile
.Path
)
4355 for Lib
in self
.DependentLibraryList
:
4356 FileSet
.add (Lib
.MetaFile
.Path
)
4358 for f
in self
.AutoGenDepSet
:
4359 FileSet
.add (f
.Path
)
4361 if os
.path
.exists (self
.GetTimeStampPath()):
4362 os
.remove (self
.GetTimeStampPath())
4363 with
open(self
.GetTimeStampPath(), 'w+') as file:
4367 Module
= property(_GetModule
)
4368 Name
= property(_GetBaseName
)
4369 Guid
= property(_GetGuid
)
4370 Version
= property(_GetVersion
)
4371 ModuleType
= property(_GetModuleType
)
4372 ComponentType
= property(_GetComponentType
)
4373 BuildType
= property(_GetBuildType
)
4374 PcdIsDriver
= property(_GetPcdIsDriver
)
4375 AutoGenVersion
= property(_GetAutoGenVersion
)
4376 Macros
= property(_GetMacros
)
4377 Specification
= property(_GetSpecification
)
4379 IsLibrary
= property(_IsLibrary
)
4380 IsBinaryModule
= property(_IsBinaryModule
)
4381 BuildDir
= property(_GetBuildDir
)
4382 OutputDir
= property(_GetOutputDir
)
4383 FfsOutputDir
= property(_GetFfsOutputDir
)
4384 DebugDir
= property(_GetDebugDir
)
4385 MakeFileDir
= property(_GetMakeFileDir
)
4386 CustomMakefile
= property(_GetCustomMakefile
)
4388 IncludePathList
= property(_GetIncludePathList
)
4389 IncludePathLength
= property(_GetIncludePathLength
)
4390 AutoGenFileList
= property(_GetAutoGenFileList
)
4391 UnicodeFileList
= property(_GetUnicodeFileList
)
4392 VfrFileList
= property(_GetVfrFileList
)
4393 SourceFileList
= property(_GetSourceFileList
)
4394 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
4395 Targets
= property(_GetTargets
)
4396 IntroTargetList
= property(_GetIntroTargetList
)
4397 CodaTargetList
= property(_GetFinalTargetList
)
4398 FileTypes
= property(_GetFileTypes
)
4399 BuildRules
= property(_GetBuildRules
)
4400 IdfFileList
= property(_GetIdfFileList
)
4402 DependentPackageList
= property(_GetDependentPackageList
)
4403 DependentLibraryList
= property(_GetLibraryList
)
4404 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
4405 DerivedPackageList
= property(_GetDerivedPackageList
)
4407 ModulePcdList
= property(_GetModulePcdList
)
4408 LibraryPcdList
= property(_GetLibraryPcdList
)
4409 GuidList
= property(_GetGuidList
)
4410 ProtocolList
= property(_GetProtocolList
)
4411 PpiList
= property(_GetPpiList
)
4412 DepexList
= property(_GetDepexTokenList
)
4413 DxsFile
= property(_GetDxsFile
)
4414 DepexExpressionDict
= property(_GetDepexExpressionTokenList
)
4415 BuildOption
= property(_GetModuleBuildOption
)
4416 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
4417 BuildCommand
= property(_GetBuildCommand
)
4419 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
4421 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4422 if __name__
== '__main__':