2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 import Common
.LongFilePathOs
as os
18 import os
.path
as path
25 from StringIO
import StringIO
27 from StrGather
import *
28 from BuildEngine
import BuildRule
30 from Common
.LongFilePathSupport
import CopyLongFilePath
31 from Common
.BuildToolError
import *
32 from Common
.DataType
import *
33 from Common
.Misc
import *
34 from Common
.String
import *
35 import Common
.GlobalData
as GlobalData
36 from GenFds
.FdfParser
import *
37 from CommonDataClass
.CommonClass
import SkuInfoClass
38 from Workspace
.BuildClassObject
import *
39 from GenPatchPcdTable
.GenPatchPcdTable
import parsePcdInfoFromMapFile
40 import Common
.VpdInfoFile
as VpdInfoFile
41 from GenPcdDb
import CreatePcdDatabaseCode
42 from Workspace
.MetaFileCommentParser
import UsageList
43 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
44 import InfSectionParser
47 ## Regular expression for splitting Dependency Expression string into tokens
48 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
51 # Match name = variable
53 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
55 # The format of guid in efivarstore statement likes following and must be correct:
56 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
58 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
60 ## Mapping Makefile type
61 gMakeTypeMap
= {"MSFT":"nmake", "GCC":"gmake"}
64 ## Build rule configuration file
65 gDefaultBuildRuleFile
= 'build_rule.txt'
67 ## Tools definition configuration file
68 gDefaultToolsDefFile
= 'tools_def.txt'
70 ## Build rule default version
71 AutoGenReqBuildRuleVerNum
= "0.1"
73 ## default file name for AutoGen
74 gAutoGenCodeFileName
= "AutoGen.c"
75 gAutoGenHeaderFileName
= "AutoGen.h"
76 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
77 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
78 gAutoGenDepexFileName
= "%(module_name)s.depex"
79 gAutoGenImageDefFileName
= "%(module_name)sImgDefs.h"
80 gAutoGenIdfFileName
= "%(module_name)sIdf.hpk"
81 gInfSpecVersion
= "0x00010017"
84 # Template string to generic AsBuilt INF
86 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
92 INF_VERSION = ${module_inf_version}
93 BASE_NAME = ${module_name}
94 FILE_GUID = ${module_guid}
95 MODULE_TYPE = ${module_module_type}${BEGIN}
96 VERSION_STRING = ${module_version_string}${END}${BEGIN}
97 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
98 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
99 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
100 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
101 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
102 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
103 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
104 SHADOW = ${module_shadow}${END}${BEGIN}
105 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
106 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
107 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
108 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
109 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
110 SPEC = ${module_spec}${END}${BEGIN}
111 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
112 MODULE_UNI_FILE = ${module_uni_file}${END}
114 [Packages.${module_arch}]${BEGIN}
115 ${package_item}${END}
117 [Binaries.${module_arch}]${BEGIN}
120 [PatchPcd.${module_arch}]${BEGIN}
124 [Protocols.${module_arch}]${BEGIN}
128 [Ppis.${module_arch}]${BEGIN}
132 [Guids.${module_arch}]${BEGIN}
136 [PcdEx.${module_arch}]${BEGIN}
140 [LibraryClasses.${module_arch}]
141 ## @LIB_INSTANCES${BEGIN}
142 # ${libraryclasses_item}${END}
148 [BuildOptions.${module_arch}]
150 ## ${flags_item}${END}
153 ## Base class for AutoGen
155 # This class just implements the cache mechanism of AutoGen objects.
157 class AutoGen(object):
158 # database to maintain the objects of xxxAutoGen
159 _CACHE_
= {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}
163 # @param Class class object of real AutoGen class
164 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
165 # @param Workspace Workspace directory or WorkspaceAutoGen object
166 # @param MetaFile The path of meta file
167 # @param Target Build target
168 # @param Toolchain Tool chain name
169 # @param Arch Target arch
170 # @param *args The specific class related parameters
171 # @param **kwargs The specific class related dict parameters
173 def __new__(Class
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
174 # check if the object has been created
175 Key
= (Target
, Toolchain
)
176 if Key
not in Class
._CACHE
_ or Arch
not in Class
._CACHE
_[Key
] \
177 or MetaFile
not in Class
._CACHE
_[Key
][Arch
]:
178 AutoGenObject
= super(AutoGen
, Class
).__new
__(Class
)
179 # call real constructor
180 if not AutoGenObject
._Init
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
182 if Key
not in Class
._CACHE
_:
183 Class
._CACHE
_[Key
] = {}
184 if Arch
not in Class
._CACHE
_[Key
]:
185 Class
._CACHE
_[Key
][Arch
] = {}
186 Class
._CACHE
_[Key
][Arch
][MetaFile
] = AutoGenObject
188 AutoGenObject
= Class
._CACHE
_[Key
][Arch
][MetaFile
]
194 # The file path of platform file will be used to represent hash value of this object
196 # @retval int Hash value of the file path of platform file
199 return hash(self
.MetaFile
)
203 # The file path of platform file will be used to represent this object
205 # @retval string String of platform file path
208 return str(self
.MetaFile
)
211 def __eq__(self
, Other
):
212 return Other
and self
.MetaFile
== Other
214 ## Workspace AutoGen class
216 # This class is used mainly to control the whole platform build for different
217 # architecture. This class will generate top level makefile.
219 class WorkspaceAutoGen(AutoGen
):
220 ## Real constructor of WorkspaceAutoGen
222 # This method behaves the same as __init__ except that it needs explicit invoke
223 # (in super class's __new__ method)
225 # @param WorkspaceDir Root directory of workspace
226 # @param ActivePlatform Meta-file of active platform
227 # @param Target Build target
228 # @param Toolchain Tool chain name
229 # @param ArchList List of architecture of current build
230 # @param MetaFileDb Database containing meta-files
231 # @param BuildConfig Configuration of build
232 # @param ToolDefinition Tool chain definitions
233 # @param FlashDefinitionFile File of flash definition
234 # @param Fds FD list to be generated
235 # @param Fvs FV list to be generated
236 # @param Caps Capsule list to be generated
237 # @param SkuId SKU id from command line
239 def _Init(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
240 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
241 Progress
=None, BuildModule
=None):
248 self
.BuildDatabase
= MetaFileDb
249 self
.MetaFile
= ActivePlatform
250 self
.WorkspaceDir
= WorkspaceDir
251 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, 'COMMON', Target
, Toolchain
]
252 GlobalData
.gActivePlatform
= self
.Platform
253 self
.BuildTarget
= Target
254 self
.ToolChain
= Toolchain
255 self
.ArchList
= ArchList
257 self
.UniFlag
= UniFlag
259 self
.TargetTxt
= BuildConfig
260 self
.ToolDef
= ToolDefinition
261 self
.FdfFile
= FlashDefinitionFile
262 self
.FdTargetList
= Fds
263 self
.FvTargetList
= Fvs
264 self
.CapTargetList
= Caps
265 self
.AutoGenObjectList
= []
267 # there's many relative directory operations, so ...
268 os
.chdir(self
.WorkspaceDir
)
273 if not self
.ArchList
:
274 ArchList
= set(self
.Platform
.SupArchList
)
276 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
278 EdkLogger
.error("build", PARAMETER_INVALID
,
279 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
280 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
281 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
282 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
283 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
284 self
.ArchList
= tuple(ArchList
)
286 # Validate build target
287 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
288 EdkLogger
.error("build", PARAMETER_INVALID
,
289 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
290 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
293 # parse FDF file to get PCDs in it, if any
295 self
.FdfFile
= self
.Platform
.FlashDefinition
299 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
300 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
301 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
303 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
305 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
308 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
310 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
313 Progress
.Start("\nProcessing meta-data")
317 # Mark now build in AutoGen Phase
319 GlobalData
.gAutoGenPhase
= True
320 Fdf
= FdfParser(self
.FdfFile
.Path
)
322 GlobalData
.gFdfParser
= Fdf
323 GlobalData
.gAutoGenPhase
= False
324 PcdSet
= Fdf
.Profile
.PcdDict
325 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
326 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
327 for FdRegion
in FdDict
.RegionList
:
328 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
329 if int(FdRegion
.Offset
) % 8 != 0:
330 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
331 ModuleList
= Fdf
.Profile
.InfList
332 self
.FdfProfile
= Fdf
.Profile
333 for fvname
in self
.FvTargetList
:
334 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
335 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
336 "No such an FV in FDF file: %s" % fvname
)
338 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
339 # but the path (self.MetaFile.Path) is the real path
340 for key
in self
.FdfProfile
.InfDict
:
344 for Arch
in self
.ArchList
:
345 Platform_cache
[Arch
] = self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
346 MetaFile_cache
[Arch
] = []
347 for Pkey
in Platform_cache
[Arch
].Modules
.keys():
348 MetaFile_cache
[Arch
].append(Platform_cache
[Arch
].Modules
[Pkey
].MetaFile
)
349 for Inf
in self
.FdfProfile
.InfDict
[key
]:
350 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
351 for Arch
in self
.ArchList
:
352 if ModuleFile
in MetaFile_cache
[Arch
]:
355 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
356 if not ModuleData
.IsBinaryModule
:
357 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
360 for Arch
in self
.ArchList
:
362 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
364 for Pkey
in Platform
.Modules
.keys():
365 MetaFileList
.append(Platform
.Modules
[Pkey
].MetaFile
)
366 for Inf
in self
.FdfProfile
.InfDict
[key
]:
367 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
368 if ModuleFile
in MetaFileList
:
370 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
371 if not ModuleData
.IsBinaryModule
:
372 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
377 self
.FdfProfile
= None
378 if self
.FdTargetList
:
379 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
380 self
.FdTargetList
= []
381 if self
.FvTargetList
:
382 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
383 self
.FvTargetList
= []
384 if self
.CapTargetList
:
385 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
386 self
.CapTargetList
= []
388 # apply SKU and inject PCDs from Flash Definition file
389 for Arch
in self
.ArchList
:
390 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
394 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
395 if GlobalData
.BuildOptionPcd
:
396 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
397 if type(pcd
) is tuple:
399 (pcdname
, pcdvalue
) = pcd
.split('=')
401 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
403 (TokenSpaceGuidCName
, TokenCName
) = pcdname
.split('.')
407 TokenSpaceGuidCName
= ''
408 HasTokenSpace
= False
409 TokenSpaceGuidCNameList
= []
413 for package
in PGen
.PackageList
:
414 for key
in package
.Pcds
:
415 PcdItem
= package
.Pcds
[key
]
417 if (PcdItem
.TokenCName
, PcdItem
.TokenSpaceGuidCName
) == (TokenCName
, TokenSpaceGuidCName
):
418 PcdDatumType
= PcdItem
.DatumType
419 NewValue
= BuildOptionPcdValueFormat(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
422 if PcdItem
.TokenCName
== TokenCName
:
423 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
424 if len (TokenSpaceGuidCNameList
) < 1:
425 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
426 PcdDatumType
= PcdItem
.DatumType
427 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
428 NewValue
= BuildOptionPcdValueFormat(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
434 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
437 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, NewValue
)
441 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, TokenCName
))
443 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (TokenCName
))
445 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
446 if BuildData
.Arch
!= Arch
:
448 if BuildData
.MetaFile
.Ext
== '.dec':
450 for key
in BuildData
.Pcds
:
451 PcdItem
= BuildData
.Pcds
[key
]
452 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
):
453 PcdItem
.DefaultValue
= NewValue
455 if (TokenCName
, TokenSpaceGuidCName
) in PcdSet
:
456 PcdSet
[(TokenCName
, TokenSpaceGuidCName
)] = NewValue
458 SourcePcdDict
= {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}
459 BinaryPcdDict
= {'DynamicEx':[], 'PatchableInModule':[]}
460 SourcePcdDict_Keys
= SourcePcdDict
.keys()
461 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
463 # generate the SourcePcdDict and BinaryPcdDict
464 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
465 if BuildData
.Arch
!= Arch
:
467 if BuildData
.MetaFile
.Ext
== '.inf':
468 for key
in BuildData
.Pcds
:
469 if BuildData
.Pcds
[key
].Pending
:
470 if key
in Platform
.Pcds
:
471 PcdInPlatform
= Platform
.Pcds
[key
]
472 if PcdInPlatform
.Type
not in [None, '']:
473 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
475 if BuildData
.MetaFile
in Platform
.Modules
:
476 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
477 if key
in PlatformModule
.Pcds
:
478 PcdInPlatform
= PlatformModule
.Pcds
[key
]
479 if PcdInPlatform
.Type
not in [None, '']:
480 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
482 if 'DynamicEx' in BuildData
.Pcds
[key
].Type
:
483 if BuildData
.IsBinaryModule
:
484 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['DynamicEx']:
485 BinaryPcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
487 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['DynamicEx']:
488 SourcePcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
490 elif 'PatchableInModule' in BuildData
.Pcds
[key
].Type
:
491 if BuildData
.MetaFile
.Ext
== '.inf':
492 if BuildData
.IsBinaryModule
:
493 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['PatchableInModule']:
494 BinaryPcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
496 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['PatchableInModule']:
497 SourcePcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
499 elif 'Dynamic' in BuildData
.Pcds
[key
].Type
:
500 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['Dynamic']:
501 SourcePcdDict
['Dynamic'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
502 elif 'FixedAtBuild' in BuildData
.Pcds
[key
].Type
:
503 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['FixedAtBuild']:
504 SourcePcdDict
['FixedAtBuild'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
508 # A PCD can only use one type for all source modules
510 for i
in SourcePcdDict_Keys
:
511 for j
in SourcePcdDict_Keys
:
513 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(SourcePcdDict
[j
])))
514 if len(IntersectionList
) > 0:
518 "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
),
519 ExtraData
="%s" % '\n\t'.join([str(P
[1]+'.'+P
[0]) for P
in IntersectionList
])
525 # intersection the BinaryPCD for Mixed PCD
527 for i
in BinaryPcdDict_Keys
:
528 for j
in BinaryPcdDict_Keys
:
530 IntersectionList
= list(set(BinaryPcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
531 for item
in IntersectionList
:
532 NewPcd1
= (item
[0] + '_' + i
, item
[1])
533 NewPcd2
= (item
[0] + '_' + j
, item
[1])
534 if item
not in GlobalData
.MixedPcd
:
535 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
537 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
538 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
539 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
540 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
545 # intersection the SourcePCD and BinaryPCD for Mixed PCD
547 for i
in SourcePcdDict_Keys
:
548 for j
in BinaryPcdDict_Keys
:
550 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
551 for item
in IntersectionList
:
552 NewPcd1
= (item
[0] + '_' + i
, item
[1])
553 NewPcd2
= (item
[0] + '_' + j
, item
[1])
554 if item
not in GlobalData
.MixedPcd
:
555 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
557 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
558 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
559 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
560 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
564 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
565 if BuildData
.Arch
!= Arch
:
567 for key
in BuildData
.Pcds
:
568 for SinglePcd
in GlobalData
.MixedPcd
:
569 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
570 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
571 Pcd_Type
= item
[0].split('_')[-1]
572 if (Pcd_Type
== BuildData
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicExPcd
) or \
573 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
574 Value
= BuildData
.Pcds
[key
]
575 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
577 newkey
= (Value
.TokenCName
, key
[1])
579 newkey
= (Value
.TokenCName
, key
[1], key
[2])
580 del BuildData
.Pcds
[key
]
581 BuildData
.Pcds
[newkey
] = Value
589 # handle the mixed pcd in FDF file
591 if key
in GlobalData
.MixedPcd
:
594 for item
in GlobalData
.MixedPcd
[key
]:
597 #Collect package set information from INF of FDF
599 for Inf
in ModuleList
:
600 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
601 if ModuleFile
in Platform
.Modules
:
603 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
604 PkgSet
.update(ModuleData
.Packages
)
605 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
608 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
609 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
611 Platform
.SkuName
= self
.SkuId
612 for Name
, Guid
in PcdSet
:
613 if (Name
, Guid
) not in DecPcds
:
617 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
618 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
619 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
622 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
623 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
624 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
625 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
626 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
628 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
632 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
633 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
634 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
637 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
639 # Explicitly collect platform's dynamic PCDs
641 Pa
.CollectPlatformDynamicPcds()
642 Pa
.CollectFixedAtBuildPcds()
643 self
.AutoGenObjectList
.append(Pa
)
646 # Check PCDs token value conflict in each DEC file.
648 self
._CheckAllPcdsTokenValueConflict
()
651 # Check PCD type and definition between DSC and DEC
653 self
._CheckPcdDefineAndType
()
656 # self._CheckDuplicateInFV(Fdf)
658 self
._BuildDir
= None
660 self
._MakeFileDir
= None
661 self
._BuildCommand
= None
664 # Create BuildOptions Macro & PCD metafile.
666 content
= 'gCommandLineDefines: '
667 content
+= str(GlobalData
.gCommandLineDefines
)
668 content
+= os
.linesep
669 content
+= 'BuildOptionPcd: '
670 content
+= str(GlobalData
.BuildOptionPcd
)
671 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'BuildOptions'), content
, False)
674 # Get set of workspace metafiles
676 AllWorkSpaceMetaFiles
= self
._GetMetaFiles
(Target
, Toolchain
, Arch
)
679 # Retrieve latest modified time of all metafiles
682 for f
in AllWorkSpaceMetaFiles
:
683 if os
.stat(f
)[8] > SrcTimeStamp
:
684 SrcTimeStamp
= os
.stat(f
)[8]
685 self
._SrcTimeStamp
= SrcTimeStamp
688 # Write metafile list to build directory
690 AutoGenFilePath
= os
.path
.join(self
.BuildDir
, 'AutoGen')
691 if os
.path
.exists (AutoGenFilePath
):
692 os
.remove(AutoGenFilePath
)
693 if not os
.path
.exists(self
.BuildDir
):
694 os
.makedirs(self
.BuildDir
)
695 with
open(os
.path
.join(self
.BuildDir
, 'AutoGen'), 'w+') as file:
696 for f
in AllWorkSpaceMetaFiles
:
701 def _GetMetaFiles(self
, Target
, Toolchain
, Arch
):
702 AllWorkSpaceMetaFiles
= set()
707 AllWorkSpaceMetaFiles
.add (self
.FdfFile
.Path
)
709 FdfFiles
= GlobalData
.gFdfParser
.GetAllIncludedFile()
711 AllWorkSpaceMetaFiles
.add (f
.FileName
)
715 AllWorkSpaceMetaFiles
.add(self
.MetaFile
.Path
)
718 # add build_rule.txt & tools_def.txt
720 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultBuildRuleFile
))
721 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultToolsDefFile
))
723 # add BuildOption metafile
725 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'BuildOptions'))
727 for Arch
in self
.ArchList
:
728 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
729 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
734 for Package
in PGen
.PackageList
:
735 AllWorkSpaceMetaFiles
.add(Package
.MetaFile
.Path
)
740 for filePath
in Platform
._RawData
.IncludedFiles
:
741 AllWorkSpaceMetaFiles
.add(filePath
.Path
)
743 return AllWorkSpaceMetaFiles
745 ## _CheckDuplicateInFV() method
747 # Check whether there is duplicate modules/files exist in FV section.
748 # The check base on the file GUID;
750 def _CheckDuplicateInFV(self
, Fdf
):
751 for Fv
in Fdf
.Profile
.FvDict
:
753 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
754 if FfsFile
.InfFileName
and FfsFile
.NameGuid
== None:
759 for Pa
in self
.AutoGenObjectList
:
762 for Module
in Pa
.ModuleAutoGenList
:
763 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
765 if not Module
.Guid
.upper() in _GuidDict
.keys():
766 _GuidDict
[Module
.Guid
.upper()] = FfsFile
769 EdkLogger
.error("build",
771 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
772 FfsFile
.CurrentLineContent
,
773 _GuidDict
[Module
.Guid
.upper()].CurrentLineNum
,
774 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
775 Module
.Guid
.upper()),
776 ExtraData
=self
.FdfFile
)
778 # Some INF files not have entity in DSC file.
781 if FfsFile
.InfFileName
.find('$') == -1:
782 InfPath
= NormPath(FfsFile
.InfFileName
)
783 if not os
.path
.exists(InfPath
):
784 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
786 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
788 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
789 # BuildObject from one of AutoGenObjectList is enough.
791 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, 'COMMON', self
.BuildTarget
, self
.ToolChain
]
792 if not InfObj
.Guid
.upper() in _GuidDict
.keys():
793 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
795 EdkLogger
.error("build",
797 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
798 FfsFile
.CurrentLineContent
,
799 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
800 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
801 InfObj
.Guid
.upper()),
802 ExtraData
=self
.FdfFile
)
805 if FfsFile
.NameGuid
!= None:
806 _CheckPCDAsGuidPattern
= re
.compile("^PCD\(.+\..+\)$")
809 # If the NameGuid reference a PCD name.
810 # The style must match: PCD(xxxx.yyy)
812 if _CheckPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
814 # Replace the PCD value.
816 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
818 for Pa
in self
.AutoGenObjectList
:
820 for PcdItem
in Pa
.AllPcdList
:
821 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
823 # First convert from CFormatGuid to GUID string
825 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
827 if not _PcdGuidString
:
829 # Then try Byte array.
831 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
833 if not _PcdGuidString
:
835 # Not Byte array or CFormat GUID, raise error.
837 EdkLogger
.error("build",
839 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
840 ExtraData
=self
.FdfFile
)
842 if not _PcdGuidString
.upper() in _GuidDict
.keys():
843 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
847 EdkLogger
.error("build",
849 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
850 FfsFile
.CurrentLineContent
,
851 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
852 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
853 FfsFile
.NameGuid
.upper()),
854 ExtraData
=self
.FdfFile
)
856 if not FfsFile
.NameGuid
.upper() in _GuidDict
.keys():
857 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
860 # Two raw file GUID conflict.
862 EdkLogger
.error("build",
864 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
865 FfsFile
.CurrentLineContent
,
866 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
867 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
868 FfsFile
.NameGuid
.upper()),
869 ExtraData
=self
.FdfFile
)
872 def _CheckPcdDefineAndType(self
):
874 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
875 "Dynamic", #"DynamicHii", "DynamicVpd",
876 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
879 # This dict store PCDs which are not used by any modules with specified arches
881 for Pa
in self
.AutoGenObjectList
:
882 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
883 for Pcd
in Pa
.Platform
.Pcds
:
884 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
886 # If no PCD type, this PCD comes from FDF
890 # Try to remove Hii and Vpd suffix
891 if PcdType
.startswith("DynamicEx"):
892 PcdType
= "DynamicEx"
893 elif PcdType
.startswith("Dynamic"):
896 for Package
in Pa
.PackageList
:
897 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
898 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
900 for Type
in PcdTypeList
:
901 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
905 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
906 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
911 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
913 for Pcd
in UnusedPcd
:
916 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
917 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
918 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
923 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
925 ## Return the directory to store FV files
927 if self
._FvDir
== None:
928 self
._FvDir
= path
.join(self
.BuildDir
, 'FV')
931 ## Return the directory to store all intermediate and final files built
932 def _GetBuildDir(self
):
933 return self
.AutoGenObjectList
[0].BuildDir
935 ## Return the build output directory platform specifies
936 def _GetOutputDir(self
):
937 return self
.Platform
.OutputDirectory
939 ## Return platform name
941 return self
.Platform
.PlatformName
943 ## Return meta-file GUID
945 return self
.Platform
.Guid
947 ## Return platform version
948 def _GetVersion(self
):
949 return self
.Platform
.Version
951 ## Return paths of tools
952 def _GetToolDefinition(self
):
953 return self
.AutoGenObjectList
[0].ToolDefinition
955 ## Return directory of platform makefile
957 # @retval string Makefile directory
959 def _GetMakeFileDir(self
):
960 if self
._MakeFileDir
== None:
961 self
._MakeFileDir
= self
.BuildDir
962 return self
._MakeFileDir
964 ## Return build command string
966 # @retval string Build command string
968 def _GetBuildCommand(self
):
969 if self
._BuildCommand
== None:
970 # BuildCommand should be all the same. So just get one from platform AutoGen
971 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
972 return self
._BuildCommand
974 ## Check the PCDs token value conflict in each DEC file.
976 # Will cause build break and raise error message while two PCDs conflict.
980 def _CheckAllPcdsTokenValueConflict(self
):
981 for Pa
in self
.AutoGenObjectList
:
982 for Package
in Pa
.PackageList
:
983 PcdList
= Package
.Pcds
.values()
984 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
986 while (Count
< len(PcdList
) - 1) :
987 Item
= PcdList
[Count
]
988 ItemNext
= PcdList
[Count
+ 1]
990 # Make sure in the same token space the TokenValue should be unique
992 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
993 SameTokenValuePcdList
= []
994 SameTokenValuePcdList
.append(Item
)
995 SameTokenValuePcdList
.append(ItemNext
)
996 RemainPcdListLength
= len(PcdList
) - Count
- 2
997 for ValueSameCount
in range(RemainPcdListLength
):
998 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
999 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
1003 # Sort same token value PCD list with TokenGuid and TokenCName
1005 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1006 SameTokenValuePcdListCount
= 0
1007 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
1009 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
1010 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
1012 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
1013 for PcdItem
in GlobalData
.MixedPcd
:
1014 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
1015 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1021 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
1022 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
1025 SameTokenValuePcdListCount
+= 1
1026 Count
+= SameTokenValuePcdListCount
1029 PcdList
= Package
.Pcds
.values()
1030 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1032 while (Count
< len(PcdList
) - 1) :
1033 Item
= PcdList
[Count
]
1034 ItemNext
= PcdList
[Count
+ 1]
1036 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
1038 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
1042 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
1043 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
1047 ## Generate fds command
1048 def _GenFdsCommand(self
):
1049 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
1051 ## Create makefile for the platform and modules in it
1053 # @param CreateDepsMakeFile Flag indicating if the makefile for
1054 # modules will be created as well
1056 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
1057 if CreateDepsMakeFile
:
1058 for Pa
in self
.AutoGenObjectList
:
1059 Pa
.CreateMakeFile(CreateDepsMakeFile
)
1061 ## Create autogen code for platform and modules
1063 # Since there's no autogen code for platform, this method will do nothing
1064 # if CreateModuleCodeFile is set to False.
1066 # @param CreateDepsCodeFile Flag indicating if creating module's
1067 # autogen code file or not
1069 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
1070 if not CreateDepsCodeFile
:
1072 for Pa
in self
.AutoGenObjectList
:
1073 Pa
.CreateCodeFile(CreateDepsCodeFile
)
1075 ## Create AsBuilt INF file the platform
1077 def CreateAsBuiltInf(self
):
1080 Name
= property(_GetName
)
1081 Guid
= property(_GetGuid
)
1082 Version
= property(_GetVersion
)
1083 OutputDir
= property(_GetOutputDir
)
1085 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
1087 BuildDir
= property(_GetBuildDir
)
1088 FvDir
= property(_GetFvDir
)
1089 MakeFileDir
= property(_GetMakeFileDir
)
1090 BuildCommand
= property(_GetBuildCommand
)
1091 GenFdsCommand
= property(_GenFdsCommand
)
1093 ## AutoGen class for platform
1095 # PlatformAutoGen class will process the original information in platform
1096 # file in order to generate makefile for platform.
1098 class PlatformAutoGen(AutoGen
):
1100 # Used to store all PCDs for both PEI and DXE phase, in order to generate
1101 # correct PCD database
1104 _NonDynaPcdList_
= []
1108 # The priority list while override build option
1110 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
1111 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1112 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1113 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1114 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1115 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1116 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1117 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1118 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1119 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1120 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1121 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1122 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1123 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1124 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1125 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1127 ## The real constructor of PlatformAutoGen
1129 # This method is not supposed to be called by users of PlatformAutoGen. It's
1130 # only used by factory method __new__() to do real initialization work for an
1131 # object of PlatformAutoGen
1133 # @param Workspace WorkspaceAutoGen object
1134 # @param PlatformFile Platform file (DSC file)
1135 # @param Target Build target (DEBUG, RELEASE)
1136 # @param Toolchain Name of tool chain
1137 # @param Arch arch of the platform supports
1139 def _Init(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1140 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1141 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1143 self
.MetaFile
= PlatformFile
1144 self
.Workspace
= Workspace
1145 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1146 self
.ToolChain
= Toolchain
1147 self
.BuildTarget
= Target
1149 self
.SourceDir
= PlatformFile
.SubDir
1150 self
.SourceOverrideDir
= None
1151 self
.FdTargetList
= self
.Workspace
.FdTargetList
1152 self
.FvTargetList
= self
.Workspace
.FvTargetList
1153 self
.AllPcdList
= []
1154 # get the original module/package/platform objects
1155 self
.BuildDatabase
= Workspace
.BuildDatabase
1157 # flag indicating if the makefile/C-code file has been created or not
1158 self
.IsMakeFileCreated
= False
1159 self
.IsCodeFileCreated
= False
1161 self
._Platform
= None
1164 self
._Version
= None
1166 self
._BuildRule
= None
1167 self
._SourceDir
= None
1168 self
._BuildDir
= None
1169 self
._OutputDir
= None
1171 self
._MakeFileDir
= None
1172 self
._FdfFile
= None
1174 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
1175 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1176 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1177 self
._NonDynamicPcdDict
= {}
1179 self
._ToolDefinitions
= None
1180 self
._ToolDefFile
= None # toolcode : tool path
1181 self
._ToolChainFamily
= None
1182 self
._BuildRuleFamily
= None
1183 self
._BuildOption
= None # toolcode : option
1184 self
._EdkBuildOption
= None # edktoolcode : option
1185 self
._EdkIIBuildOption
= None # edkiitoolcode : option
1186 self
._PackageList
= None
1187 self
._ModuleAutoGenList
= None
1188 self
._LibraryAutoGenList
= None
1189 self
._BuildCommand
= None
1190 self
._AsBuildInfList
= []
1191 self
._AsBuildModuleList
= []
1192 if GlobalData
.gFdfParser
!= None:
1193 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1194 for Inf
in self
._AsBuildInfList
:
1195 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1196 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1197 if not M
.IsSupportedArch
:
1199 self
._AsBuildModuleList
.append(InfClass
)
1200 # get library/modules for build
1201 self
.LibraryBuildDirectoryList
= []
1202 self
.ModuleBuildDirectoryList
= []
1206 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1208 ## Create autogen code for platform and modules
1210 # Since there's no autogen code for platform, this method will do nothing
1211 # if CreateModuleCodeFile is set to False.
1213 # @param CreateModuleCodeFile Flag indicating if creating module's
1214 # autogen code file or not
1216 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1217 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1218 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
1221 for Ma
in self
.ModuleAutoGenList
:
1222 Ma
.CreateCodeFile(True)
1224 # don't do this twice
1225 self
.IsCodeFileCreated
= True
1227 ## Generate Fds Command
1228 def _GenFdsCommand(self
):
1229 return self
.Workspace
.GenFdsCommand
1231 ## Create makefile for the platform and mdoules in it
1233 # @param CreateModuleMakeFile Flag indicating if the makefile for
1234 # modules will be created as well
1236 def CreateMakeFile(self
, CreateModuleMakeFile
=False):
1237 if CreateModuleMakeFile
:
1238 for ModuleFile
in self
.Platform
.Modules
:
1239 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
1240 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1241 Ma
.CreateMakeFile(True)
1242 #Ma.CreateAsBuiltInf()
1244 # no need to create makefile for the platform more than once
1245 if self
.IsMakeFileCreated
:
1248 # create library/module build dirs for platform
1249 Makefile
= GenMake
.PlatformMakefile(self
)
1250 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1251 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1253 self
.IsMakeFileCreated
= True
1255 ## Deal with Shared FixedAtBuild Pcds
1257 def CollectFixedAtBuildPcds(self
):
1258 for LibAuto
in self
.LibraryAutoGenList
:
1259 FixedAtBuildPcds
= {}
1260 ShareFixedAtBuildPcdsSameValue
= {}
1261 for Module
in LibAuto
._ReferenceModules
:
1262 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
1263 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1264 if key
not in FixedAtBuildPcds
:
1265 ShareFixedAtBuildPcdsSameValue
[key
] = True
1266 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
1268 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
1269 ShareFixedAtBuildPcdsSameValue
[key
] = False
1270 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1271 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1272 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1275 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
1276 if DscPcd
.Type
!= "FixedAtBuild":
1278 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1279 LibAuto
.ConstPcd
[key
] = Pcd
.DefaultValue
1281 ## Collect dynamic PCDs
1283 # Gather dynamic PCDs list from each module and their settings from platform
1284 # This interface should be invoked explicitly when platform action is created.
1286 def CollectPlatformDynamicPcds(self
):
1287 # Override the platform Pcd's value by build option
1288 if GlobalData
.BuildOptionPcd
:
1289 for key
in self
.Platform
.Pcds
:
1290 PlatformPcd
= self
.Platform
.Pcds
[key
]
1291 for PcdItem
in GlobalData
.BuildOptionPcd
:
1292 if (PlatformPcd
.TokenSpaceGuidCName
, PlatformPcd
.TokenCName
) == (PcdItem
[0], PcdItem
[1]):
1293 PlatformPcd
.DefaultValue
= PcdItem
[2]
1294 if PlatformPcd
.SkuInfoList
:
1295 Sku
= PlatformPcd
.SkuInfoList
[PlatformPcd
.SkuInfoList
.keys()[0]]
1296 Sku
.DefaultValue
= PcdItem
[2]
1299 for key
in self
.Platform
.Pcds
:
1300 for SinglePcd
in GlobalData
.MixedPcd
:
1301 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1302 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1303 Pcd_Type
= item
[0].split('_')[-1]
1304 if (Pcd_Type
== self
.Platform
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and self
.Platform
.Pcds
[key
].Type
in GenC
.gDynamicExPcd
) or \
1305 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
1306 Value
= self
.Platform
.Pcds
[key
]
1307 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1309 newkey
= (Value
.TokenCName
, key
[1])
1311 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1312 del self
.Platform
.Pcds
[key
]
1313 self
.Platform
.Pcds
[newkey
] = Value
1321 # for gathering error information
1322 NoDatumTypePcdList
= set()
1324 self
._GuidValue
= {}
1326 for InfName
in self
._AsBuildInfList
:
1327 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1328 FdfModuleList
.append(os
.path
.normpath(InfName
))
1329 for F
in self
.Platform
.Modules
.keys():
1330 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1331 #GuidValue.update(M.Guids)
1333 self
.Platform
.Modules
[F
].M
= M
1335 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1336 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1337 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1338 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1340 # Check the PCD from Binary INF or Source INF
1341 if M
.IsBinaryModule
== True:
1342 PcdFromModule
.IsFromBinaryInf
= True
1344 # Check the PCD from DSC or not
1345 if (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
.keys():
1346 PcdFromModule
.IsFromDsc
= True
1348 PcdFromModule
.IsFromDsc
= False
1349 if PcdFromModule
.Type
in GenC
.gDynamicPcd
or PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1350 if F
.Path
not in FdfModuleList
:
1351 # If one of the Source built modules listed in the DSC is not listed
1352 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1353 # access method (it is only listed in the DEC file that declares the
1354 # PCD as PcdsDynamic), then build tool will report warning message
1355 # notify the PI that they are attempting to build a module that must
1356 # be included in a flash image in order to be functional. These Dynamic
1357 # PCD will not be added into the Database unless it is used by other
1358 # modules that are included in the FDF file.
1359 if PcdFromModule
.Type
in GenC
.gDynamicPcd
and \
1360 PcdFromModule
.IsFromBinaryInf
== False:
1361 # Print warning message to let the developer make a determine.
1362 if PcdFromModule
not in PcdNotInDb
:
1363 PcdNotInDb
.append(PcdFromModule
)
1365 # If one of the Source built modules listed in the DSC is not listed in
1366 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1367 # access method (it is only listed in the DEC file that declares the
1368 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1369 # PCD to the Platform's PCD Database.
1370 if PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1371 if PcdFromModule
not in PcdNotInDb
:
1372 PcdNotInDb
.append(PcdFromModule
)
1375 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1376 # it should be stored in Pcd PEI database, If a dynamic only
1377 # used by DXE module, it should be stored in DXE PCD database.
1378 # The default Phase is DXE
1380 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1381 PcdFromModule
.Phase
= "PEI"
1382 if PcdFromModule
not in self
._DynaPcdList
_:
1383 self
._DynaPcdList
_.append(PcdFromModule
)
1384 elif PcdFromModule
.Phase
== 'PEI':
1385 # overwrite any the same PCD existing, if Phase is PEI
1386 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1387 self
._DynaPcdList
_[Index
] = PcdFromModule
1388 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1389 self
._NonDynaPcdList
_.append(PcdFromModule
)
1390 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1391 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1392 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1393 #The PCD from Binary INF will override the same one from source INF
1394 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1395 PcdFromModule
.Pending
= False
1396 self
._NonDynaPcdList
_.append (PcdFromModule
)
1397 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1399 for ModuleInf
in self
.Platform
.Modules
.keys():
1400 DscModuleList
.append (os
.path
.normpath(ModuleInf
.Path
))
1401 # add the PCD from modules that listed in FDF but not in DSC to Database
1402 for InfName
in FdfModuleList
:
1403 if InfName
not in DscModuleList
:
1404 InfClass
= PathClass(InfName
)
1405 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1406 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1407 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1408 # For binary module, if in current arch, we need to list the PCDs into database.
1409 if not M
.IsSupportedArch
:
1411 # Override the module PCD setting by platform setting
1412 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1413 for PcdFromModule
in ModulePcdList
:
1414 PcdFromModule
.IsFromBinaryInf
= True
1415 PcdFromModule
.IsFromDsc
= False
1416 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1417 if PcdFromModule
.Type
not in GenC
.gDynamicExPcd
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1418 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1420 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1421 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1422 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1423 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1424 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1425 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1426 PcdFromModule
.Phase
= "PEI"
1427 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1428 self
._DynaPcdList
_.append(PcdFromModule
)
1429 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1430 self
._NonDynaPcdList
_.append(PcdFromModule
)
1431 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1432 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1433 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1434 # module & DXE module at a same time.
1435 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1436 # INF file as DynamicEx.
1437 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1438 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1439 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1440 for PcdFromModule
in self
._NonDynaPcdList
_:
1441 # If a PCD is not listed in the DSC file, but binary INF files used by
1442 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1443 # section, AND all source INF files used by this platform the build
1444 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1445 # section, then the tools must NOT add the PCD to the Platform's PCD
1446 # Database; the build must assign the access method for this PCD as
1447 # PcdsPatchableInModule.
1448 if PcdFromModule
not in self
._DynaPcdList
_:
1450 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1451 if PcdFromModule
.IsFromDsc
== False and \
1452 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1453 PcdFromModule
.IsFromBinaryInf
== True and \
1454 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1455 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1456 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1458 # print out error information and break the build, if error found
1459 if len(NoDatumTypePcdList
) > 0:
1460 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1461 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1463 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1464 % NoDatumTypePcdListString
)
1465 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1466 self
._DynamicPcdList
= self
._DynaPcdList
_
1468 # Sort dynamic PCD list to:
1469 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1470 # try to be put header of dynamicd List
1471 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1473 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1475 UnicodePcdArray
= []
1479 VpdFile
= VpdInfoFile
.VpdInfoFile()
1480 NeedProcessVpdMapFile
= False
1482 for pcd
in self
.Platform
.Pcds
.keys():
1483 if pcd
not in self
._PlatformPcds
.keys():
1484 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1486 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1487 for Pcd
in self
._DynamicPcdList
:
1488 # just pick the a value to determine whether is unicode string type
1489 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1490 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1492 PcdValue
= Sku
.DefaultValue
1493 if Pcd
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1494 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1495 UnicodePcdArray
.append(Pcd
)
1496 elif len(Sku
.VariableName
) > 0:
1497 # if found HII type PCD then insert to right of UnicodeIndex
1498 HiiPcdArray
.append(Pcd
)
1500 OtherPcdArray
.append(Pcd
)
1501 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1502 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1504 PlatformPcds
= self
._PlatformPcds
.keys()
1507 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1509 for PcdKey
in PlatformPcds
:
1510 Pcd
= self
._PlatformPcds
[PcdKey
]
1511 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1512 PcdKey
in VpdPcdDict
:
1513 Pcd
= VpdPcdDict
[PcdKey
]
1514 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1515 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1516 PcdValue
= Sku
.DefaultValue
1518 PcdValue
= Pcd
.DefaultValue
1519 if Sku
.VpdOffset
!= '*':
1520 if PcdValue
.startswith("{"):
1522 elif PcdValue
.startswith("L"):
1527 VpdOffset
= int(Sku
.VpdOffset
)
1530 VpdOffset
= int(Sku
.VpdOffset
, 16)
1532 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1533 if VpdOffset
% Alignment
!= 0:
1534 if PcdValue
.startswith("{"):
1535 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1537 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1538 VpdFile
.Add(Pcd
, Sku
.VpdOffset
)
1539 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1540 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1541 NeedProcessVpdMapFile
= True
1542 if self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== '':
1543 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1544 "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.")
1548 # Fix the PCDs define in VPD PCD section that never referenced by module.
1549 # An example is PCD for signature usage.
1551 for DscPcd
in PlatformPcds
:
1552 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1553 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1554 if not (self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== ''):
1556 for VpdPcd
in VpdFile
._VpdArray
.keys():
1557 # This PCD has been referenced by module
1558 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1559 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1562 # Not found, it should be signature
1564 # just pick the a value to determine whether is unicode string type
1565 for (SkuName
,Sku
) in DscPcdEntry
.SkuInfoList
.items():
1566 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1568 # Need to iterate DEC pcd information to get the value & datumtype
1569 for eachDec
in self
.PackageList
:
1570 for DecPcd
in eachDec
.Pcds
:
1571 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1572 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1573 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1574 # Print warning message to let the developer make a determine.
1575 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1576 File
=self
.MetaFile
, \
1577 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1578 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1580 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1581 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1582 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1583 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1584 # Only fix the value while no value provided in DSC file.
1585 if (Sku
.DefaultValue
== "" or Sku
.DefaultValue
==None):
1586 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1588 if DscPcdEntry
not in self
._DynamicPcdList
:
1589 self
._DynamicPcdList
.append(DscPcdEntry
)
1590 # Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]
1591 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1592 PcdValue
= Sku
.DefaultValue
1594 PcdValue
= DscPcdEntry
.DefaultValue
1595 if Sku
.VpdOffset
!= '*':
1596 if PcdValue
.startswith("{"):
1598 elif PcdValue
.startswith("L"):
1603 VpdOffset
= int(Sku
.VpdOffset
)
1606 VpdOffset
= int(Sku
.VpdOffset
, 16)
1608 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1609 if VpdOffset
% Alignment
!= 0:
1610 if PcdValue
.startswith("{"):
1611 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1613 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1614 VpdFile
.Add(DscPcdEntry
, Sku
.VpdOffset
)
1615 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1616 NeedProcessVpdMapFile
= True
1617 if DscPcdEntry
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1618 UnicodePcdArray
.append(DscPcdEntry
)
1619 elif len(Sku
.VariableName
) > 0:
1620 HiiPcdArray
.append(DscPcdEntry
)
1622 OtherPcdArray
.append(DscPcdEntry
)
1624 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1628 if (self
.Platform
.FlashDefinition
== None or self
.Platform
.FlashDefinition
== '') and \
1629 VpdFile
.GetCount() != 0:
1630 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1631 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1633 if VpdFile
.GetCount() != 0:
1634 FvPath
= os
.path
.join(self
.BuildDir
, "FV")
1635 if not os
.path
.exists(FvPath
):
1639 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1641 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1643 if VpdFile
.Write(VpdFilePath
):
1644 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1646 for ToolDef
in self
.ToolDefinition
.values():
1647 if ToolDef
.has_key("GUID") and ToolDef
["GUID"] == self
.Platform
.VpdToolGuid
:
1648 if not ToolDef
.has_key("PATH"):
1649 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1650 BPDGToolName
= ToolDef
["PATH"]
1652 # Call third party GUID BPDG tool.
1653 if BPDGToolName
!= None:
1654 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1656 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.")
1658 # Process VPD map file generated by third party BPDG tool
1659 if NeedProcessVpdMapFile
:
1660 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1661 if os
.path
.exists(VpdMapFilePath
):
1662 VpdFile
.Read(VpdMapFilePath
)
1665 for Pcd
in self
._DynamicPcdList
:
1666 # just pick the a value to determine whether is unicode string type
1668 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1669 if Sku
.VpdOffset
== "*":
1670 Sku
.VpdOffset
= VpdFile
.GetOffset(Pcd
)[i
].strip()
1673 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1675 # Delete the DynamicPcdList At the last time enter into this function
1676 del self
._DynamicPcdList
[:]
1677 self
._DynamicPcdList
.extend(UnicodePcdArray
)
1678 self
._DynamicPcdList
.extend(HiiPcdArray
)
1679 self
._DynamicPcdList
.extend(OtherPcdArray
)
1680 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1682 ## Return the platform build data object
1683 def _GetPlatform(self
):
1684 if self
._Platform
== None:
1685 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1686 return self
._Platform
1688 ## Return platform name
1690 return self
.Platform
.PlatformName
1692 ## Return the meta file GUID
1694 return self
.Platform
.Guid
1696 ## Return the platform version
1697 def _GetVersion(self
):
1698 return self
.Platform
.Version
1700 ## Return the FDF file name
1701 def _GetFdfFile(self
):
1702 if self
._FdfFile
== None:
1703 if self
.Workspace
.FdfFile
!= "":
1704 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1707 return self
._FdfFile
1709 ## Return the build output directory platform specifies
1710 def _GetOutputDir(self
):
1711 return self
.Platform
.OutputDirectory
1713 ## Return the directory to store all intermediate and final files built
1714 def _GetBuildDir(self
):
1715 if self
._BuildDir
== None:
1716 if os
.path
.isabs(self
.OutputDir
):
1717 self
._BuildDir
= path
.join(
1718 path
.abspath(self
.OutputDir
),
1719 self
.BuildTarget
+ "_" + self
.ToolChain
,
1722 self
._BuildDir
= path
.join(
1725 self
.BuildTarget
+ "_" + self
.ToolChain
,
1727 return self
._BuildDir
1729 ## Return directory of platform makefile
1731 # @retval string Makefile directory
1733 def _GetMakeFileDir(self
):
1734 if self
._MakeFileDir
== None:
1735 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1736 return self
._MakeFileDir
1738 ## Return build command string
1740 # @retval string Build command string
1742 def _GetBuildCommand(self
):
1743 if self
._BuildCommand
== None:
1744 self
._BuildCommand
= []
1745 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1746 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1747 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1748 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1750 self
._BuildCommand
+= SplitOption(NewOption
)
1751 return self
._BuildCommand
1753 ## Get tool chain definition
1755 # Get each tool defition for given tool chain from tools_def.txt and platform
1757 def _GetToolDefinition(self
):
1758 if self
._ToolDefinitions
== None:
1759 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1760 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1761 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1762 ExtraData
="[%s]" % self
.MetaFile
)
1763 self
._ToolDefinitions
= {}
1765 for Def
in ToolDefinition
:
1766 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1767 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1770 Value
= ToolDefinition
[Def
]
1771 # don't record the DLL
1773 DllPathList
.add(Value
)
1776 if Tool
not in self
._ToolDefinitions
:
1777 self
._ToolDefinitions
[Tool
] = {}
1778 self
._ToolDefinitions
[Tool
][Attr
] = Value
1782 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1783 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1784 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1785 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1787 for Tool
in self
._ToolDefinitions
:
1788 for Attr
in self
._ToolDefinitions
[Tool
]:
1789 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1790 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1791 # check if override is indicated
1792 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1793 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1796 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1798 Value
= self
.BuildOption
[Tool
][Attr
]
1801 # Don't put MAKE definition in the file
1805 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1807 # Don't put MAKE definition in the file
1812 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1815 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1816 for DllPath
in DllPathList
:
1817 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1818 os
.environ
["MAKE_FLAGS"] = MakeFlags
1820 return self
._ToolDefinitions
1822 ## Return the paths of tools
1823 def _GetToolDefFile(self
):
1824 if self
._ToolDefFile
== None:
1825 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1826 return self
._ToolDefFile
1828 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1829 def _GetToolChainFamily(self
):
1830 if self
._ToolChainFamily
== None:
1831 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1832 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1833 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1834 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1835 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1837 self
._ToolChainFamily
= "MSFT"
1839 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1840 return self
._ToolChainFamily
1842 def _GetBuildRuleFamily(self
):
1843 if self
._BuildRuleFamily
== None:
1844 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1845 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1846 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1847 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1848 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1850 self
._BuildRuleFamily
= "MSFT"
1852 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1853 return self
._BuildRuleFamily
1855 ## Return the build options specific for all modules in this platform
1856 def _GetBuildOptions(self
):
1857 if self
._BuildOption
== None:
1858 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1859 return self
._BuildOption
1861 ## Return the build options specific for EDK modules in this platform
1862 def _GetEdkBuildOptions(self
):
1863 if self
._EdkBuildOption
== None:
1864 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1865 return self
._EdkBuildOption
1867 ## Return the build options specific for EDKII modules in this platform
1868 def _GetEdkIIBuildOptions(self
):
1869 if self
._EdkIIBuildOption
== None:
1870 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1871 return self
._EdkIIBuildOption
1873 ## Parse build_rule.txt in Conf Directory.
1875 # @retval BuildRule object
1877 def _GetBuildRule(self
):
1878 if self
._BuildRule
== None:
1879 BuildRuleFile
= None
1880 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1881 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1882 if BuildRuleFile
in [None, '']:
1883 BuildRuleFile
= gDefaultBuildRuleFile
1884 self
._BuildRule
= BuildRule(BuildRuleFile
)
1885 if self
._BuildRule
._FileVersion
== "":
1886 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
1888 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1889 # If Build Rule's version is less than the version number required by the tools, halting the build.
1890 EdkLogger
.error("build", AUTOGEN_ERROR
,
1891 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])"\
1892 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1894 return self
._BuildRule
1896 ## Summarize the packages used by modules in this platform
1897 def _GetPackageList(self
):
1898 if self
._PackageList
== None:
1899 self
._PackageList
= set()
1900 for La
in self
.LibraryAutoGenList
:
1901 self
._PackageList
.update(La
.DependentPackageList
)
1902 for Ma
in self
.ModuleAutoGenList
:
1903 self
._PackageList
.update(Ma
.DependentPackageList
)
1904 #Collect package set information from INF of FDF
1906 for ModuleFile
in self
._AsBuildModuleList
:
1907 if ModuleFile
in self
.Platform
.Modules
:
1909 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1910 PkgSet
.update(ModuleData
.Packages
)
1911 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
1912 return self
._PackageList
1914 def _GetNonDynamicPcdDict(self
):
1915 if self
._NonDynamicPcdDict
:
1916 return self
._NonDynamicPcdDict
1917 for Pcd
in self
.NonDynamicPcdList
:
1918 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
1919 return self
._NonDynamicPcdDict
1921 ## Get list of non-dynamic PCDs
1922 def _GetNonDynamicPcdList(self
):
1923 if self
._NonDynamicPcdList
== None:
1924 self
.CollectPlatformDynamicPcds()
1925 return self
._NonDynamicPcdList
1927 ## Get list of dynamic PCDs
1928 def _GetDynamicPcdList(self
):
1929 if self
._DynamicPcdList
== None:
1930 self
.CollectPlatformDynamicPcds()
1931 return self
._DynamicPcdList
1933 ## Generate Token Number for all PCD
1934 def _GetPcdTokenNumbers(self
):
1935 if self
._PcdTokenNumber
== None:
1936 self
._PcdTokenNumber
= sdict()
1939 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1943 # TokenNumber 0 ~ 10
1945 # TokeNumber 11 ~ 20
1947 for Pcd
in self
.DynamicPcdList
:
1948 if Pcd
.Phase
== "PEI":
1949 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1950 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1951 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1954 for Pcd
in self
.DynamicPcdList
:
1955 if Pcd
.Phase
== "PEI":
1956 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1957 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1958 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1961 for Pcd
in self
.DynamicPcdList
:
1962 if Pcd
.Phase
== "DXE":
1963 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1964 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1965 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1968 for Pcd
in self
.DynamicPcdList
:
1969 if Pcd
.Phase
== "DXE":
1970 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1971 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1972 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1975 for Pcd
in self
.NonDynamicPcdList
:
1976 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1978 return self
._PcdTokenNumber
1980 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
1981 def _GetAutoGenObjectList(self
):
1982 self
._ModuleAutoGenList
= []
1983 self
._LibraryAutoGenList
= []
1984 for ModuleFile
in self
.Platform
.Modules
:
1993 if Ma
not in self
._ModuleAutoGenList
:
1994 self
._ModuleAutoGenList
.append(Ma
)
1995 for La
in Ma
.LibraryAutoGenList
:
1996 if La
not in self
._LibraryAutoGenList
:
1997 self
._LibraryAutoGenList
.append(La
)
1998 if Ma
not in La
._ReferenceModules
:
1999 La
._ReferenceModules
.append(Ma
)
2001 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
2002 def _GetModuleAutoGenList(self
):
2003 if self
._ModuleAutoGenList
== None:
2004 self
._GetAutoGenObjectList
()
2005 return self
._ModuleAutoGenList
2007 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
2008 def _GetLibraryAutoGenList(self
):
2009 if self
._LibraryAutoGenList
== None:
2010 self
._GetAutoGenObjectList
()
2011 return self
._LibraryAutoGenList
2013 ## Test if a module is supported by the platform
2015 # An error will be raised directly if the module or its arch is not supported
2016 # by the platform or current configuration
2018 def ValidModule(self
, Module
):
2019 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
2020 or Module
in self
._AsBuildModuleList
2022 ## Resolve the library classes in a module to library instances
2024 # This method will not only resolve library classes but also sort the library
2025 # instances according to the dependency-ship.
2027 # @param Module The module from which the library classes will be resolved
2029 # @retval library_list List of library instances sorted
2031 def ApplyLibraryInstance(self
, Module
):
2032 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
2033 if str(Module
) not in self
.Platform
.Modules
:
2036 ModuleType
= Module
.ModuleType
2038 # for overridding library instances with module specific setting
2039 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2041 # add forced library instances (specified under LibraryClasses sections)
2043 # If a module has a MODULE_TYPE of USER_DEFINED,
2044 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
2046 if Module
.ModuleType
!= SUP_MODULE_USER_DEFINED
:
2047 for LibraryClass
in self
.Platform
.LibraryClasses
.GetKeys():
2048 if LibraryClass
.startswith("NULL") and self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]:
2049 Module
.LibraryClasses
[LibraryClass
] = self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]
2051 # add forced library instances (specified in module overrides)
2052 for LibraryClass
in PlatformModule
.LibraryClasses
:
2053 if LibraryClass
.startswith("NULL"):
2054 Module
.LibraryClasses
[LibraryClass
] = PlatformModule
.LibraryClasses
[LibraryClass
]
2057 LibraryConsumerList
= [Module
]
2059 ConsumedByList
= sdict()
2060 LibraryInstance
= sdict()
2062 EdkLogger
.verbose("")
2063 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2064 while len(LibraryConsumerList
) > 0:
2065 M
= LibraryConsumerList
.pop()
2066 for LibraryClassName
in M
.LibraryClasses
:
2067 if LibraryClassName
not in LibraryInstance
:
2068 # override library instance for this module
2069 if LibraryClassName
in PlatformModule
.LibraryClasses
:
2070 LibraryPath
= PlatformModule
.LibraryClasses
[LibraryClassName
]
2072 LibraryPath
= self
.Platform
.LibraryClasses
[LibraryClassName
, ModuleType
]
2073 if LibraryPath
== None or LibraryPath
== "":
2074 LibraryPath
= M
.LibraryClasses
[LibraryClassName
]
2075 if LibraryPath
== None or LibraryPath
== "":
2076 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
2077 "Instance of library class [%s] is not found" % LibraryClassName
,
2079 ExtraData
="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M
), self
.Arch
, str(Module
)))
2081 LibraryModule
= self
.BuildDatabase
[LibraryPath
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2082 # for those forced library instance (NULL library), add a fake library class
2083 if LibraryClassName
.startswith("NULL"):
2084 LibraryModule
.LibraryClass
.append(LibraryClassObject(LibraryClassName
, [ModuleType
]))
2085 elif LibraryModule
.LibraryClass
== None \
2086 or len(LibraryModule
.LibraryClass
) == 0 \
2087 or (ModuleType
!= 'USER_DEFINED'
2088 and ModuleType
not in LibraryModule
.LibraryClass
[0].SupModList
):
2089 # only USER_DEFINED can link against any library instance despite of its SupModList
2090 EdkLogger
.error("build", OPTION_MISSING
,
2091 "Module type [%s] is not supported by library instance [%s]" \
2092 % (ModuleType
, LibraryPath
), File
=self
.MetaFile
,
2093 ExtraData
="consumed by [%s]" % str(Module
))
2095 LibraryInstance
[LibraryClassName
] = LibraryModule
2096 LibraryConsumerList
.append(LibraryModule
)
2097 EdkLogger
.verbose("\t" + str(LibraryClassName
) + " : " + str(LibraryModule
))
2099 LibraryModule
= LibraryInstance
[LibraryClassName
]
2101 if LibraryModule
== None:
2104 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
2105 Constructor
.append(LibraryModule
)
2107 if LibraryModule
not in ConsumedByList
:
2108 ConsumedByList
[LibraryModule
] = []
2109 # don't add current module itself to consumer list
2111 if M
in ConsumedByList
[LibraryModule
]:
2113 ConsumedByList
[LibraryModule
].append(M
)
2115 # Initialize the sorted output list to the empty set
2117 SortedLibraryList
= []
2119 # Q <- Set of all nodes with no incoming edges
2121 LibraryList
= [] #LibraryInstance.values()
2123 for LibraryClassName
in LibraryInstance
:
2124 M
= LibraryInstance
[LibraryClassName
]
2125 LibraryList
.append(M
)
2126 if ConsumedByList
[M
] == []:
2130 # start the DAG algorithm
2134 while Q
== [] and EdgeRemoved
:
2136 # for each node Item with a Constructor
2137 for Item
in LibraryList
:
2138 if Item
not in Constructor
:
2140 # for each Node without a constructor with an edge e from Item to Node
2141 for Node
in ConsumedByList
[Item
]:
2142 if Node
in Constructor
:
2144 # remove edge e from the graph if Node has no constructor
2145 ConsumedByList
[Item
].remove(Node
)
2147 if ConsumedByList
[Item
] == []:
2148 # insert Item into Q
2153 # DAG is done if there's no more incoming edge for all nodes
2157 # remove node from Q
2160 SortedLibraryList
.append(Node
)
2162 # for each node Item with an edge e from Node to Item do
2163 for Item
in LibraryList
:
2164 if Node
not in ConsumedByList
[Item
]:
2166 # remove edge e from the graph
2167 ConsumedByList
[Item
].remove(Node
)
2169 if ConsumedByList
[Item
] != []:
2171 # insert Item into Q, if Item has no other incoming edges
2175 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
2177 for Item
in LibraryList
:
2178 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
2179 ErrorMessage
= "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]])
2180 EdkLogger
.error("build", BUILD_ERROR
, 'Library [%s] with constructors has a cycle' % str(Item
),
2181 ExtraData
=ErrorMessage
, File
=self
.MetaFile
)
2182 if Item
not in SortedLibraryList
:
2183 SortedLibraryList
.append(Item
)
2186 # Build the list of constructor and destructir names
2187 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
2189 SortedLibraryList
.reverse()
2190 return SortedLibraryList
2193 ## Override PCD setting (type, value, ...)
2195 # @param ToPcd The PCD to be overrided
2196 # @param FromPcd The PCD overrideing from
2198 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
=""):
2200 # in case there's PCDs coming from FDF file, which have no type given.
2201 # at this point, ToPcd.Type has the type found from dependent
2204 TokenCName
= ToPcd
.TokenCName
2205 for PcdItem
in GlobalData
.MixedPcd
:
2206 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2207 TokenCName
= PcdItem
[0]
2210 if GlobalData
.BuildOptionPcd
:
2211 for pcd
in GlobalData
.BuildOptionPcd
:
2212 if (FromPcd
.TokenSpaceGuidCName
, FromPcd
.TokenCName
) == (pcd
[0], pcd
[1]):
2213 FromPcd
.DefaultValue
= pcd
[2]
2215 if ToPcd
.Pending
and FromPcd
.Type
not in [None, '']:
2216 ToPcd
.Type
= FromPcd
.Type
2217 elif (ToPcd
.Type
not in [None, '']) and (FromPcd
.Type
not in [None, ''])\
2218 and (ToPcd
.Type
!= FromPcd
.Type
) and (ToPcd
.Type
in FromPcd
.Type
):
2219 if ToPcd
.Type
.strip() == "DynamicEx":
2220 ToPcd
.Type
= FromPcd
.Type
2221 elif ToPcd
.Type
not in [None, ''] and FromPcd
.Type
not in [None, ''] \
2222 and ToPcd
.Type
!= FromPcd
.Type
:
2223 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2224 ExtraData
="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
2225 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2226 ToPcd
.Type
, Module
, FromPcd
.Type
),
2229 if FromPcd
.MaxDatumSize
not in [None, '']:
2230 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2231 if FromPcd
.DefaultValue
not in [None, '']:
2232 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2233 if FromPcd
.TokenValue
not in [None, '']:
2234 ToPcd
.TokenValue
= FromPcd
.TokenValue
2235 if FromPcd
.MaxDatumSize
not in [None, '']:
2236 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2237 if FromPcd
.DatumType
not in [None, '']:
2238 ToPcd
.DatumType
= FromPcd
.DatumType
2239 if FromPcd
.SkuInfoList
not in [None, '', []]:
2240 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2242 # check the validation of datum
2243 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2245 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2246 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2247 ToPcd
.validateranges
= FromPcd
.validateranges
2248 ToPcd
.validlists
= FromPcd
.validlists
2249 ToPcd
.expressions
= FromPcd
.expressions
2251 if ToPcd
.DatumType
== "VOID*" and ToPcd
.MaxDatumSize
in ['', None]:
2252 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2253 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2254 Value
= ToPcd
.DefaultValue
2255 if Value
in [None, '']:
2256 ToPcd
.MaxDatumSize
= '1'
2257 elif Value
[0] == 'L':
2258 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2259 elif Value
[0] == '{':
2260 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2262 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2264 # apply default SKU for dynamic PCDS if specified one is not available
2265 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_LIST
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_LIST
) \
2266 and ToPcd
.SkuInfoList
in [None, {}, '']:
2267 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2268 SkuName
= self
.Platform
.SkuName
2271 ToPcd
.SkuInfoList
= {
2272 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
], '', '', '', '', '', ToPcd
.DefaultValue
)
2275 ## Apply PCD setting defined platform to a module
2277 # @param Module The module from which the PCD setting will be overrided
2279 # @retval PCD_list The list PCDs with settings from platform
2281 def ApplyPcdSetting(self
, Module
, Pcds
):
2282 # for each PCD in module
2283 for Name
, Guid
in Pcds
:
2284 PcdInModule
= Pcds
[Name
, Guid
]
2285 # find out the PCD setting in platform
2286 if (Name
, Guid
) in self
.Platform
.Pcds
:
2287 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2289 PcdInPlatform
= None
2290 # then override the settings if any
2291 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
)
2292 # resolve the VariableGuid value
2293 for SkuId
in PcdInModule
.SkuInfoList
:
2294 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2295 if Sku
.VariableGuid
== '': continue
2296 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
2297 if Sku
.VariableGuidValue
== None:
2298 PackageList
= "\n\t".join([str(P
) for P
in self
.PackageList
])
2301 RESOURCE_NOT_AVAILABLE
,
2302 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2303 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2304 % (Guid
, Name
, str(Module
)),
2308 # override PCD settings with module specific setting
2309 if Module
in self
.Platform
.Modules
:
2310 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2311 for Key
in PlatformModule
.Pcds
:
2313 self
._OverridePcd
(Pcds
[Key
], PlatformModule
.Pcds
[Key
], Module
)
2314 return Pcds
.values()
2316 ## Resolve library names to library modules
2318 # (for Edk.x modules)
2320 # @param Module The module from which the library names will be resolved
2322 # @retval library_list The list of library modules
2324 def ResolveLibraryReference(self
, Module
):
2325 EdkLogger
.verbose("")
2326 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2327 LibraryConsumerList
= [Module
]
2329 # "CompilerStub" is a must for Edk modules
2330 if Module
.Libraries
:
2331 Module
.Libraries
.append("CompilerStub")
2333 while len(LibraryConsumerList
) > 0:
2334 M
= LibraryConsumerList
.pop()
2335 for LibraryName
in M
.Libraries
:
2336 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2338 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
2339 if LibraryName
.upper() == Key
.upper():
2340 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2343 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2344 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2347 if Library
not in LibraryList
:
2348 LibraryList
.append(Library
)
2349 LibraryConsumerList
.append(Library
)
2350 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2353 ## Calculate the priority value of the build option
2355 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2357 # @retval Value Priority value based on the priority list.
2359 def CalculatePriorityValue(self
, Key
):
2360 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2361 PriorityValue
= 0x11111
2363 PriorityValue
&= 0x01111
2364 if ToolChain
== "*":
2365 PriorityValue
&= 0x10111
2367 PriorityValue
&= 0x11011
2368 if CommandType
== "*":
2369 PriorityValue
&= 0x11101
2371 PriorityValue
&= 0x11110
2373 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2376 ## Expand * in build option key
2378 # @param Options Options to be expanded
2380 # @retval options Options expanded
2382 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2389 # Construct a list contain the build options which need override.
2393 # Key[0] -- tool family
2394 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2396 if (Key
[0] == self
.BuildRuleFamily
and
2397 (ModuleStyle
== None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2398 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2399 if Target
== self
.BuildTarget
or Target
== "*":
2400 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
2401 if Arch
== self
.Arch
or Arch
== "*":
2402 if Options
[Key
].startswith("="):
2403 if OverrideList
.get(Key
[1]) != None:
2404 OverrideList
.pop(Key
[1])
2405 OverrideList
[Key
[1]] = Options
[Key
]
2408 # Use the highest priority value.
2410 if (len(OverrideList
) >= 2):
2411 KeyList
= OverrideList
.keys()
2412 for Index
in range(len(KeyList
)):
2413 NowKey
= KeyList
[Index
]
2414 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2415 for Index1
in range(len(KeyList
) - Index
- 1):
2416 NextKey
= KeyList
[Index1
+ Index
+ 1]
2418 # Compare two Key, if one is included by another, choose the higher priority one
2420 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2421 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2422 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2423 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2424 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2425 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2426 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2427 if Options
.get((self
.BuildRuleFamily
, NextKey
)) != None:
2428 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2430 if Options
.get((self
.BuildRuleFamily
, NowKey
)) != None:
2431 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2434 if ModuleStyle
!= None and len (Key
) > 2:
2435 # Check Module style is EDK or EDKII.
2436 # Only append build option for the matched style module.
2437 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2439 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2442 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2443 # if tool chain family doesn't match, skip it
2444 if Tool
in self
.ToolDefinition
and Family
!= "":
2445 FamilyIsNull
= False
2446 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2447 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2449 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2452 # expand any wildcard
2453 if Target
== "*" or Target
== self
.BuildTarget
:
2454 if Tag
== "*" or Tag
== self
.ToolChain
:
2455 if Arch
== "*" or Arch
== self
.Arch
:
2456 if Tool
not in BuildOptions
:
2457 BuildOptions
[Tool
] = {}
2458 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2459 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2461 # append options for the same tool except PATH
2463 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2465 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2466 # Build Option Family has been checked, which need't to be checked again for family.
2467 if FamilyMatch
or FamilyIsNull
:
2471 if ModuleStyle
!= None and len (Key
) > 2:
2472 # Check Module style is EDK or EDKII.
2473 # Only append build option for the matched style module.
2474 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2476 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2479 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2480 # if tool chain family doesn't match, skip it
2481 if Tool
not in self
.ToolDefinition
or Family
== "":
2483 # option has been added before
2484 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2487 # expand any wildcard
2488 if Target
== "*" or Target
== self
.BuildTarget
:
2489 if Tag
== "*" or Tag
== self
.ToolChain
:
2490 if Arch
== "*" or Arch
== self
.Arch
:
2491 if Tool
not in BuildOptions
:
2492 BuildOptions
[Tool
] = {}
2493 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2494 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2496 # append options for the same tool except PATH
2498 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2500 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2503 ## Append build options in platform to a module
2505 # @param Module The module to which the build options will be appened
2507 # @retval options The options appended with build options in platform
2509 def ApplyBuildOption(self
, Module
):
2510 # Get the different options for the different style module
2511 if Module
.AutoGenVersion
< 0x00010005:
2512 PlatformOptions
= self
.EdkBuildOption
2513 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2515 PlatformOptions
= self
.EdkIIBuildOption
2516 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2517 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2518 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2519 if Module
in self
.Platform
.Modules
:
2520 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2521 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2523 PlatformModuleOptions
= {}
2525 BuildRuleOrder
= None
2526 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2527 for Tool
in Options
:
2528 for Attr
in Options
[Tool
]:
2529 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2530 BuildRuleOrder
= Options
[Tool
][Attr
]
2532 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2533 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2534 self
.ToolDefinition
.keys())
2536 for Tool
in AllTools
:
2537 if Tool
not in BuildOptions
:
2538 BuildOptions
[Tool
] = {}
2540 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2541 if Tool
not in Options
:
2543 for Attr
in Options
[Tool
]:
2544 Value
= Options
[Tool
][Attr
]
2546 # Do not generate it in Makefile
2548 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2550 if Attr
not in BuildOptions
[Tool
]:
2551 BuildOptions
[Tool
][Attr
] = ""
2552 # check if override is indicated
2553 if Value
.startswith('='):
2554 ToolPath
= Value
[1:]
2555 ToolPath
= mws
.handleWsMacro(ToolPath
)
2556 BuildOptions
[Tool
][Attr
] = ToolPath
2558 Value
= mws
.handleWsMacro(Value
)
2560 BuildOptions
[Tool
][Attr
] += " " + Value
2562 BuildOptions
[Tool
][Attr
] = Value
2563 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
!= None:
2565 # Override UNI flag only for EDK module.
2567 if 'BUILD' not in BuildOptions
:
2568 BuildOptions
['BUILD'] = {}
2569 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2570 return BuildOptions
, BuildRuleOrder
2572 Platform
= property(_GetPlatform
)
2573 Name
= property(_GetName
)
2574 Guid
= property(_GetGuid
)
2575 Version
= property(_GetVersion
)
2577 OutputDir
= property(_GetOutputDir
)
2578 BuildDir
= property(_GetBuildDir
)
2579 MakeFileDir
= property(_GetMakeFileDir
)
2580 FdfFile
= property(_GetFdfFile
)
2582 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2583 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2584 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2585 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2586 PackageList
= property(_GetPackageList
)
2588 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2589 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2590 ToolChainFamily
= property(_GetToolChainFamily
)
2591 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2592 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2593 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2594 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2596 BuildCommand
= property(_GetBuildCommand
)
2597 BuildRule
= property(_GetBuildRule
)
2598 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2599 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2600 GenFdsCommand
= property(_GenFdsCommand
)
2602 ## ModuleAutoGen class
2604 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2605 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2606 # to the [depex] section in module's inf file.
2608 class ModuleAutoGen(AutoGen
):
2609 ## Cache the timestamps of metafiles of every module in a class variable
2613 ## The real constructor of ModuleAutoGen
2615 # This method is not supposed to be called by users of ModuleAutoGen. It's
2616 # only used by factory method __new__() to do real initialization work for an
2617 # object of ModuleAutoGen
2619 # @param Workspace EdkIIWorkspaceBuild object
2620 # @param ModuleFile The path of module file
2621 # @param Target Build target (DEBUG, RELEASE)
2622 # @param Toolchain Name of tool chain
2623 # @param Arch The arch the module supports
2624 # @param PlatformFile Platform meta-file
2626 def _Init(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2627 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2628 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2630 self
.Workspace
= Workspace
2631 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2633 self
.MetaFile
= ModuleFile
2634 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2635 # check if this module is employed by active platform
2636 if not self
.PlatformInfo
.ValidModule(self
.MetaFile
):
2637 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2638 % (self
.MetaFile
, Arch
))
2641 self
.SourceDir
= self
.MetaFile
.SubDir
2642 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2644 self
.SourceOverrideDir
= None
2645 # use overrided path defined in DSC file
2646 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2647 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2649 self
.ToolChain
= Toolchain
2650 self
.BuildTarget
= Target
2652 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2653 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2655 self
.IsMakeFileCreated
= False
2656 self
.IsCodeFileCreated
= False
2657 self
.IsAsBuiltInfCreated
= False
2658 self
.DepexGenerated
= False
2660 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2661 self
.BuildRuleOrder
= None
2666 self
._Version
= None
2667 self
._ModuleType
= None
2668 self
._ComponentType
= None
2669 self
._PcdIsDriver
= None
2670 self
._AutoGenVersion
= None
2671 self
._LibraryFlag
= None
2672 self
._CustomMakefile
= None
2675 self
._BuildDir
= None
2676 self
._OutputDir
= None
2677 self
._DebugDir
= None
2678 self
._MakeFileDir
= None
2680 self
._IncludePathList
= None
2681 self
._IncludePathLength
= 0
2682 self
._AutoGenFileList
= None
2683 self
._UnicodeFileList
= None
2684 self
._VfrFileList
= None
2685 self
._IdfFileList
= None
2686 self
._SourceFileList
= None
2687 self
._ObjectFileList
= None
2688 self
._BinaryFileList
= None
2690 self
._DependentPackageList
= None
2691 self
._DependentLibraryList
= None
2692 self
._LibraryAutoGenList
= None
2693 self
._DerivedPackageList
= None
2694 self
._ModulePcdList
= None
2695 self
._LibraryPcdList
= None
2696 self
._PcdComments
= sdict()
2697 self
._GuidList
= None
2698 self
._GuidsUsedByPcd
= None
2699 self
._GuidComments
= sdict()
2700 self
._ProtocolList
= None
2701 self
._ProtocolComments
= sdict()
2702 self
._PpiList
= None
2703 self
._PpiComments
= sdict()
2704 self
._DepexList
= None
2705 self
._DepexExpressionList
= None
2706 self
._BuildOption
= None
2707 self
._BuildOptionIncPathList
= None
2708 self
._BuildTargets
= None
2709 self
._IntroBuildTargetList
= None
2710 self
._FinalBuildTargetList
= None
2711 self
._FileTypes
= None
2712 self
._BuildRules
= None
2714 self
._TimeStampPath
= None
2716 self
.AutoGenDepSet
= set()
2719 ## The Modules referenced to this Library
2720 # Only Library has this attribute
2721 self
._ReferenceModules
= []
2723 ## Store the FixedAtBuild Pcds
2725 self
._FixedAtBuildPcds
= []
2730 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2732 # Get FixedAtBuild Pcds of this Module
2733 def _GetFixedAtBuildPcds(self
):
2734 if self
._FixedAtBuildPcds
:
2735 return self
._FixedAtBuildPcds
2736 for Pcd
in self
.ModulePcdList
:
2737 if Pcd
.Type
!= "FixedAtBuild":
2739 if Pcd
not in self
._FixedAtBuildPcds
:
2740 self
._FixedAtBuildPcds
.append(Pcd
)
2742 return self
._FixedAtBuildPcds
2744 def _GetUniqueBaseName(self
):
2745 BaseName
= self
.Name
2746 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2747 if Module
.MetaFile
== self
.MetaFile
:
2749 if Module
.Name
== self
.Name
:
2750 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2751 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2752 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2753 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2756 # Macros could be used in build_rule.txt (also Makefile)
2757 def _GetMacros(self
):
2758 if self
._Macro
== None:
2759 self
._Macro
= sdict()
2760 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2761 self
._Macro
["MODULE_NAME" ] = self
.Name
2762 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2763 self
._Macro
["MODULE_GUID" ] = self
.Guid
2764 self
._Macro
["MODULE_VERSION" ] = self
.Version
2765 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2766 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2767 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2768 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2769 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2771 self
._Macro
["BASE_NAME" ] = self
.Name
2773 self
._Macro
["ARCH" ] = self
.Arch
2774 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2775 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2776 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2777 self
._Macro
["TARGET" ] = self
.BuildTarget
2779 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2780 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2781 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2782 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2783 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2784 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2785 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2786 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2787 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2788 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2789 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2790 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2791 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2792 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2795 ## Return the module build data object
2796 def _GetModule(self
):
2797 if self
._Module
== None:
2798 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2801 ## Return the module name
2802 def _GetBaseName(self
):
2803 return self
.Module
.BaseName
2805 ## Return the module DxsFile if exist
2806 def _GetDxsFile(self
):
2807 return self
.Module
.DxsFile
2809 ## Return the module SourceOverridePath
2810 def _GetSourceOverridePath(self
):
2811 return self
.Module
.SourceOverridePath
2813 ## Return the module meta-file GUID
2816 # To build same module more than once, the module path with FILE_GUID overridden has
2817 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2818 # in DSC. The overridden GUID can be retrieved from file name
2820 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2822 # Length of GUID is 36
2824 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2825 return self
.Module
.Guid
2827 ## Return the module version
2828 def _GetVersion(self
):
2829 return self
.Module
.Version
2831 ## Return the module type
2832 def _GetModuleType(self
):
2833 return self
.Module
.ModuleType
2835 ## Return the component type (for Edk.x style of module)
2836 def _GetComponentType(self
):
2837 return self
.Module
.ComponentType
2839 ## Return the build type
2840 def _GetBuildType(self
):
2841 return self
.Module
.BuildType
2843 ## Return the PCD_IS_DRIVER setting
2844 def _GetPcdIsDriver(self
):
2845 return self
.Module
.PcdIsDriver
2847 ## Return the autogen version, i.e. module meta-file version
2848 def _GetAutoGenVersion(self
):
2849 return self
.Module
.AutoGenVersion
2851 ## Check if the module is library or not
2852 def _IsLibrary(self
):
2853 if self
._LibraryFlag
== None:
2854 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2855 self
._LibraryFlag
= True
2857 self
._LibraryFlag
= False
2858 return self
._LibraryFlag
2860 ## Check if the module is binary module or not
2861 def _IsBinaryModule(self
):
2862 return self
.Module
.IsBinaryModule
2864 ## Return the directory to store intermediate files of the module
2865 def _GetBuildDir(self
):
2866 if self
._BuildDir
== None:
2867 self
._BuildDir
= path
.join(
2868 self
.PlatformInfo
.BuildDir
,
2871 self
.MetaFile
.BaseName
2873 CreateDirectory(self
._BuildDir
)
2874 return self
._BuildDir
2876 ## Return the directory to store the intermediate object files of the mdoule
2877 def _GetOutputDir(self
):
2878 if self
._OutputDir
== None:
2879 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2880 CreateDirectory(self
._OutputDir
)
2881 return self
._OutputDir
2883 ## Return the directory to store auto-gened source files of the mdoule
2884 def _GetDebugDir(self
):
2885 if self
._DebugDir
== None:
2886 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2887 CreateDirectory(self
._DebugDir
)
2888 return self
._DebugDir
2890 ## Return the path of custom file
2891 def _GetCustomMakefile(self
):
2892 if self
._CustomMakefile
== None:
2893 self
._CustomMakefile
= {}
2894 for Type
in self
.Module
.CustomMakefile
:
2895 if Type
in gMakeTypeMap
:
2896 MakeType
= gMakeTypeMap
[Type
]
2899 if self
.SourceOverrideDir
!= None:
2900 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2901 if not os
.path
.exists(File
):
2902 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2904 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2905 self
._CustomMakefile
[MakeType
] = File
2906 return self
._CustomMakefile
2908 ## Return the directory of the makefile
2910 # @retval string The directory string of module's makefile
2912 def _GetMakeFileDir(self
):
2913 return self
.BuildDir
2915 ## Return build command string
2917 # @retval string Build command string
2919 def _GetBuildCommand(self
):
2920 return self
.PlatformInfo
.BuildCommand
2922 ## Get object list of all packages the module and its dependent libraries belong to
2924 # @retval list The list of package object
2926 def _GetDerivedPackageList(self
):
2928 for M
in [self
.Module
] + self
.DependentLibraryList
:
2929 for Package
in M
.Packages
:
2930 if Package
in PackageList
:
2932 PackageList
.append(Package
)
2935 ## Get the depex string
2937 # @return : a string contain all depex expresion.
2938 def _GetDepexExpresionString(self
):
2941 ## DPX_SOURCE IN Define section.
2942 if self
.Module
.DxsFile
:
2944 for M
in [self
.Module
] + self
.DependentLibraryList
:
2945 Filename
= M
.MetaFile
.Path
2946 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2947 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2948 for DepexExpresion
in DepexExpresionList
:
2949 for key
in DepexExpresion
.keys():
2950 Arch
, ModuleType
= key
2951 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
2952 # the type of build module is USER_DEFINED.
2953 # All different DEPEX section tags would be copied into the As Built INF file
2954 # and there would be separate DEPEX section tags
2955 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2956 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2957 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2959 if Arch
.upper() == TAB_ARCH_COMMON
or \
2960 (Arch
.upper() == self
.Arch
.upper() and \
2961 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2962 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2964 #the type of build module is USER_DEFINED.
2965 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2966 for Depex
in DepexList
:
2967 for key
in Depex
.keys():
2968 DepexStr
+= '[Depex.%s.%s]\n' % key
2969 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
2972 return '[Depex.%s]\n' % self
.Arch
2975 #the type of build module not is USER_DEFINED.
2977 for Depex
in DepexList
:
2982 for D
in Depex
.values():
2983 DepexStr
+= ' '.join([val
for val
in D
])
2984 Index
= DepexStr
.find('END')
2985 if Index
> -1 and Index
== len(DepexStr
) - 3:
2986 DepexStr
= DepexStr
[:-3]
2987 DepexStr
= DepexStr
.strip()
2990 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
2992 return '[Depex.%s]\n' % self
.Arch
2993 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
2995 ## Merge dependency expression
2997 # @retval list The token list of the dependency expression after parsed
2999 def _GetDepexTokenList(self
):
3000 if self
._DepexList
== None:
3001 self
._DepexList
= {}
3002 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3003 return self
._DepexList
3005 self
._DepexList
[self
.ModuleType
] = []
3007 for ModuleType
in self
._DepexList
:
3008 DepexList
= self
._DepexList
[ModuleType
]
3010 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3012 for M
in [self
.Module
] + self
.DependentLibraryList
:
3014 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
3016 DepexList
.append('AND')
3017 DepexList
.append('(')
3019 if DepexList
[-1] == 'END': # no need of a END at this time
3021 DepexList
.append(')')
3024 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
3025 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
3027 if len(DepexList
) > 0:
3028 EdkLogger
.verbose('')
3029 return self
._DepexList
3031 ## Merge dependency expression
3033 # @retval list The token list of the dependency expression after parsed
3035 def _GetDepexExpressionTokenList(self
):
3036 if self
._DepexExpressionList
== None:
3037 self
._DepexExpressionList
= {}
3038 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3039 return self
._DepexExpressionList
3041 self
._DepexExpressionList
[self
.ModuleType
] = ''
3043 for ModuleType
in self
._DepexExpressionList
:
3044 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
3046 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3048 for M
in [self
.Module
] + self
.DependentLibraryList
:
3050 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
3051 if DepexExpressionList
!= '':
3052 DepexExpressionList
+= ' AND '
3053 DepexExpressionList
+= '('
3054 DepexExpressionList
+= D
3055 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
3056 DepexExpressionList
+= ')'
3059 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
3060 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
3062 if len(DepexExpressionList
) > 0:
3063 EdkLogger
.verbose('')
3064 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
3065 return self
._DepexExpressionList
3067 ## Return the list of specification version required for the module
3069 # @retval list The list of specification defined in module file
3071 def _GetSpecification(self
):
3072 return self
.Module
.Specification
3074 ## Tool option for the module build
3076 # @param PlatformInfo The object of PlatformBuildInfo
3077 # @retval dict The dict containing valid options
3079 def _GetModuleBuildOption(self
):
3080 if self
._BuildOption
== None:
3081 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
3082 if self
.BuildRuleOrder
:
3083 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
3084 return self
._BuildOption
3086 ## Get include path list from tool option for the module build
3088 # @retval list The include path list
3090 def _GetBuildOptionIncPathList(self
):
3091 if self
._BuildOptionIncPathList
== None:
3093 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3094 # is the former use /I , the Latter used -I to specify include directories
3096 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
3097 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3098 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
3099 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3102 # New ToolChainFamily, don't known whether there is option to specify include directories
3104 self
._BuildOptionIncPathList
= []
3105 return self
._BuildOptionIncPathList
3107 BuildOptionIncPathList
= []
3108 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3111 FlagOption
= self
.BuildOption
[Tool
][Attr
]
3115 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
3116 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
3119 # RVCT may specify a list of directory seperated by commas
3122 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
3123 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3124 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
3127 # EDK II modules must not reference header files outside of the packages they depend on or
3128 # within the module's directory tree. Report error if violation.
3130 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
3131 for Path
in IncPathList
:
3132 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3133 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3134 EdkLogger
.error("build",
3137 File
=str(self
.MetaFile
))
3140 BuildOptionIncPathList
+= IncPathList
3142 self
._BuildOptionIncPathList
= BuildOptionIncPathList
3144 return self
._BuildOptionIncPathList
3146 ## Return a list of files which can be built from source
3148 # What kind of files can be built is determined by build rules in
3149 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3151 def _GetSourceFileList(self
):
3152 if self
._SourceFileList
== None:
3153 self
._SourceFileList
= []
3154 for F
in self
.Module
.Sources
:
3156 if F
.TagName
not in ("", "*", self
.ToolChain
):
3157 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3158 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
3160 # match tool chain family
3161 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
3164 "The file [%s] must be built by tools of [%s], " \
3165 "but current toolchain family is [%s]" \
3166 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
3169 # add the file path into search path list for file including
3170 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3171 self
.IncludePathList
.insert(0, F
.Dir
)
3172 self
._SourceFileList
.append(F
)
3174 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
3176 for F
in self
._SourceFileList
:
3177 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3178 return self
._SourceFileList
3180 def _MatchBuildRuleOrder(self
, FileList
):
3182 self
._GetModuleBuildOption
()
3183 for SingleFile
in FileList
:
3184 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3185 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3186 if key
in Order_Dict
:
3187 Order_Dict
[key
].append(SingleFile
.Ext
)
3189 Order_Dict
[key
] = [SingleFile
.Ext
]
3192 for F
in Order_Dict
:
3193 if len(Order_Dict
[F
]) > 1:
3194 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3195 for Ext
in Order_Dict
[F
][1:]:
3196 RemoveList
.append(F
+ Ext
)
3198 for item
in RemoveList
:
3199 FileList
.remove(item
)
3203 ## Return the list of unicode files
3204 def _GetUnicodeFileList(self
):
3205 if self
._UnicodeFileList
== None:
3206 if TAB_UNICODE_FILE
in self
.FileTypes
:
3207 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
3209 self
._UnicodeFileList
= []
3210 return self
._UnicodeFileList
3212 ## Return the list of vfr files
3213 def _GetVfrFileList(self
):
3214 if self
._VfrFileList
== None:
3215 if TAB_VFR_FILE
in self
.FileTypes
:
3216 self
._VfrFileList
= self
.FileTypes
[TAB_VFR_FILE
]
3218 self
._VfrFileList
= []
3219 return self
._VfrFileList
3221 ## Return the list of Image Definition files
3222 def _GetIdfFileList(self
):
3223 if self
._IdfFileList
== None:
3224 if TAB_IMAGE_FILE
in self
.FileTypes
:
3225 self
._IdfFileList
= self
.FileTypes
[TAB_IMAGE_FILE
]
3227 self
._IdfFileList
= []
3228 return self
._IdfFileList
3230 ## Return a list of files which can be built from binary
3232 # "Build" binary files are just to copy them to build directory.
3234 # @retval list The list of files which can be built later
3236 def _GetBinaryFiles(self
):
3237 if self
._BinaryFileList
== None:
3238 self
._BinaryFileList
= []
3239 for F
in self
.Module
.Binaries
:
3240 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
3242 self
._BinaryFileList
.append(F
)
3243 self
._ApplyBuildRule
(F
, F
.Type
)
3244 return self
._BinaryFileList
3246 def _GetBuildRules(self
):
3247 if self
._BuildRules
== None:
3249 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3250 for Type
in BuildRuleDatabase
.FileTypeList
:
3251 #first try getting build rule by BuildRuleFamily
3252 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3254 # build type is always module type, but ...
3255 if self
.ModuleType
!= self
.BuildType
:
3256 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3257 #second try getting build rule by ToolChainFamily
3259 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3261 # build type is always module type, but ...
3262 if self
.ModuleType
!= self
.BuildType
:
3263 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3266 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3267 BuildRules
[Type
] = RuleObject
3268 for Ext
in RuleObject
.SourceFileExtList
:
3269 BuildRules
[Ext
] = RuleObject
3270 self
._BuildRules
= BuildRules
3271 return self
._BuildRules
3273 def _ApplyBuildRule(self
, File
, FileType
):
3274 if self
._BuildTargets
== None:
3275 self
._IntroBuildTargetList
= set()
3276 self
._FinalBuildTargetList
= set()
3277 self
._BuildTargets
= {}
3278 self
._FileTypes
= {}
3280 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3281 if not os
.path
.exists(SubDirectory
):
3282 CreateDirectory(SubDirectory
)
3288 # Make sure to get build rule order value
3290 self
._GetModuleBuildOption
()
3292 while Index
< len(SourceList
):
3293 Source
= SourceList
[Index
]
3297 CreateDirectory(Source
.Dir
)
3299 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
3300 # Skip all files that are not binary libraries
3301 if not self
.IsLibrary
:
3303 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3304 elif FileType
in self
.BuildRules
:
3305 RuleObject
= self
.BuildRules
[FileType
]
3306 elif Source
.Ext
in self
.BuildRules
:
3307 RuleObject
= self
.BuildRules
[Source
.Ext
]
3309 # stop at no more rules
3311 self
._FinalBuildTargetList
.add(LastTarget
)
3314 FileType
= RuleObject
.SourceFileType
3315 if FileType
not in self
._FileTypes
:
3316 self
._FileTypes
[FileType
] = set()
3317 self
._FileTypes
[FileType
].add(Source
)
3319 # stop at STATIC_LIBRARY for library
3320 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3322 self
._FinalBuildTargetList
.add(LastTarget
)
3325 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3328 self
._FinalBuildTargetList
.add(LastTarget
)
3330 elif not Target
.Outputs
:
3331 # Only do build for target with outputs
3332 self
._FinalBuildTargetList
.add(Target
)
3334 if FileType
not in self
._BuildTargets
:
3335 self
._BuildTargets
[FileType
] = set()
3336 self
._BuildTargets
[FileType
].add(Target
)
3338 if not Source
.IsBinary
and Source
== File
:
3339 self
._IntroBuildTargetList
.add(Target
)
3341 # to avoid cyclic rule
3342 if FileType
in RuleChain
:
3345 RuleChain
.append(FileType
)
3346 SourceList
.extend(Target
.Outputs
)
3348 FileType
= TAB_UNKNOWN_FILE
3350 def _GetTargets(self
):
3351 if self
._BuildTargets
== None:
3352 self
._IntroBuildTargetList
= set()
3353 self
._FinalBuildTargetList
= set()
3354 self
._BuildTargets
= {}
3355 self
._FileTypes
= {}
3357 #TRICK: call _GetSourceFileList to apply build rule for source files
3358 if self
.SourceFileList
:
3361 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3362 if self
.BinaryFileList
:
3365 return self
._BuildTargets
3367 def _GetIntroTargetList(self
):
3369 return self
._IntroBuildTargetList
3371 def _GetFinalTargetList(self
):
3373 return self
._FinalBuildTargetList
3375 def _GetFileTypes(self
):
3377 return self
._FileTypes
3379 ## Get the list of package object the module depends on
3381 # @retval list The package object list
3383 def _GetDependentPackageList(self
):
3384 return self
.Module
.Packages
3386 ## Return the list of auto-generated code file
3388 # @retval list The list of auto-generated file
3390 def _GetAutoGenFileList(self
):
3391 UniStringAutoGenC
= True
3392 IdfStringAutoGenC
= True
3393 UniStringBinBuffer
= StringIO()
3394 IdfGenBinBuffer
= StringIO()
3395 if self
.BuildType
== 'UEFI_HII':
3396 UniStringAutoGenC
= False
3397 IdfStringAutoGenC
= False
3398 if self
._AutoGenFileList
== None:
3399 self
._AutoGenFileList
= {}
3400 AutoGenC
= TemplateString()
3401 AutoGenH
= TemplateString()
3402 StringH
= TemplateString()
3403 StringIdf
= TemplateString()
3404 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
, StringIdf
, IdfStringAutoGenC
, IdfGenBinBuffer
)
3406 # AutoGen.c is generated if there are library classes in inf, or there are object files
3408 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3409 or TAB_OBJECT_FILE
in self
.FileTypes
):
3410 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3411 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3412 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3413 if str(AutoGenH
) != "":
3414 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3415 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3416 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3417 if str(StringH
) != "":
3418 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3419 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3420 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3421 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
3422 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3423 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3424 AutoFile
.IsBinary
= True
3425 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3426 if UniStringBinBuffer
!= None:
3427 UniStringBinBuffer
.close()
3428 if str(StringIdf
) != "":
3429 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3430 self
._AutoGenFileList
[AutoFile
] = str(StringIdf
)
3431 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3432 if IdfGenBinBuffer
!= None and IdfGenBinBuffer
.getvalue() != "":
3433 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3434 self
._AutoGenFileList
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3435 AutoFile
.IsBinary
= True
3436 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3437 if IdfGenBinBuffer
!= None:
3438 IdfGenBinBuffer
.close()
3439 return self
._AutoGenFileList
3441 ## Return the list of library modules explicitly or implicityly used by this module
3442 def _GetLibraryList(self
):
3443 if self
._DependentLibraryList
== None:
3444 # only merge library classes and PCD for non-library module
3446 self
._DependentLibraryList
= []
3448 if self
.AutoGenVersion
< 0x00010005:
3449 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3451 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3452 return self
._DependentLibraryList
3455 def UpdateComments(Recver
, Src
):
3457 if Key
not in Recver
:
3459 Recver
[Key
].extend(Src
[Key
])
3460 ## Get the list of PCDs from current module
3462 # @retval list The list of PCD
3464 def _GetModulePcdList(self
):
3465 if self
._ModulePcdList
== None:
3466 # apply PCD settings from platform
3467 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3468 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3469 return self
._ModulePcdList
3471 ## Get the list of PCDs from dependent libraries
3473 # @retval list The list of PCD
3475 def _GetLibraryPcdList(self
):
3476 if self
._LibraryPcdList
== None:
3478 if not self
.IsLibrary
:
3479 # get PCDs from dependent libraries
3480 for Library
in self
.DependentLibraryList
:
3481 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3482 for Key
in Library
.Pcds
:
3483 # skip duplicated PCDs
3484 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3486 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3487 # apply PCD settings from platform
3488 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3490 self
._LibraryPcdList
= []
3491 return self
._LibraryPcdList
3493 ## Get the GUID value mapping
3495 # @retval dict The mapping between GUID cname and its value
3497 def _GetGuidList(self
):
3498 if self
._GuidList
== None:
3499 self
._GuidList
= sdict()
3500 self
._GuidList
.update(self
.Module
.Guids
)
3501 for Library
in self
.DependentLibraryList
:
3502 self
._GuidList
.update(Library
.Guids
)
3503 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3504 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3505 return self
._GuidList
3507 def GetGuidsUsedByPcd(self
):
3508 if self
._GuidsUsedByPcd
== None:
3509 self
._GuidsUsedByPcd
= sdict()
3510 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3511 for Library
in self
.DependentLibraryList
:
3512 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3513 return self
._GuidsUsedByPcd
3514 ## Get the protocol value mapping
3516 # @retval dict The mapping between protocol cname and its value
3518 def _GetProtocolList(self
):
3519 if self
._ProtocolList
== None:
3520 self
._ProtocolList
= sdict()
3521 self
._ProtocolList
.update(self
.Module
.Protocols
)
3522 for Library
in self
.DependentLibraryList
:
3523 self
._ProtocolList
.update(Library
.Protocols
)
3524 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3525 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3526 return self
._ProtocolList
3528 ## Get the PPI value mapping
3530 # @retval dict The mapping between PPI cname and its value
3532 def _GetPpiList(self
):
3533 if self
._PpiList
== None:
3534 self
._PpiList
= sdict()
3535 self
._PpiList
.update(self
.Module
.Ppis
)
3536 for Library
in self
.DependentLibraryList
:
3537 self
._PpiList
.update(Library
.Ppis
)
3538 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3539 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3540 return self
._PpiList
3542 ## Get the list of include search path
3544 # @retval list The list path
3546 def _GetIncludePathList(self
):
3547 if self
._IncludePathList
== None:
3548 self
._IncludePathList
= []
3549 if self
.AutoGenVersion
< 0x00010005:
3550 for Inc
in self
.Module
.Includes
:
3551 if Inc
not in self
._IncludePathList
:
3552 self
._IncludePathList
.append(Inc
)
3554 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3555 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3556 self
._IncludePathList
.append(Inc
)
3557 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3558 self
._IncludePathList
.append(self
.DebugDir
)
3560 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3561 self
._IncludePathList
.append(self
.DebugDir
)
3563 for Package
in self
.Module
.Packages
:
3564 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3565 if PackageDir
not in self
._IncludePathList
:
3566 self
._IncludePathList
.append(PackageDir
)
3567 IncludesList
= Package
.Includes
3568 if Package
._PrivateIncludes
:
3569 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3570 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3571 for Inc
in IncludesList
:
3572 if Inc
not in self
._IncludePathList
:
3573 self
._IncludePathList
.append(str(Inc
))
3574 return self
._IncludePathList
3576 def _GetIncludePathLength(self
):
3577 self
._IncludePathLength
= 0
3578 if self
._IncludePathList
:
3579 for inc
in self
._IncludePathList
:
3580 self
._IncludePathLength
+= len(' ' + inc
)
3581 return self
._IncludePathLength
3583 ## Get HII EX PCDs which maybe used by VFR
3585 # efivarstore used by VFR may relate with HII EX PCDs
3586 # Get the variable name and GUID from efivarstore and HII EX PCD
3587 # List the HII EX PCDs in As Built INF if both name and GUID match.
3589 # @retval list HII EX PCDs
3591 def _GetPcdsMaybeUsedByVfr(self
):
3592 if not self
.SourceFileList
:
3596 for SrcFile
in self
.SourceFileList
:
3597 if SrcFile
.Ext
.lower() != '.vfr':
3599 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3600 if not os
.path
.exists(Vfri
):
3602 VfriFile
= open(Vfri
, 'r')
3603 Content
= VfriFile
.read()
3605 Pos
= Content
.find('efivarstore')
3608 # Make sure 'efivarstore' is the start of efivarstore statement
3609 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3612 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3614 if Index
>= 0 and Content
[Index
] != ';':
3615 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3618 # 'efivarstore' must be followed by name and guid
3620 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3623 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3626 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3627 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3628 Pos
= Content
.find('efivarstore', Name
.end())
3632 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3633 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3635 for SkuName
in Pcd
.SkuInfoList
:
3636 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3637 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3638 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3641 Guid
= GuidStructureStringToGuidString(Value
)
3642 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3643 HiiExPcds
.append(Pcd
)
3648 def _GenOffsetBin(self
):
3650 for SourceFile
in self
.Module
.Sources
:
3651 if SourceFile
.Type
.upper() == ".VFR" :
3653 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3655 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3656 if SourceFile
.Type
.upper() == ".UNI" :
3658 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3660 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3662 if len(VfrUniBaseName
) == 0:
3664 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3665 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3666 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3667 if not VfrUniOffsetList
:
3670 OutputName
= '%sOffset.bin' % self
.Name
3671 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3674 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3676 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3678 # Use a instance of StringIO to cache data
3679 fStringIO
= StringIO('')
3681 for Item
in VfrUniOffsetList
:
3682 if (Item
[0].find("Strings") != -1):
3684 # UNI offset in image.
3686 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3688 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3689 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3690 fStringIO
.write(''.join(UniGuid
))
3691 UniValue
= pack ('Q', int (Item
[1], 16))
3692 fStringIO
.write (UniValue
)
3695 # VFR binary offset in image.
3697 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3699 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3700 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3701 fStringIO
.write(''.join(VfrGuid
))
3703 VfrValue
= pack ('Q', int (Item
[1], 16))
3704 fStringIO
.write (VfrValue
)
3706 # write data into file.
3709 fInputfile
.write (fStringIO
.getvalue())
3711 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3712 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3718 ## Create AsBuilt INF file the module
3720 def CreateAsBuiltInf(self
):
3721 if self
.IsAsBuiltInfCreated
:
3724 # Skip the following code for EDK I inf
3725 if self
.AutoGenVersion
< 0x00010005:
3728 # Skip the following code for libraries
3732 # Skip the following code for modules with no source files
3733 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3736 # Skip the following code for modules without any binary files
3737 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3740 ### TODO: How to handles mixed source and binary modules
3742 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3743 # Also find all packages that the DynamicEx PCDs depend on
3748 PcdTokenSpaceList
= []
3749 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3750 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3751 PatchablePcds
+= [Pcd
]
3752 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3753 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3756 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3757 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3758 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3760 GuidList
.update(self
.GuidList
)
3761 for TokenSpace
in self
.GetGuidsUsedByPcd():
3762 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3763 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3764 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3765 GuidList
.pop(TokenSpace
)
3766 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3767 for Package
in self
.DerivedPackageList
:
3768 if Package
in Packages
:
3770 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3772 for Index
in range(len(BeChecked
)):
3773 for Item
in CheckList
[Index
]:
3774 if Item
in BeChecked
[Index
]:
3775 Packages
+= [Package
]
3780 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3781 for Pkg
in self
.PlatformInfo
.PackageList
:
3784 for VfrPcd
in VfrPcds
:
3785 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3786 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3790 ModuleType
= self
.ModuleType
3791 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3792 ModuleType
= 'DXE_DRIVER'
3795 if self
.PcdIsDriver
!= '':
3796 DriverType
= self
.PcdIsDriver
3799 MDefs
= self
.Module
.Defines
3802 'module_name' : self
.Name
,
3803 'module_guid' : Guid
,
3804 'module_module_type' : ModuleType
,
3805 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3806 'pcd_is_driver_string' : [],
3807 'module_uefi_specification_version' : [],
3808 'module_pi_specification_version' : [],
3809 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3810 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3811 'module_constructor' : self
.Module
.ConstructorList
,
3812 'module_destructor' : self
.Module
.DestructorList
,
3813 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3814 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3815 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3816 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3817 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3818 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3819 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3820 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3821 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3822 'module_arch' : self
.Arch
,
3823 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3825 'patchablepcd_item' : [],
3827 'protocol_item' : [],
3831 'libraryclasses_item' : []
3834 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3835 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3837 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3840 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3842 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3843 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3844 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3845 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3847 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3849 for Item
in self
.CodaTargetList
:
3850 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3851 if Item
.Target
.Ext
.lower() == '.aml':
3852 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3853 elif Item
.Target
.Ext
.lower() == '.acpi':
3854 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3855 elif Item
.Target
.Ext
.lower() == '.efi':
3856 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3858 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3859 if self
.DepexGenerated
:
3860 if self
.ModuleType
in ['PEIM']:
3861 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3862 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3863 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3864 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3865 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3867 Bin
= self
._GenOffsetBin
()
3869 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3871 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3873 if File
.lower().endswith('.pdb'):
3874 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3875 HeaderComments
= self
.Module
.HeaderComments
3877 for Index
in range(len(HeaderComments
)):
3878 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3879 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3882 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3883 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3886 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3887 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3888 (GuidList
, self
._GuidComments
, 'guid_item')
3890 for Item
in GenList
:
3891 for CName
in Item
[0]:
3893 if CName
in Item
[1]:
3894 Comments
= '\n '.join(Item
[1][CName
])
3897 Entry
= Comments
+ '\n ' + CName
3898 AsBuiltInfDict
[Item
[2]].append(Entry
)
3899 PatchList
= parsePcdInfoFromMapFile(
3900 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3901 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3904 for Pcd
in PatchablePcds
:
3905 TokenCName
= Pcd
.TokenCName
3906 for PcdItem
in GlobalData
.MixedPcd
:
3907 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3908 TokenCName
= PcdItem
[0]
3910 for PatchPcd
in PatchList
:
3911 if TokenCName
== PatchPcd
[0]:
3916 if Pcd
.DatumType
== 'BOOLEAN':
3917 BoolValue
= Pcd
.DefaultValue
.upper()
3918 if BoolValue
== 'TRUE':
3919 Pcd
.DefaultValue
= '1'
3920 elif BoolValue
== 'FALSE':
3921 Pcd
.DefaultValue
= '0'
3923 if Pcd
.DatumType
!= 'VOID*':
3924 HexFormat
= '0x%02x'
3925 if Pcd
.DatumType
== 'UINT16':
3926 HexFormat
= '0x%04x'
3927 elif Pcd
.DatumType
== 'UINT32':
3928 HexFormat
= '0x%08x'
3929 elif Pcd
.DatumType
== 'UINT64':
3930 HexFormat
= '0x%016x'
3931 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3933 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
3934 EdkLogger
.error("build", AUTOGEN_ERROR
,
3935 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3937 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3938 PcdValue
= Pcd
.DefaultValue
3939 if PcdValue
[0] != '{':
3941 if PcdValue
[0] == 'L':
3943 PcdValue
= PcdValue
.lstrip('L')
3944 PcdValue
= eval(PcdValue
)
3946 for Index
in range(0, len(PcdValue
)):
3948 CharVal
= ord(PcdValue
[Index
])
3949 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3950 + '0x%02x' % (CharVal
>> 8) + ', '
3952 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3955 Padding
= Padding
* 2
3956 ArraySize
= ArraySize
/ 2
3957 if ArraySize
< (len(PcdValue
) + 1):
3958 EdkLogger
.error("build", AUTOGEN_ERROR
,
3959 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3961 if ArraySize
> len(PcdValue
) + 1:
3962 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3963 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3964 elif len(PcdValue
.split(',')) <= ArraySize
:
3965 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3968 EdkLogger
.error("build", AUTOGEN_ERROR
,
3969 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3971 PcdItem
= '%s.%s|%s|0x%X' % \
3972 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
3974 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3975 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
3977 PcdItem
= PcdComments
+ '\n ' + PcdItem
3978 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
3981 for Pcd
in Pcds
+ VfrPcds
:
3986 TokenCName
= Pcd
.TokenCName
3987 for PcdItem
in GlobalData
.MixedPcd
:
3988 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3989 TokenCName
= PcdItem
[0]
3991 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
3992 for SkuName
in Pcd
.SkuInfoList
:
3993 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3994 SkuId
= SkuInfo
.SkuId
3995 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
3999 # Don't generate duplicated HII PCD
4001 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
4004 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
4005 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4006 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
4010 for Index
, Comment
in enumerate(PcdCommentList
):
4011 for Usage
in UsageList
:
4012 if Comment
.find(Usage
) != -1:
4016 if UsageIndex
!= -1:
4017 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
4019 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
4020 PcdComments
= '\n '.join(PcdCommentList
)
4021 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
4023 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
4024 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
4025 for Item
in self
.BuildOption
:
4026 if 'FLAGS' in self
.BuildOption
[Item
]:
4027 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
4029 # Generated LibraryClasses section in comments.
4030 for Library
in self
.LibraryAutoGenList
:
4031 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
4033 # Generated depex expression section in comments.
4034 AsBuiltInfDict
['depexsection_item'] = ''
4035 DepexExpresion
= self
._GetDepexExpresionString
()
4037 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
4039 AsBuiltInf
= TemplateString()
4040 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
4042 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
4044 self
.IsAsBuiltInfCreated
= True
4046 ## Create makefile for the module and its dependent libraries
4048 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
4049 # dependent libraries will be created
4051 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
4052 # Ignore generating makefile when it is a binary module
4053 if self
.IsBinaryModule
:
4056 if self
.IsMakeFileCreated
:
4061 if not self
.IsLibrary
and CreateLibraryMakeFile
:
4062 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4063 LibraryAutoGen
.CreateMakeFile()
4065 if len(self
.CustomMakefile
) == 0:
4066 Makefile
= GenMake
.ModuleMakefile(self
)
4068 Makefile
= GenMake
.CustomMakefile(self
)
4069 if Makefile
.Generate():
4070 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
4071 (self
.Name
, self
.Arch
))
4073 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
4074 (self
.Name
, self
.Arch
))
4076 self
.CreateTimeStamp(Makefile
)
4077 self
.IsMakeFileCreated
= True
4079 def CopyBinaryFiles(self
):
4080 for File
in self
.Module
.Binaries
:
4082 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4083 CopyLongFilePath(SrcPath
, DstPath
)
4084 ## Create autogen code for the module and its dependent libraries
4086 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4087 # dependent libraries will be created
4089 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4090 if self
.IsCodeFileCreated
:
4095 # Need to generate PcdDatabase even PcdDriver is binarymodule
4096 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4097 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4099 if self
.IsBinaryModule
:
4101 self
.CopyBinaryFiles()
4104 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4105 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4106 LibraryAutoGen
.CreateCodeFile()
4109 IgoredAutoGenList
= []
4111 for File
in self
.AutoGenFileList
:
4112 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4113 #Ignore Edk AutoGen.c
4114 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
4117 AutoGenList
.append(str(File
))
4119 IgoredAutoGenList
.append(str(File
))
4121 # Skip the following code for EDK I inf
4122 if self
.AutoGenVersion
< 0x00010005:
4125 for ModuleType
in self
.DepexList
:
4126 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
4127 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
4130 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4131 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4133 if len(Dpx
.PostfixNotation
) <> 0:
4134 self
.DepexGenerated
= True
4136 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4137 AutoGenList
.append(str(DpxFile
))
4139 IgoredAutoGenList
.append(str(DpxFile
))
4141 if IgoredAutoGenList
== []:
4142 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4143 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4144 elif AutoGenList
== []:
4145 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4146 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4148 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4149 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4151 self
.IsCodeFileCreated
= True
4154 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4155 def _GetLibraryAutoGenList(self
):
4156 if self
._LibraryAutoGenList
== None:
4157 self
._LibraryAutoGenList
= []
4158 for Library
in self
.DependentLibraryList
:
4165 self
.PlatformInfo
.MetaFile
4167 if La
not in self
._LibraryAutoGenList
:
4168 self
._LibraryAutoGenList
.append(La
)
4169 for Lib
in La
.CodaTargetList
:
4170 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4171 return self
._LibraryAutoGenList
4173 ## Decide whether we can skip the ModuleAutoGen process
4174 # If any source file is newer than the modeule than we cannot skip
4177 if not os
.path
.exists(self
.GetTimeStampPath()):
4179 #last creation time of the module
4180 DstTimeStamp
= os
.stat(self
.GetTimeStampPath())[8]
4182 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4183 if SrcTimeStamp
> DstTimeStamp
:
4186 with
open(self
.GetTimeStampPath(),'r') as f
:
4188 source
= source
.rstrip('\n')
4189 if source
not in ModuleAutoGen
.TimeDict
:
4190 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4191 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4195 def GetTimeStampPath(self
):
4196 if self
._TimeStampPath
== None:
4197 self
._TimeStampPath
= os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')
4198 return self
._TimeStampPath
4199 def CreateTimeStamp(self
, Makefile
):
4203 FileSet
.add (self
.MetaFile
.Path
)
4205 for SourceFile
in self
.Module
.Sources
:
4206 FileSet
.add (SourceFile
.Path
)
4208 for Lib
in self
.DependentLibraryList
:
4209 FileSet
.add (Lib
.MetaFile
.Path
)
4211 for f
in self
.AutoGenDepSet
:
4212 FileSet
.add (f
.Path
)
4214 if os
.path
.exists (self
.GetTimeStampPath()):
4215 os
.remove (self
.GetTimeStampPath())
4216 with
open(self
.GetTimeStampPath(), 'w+') as file:
4220 Module
= property(_GetModule
)
4221 Name
= property(_GetBaseName
)
4222 Guid
= property(_GetGuid
)
4223 Version
= property(_GetVersion
)
4224 ModuleType
= property(_GetModuleType
)
4225 ComponentType
= property(_GetComponentType
)
4226 BuildType
= property(_GetBuildType
)
4227 PcdIsDriver
= property(_GetPcdIsDriver
)
4228 AutoGenVersion
= property(_GetAutoGenVersion
)
4229 Macros
= property(_GetMacros
)
4230 Specification
= property(_GetSpecification
)
4232 IsLibrary
= property(_IsLibrary
)
4233 IsBinaryModule
= property(_IsBinaryModule
)
4234 BuildDir
= property(_GetBuildDir
)
4235 OutputDir
= property(_GetOutputDir
)
4236 DebugDir
= property(_GetDebugDir
)
4237 MakeFileDir
= property(_GetMakeFileDir
)
4238 CustomMakefile
= property(_GetCustomMakefile
)
4240 IncludePathList
= property(_GetIncludePathList
)
4241 IncludePathLength
= property(_GetIncludePathLength
)
4242 AutoGenFileList
= property(_GetAutoGenFileList
)
4243 UnicodeFileList
= property(_GetUnicodeFileList
)
4244 VfrFileList
= property(_GetVfrFileList
)
4245 SourceFileList
= property(_GetSourceFileList
)
4246 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
4247 Targets
= property(_GetTargets
)
4248 IntroTargetList
= property(_GetIntroTargetList
)
4249 CodaTargetList
= property(_GetFinalTargetList
)
4250 FileTypes
= property(_GetFileTypes
)
4251 BuildRules
= property(_GetBuildRules
)
4252 IdfFileList
= property(_GetIdfFileList
)
4254 DependentPackageList
= property(_GetDependentPackageList
)
4255 DependentLibraryList
= property(_GetLibraryList
)
4256 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
4257 DerivedPackageList
= property(_GetDerivedPackageList
)
4259 ModulePcdList
= property(_GetModulePcdList
)
4260 LibraryPcdList
= property(_GetLibraryPcdList
)
4261 GuidList
= property(_GetGuidList
)
4262 ProtocolList
= property(_GetProtocolList
)
4263 PpiList
= property(_GetPpiList
)
4264 DepexList
= property(_GetDepexTokenList
)
4265 DxsFile
= property(_GetDxsFile
)
4266 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
4267 BuildOption
= property(_GetModuleBuildOption
)
4268 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
4269 BuildCommand
= property(_GetBuildCommand
)
4271 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
4273 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4274 if __name__
== '__main__':