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}
146 ${userextension_tianocore_item}
150 [BuildOptions.${module_arch}]
152 ## ${flags_item}${END}
155 ## Base class for AutoGen
157 # This class just implements the cache mechanism of AutoGen objects.
159 class AutoGen(object):
160 # database to maintain the objects of xxxAutoGen
161 _CACHE_
= {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}
165 # @param Class class object of real AutoGen class
166 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
167 # @param Workspace Workspace directory or WorkspaceAutoGen object
168 # @param MetaFile The path of meta file
169 # @param Target Build target
170 # @param Toolchain Tool chain name
171 # @param Arch Target arch
172 # @param *args The specific class related parameters
173 # @param **kwargs The specific class related dict parameters
175 def __new__(Class
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
176 # check if the object has been created
177 Key
= (Target
, Toolchain
)
178 if Key
not in Class
._CACHE
_ or Arch
not in Class
._CACHE
_[Key
] \
179 or MetaFile
not in Class
._CACHE
_[Key
][Arch
]:
180 AutoGenObject
= super(AutoGen
, Class
).__new
__(Class
)
181 # call real constructor
182 if not AutoGenObject
._Init
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
184 if Key
not in Class
._CACHE
_:
185 Class
._CACHE
_[Key
] = {}
186 if Arch
not in Class
._CACHE
_[Key
]:
187 Class
._CACHE
_[Key
][Arch
] = {}
188 Class
._CACHE
_[Key
][Arch
][MetaFile
] = AutoGenObject
190 AutoGenObject
= Class
._CACHE
_[Key
][Arch
][MetaFile
]
196 # The file path of platform file will be used to represent hash value of this object
198 # @retval int Hash value of the file path of platform file
201 return hash(self
.MetaFile
)
205 # The file path of platform file will be used to represent this object
207 # @retval string String of platform file path
210 return str(self
.MetaFile
)
213 def __eq__(self
, Other
):
214 return Other
and self
.MetaFile
== Other
216 ## Workspace AutoGen class
218 # This class is used mainly to control the whole platform build for different
219 # architecture. This class will generate top level makefile.
221 class WorkspaceAutoGen(AutoGen
):
222 ## Real constructor of WorkspaceAutoGen
224 # This method behaves the same as __init__ except that it needs explicit invoke
225 # (in super class's __new__ method)
227 # @param WorkspaceDir Root directory of workspace
228 # @param ActivePlatform Meta-file of active platform
229 # @param Target Build target
230 # @param Toolchain Tool chain name
231 # @param ArchList List of architecture of current build
232 # @param MetaFileDb Database containing meta-files
233 # @param BuildConfig Configuration of build
234 # @param ToolDefinition Tool chain definitions
235 # @param FlashDefinitionFile File of flash definition
236 # @param Fds FD list to be generated
237 # @param Fvs FV list to be generated
238 # @param Caps Capsule list to be generated
239 # @param SkuId SKU id from command line
241 def _Init(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
242 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
243 Progress
=None, BuildModule
=None):
250 self
.BuildDatabase
= MetaFileDb
251 self
.MetaFile
= ActivePlatform
252 self
.WorkspaceDir
= WorkspaceDir
253 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, 'COMMON', Target
, Toolchain
]
254 GlobalData
.gActivePlatform
= self
.Platform
255 self
.BuildTarget
= Target
256 self
.ToolChain
= Toolchain
257 self
.ArchList
= ArchList
259 self
.UniFlag
= UniFlag
261 self
.TargetTxt
= BuildConfig
262 self
.ToolDef
= ToolDefinition
263 self
.FdfFile
= FlashDefinitionFile
264 self
.FdTargetList
= Fds
265 self
.FvTargetList
= Fvs
266 self
.CapTargetList
= Caps
267 self
.AutoGenObjectList
= []
269 # there's many relative directory operations, so ...
270 os
.chdir(self
.WorkspaceDir
)
275 if not self
.ArchList
:
276 ArchList
= set(self
.Platform
.SupArchList
)
278 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
280 EdkLogger
.error("build", PARAMETER_INVALID
,
281 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
282 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
283 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
284 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
285 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
286 self
.ArchList
= tuple(ArchList
)
288 # Validate build target
289 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
290 EdkLogger
.error("build", PARAMETER_INVALID
,
291 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
292 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
295 # parse FDF file to get PCDs in it, if any
297 self
.FdfFile
= self
.Platform
.FlashDefinition
301 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
302 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
303 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
305 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
307 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
310 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
312 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
315 Progress
.Start("\nProcessing meta-data")
319 # Mark now build in AutoGen Phase
321 GlobalData
.gAutoGenPhase
= True
322 Fdf
= FdfParser(self
.FdfFile
.Path
)
324 GlobalData
.gFdfParser
= Fdf
325 GlobalData
.gAutoGenPhase
= False
326 PcdSet
= Fdf
.Profile
.PcdDict
327 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
328 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
329 for FdRegion
in FdDict
.RegionList
:
330 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
331 if int(FdRegion
.Offset
) % 8 != 0:
332 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
333 ModuleList
= Fdf
.Profile
.InfList
334 self
.FdfProfile
= Fdf
.Profile
335 for fvname
in self
.FvTargetList
:
336 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
337 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
338 "No such an FV in FDF file: %s" % fvname
)
340 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
341 # but the path (self.MetaFile.Path) is the real path
342 for key
in self
.FdfProfile
.InfDict
:
346 for Arch
in self
.ArchList
:
347 Platform_cache
[Arch
] = self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
348 MetaFile_cache
[Arch
] = []
349 for Pkey
in Platform_cache
[Arch
].Modules
.keys():
350 MetaFile_cache
[Arch
].append(Platform_cache
[Arch
].Modules
[Pkey
].MetaFile
)
351 for Inf
in self
.FdfProfile
.InfDict
[key
]:
352 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
353 for Arch
in self
.ArchList
:
354 if ModuleFile
in MetaFile_cache
[Arch
]:
357 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
358 if not ModuleData
.IsBinaryModule
:
359 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
362 for Arch
in self
.ArchList
:
364 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
366 for Pkey
in Platform
.Modules
.keys():
367 MetaFileList
.append(Platform
.Modules
[Pkey
].MetaFile
)
368 for Inf
in self
.FdfProfile
.InfDict
[key
]:
369 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
370 if ModuleFile
in MetaFileList
:
372 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
373 if not ModuleData
.IsBinaryModule
:
374 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
379 self
.FdfProfile
= None
380 if self
.FdTargetList
:
381 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
382 self
.FdTargetList
= []
383 if self
.FvTargetList
:
384 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
385 self
.FvTargetList
= []
386 if self
.CapTargetList
:
387 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
388 self
.CapTargetList
= []
390 # apply SKU and inject PCDs from Flash Definition file
391 for Arch
in self
.ArchList
:
392 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
396 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
397 if GlobalData
.BuildOptionPcd
:
398 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
399 if type(pcd
) is tuple:
401 (pcdname
, pcdvalue
) = pcd
.split('=')
403 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
405 (TokenSpaceGuidCName
, TokenCName
) = pcdname
.split('.')
409 TokenSpaceGuidCName
= ''
410 HasTokenSpace
= False
411 TokenSpaceGuidCNameList
= []
415 for package
in PGen
.PackageList
:
416 for key
in package
.Pcds
:
417 PcdItem
= package
.Pcds
[key
]
419 if (PcdItem
.TokenCName
, PcdItem
.TokenSpaceGuidCName
) == (TokenCName
, TokenSpaceGuidCName
):
420 PcdDatumType
= PcdItem
.DatumType
421 NewValue
= BuildOptionPcdValueFormat(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
424 if PcdItem
.TokenCName
== TokenCName
:
425 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
426 if len (TokenSpaceGuidCNameList
) < 1:
427 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
428 PcdDatumType
= PcdItem
.DatumType
429 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
430 NewValue
= BuildOptionPcdValueFormat(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
436 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
439 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, NewValue
)
443 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, TokenCName
))
445 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (TokenCName
))
447 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
448 if BuildData
.Arch
!= Arch
:
450 if BuildData
.MetaFile
.Ext
== '.dec':
452 for key
in BuildData
.Pcds
:
453 PcdItem
= BuildData
.Pcds
[key
]
454 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
):
455 PcdItem
.DefaultValue
= NewValue
457 if (TokenCName
, TokenSpaceGuidCName
) in PcdSet
:
458 PcdSet
[(TokenCName
, TokenSpaceGuidCName
)] = NewValue
460 SourcePcdDict
= {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}
461 BinaryPcdDict
= {'DynamicEx':[], 'PatchableInModule':[]}
462 SourcePcdDict_Keys
= SourcePcdDict
.keys()
463 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
465 # generate the SourcePcdDict and BinaryPcdDict
466 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
467 if BuildData
.Arch
!= Arch
:
469 if BuildData
.MetaFile
.Ext
== '.inf':
470 for key
in BuildData
.Pcds
:
471 if BuildData
.Pcds
[key
].Pending
:
472 if key
in Platform
.Pcds
:
473 PcdInPlatform
= Platform
.Pcds
[key
]
474 if PcdInPlatform
.Type
not in [None, '']:
475 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
477 if BuildData
.MetaFile
in Platform
.Modules
:
478 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
479 if key
in PlatformModule
.Pcds
:
480 PcdInPlatform
= PlatformModule
.Pcds
[key
]
481 if PcdInPlatform
.Type
not in [None, '']:
482 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
484 if 'DynamicEx' in BuildData
.Pcds
[key
].Type
:
485 if BuildData
.IsBinaryModule
:
486 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['DynamicEx']:
487 BinaryPcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
489 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['DynamicEx']:
490 SourcePcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
492 elif 'PatchableInModule' in BuildData
.Pcds
[key
].Type
:
493 if BuildData
.MetaFile
.Ext
== '.inf':
494 if BuildData
.IsBinaryModule
:
495 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['PatchableInModule']:
496 BinaryPcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
498 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['PatchableInModule']:
499 SourcePcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
501 elif 'Dynamic' in BuildData
.Pcds
[key
].Type
:
502 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['Dynamic']:
503 SourcePcdDict
['Dynamic'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
504 elif 'FixedAtBuild' in BuildData
.Pcds
[key
].Type
:
505 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['FixedAtBuild']:
506 SourcePcdDict
['FixedAtBuild'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
510 # A PCD can only use one type for all source modules
512 for i
in SourcePcdDict_Keys
:
513 for j
in SourcePcdDict_Keys
:
515 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(SourcePcdDict
[j
])))
516 if len(IntersectionList
) > 0:
520 "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
),
521 ExtraData
="%s" % '\n\t'.join([str(P
[1]+'.'+P
[0]) for P
in IntersectionList
])
527 # intersection the BinaryPCD for Mixed PCD
529 for i
in BinaryPcdDict_Keys
:
530 for j
in BinaryPcdDict_Keys
:
532 IntersectionList
= list(set(BinaryPcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
533 for item
in IntersectionList
:
534 NewPcd1
= (item
[0] + '_' + i
, item
[1])
535 NewPcd2
= (item
[0] + '_' + j
, item
[1])
536 if item
not in GlobalData
.MixedPcd
:
537 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
539 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
540 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
541 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
542 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
547 # intersection the SourcePCD and BinaryPCD for Mixed PCD
549 for i
in SourcePcdDict_Keys
:
550 for j
in BinaryPcdDict_Keys
:
552 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
553 for item
in IntersectionList
:
554 NewPcd1
= (item
[0] + '_' + i
, item
[1])
555 NewPcd2
= (item
[0] + '_' + j
, item
[1])
556 if item
not in GlobalData
.MixedPcd
:
557 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
559 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
560 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
561 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
562 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
566 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
567 if BuildData
.Arch
!= Arch
:
569 for key
in BuildData
.Pcds
:
570 for SinglePcd
in GlobalData
.MixedPcd
:
571 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
572 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
573 Pcd_Type
= item
[0].split('_')[-1]
574 if (Pcd_Type
== BuildData
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicExPcd
) or \
575 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
576 Value
= BuildData
.Pcds
[key
]
577 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
579 newkey
= (Value
.TokenCName
, key
[1])
581 newkey
= (Value
.TokenCName
, key
[1], key
[2])
582 del BuildData
.Pcds
[key
]
583 BuildData
.Pcds
[newkey
] = Value
591 # handle the mixed pcd in FDF file
593 if key
in GlobalData
.MixedPcd
:
596 for item
in GlobalData
.MixedPcd
[key
]:
599 #Collect package set information from INF of FDF
601 for Inf
in ModuleList
:
602 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
603 if ModuleFile
in Platform
.Modules
:
605 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
606 PkgSet
.update(ModuleData
.Packages
)
607 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
610 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
611 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
613 Platform
.SkuName
= self
.SkuId
614 for Name
, Guid
in PcdSet
:
615 if (Name
, Guid
) not in DecPcds
:
619 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
620 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
621 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
624 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
625 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
626 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
627 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
628 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
630 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
634 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
635 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
636 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
639 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
641 # Explicitly collect platform's dynamic PCDs
643 Pa
.CollectPlatformDynamicPcds()
644 Pa
.CollectFixedAtBuildPcds()
645 self
.AutoGenObjectList
.append(Pa
)
648 # Check PCDs token value conflict in each DEC file.
650 self
._CheckAllPcdsTokenValueConflict
()
653 # Check PCD type and definition between DSC and DEC
655 self
._CheckPcdDefineAndType
()
658 # self._CheckDuplicateInFV(Fdf)
660 self
._BuildDir
= None
662 self
._MakeFileDir
= None
663 self
._BuildCommand
= None
666 # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.
668 content
= 'gCommandLineDefines: '
669 content
+= str(GlobalData
.gCommandLineDefines
)
670 content
+= os
.linesep
671 content
+= 'BuildOptionPcd: '
672 content
+= str(GlobalData
.BuildOptionPcd
)
673 content
+= os
.linesep
674 content
+= 'Active Platform: '
675 content
+= str(self
.Platform
)
676 content
+= os
.linesep
678 content
+= 'Flash Image Definition: '
679 content
+= str(self
.FdfFile
)
680 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'BuildOptions'), content
, False)
683 # Create PcdToken Number file for Dynamic/DynamicEx Pcd.
685 PcdTokenNumber
= 'PcdTokenNumber: '
686 if Pa
.PcdTokenNumber
:
687 if Pa
.DynamicPcdList
:
688 for Pcd
in Pa
.DynamicPcdList
:
689 PcdTokenNumber
+= os
.linesep
690 PcdTokenNumber
+= str((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
))
691 PcdTokenNumber
+= ' : '
692 PcdTokenNumber
+= str(Pa
.PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
])
693 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'), PcdTokenNumber
, False)
696 # Get set of workspace metafiles
698 AllWorkSpaceMetaFiles
= self
._GetMetaFiles
(Target
, Toolchain
, Arch
)
701 # Retrieve latest modified time of all metafiles
704 for f
in AllWorkSpaceMetaFiles
:
705 if os
.stat(f
)[8] > SrcTimeStamp
:
706 SrcTimeStamp
= os
.stat(f
)[8]
707 self
._SrcTimeStamp
= SrcTimeStamp
710 # Write metafile list to build directory
712 AutoGenFilePath
= os
.path
.join(self
.BuildDir
, 'AutoGen')
713 if os
.path
.exists (AutoGenFilePath
):
714 os
.remove(AutoGenFilePath
)
715 if not os
.path
.exists(self
.BuildDir
):
716 os
.makedirs(self
.BuildDir
)
717 with
open(os
.path
.join(self
.BuildDir
, 'AutoGen'), 'w+') as file:
718 for f
in AllWorkSpaceMetaFiles
:
723 def _GetMetaFiles(self
, Target
, Toolchain
, Arch
):
724 AllWorkSpaceMetaFiles
= set()
729 AllWorkSpaceMetaFiles
.add (self
.FdfFile
.Path
)
731 FdfFiles
= GlobalData
.gFdfParser
.GetAllIncludedFile()
733 AllWorkSpaceMetaFiles
.add (f
.FileName
)
737 AllWorkSpaceMetaFiles
.add(self
.MetaFile
.Path
)
740 # add build_rule.txt & tools_def.txt
742 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultBuildRuleFile
))
743 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultToolsDefFile
))
745 # add BuildOption metafile
747 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'BuildOptions'))
749 # add PcdToken Number file for Dynamic/DynamicEx Pcd
751 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'PcdTokenNumber'))
753 for Arch
in self
.ArchList
:
754 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
755 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
760 for Package
in PGen
.PackageList
:
761 AllWorkSpaceMetaFiles
.add(Package
.MetaFile
.Path
)
766 for filePath
in Platform
._RawData
.IncludedFiles
:
767 AllWorkSpaceMetaFiles
.add(filePath
.Path
)
769 return AllWorkSpaceMetaFiles
771 ## _CheckDuplicateInFV() method
773 # Check whether there is duplicate modules/files exist in FV section.
774 # The check base on the file GUID;
776 def _CheckDuplicateInFV(self
, Fdf
):
777 for Fv
in Fdf
.Profile
.FvDict
:
779 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
780 if FfsFile
.InfFileName
and FfsFile
.NameGuid
== None:
785 for Pa
in self
.AutoGenObjectList
:
788 for Module
in Pa
.ModuleAutoGenList
:
789 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
791 if not Module
.Guid
.upper() in _GuidDict
.keys():
792 _GuidDict
[Module
.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
[Module
.Guid
.upper()].CurrentLineNum
,
800 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
801 Module
.Guid
.upper()),
802 ExtraData
=self
.FdfFile
)
804 # Some INF files not have entity in DSC file.
807 if FfsFile
.InfFileName
.find('$') == -1:
808 InfPath
= NormPath(FfsFile
.InfFileName
)
809 if not os
.path
.exists(InfPath
):
810 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
812 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
814 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
815 # BuildObject from one of AutoGenObjectList is enough.
817 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, 'COMMON', self
.BuildTarget
, self
.ToolChain
]
818 if not InfObj
.Guid
.upper() in _GuidDict
.keys():
819 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
821 EdkLogger
.error("build",
823 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
824 FfsFile
.CurrentLineContent
,
825 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
826 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
827 InfObj
.Guid
.upper()),
828 ExtraData
=self
.FdfFile
)
831 if FfsFile
.NameGuid
!= None:
832 _CheckPCDAsGuidPattern
= re
.compile("^PCD\(.+\..+\)$")
835 # If the NameGuid reference a PCD name.
836 # The style must match: PCD(xxxx.yyy)
838 if _CheckPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
840 # Replace the PCD value.
842 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
844 for Pa
in self
.AutoGenObjectList
:
846 for PcdItem
in Pa
.AllPcdList
:
847 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
849 # First convert from CFormatGuid to GUID string
851 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
853 if not _PcdGuidString
:
855 # Then try Byte array.
857 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
859 if not _PcdGuidString
:
861 # Not Byte array or CFormat GUID, raise error.
863 EdkLogger
.error("build",
865 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
866 ExtraData
=self
.FdfFile
)
868 if not _PcdGuidString
.upper() in _GuidDict
.keys():
869 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
873 EdkLogger
.error("build",
875 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
876 FfsFile
.CurrentLineContent
,
877 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
878 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
879 FfsFile
.NameGuid
.upper()),
880 ExtraData
=self
.FdfFile
)
882 if not FfsFile
.NameGuid
.upper() in _GuidDict
.keys():
883 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
886 # Two raw file GUID conflict.
888 EdkLogger
.error("build",
890 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
891 FfsFile
.CurrentLineContent
,
892 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
893 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
894 FfsFile
.NameGuid
.upper()),
895 ExtraData
=self
.FdfFile
)
898 def _CheckPcdDefineAndType(self
):
900 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
901 "Dynamic", #"DynamicHii", "DynamicVpd",
902 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
905 # This dict store PCDs which are not used by any modules with specified arches
907 for Pa
in self
.AutoGenObjectList
:
908 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
909 for Pcd
in Pa
.Platform
.Pcds
:
910 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
912 # If no PCD type, this PCD comes from FDF
916 # Try to remove Hii and Vpd suffix
917 if PcdType
.startswith("DynamicEx"):
918 PcdType
= "DynamicEx"
919 elif PcdType
.startswith("Dynamic"):
922 for Package
in Pa
.PackageList
:
923 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
924 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
926 for Type
in PcdTypeList
:
927 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
931 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
932 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
937 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
939 for Pcd
in UnusedPcd
:
942 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
943 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
944 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
949 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
951 ## Return the directory to store FV files
953 if self
._FvDir
== None:
954 self
._FvDir
= path
.join(self
.BuildDir
, 'FV')
957 ## Return the directory to store all intermediate and final files built
958 def _GetBuildDir(self
):
959 return self
.AutoGenObjectList
[0].BuildDir
961 ## Return the build output directory platform specifies
962 def _GetOutputDir(self
):
963 return self
.Platform
.OutputDirectory
965 ## Return platform name
967 return self
.Platform
.PlatformName
969 ## Return meta-file GUID
971 return self
.Platform
.Guid
973 ## Return platform version
974 def _GetVersion(self
):
975 return self
.Platform
.Version
977 ## Return paths of tools
978 def _GetToolDefinition(self
):
979 return self
.AutoGenObjectList
[0].ToolDefinition
981 ## Return directory of platform makefile
983 # @retval string Makefile directory
985 def _GetMakeFileDir(self
):
986 if self
._MakeFileDir
== None:
987 self
._MakeFileDir
= self
.BuildDir
988 return self
._MakeFileDir
990 ## Return build command string
992 # @retval string Build command string
994 def _GetBuildCommand(self
):
995 if self
._BuildCommand
== None:
996 # BuildCommand should be all the same. So just get one from platform AutoGen
997 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
998 return self
._BuildCommand
1000 ## Check the PCDs token value conflict in each DEC file.
1002 # Will cause build break and raise error message while two PCDs conflict.
1006 def _CheckAllPcdsTokenValueConflict(self
):
1007 for Pa
in self
.AutoGenObjectList
:
1008 for Package
in Pa
.PackageList
:
1009 PcdList
= Package
.Pcds
.values()
1010 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
1012 while (Count
< len(PcdList
) - 1) :
1013 Item
= PcdList
[Count
]
1014 ItemNext
= PcdList
[Count
+ 1]
1016 # Make sure in the same token space the TokenValue should be unique
1018 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
1019 SameTokenValuePcdList
= []
1020 SameTokenValuePcdList
.append(Item
)
1021 SameTokenValuePcdList
.append(ItemNext
)
1022 RemainPcdListLength
= len(PcdList
) - Count
- 2
1023 for ValueSameCount
in range(RemainPcdListLength
):
1024 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
1025 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
1029 # Sort same token value PCD list with TokenGuid and TokenCName
1031 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1032 SameTokenValuePcdListCount
= 0
1033 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
1035 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
1036 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
1038 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
1039 for PcdItem
in GlobalData
.MixedPcd
:
1040 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
1041 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1047 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
1048 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
1051 SameTokenValuePcdListCount
+= 1
1052 Count
+= SameTokenValuePcdListCount
1055 PcdList
= Package
.Pcds
.values()
1056 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1058 while (Count
< len(PcdList
) - 1) :
1059 Item
= PcdList
[Count
]
1060 ItemNext
= PcdList
[Count
+ 1]
1062 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
1064 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
1068 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
1069 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
1073 ## Generate fds command
1074 def _GenFdsCommand(self
):
1075 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
1077 ## Create makefile for the platform and modules in it
1079 # @param CreateDepsMakeFile Flag indicating if the makefile for
1080 # modules will be created as well
1082 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
1083 if CreateDepsMakeFile
:
1084 for Pa
in self
.AutoGenObjectList
:
1085 Pa
.CreateMakeFile(CreateDepsMakeFile
)
1087 ## Create autogen code for platform and modules
1089 # Since there's no autogen code for platform, this method will do nothing
1090 # if CreateModuleCodeFile is set to False.
1092 # @param CreateDepsCodeFile Flag indicating if creating module's
1093 # autogen code file or not
1095 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
1096 if not CreateDepsCodeFile
:
1098 for Pa
in self
.AutoGenObjectList
:
1099 Pa
.CreateCodeFile(CreateDepsCodeFile
)
1101 ## Create AsBuilt INF file the platform
1103 def CreateAsBuiltInf(self
):
1106 Name
= property(_GetName
)
1107 Guid
= property(_GetGuid
)
1108 Version
= property(_GetVersion
)
1109 OutputDir
= property(_GetOutputDir
)
1111 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
1113 BuildDir
= property(_GetBuildDir
)
1114 FvDir
= property(_GetFvDir
)
1115 MakeFileDir
= property(_GetMakeFileDir
)
1116 BuildCommand
= property(_GetBuildCommand
)
1117 GenFdsCommand
= property(_GenFdsCommand
)
1119 ## AutoGen class for platform
1121 # PlatformAutoGen class will process the original information in platform
1122 # file in order to generate makefile for platform.
1124 class PlatformAutoGen(AutoGen
):
1126 # Used to store all PCDs for both PEI and DXE phase, in order to generate
1127 # correct PCD database
1130 _NonDynaPcdList_
= []
1134 # The priority list while override build option
1136 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
1137 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1138 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1139 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1140 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1141 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1142 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1143 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1144 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1145 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1146 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1147 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1148 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1149 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1150 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1151 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1153 ## The real constructor of PlatformAutoGen
1155 # This method is not supposed to be called by users of PlatformAutoGen. It's
1156 # only used by factory method __new__() to do real initialization work for an
1157 # object of PlatformAutoGen
1159 # @param Workspace WorkspaceAutoGen object
1160 # @param PlatformFile Platform file (DSC file)
1161 # @param Target Build target (DEBUG, RELEASE)
1162 # @param Toolchain Name of tool chain
1163 # @param Arch arch of the platform supports
1165 def _Init(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1166 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1167 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1169 self
.MetaFile
= PlatformFile
1170 self
.Workspace
= Workspace
1171 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1172 self
.ToolChain
= Toolchain
1173 self
.BuildTarget
= Target
1175 self
.SourceDir
= PlatformFile
.SubDir
1176 self
.SourceOverrideDir
= None
1177 self
.FdTargetList
= self
.Workspace
.FdTargetList
1178 self
.FvTargetList
= self
.Workspace
.FvTargetList
1179 self
.AllPcdList
= []
1180 # get the original module/package/platform objects
1181 self
.BuildDatabase
= Workspace
.BuildDatabase
1183 # flag indicating if the makefile/C-code file has been created or not
1184 self
.IsMakeFileCreated
= False
1185 self
.IsCodeFileCreated
= False
1187 self
._Platform
= None
1190 self
._Version
= None
1192 self
._BuildRule
= None
1193 self
._SourceDir
= None
1194 self
._BuildDir
= None
1195 self
._OutputDir
= None
1197 self
._MakeFileDir
= None
1198 self
._FdfFile
= None
1200 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
1201 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1202 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1203 self
._NonDynamicPcdDict
= {}
1205 self
._ToolDefinitions
= None
1206 self
._ToolDefFile
= None # toolcode : tool path
1207 self
._ToolChainFamily
= None
1208 self
._BuildRuleFamily
= None
1209 self
._BuildOption
= None # toolcode : option
1210 self
._EdkBuildOption
= None # edktoolcode : option
1211 self
._EdkIIBuildOption
= None # edkiitoolcode : option
1212 self
._PackageList
= None
1213 self
._ModuleAutoGenList
= None
1214 self
._LibraryAutoGenList
= None
1215 self
._BuildCommand
= None
1216 self
._AsBuildInfList
= []
1217 self
._AsBuildModuleList
= []
1218 if GlobalData
.gFdfParser
!= None:
1219 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1220 for Inf
in self
._AsBuildInfList
:
1221 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1222 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1223 if not M
.IsSupportedArch
:
1225 self
._AsBuildModuleList
.append(InfClass
)
1226 # get library/modules for build
1227 self
.LibraryBuildDirectoryList
= []
1228 self
.ModuleBuildDirectoryList
= []
1232 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1234 ## Create autogen code for platform and modules
1236 # Since there's no autogen code for platform, this method will do nothing
1237 # if CreateModuleCodeFile is set to False.
1239 # @param CreateModuleCodeFile Flag indicating if creating module's
1240 # autogen code file or not
1242 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1243 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1244 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
1247 for Ma
in self
.ModuleAutoGenList
:
1248 Ma
.CreateCodeFile(True)
1250 # don't do this twice
1251 self
.IsCodeFileCreated
= True
1253 ## Generate Fds Command
1254 def _GenFdsCommand(self
):
1255 return self
.Workspace
.GenFdsCommand
1257 ## Create makefile for the platform and mdoules in it
1259 # @param CreateModuleMakeFile Flag indicating if the makefile for
1260 # modules will be created as well
1262 def CreateMakeFile(self
, CreateModuleMakeFile
=False):
1263 if CreateModuleMakeFile
:
1264 for ModuleFile
in self
.Platform
.Modules
:
1265 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
1266 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1267 Ma
.CreateMakeFile(True)
1268 #Ma.CreateAsBuiltInf()
1270 # no need to create makefile for the platform more than once
1271 if self
.IsMakeFileCreated
:
1274 # create library/module build dirs for platform
1275 Makefile
= GenMake
.PlatformMakefile(self
)
1276 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1277 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1279 self
.IsMakeFileCreated
= True
1281 ## Deal with Shared FixedAtBuild Pcds
1283 def CollectFixedAtBuildPcds(self
):
1284 for LibAuto
in self
.LibraryAutoGenList
:
1285 FixedAtBuildPcds
= {}
1286 ShareFixedAtBuildPcdsSameValue
= {}
1287 for Module
in LibAuto
._ReferenceModules
:
1288 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
1289 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1290 if key
not in FixedAtBuildPcds
:
1291 ShareFixedAtBuildPcdsSameValue
[key
] = True
1292 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
1294 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
1295 ShareFixedAtBuildPcdsSameValue
[key
] = False
1296 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1297 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1298 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1301 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
1302 if DscPcd
.Type
!= "FixedAtBuild":
1304 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1305 LibAuto
.ConstPcd
[key
] = Pcd
.DefaultValue
1307 ## Collect dynamic PCDs
1309 # Gather dynamic PCDs list from each module and their settings from platform
1310 # This interface should be invoked explicitly when platform action is created.
1312 def CollectPlatformDynamicPcds(self
):
1313 # Override the platform Pcd's value by build option
1314 if GlobalData
.BuildOptionPcd
:
1315 for key
in self
.Platform
.Pcds
:
1316 PlatformPcd
= self
.Platform
.Pcds
[key
]
1317 for PcdItem
in GlobalData
.BuildOptionPcd
:
1318 if (PlatformPcd
.TokenSpaceGuidCName
, PlatformPcd
.TokenCName
) == (PcdItem
[0], PcdItem
[1]):
1319 PlatformPcd
.DefaultValue
= PcdItem
[2]
1320 if PlatformPcd
.SkuInfoList
:
1321 Sku
= PlatformPcd
.SkuInfoList
[PlatformPcd
.SkuInfoList
.keys()[0]]
1322 Sku
.DefaultValue
= PcdItem
[2]
1325 for key
in self
.Platform
.Pcds
:
1326 for SinglePcd
in GlobalData
.MixedPcd
:
1327 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1328 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1329 Pcd_Type
= item
[0].split('_')[-1]
1330 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 \
1331 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
1332 Value
= self
.Platform
.Pcds
[key
]
1333 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1335 newkey
= (Value
.TokenCName
, key
[1])
1337 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1338 del self
.Platform
.Pcds
[key
]
1339 self
.Platform
.Pcds
[newkey
] = Value
1347 # for gathering error information
1348 NoDatumTypePcdList
= set()
1350 self
._GuidValue
= {}
1352 for InfName
in self
._AsBuildInfList
:
1353 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1354 FdfModuleList
.append(os
.path
.normpath(InfName
))
1355 for F
in self
.Platform
.Modules
.keys():
1356 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1357 #GuidValue.update(M.Guids)
1359 self
.Platform
.Modules
[F
].M
= M
1361 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1362 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1363 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1364 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1366 # Check the PCD from Binary INF or Source INF
1367 if M
.IsBinaryModule
== True:
1368 PcdFromModule
.IsFromBinaryInf
= True
1370 # Check the PCD from DSC or not
1371 if (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
.keys():
1372 PcdFromModule
.IsFromDsc
= True
1374 PcdFromModule
.IsFromDsc
= False
1375 if PcdFromModule
.Type
in GenC
.gDynamicPcd
or PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1376 if F
.Path
not in FdfModuleList
:
1377 # If one of the Source built modules listed in the DSC is not listed
1378 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1379 # access method (it is only listed in the DEC file that declares the
1380 # PCD as PcdsDynamic), then build tool will report warning message
1381 # notify the PI that they are attempting to build a module that must
1382 # be included in a flash image in order to be functional. These Dynamic
1383 # PCD will not be added into the Database unless it is used by other
1384 # modules that are included in the FDF file.
1385 if PcdFromModule
.Type
in GenC
.gDynamicPcd
and \
1386 PcdFromModule
.IsFromBinaryInf
== False:
1387 # Print warning message to let the developer make a determine.
1388 if PcdFromModule
not in PcdNotInDb
:
1389 PcdNotInDb
.append(PcdFromModule
)
1391 # If one of the Source built modules listed in the DSC is not listed in
1392 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1393 # access method (it is only listed in the DEC file that declares the
1394 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1395 # PCD to the Platform's PCD Database.
1396 if PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1397 if PcdFromModule
not in PcdNotInDb
:
1398 PcdNotInDb
.append(PcdFromModule
)
1401 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1402 # it should be stored in Pcd PEI database, If a dynamic only
1403 # used by DXE module, it should be stored in DXE PCD database.
1404 # The default Phase is DXE
1406 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1407 PcdFromModule
.Phase
= "PEI"
1408 if PcdFromModule
not in self
._DynaPcdList
_:
1409 self
._DynaPcdList
_.append(PcdFromModule
)
1410 elif PcdFromModule
.Phase
== 'PEI':
1411 # overwrite any the same PCD existing, if Phase is PEI
1412 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1413 self
._DynaPcdList
_[Index
] = PcdFromModule
1414 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1415 self
._NonDynaPcdList
_.append(PcdFromModule
)
1416 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1417 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1418 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1419 #The PCD from Binary INF will override the same one from source INF
1420 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1421 PcdFromModule
.Pending
= False
1422 self
._NonDynaPcdList
_.append (PcdFromModule
)
1423 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1425 for ModuleInf
in self
.Platform
.Modules
.keys():
1426 DscModuleList
.append (os
.path
.normpath(ModuleInf
.Path
))
1427 # add the PCD from modules that listed in FDF but not in DSC to Database
1428 for InfName
in FdfModuleList
:
1429 if InfName
not in DscModuleList
:
1430 InfClass
= PathClass(InfName
)
1431 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1432 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1433 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1434 # For binary module, if in current arch, we need to list the PCDs into database.
1435 if not M
.IsSupportedArch
:
1437 # Override the module PCD setting by platform setting
1438 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1439 for PcdFromModule
in ModulePcdList
:
1440 PcdFromModule
.IsFromBinaryInf
= True
1441 PcdFromModule
.IsFromDsc
= False
1442 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1443 if PcdFromModule
.Type
not in GenC
.gDynamicExPcd
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1444 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1446 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1447 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1448 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1449 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1450 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1451 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1452 PcdFromModule
.Phase
= "PEI"
1453 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1454 self
._DynaPcdList
_.append(PcdFromModule
)
1455 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1456 self
._NonDynaPcdList
_.append(PcdFromModule
)
1457 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1458 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1459 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1460 # module & DXE module at a same time.
1461 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1462 # INF file as DynamicEx.
1463 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1464 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1465 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1466 for PcdFromModule
in self
._NonDynaPcdList
_:
1467 # If a PCD is not listed in the DSC file, but binary INF files used by
1468 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1469 # section, AND all source INF files used by this platform the build
1470 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1471 # section, then the tools must NOT add the PCD to the Platform's PCD
1472 # Database; the build must assign the access method for this PCD as
1473 # PcdsPatchableInModule.
1474 if PcdFromModule
not in self
._DynaPcdList
_:
1476 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1477 if PcdFromModule
.IsFromDsc
== False and \
1478 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1479 PcdFromModule
.IsFromBinaryInf
== True and \
1480 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1481 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1482 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1484 # print out error information and break the build, if error found
1485 if len(NoDatumTypePcdList
) > 0:
1486 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1487 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1489 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1490 % NoDatumTypePcdListString
)
1491 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1492 self
._DynamicPcdList
= self
._DynaPcdList
_
1494 # Sort dynamic PCD list to:
1495 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1496 # try to be put header of dynamicd List
1497 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1499 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1501 UnicodePcdArray
= []
1505 VpdFile
= VpdInfoFile
.VpdInfoFile()
1506 NeedProcessVpdMapFile
= False
1508 for pcd
in self
.Platform
.Pcds
.keys():
1509 if pcd
not in self
._PlatformPcds
.keys():
1510 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1512 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1513 for Pcd
in self
._DynamicPcdList
:
1514 # just pick the a value to determine whether is unicode string type
1515 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1516 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1518 PcdValue
= Sku
.DefaultValue
1519 if Pcd
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1520 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1521 UnicodePcdArray
.append(Pcd
)
1522 elif len(Sku
.VariableName
) > 0:
1523 # if found HII type PCD then insert to right of UnicodeIndex
1524 HiiPcdArray
.append(Pcd
)
1526 OtherPcdArray
.append(Pcd
)
1527 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1528 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1530 PlatformPcds
= self
._PlatformPcds
.keys()
1533 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1535 for PcdKey
in PlatformPcds
:
1536 Pcd
= self
._PlatformPcds
[PcdKey
]
1537 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1538 PcdKey
in VpdPcdDict
:
1539 Pcd
= VpdPcdDict
[PcdKey
]
1540 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1541 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1542 PcdValue
= Sku
.DefaultValue
1544 PcdValue
= Pcd
.DefaultValue
1545 if Sku
.VpdOffset
!= '*':
1546 if PcdValue
.startswith("{"):
1548 elif PcdValue
.startswith("L"):
1553 VpdOffset
= int(Sku
.VpdOffset
)
1556 VpdOffset
= int(Sku
.VpdOffset
, 16)
1558 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1559 if VpdOffset
% Alignment
!= 0:
1560 if PcdValue
.startswith("{"):
1561 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1563 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1564 VpdFile
.Add(Pcd
, Sku
.VpdOffset
)
1565 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1566 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1567 NeedProcessVpdMapFile
= True
1568 if self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== '':
1569 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1570 "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.")
1574 # Fix the PCDs define in VPD PCD section that never referenced by module.
1575 # An example is PCD for signature usage.
1577 for DscPcd
in PlatformPcds
:
1578 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1579 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1580 if not (self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== ''):
1582 for VpdPcd
in VpdFile
._VpdArray
.keys():
1583 # This PCD has been referenced by module
1584 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1585 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1588 # Not found, it should be signature
1590 # just pick the a value to determine whether is unicode string type
1591 for (SkuName
,Sku
) in DscPcdEntry
.SkuInfoList
.items():
1592 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1594 # Need to iterate DEC pcd information to get the value & datumtype
1595 for eachDec
in self
.PackageList
:
1596 for DecPcd
in eachDec
.Pcds
:
1597 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1598 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1599 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1600 # Print warning message to let the developer make a determine.
1601 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1602 File
=self
.MetaFile
, \
1603 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1604 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1606 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1607 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1608 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1609 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1610 # Only fix the value while no value provided in DSC file.
1611 if (Sku
.DefaultValue
== "" or Sku
.DefaultValue
==None):
1612 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1614 if DscPcdEntry
not in self
._DynamicPcdList
:
1615 self
._DynamicPcdList
.append(DscPcdEntry
)
1616 # Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]
1617 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1618 PcdValue
= Sku
.DefaultValue
1620 PcdValue
= DscPcdEntry
.DefaultValue
1621 if Sku
.VpdOffset
!= '*':
1622 if PcdValue
.startswith("{"):
1624 elif PcdValue
.startswith("L"):
1629 VpdOffset
= int(Sku
.VpdOffset
)
1632 VpdOffset
= int(Sku
.VpdOffset
, 16)
1634 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1635 if VpdOffset
% Alignment
!= 0:
1636 if PcdValue
.startswith("{"):
1637 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1639 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1640 VpdFile
.Add(DscPcdEntry
, Sku
.VpdOffset
)
1641 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1642 NeedProcessVpdMapFile
= True
1643 if DscPcdEntry
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1644 UnicodePcdArray
.append(DscPcdEntry
)
1645 elif len(Sku
.VariableName
) > 0:
1646 HiiPcdArray
.append(DscPcdEntry
)
1648 OtherPcdArray
.append(DscPcdEntry
)
1650 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1654 if (self
.Platform
.FlashDefinition
== None or self
.Platform
.FlashDefinition
== '') and \
1655 VpdFile
.GetCount() != 0:
1656 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1657 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1659 if VpdFile
.GetCount() != 0:
1660 FvPath
= os
.path
.join(self
.BuildDir
, "FV")
1661 if not os
.path
.exists(FvPath
):
1665 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1667 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1669 if VpdFile
.Write(VpdFilePath
):
1670 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1672 for ToolDef
in self
.ToolDefinition
.values():
1673 if ToolDef
.has_key("GUID") and ToolDef
["GUID"] == self
.Platform
.VpdToolGuid
:
1674 if not ToolDef
.has_key("PATH"):
1675 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1676 BPDGToolName
= ToolDef
["PATH"]
1678 # Call third party GUID BPDG tool.
1679 if BPDGToolName
!= None:
1680 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1682 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.")
1684 # Process VPD map file generated by third party BPDG tool
1685 if NeedProcessVpdMapFile
:
1686 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1687 if os
.path
.exists(VpdMapFilePath
):
1688 VpdFile
.Read(VpdMapFilePath
)
1691 for Pcd
in self
._DynamicPcdList
:
1692 # just pick the a value to determine whether is unicode string type
1694 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1695 if Sku
.VpdOffset
== "*":
1696 Sku
.VpdOffset
= VpdFile
.GetOffset(Pcd
)[i
].strip()
1699 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1701 # Delete the DynamicPcdList At the last time enter into this function
1702 del self
._DynamicPcdList
[:]
1703 self
._DynamicPcdList
.extend(UnicodePcdArray
)
1704 self
._DynamicPcdList
.extend(HiiPcdArray
)
1705 self
._DynamicPcdList
.extend(OtherPcdArray
)
1706 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1708 ## Return the platform build data object
1709 def _GetPlatform(self
):
1710 if self
._Platform
== None:
1711 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1712 return self
._Platform
1714 ## Return platform name
1716 return self
.Platform
.PlatformName
1718 ## Return the meta file GUID
1720 return self
.Platform
.Guid
1722 ## Return the platform version
1723 def _GetVersion(self
):
1724 return self
.Platform
.Version
1726 ## Return the FDF file name
1727 def _GetFdfFile(self
):
1728 if self
._FdfFile
== None:
1729 if self
.Workspace
.FdfFile
!= "":
1730 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1733 return self
._FdfFile
1735 ## Return the build output directory platform specifies
1736 def _GetOutputDir(self
):
1737 return self
.Platform
.OutputDirectory
1739 ## Return the directory to store all intermediate and final files built
1740 def _GetBuildDir(self
):
1741 if self
._BuildDir
== None:
1742 if os
.path
.isabs(self
.OutputDir
):
1743 self
._BuildDir
= path
.join(
1744 path
.abspath(self
.OutputDir
),
1745 self
.BuildTarget
+ "_" + self
.ToolChain
,
1748 self
._BuildDir
= path
.join(
1751 self
.BuildTarget
+ "_" + self
.ToolChain
,
1753 return self
._BuildDir
1755 ## Return directory of platform makefile
1757 # @retval string Makefile directory
1759 def _GetMakeFileDir(self
):
1760 if self
._MakeFileDir
== None:
1761 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1762 return self
._MakeFileDir
1764 ## Return build command string
1766 # @retval string Build command string
1768 def _GetBuildCommand(self
):
1769 if self
._BuildCommand
== None:
1770 self
._BuildCommand
= []
1771 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1772 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1773 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1774 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1776 self
._BuildCommand
+= SplitOption(NewOption
)
1777 return self
._BuildCommand
1779 ## Get tool chain definition
1781 # Get each tool defition for given tool chain from tools_def.txt and platform
1783 def _GetToolDefinition(self
):
1784 if self
._ToolDefinitions
== None:
1785 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1786 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1787 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1788 ExtraData
="[%s]" % self
.MetaFile
)
1789 self
._ToolDefinitions
= {}
1791 for Def
in ToolDefinition
:
1792 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1793 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1796 Value
= ToolDefinition
[Def
]
1797 # don't record the DLL
1799 DllPathList
.add(Value
)
1802 if Tool
not in self
._ToolDefinitions
:
1803 self
._ToolDefinitions
[Tool
] = {}
1804 self
._ToolDefinitions
[Tool
][Attr
] = Value
1808 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1809 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1810 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1811 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1813 for Tool
in self
._ToolDefinitions
:
1814 for Attr
in self
._ToolDefinitions
[Tool
]:
1815 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1816 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1817 # check if override is indicated
1818 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1819 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1822 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1824 Value
= self
.BuildOption
[Tool
][Attr
]
1827 # Don't put MAKE definition in the file
1831 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1833 # Don't put MAKE definition in the file
1838 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1841 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1842 for DllPath
in DllPathList
:
1843 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1844 os
.environ
["MAKE_FLAGS"] = MakeFlags
1846 return self
._ToolDefinitions
1848 ## Return the paths of tools
1849 def _GetToolDefFile(self
):
1850 if self
._ToolDefFile
== None:
1851 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1852 return self
._ToolDefFile
1854 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1855 def _GetToolChainFamily(self
):
1856 if self
._ToolChainFamily
== None:
1857 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1858 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1859 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1860 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1861 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1863 self
._ToolChainFamily
= "MSFT"
1865 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1866 return self
._ToolChainFamily
1868 def _GetBuildRuleFamily(self
):
1869 if self
._BuildRuleFamily
== None:
1870 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1871 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1872 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1873 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1874 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1876 self
._BuildRuleFamily
= "MSFT"
1878 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1879 return self
._BuildRuleFamily
1881 ## Return the build options specific for all modules in this platform
1882 def _GetBuildOptions(self
):
1883 if self
._BuildOption
== None:
1884 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1885 return self
._BuildOption
1887 ## Return the build options specific for EDK modules in this platform
1888 def _GetEdkBuildOptions(self
):
1889 if self
._EdkBuildOption
== None:
1890 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1891 return self
._EdkBuildOption
1893 ## Return the build options specific for EDKII modules in this platform
1894 def _GetEdkIIBuildOptions(self
):
1895 if self
._EdkIIBuildOption
== None:
1896 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1897 return self
._EdkIIBuildOption
1899 ## Parse build_rule.txt in Conf Directory.
1901 # @retval BuildRule object
1903 def _GetBuildRule(self
):
1904 if self
._BuildRule
== None:
1905 BuildRuleFile
= None
1906 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1907 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1908 if BuildRuleFile
in [None, '']:
1909 BuildRuleFile
= gDefaultBuildRuleFile
1910 self
._BuildRule
= BuildRule(BuildRuleFile
)
1911 if self
._BuildRule
._FileVersion
== "":
1912 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
1914 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1915 # If Build Rule's version is less than the version number required by the tools, halting the build.
1916 EdkLogger
.error("build", AUTOGEN_ERROR
,
1917 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])"\
1918 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1920 return self
._BuildRule
1922 ## Summarize the packages used by modules in this platform
1923 def _GetPackageList(self
):
1924 if self
._PackageList
== None:
1925 self
._PackageList
= set()
1926 for La
in self
.LibraryAutoGenList
:
1927 self
._PackageList
.update(La
.DependentPackageList
)
1928 for Ma
in self
.ModuleAutoGenList
:
1929 self
._PackageList
.update(Ma
.DependentPackageList
)
1930 #Collect package set information from INF of FDF
1932 for ModuleFile
in self
._AsBuildModuleList
:
1933 if ModuleFile
in self
.Platform
.Modules
:
1935 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1936 PkgSet
.update(ModuleData
.Packages
)
1937 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
1938 return self
._PackageList
1940 def _GetNonDynamicPcdDict(self
):
1941 if self
._NonDynamicPcdDict
:
1942 return self
._NonDynamicPcdDict
1943 for Pcd
in self
.NonDynamicPcdList
:
1944 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
1945 return self
._NonDynamicPcdDict
1947 ## Get list of non-dynamic PCDs
1948 def _GetNonDynamicPcdList(self
):
1949 if self
._NonDynamicPcdList
== None:
1950 self
.CollectPlatformDynamicPcds()
1951 return self
._NonDynamicPcdList
1953 ## Get list of dynamic PCDs
1954 def _GetDynamicPcdList(self
):
1955 if self
._DynamicPcdList
== None:
1956 self
.CollectPlatformDynamicPcds()
1957 return self
._DynamicPcdList
1959 ## Generate Token Number for all PCD
1960 def _GetPcdTokenNumbers(self
):
1961 if self
._PcdTokenNumber
== None:
1962 self
._PcdTokenNumber
= sdict()
1965 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1969 # TokenNumber 0 ~ 10
1971 # TokeNumber 11 ~ 20
1973 for Pcd
in self
.DynamicPcdList
:
1974 if Pcd
.Phase
== "PEI":
1975 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1976 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1977 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1980 for Pcd
in self
.DynamicPcdList
:
1981 if Pcd
.Phase
== "PEI":
1982 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1983 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1984 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1987 for Pcd
in self
.DynamicPcdList
:
1988 if Pcd
.Phase
== "DXE":
1989 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1990 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1991 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1994 for Pcd
in self
.DynamicPcdList
:
1995 if Pcd
.Phase
== "DXE":
1996 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1997 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1998 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2001 for Pcd
in self
.NonDynamicPcdList
:
2002 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2004 return self
._PcdTokenNumber
2006 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
2007 def _GetAutoGenObjectList(self
):
2008 self
._ModuleAutoGenList
= []
2009 self
._LibraryAutoGenList
= []
2010 for ModuleFile
in self
.Platform
.Modules
:
2019 if Ma
not in self
._ModuleAutoGenList
:
2020 self
._ModuleAutoGenList
.append(Ma
)
2021 for La
in Ma
.LibraryAutoGenList
:
2022 if La
not in self
._LibraryAutoGenList
:
2023 self
._LibraryAutoGenList
.append(La
)
2024 if Ma
not in La
._ReferenceModules
:
2025 La
._ReferenceModules
.append(Ma
)
2027 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
2028 def _GetModuleAutoGenList(self
):
2029 if self
._ModuleAutoGenList
== None:
2030 self
._GetAutoGenObjectList
()
2031 return self
._ModuleAutoGenList
2033 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
2034 def _GetLibraryAutoGenList(self
):
2035 if self
._LibraryAutoGenList
== None:
2036 self
._GetAutoGenObjectList
()
2037 return self
._LibraryAutoGenList
2039 ## Test if a module is supported by the platform
2041 # An error will be raised directly if the module or its arch is not supported
2042 # by the platform or current configuration
2044 def ValidModule(self
, Module
):
2045 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
2046 or Module
in self
._AsBuildModuleList
2048 ## Resolve the library classes in a module to library instances
2050 # This method will not only resolve library classes but also sort the library
2051 # instances according to the dependency-ship.
2053 # @param Module The module from which the library classes will be resolved
2055 # @retval library_list List of library instances sorted
2057 def ApplyLibraryInstance(self
, Module
):
2058 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
2059 if str(Module
) not in self
.Platform
.Modules
:
2062 ModuleType
= Module
.ModuleType
2064 # for overridding library instances with module specific setting
2065 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2067 # add forced library instances (specified under LibraryClasses sections)
2069 # If a module has a MODULE_TYPE of USER_DEFINED,
2070 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
2072 if Module
.ModuleType
!= SUP_MODULE_USER_DEFINED
:
2073 for LibraryClass
in self
.Platform
.LibraryClasses
.GetKeys():
2074 if LibraryClass
.startswith("NULL") and self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]:
2075 Module
.LibraryClasses
[LibraryClass
] = self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]
2077 # add forced library instances (specified in module overrides)
2078 for LibraryClass
in PlatformModule
.LibraryClasses
:
2079 if LibraryClass
.startswith("NULL"):
2080 Module
.LibraryClasses
[LibraryClass
] = PlatformModule
.LibraryClasses
[LibraryClass
]
2083 LibraryConsumerList
= [Module
]
2085 ConsumedByList
= sdict()
2086 LibraryInstance
= sdict()
2088 EdkLogger
.verbose("")
2089 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2090 while len(LibraryConsumerList
) > 0:
2091 M
= LibraryConsumerList
.pop()
2092 for LibraryClassName
in M
.LibraryClasses
:
2093 if LibraryClassName
not in LibraryInstance
:
2094 # override library instance for this module
2095 if LibraryClassName
in PlatformModule
.LibraryClasses
:
2096 LibraryPath
= PlatformModule
.LibraryClasses
[LibraryClassName
]
2098 LibraryPath
= self
.Platform
.LibraryClasses
[LibraryClassName
, ModuleType
]
2099 if LibraryPath
== None or LibraryPath
== "":
2100 LibraryPath
= M
.LibraryClasses
[LibraryClassName
]
2101 if LibraryPath
== None or LibraryPath
== "":
2102 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
2103 "Instance of library class [%s] is not found" % LibraryClassName
,
2105 ExtraData
="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M
), self
.Arch
, str(Module
)))
2107 LibraryModule
= self
.BuildDatabase
[LibraryPath
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2108 # for those forced library instance (NULL library), add a fake library class
2109 if LibraryClassName
.startswith("NULL"):
2110 LibraryModule
.LibraryClass
.append(LibraryClassObject(LibraryClassName
, [ModuleType
]))
2111 elif LibraryModule
.LibraryClass
== None \
2112 or len(LibraryModule
.LibraryClass
) == 0 \
2113 or (ModuleType
!= 'USER_DEFINED'
2114 and ModuleType
not in LibraryModule
.LibraryClass
[0].SupModList
):
2115 # only USER_DEFINED can link against any library instance despite of its SupModList
2116 EdkLogger
.error("build", OPTION_MISSING
,
2117 "Module type [%s] is not supported by library instance [%s]" \
2118 % (ModuleType
, LibraryPath
), File
=self
.MetaFile
,
2119 ExtraData
="consumed by [%s]" % str(Module
))
2121 LibraryInstance
[LibraryClassName
] = LibraryModule
2122 LibraryConsumerList
.append(LibraryModule
)
2123 EdkLogger
.verbose("\t" + str(LibraryClassName
) + " : " + str(LibraryModule
))
2125 LibraryModule
= LibraryInstance
[LibraryClassName
]
2127 if LibraryModule
== None:
2130 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
2131 Constructor
.append(LibraryModule
)
2133 if LibraryModule
not in ConsumedByList
:
2134 ConsumedByList
[LibraryModule
] = []
2135 # don't add current module itself to consumer list
2137 if M
in ConsumedByList
[LibraryModule
]:
2139 ConsumedByList
[LibraryModule
].append(M
)
2141 # Initialize the sorted output list to the empty set
2143 SortedLibraryList
= []
2145 # Q <- Set of all nodes with no incoming edges
2147 LibraryList
= [] #LibraryInstance.values()
2149 for LibraryClassName
in LibraryInstance
:
2150 M
= LibraryInstance
[LibraryClassName
]
2151 LibraryList
.append(M
)
2152 if ConsumedByList
[M
] == []:
2156 # start the DAG algorithm
2160 while Q
== [] and EdgeRemoved
:
2162 # for each node Item with a Constructor
2163 for Item
in LibraryList
:
2164 if Item
not in Constructor
:
2166 # for each Node without a constructor with an edge e from Item to Node
2167 for Node
in ConsumedByList
[Item
]:
2168 if Node
in Constructor
:
2170 # remove edge e from the graph if Node has no constructor
2171 ConsumedByList
[Item
].remove(Node
)
2173 if ConsumedByList
[Item
] == []:
2174 # insert Item into Q
2179 # DAG is done if there's no more incoming edge for all nodes
2183 # remove node from Q
2186 SortedLibraryList
.append(Node
)
2188 # for each node Item with an edge e from Node to Item do
2189 for Item
in LibraryList
:
2190 if Node
not in ConsumedByList
[Item
]:
2192 # remove edge e from the graph
2193 ConsumedByList
[Item
].remove(Node
)
2195 if ConsumedByList
[Item
] != []:
2197 # insert Item into Q, if Item has no other incoming edges
2201 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
2203 for Item
in LibraryList
:
2204 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
2205 ErrorMessage
= "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]])
2206 EdkLogger
.error("build", BUILD_ERROR
, 'Library [%s] with constructors has a cycle' % str(Item
),
2207 ExtraData
=ErrorMessage
, File
=self
.MetaFile
)
2208 if Item
not in SortedLibraryList
:
2209 SortedLibraryList
.append(Item
)
2212 # Build the list of constructor and destructir names
2213 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
2215 SortedLibraryList
.reverse()
2216 return SortedLibraryList
2219 ## Override PCD setting (type, value, ...)
2221 # @param ToPcd The PCD to be overrided
2222 # @param FromPcd The PCD overrideing from
2224 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
=""):
2226 # in case there's PCDs coming from FDF file, which have no type given.
2227 # at this point, ToPcd.Type has the type found from dependent
2230 TokenCName
= ToPcd
.TokenCName
2231 for PcdItem
in GlobalData
.MixedPcd
:
2232 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2233 TokenCName
= PcdItem
[0]
2236 if GlobalData
.BuildOptionPcd
:
2237 for pcd
in GlobalData
.BuildOptionPcd
:
2238 if (FromPcd
.TokenSpaceGuidCName
, FromPcd
.TokenCName
) == (pcd
[0], pcd
[1]):
2239 FromPcd
.DefaultValue
= pcd
[2]
2241 if ToPcd
.Pending
and FromPcd
.Type
not in [None, '']:
2242 ToPcd
.Type
= FromPcd
.Type
2243 elif (ToPcd
.Type
not in [None, '']) and (FromPcd
.Type
not in [None, ''])\
2244 and (ToPcd
.Type
!= FromPcd
.Type
) and (ToPcd
.Type
in FromPcd
.Type
):
2245 if ToPcd
.Type
.strip() == "DynamicEx":
2246 ToPcd
.Type
= FromPcd
.Type
2247 elif ToPcd
.Type
not in [None, ''] and FromPcd
.Type
not in [None, ''] \
2248 and ToPcd
.Type
!= FromPcd
.Type
:
2249 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2250 ExtraData
="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
2251 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2252 ToPcd
.Type
, Module
, FromPcd
.Type
),
2255 if FromPcd
.MaxDatumSize
not in [None, '']:
2256 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2257 if FromPcd
.DefaultValue
not in [None, '']:
2258 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2259 if FromPcd
.TokenValue
not in [None, '']:
2260 ToPcd
.TokenValue
= FromPcd
.TokenValue
2261 if FromPcd
.MaxDatumSize
not in [None, '']:
2262 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2263 if FromPcd
.DatumType
not in [None, '']:
2264 ToPcd
.DatumType
= FromPcd
.DatumType
2265 if FromPcd
.SkuInfoList
not in [None, '', []]:
2266 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2268 # check the validation of datum
2269 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2271 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2272 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2273 ToPcd
.validateranges
= FromPcd
.validateranges
2274 ToPcd
.validlists
= FromPcd
.validlists
2275 ToPcd
.expressions
= FromPcd
.expressions
2277 if ToPcd
.DatumType
== "VOID*" and ToPcd
.MaxDatumSize
in ['', None]:
2278 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2279 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2280 Value
= ToPcd
.DefaultValue
2281 if Value
in [None, '']:
2282 ToPcd
.MaxDatumSize
= '1'
2283 elif Value
[0] == 'L':
2284 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2285 elif Value
[0] == '{':
2286 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2288 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2290 # apply default SKU for dynamic PCDS if specified one is not available
2291 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_LIST
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_LIST
) \
2292 and ToPcd
.SkuInfoList
in [None, {}, '']:
2293 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2294 SkuName
= self
.Platform
.SkuName
2297 ToPcd
.SkuInfoList
= {
2298 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
], '', '', '', '', '', ToPcd
.DefaultValue
)
2301 ## Apply PCD setting defined platform to a module
2303 # @param Module The module from which the PCD setting will be overrided
2305 # @retval PCD_list The list PCDs with settings from platform
2307 def ApplyPcdSetting(self
, Module
, Pcds
):
2308 # for each PCD in module
2309 for Name
, Guid
in Pcds
:
2310 PcdInModule
= Pcds
[Name
, Guid
]
2311 # find out the PCD setting in platform
2312 if (Name
, Guid
) in self
.Platform
.Pcds
:
2313 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2315 PcdInPlatform
= None
2316 # then override the settings if any
2317 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
)
2318 # resolve the VariableGuid value
2319 for SkuId
in PcdInModule
.SkuInfoList
:
2320 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2321 if Sku
.VariableGuid
== '': continue
2322 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
2323 if Sku
.VariableGuidValue
== None:
2324 PackageList
= "\n\t".join([str(P
) for P
in self
.PackageList
])
2327 RESOURCE_NOT_AVAILABLE
,
2328 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2329 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2330 % (Guid
, Name
, str(Module
)),
2334 # override PCD settings with module specific setting
2335 if Module
in self
.Platform
.Modules
:
2336 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2337 for Key
in PlatformModule
.Pcds
:
2339 self
._OverridePcd
(Pcds
[Key
], PlatformModule
.Pcds
[Key
], Module
)
2340 return Pcds
.values()
2342 ## Resolve library names to library modules
2344 # (for Edk.x modules)
2346 # @param Module The module from which the library names will be resolved
2348 # @retval library_list The list of library modules
2350 def ResolveLibraryReference(self
, Module
):
2351 EdkLogger
.verbose("")
2352 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2353 LibraryConsumerList
= [Module
]
2355 # "CompilerStub" is a must for Edk modules
2356 if Module
.Libraries
:
2357 Module
.Libraries
.append("CompilerStub")
2359 while len(LibraryConsumerList
) > 0:
2360 M
= LibraryConsumerList
.pop()
2361 for LibraryName
in M
.Libraries
:
2362 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2364 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
2365 if LibraryName
.upper() == Key
.upper():
2366 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2369 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2370 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2373 if Library
not in LibraryList
:
2374 LibraryList
.append(Library
)
2375 LibraryConsumerList
.append(Library
)
2376 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2379 ## Calculate the priority value of the build option
2381 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2383 # @retval Value Priority value based on the priority list.
2385 def CalculatePriorityValue(self
, Key
):
2386 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2387 PriorityValue
= 0x11111
2389 PriorityValue
&= 0x01111
2390 if ToolChain
== "*":
2391 PriorityValue
&= 0x10111
2393 PriorityValue
&= 0x11011
2394 if CommandType
== "*":
2395 PriorityValue
&= 0x11101
2397 PriorityValue
&= 0x11110
2399 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2402 ## Expand * in build option key
2404 # @param Options Options to be expanded
2406 # @retval options Options expanded
2408 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2415 # Construct a list contain the build options which need override.
2419 # Key[0] -- tool family
2420 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2422 if (Key
[0] == self
.BuildRuleFamily
and
2423 (ModuleStyle
== None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2424 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2425 if Target
== self
.BuildTarget
or Target
== "*":
2426 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
2427 if Arch
== self
.Arch
or Arch
== "*":
2428 if Options
[Key
].startswith("="):
2429 if OverrideList
.get(Key
[1]) != None:
2430 OverrideList
.pop(Key
[1])
2431 OverrideList
[Key
[1]] = Options
[Key
]
2434 # Use the highest priority value.
2436 if (len(OverrideList
) >= 2):
2437 KeyList
= OverrideList
.keys()
2438 for Index
in range(len(KeyList
)):
2439 NowKey
= KeyList
[Index
]
2440 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2441 for Index1
in range(len(KeyList
) - Index
- 1):
2442 NextKey
= KeyList
[Index1
+ Index
+ 1]
2444 # Compare two Key, if one is included by another, choose the higher priority one
2446 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2447 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2448 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2449 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2450 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2451 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2452 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2453 if Options
.get((self
.BuildRuleFamily
, NextKey
)) != None:
2454 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2456 if Options
.get((self
.BuildRuleFamily
, NowKey
)) != None:
2457 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2460 if ModuleStyle
!= None and len (Key
) > 2:
2461 # Check Module style is EDK or EDKII.
2462 # Only append build option for the matched style module.
2463 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2465 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2468 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2469 # if tool chain family doesn't match, skip it
2470 if Tool
in self
.ToolDefinition
and Family
!= "":
2471 FamilyIsNull
= False
2472 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2473 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2475 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2478 # expand any wildcard
2479 if Target
== "*" or Target
== self
.BuildTarget
:
2480 if Tag
== "*" or Tag
== self
.ToolChain
:
2481 if Arch
== "*" or Arch
== self
.Arch
:
2482 if Tool
not in BuildOptions
:
2483 BuildOptions
[Tool
] = {}
2484 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2485 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2487 # append options for the same tool except PATH
2489 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2491 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2492 # Build Option Family has been checked, which need't to be checked again for family.
2493 if FamilyMatch
or FamilyIsNull
:
2497 if ModuleStyle
!= None and len (Key
) > 2:
2498 # Check Module style is EDK or EDKII.
2499 # Only append build option for the matched style module.
2500 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2502 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2505 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2506 # if tool chain family doesn't match, skip it
2507 if Tool
not in self
.ToolDefinition
or Family
== "":
2509 # option has been added before
2510 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2513 # expand any wildcard
2514 if Target
== "*" or Target
== self
.BuildTarget
:
2515 if Tag
== "*" or Tag
== self
.ToolChain
:
2516 if Arch
== "*" or Arch
== self
.Arch
:
2517 if Tool
not in BuildOptions
:
2518 BuildOptions
[Tool
] = {}
2519 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2520 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2522 # append options for the same tool except PATH
2524 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2526 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2529 ## Append build options in platform to a module
2531 # @param Module The module to which the build options will be appened
2533 # @retval options The options appended with build options in platform
2535 def ApplyBuildOption(self
, Module
):
2536 # Get the different options for the different style module
2537 if Module
.AutoGenVersion
< 0x00010005:
2538 PlatformOptions
= self
.EdkBuildOption
2539 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2541 PlatformOptions
= self
.EdkIIBuildOption
2542 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2543 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2544 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2545 if Module
in self
.Platform
.Modules
:
2546 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2547 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2549 PlatformModuleOptions
= {}
2551 BuildRuleOrder
= None
2552 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2553 for Tool
in Options
:
2554 for Attr
in Options
[Tool
]:
2555 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2556 BuildRuleOrder
= Options
[Tool
][Attr
]
2558 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2559 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2560 self
.ToolDefinition
.keys())
2562 for Tool
in AllTools
:
2563 if Tool
not in BuildOptions
:
2564 BuildOptions
[Tool
] = {}
2566 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2567 if Tool
not in Options
:
2569 for Attr
in Options
[Tool
]:
2570 Value
= Options
[Tool
][Attr
]
2572 # Do not generate it in Makefile
2574 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2576 if Attr
not in BuildOptions
[Tool
]:
2577 BuildOptions
[Tool
][Attr
] = ""
2578 # check if override is indicated
2579 if Value
.startswith('='):
2580 ToolPath
= Value
[1:]
2581 ToolPath
= mws
.handleWsMacro(ToolPath
)
2582 BuildOptions
[Tool
][Attr
] = ToolPath
2584 Value
= mws
.handleWsMacro(Value
)
2586 BuildOptions
[Tool
][Attr
] += " " + Value
2588 BuildOptions
[Tool
][Attr
] = Value
2589 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
!= None:
2591 # Override UNI flag only for EDK module.
2593 if 'BUILD' not in BuildOptions
:
2594 BuildOptions
['BUILD'] = {}
2595 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2596 return BuildOptions
, BuildRuleOrder
2598 Platform
= property(_GetPlatform
)
2599 Name
= property(_GetName
)
2600 Guid
= property(_GetGuid
)
2601 Version
= property(_GetVersion
)
2603 OutputDir
= property(_GetOutputDir
)
2604 BuildDir
= property(_GetBuildDir
)
2605 MakeFileDir
= property(_GetMakeFileDir
)
2606 FdfFile
= property(_GetFdfFile
)
2608 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2609 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2610 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2611 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2612 PackageList
= property(_GetPackageList
)
2614 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2615 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2616 ToolChainFamily
= property(_GetToolChainFamily
)
2617 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2618 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2619 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2620 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2622 BuildCommand
= property(_GetBuildCommand
)
2623 BuildRule
= property(_GetBuildRule
)
2624 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2625 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2626 GenFdsCommand
= property(_GenFdsCommand
)
2628 ## ModuleAutoGen class
2630 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2631 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2632 # to the [depex] section in module's inf file.
2634 class ModuleAutoGen(AutoGen
):
2635 ## Cache the timestamps of metafiles of every module in a class variable
2639 ## The real constructor of ModuleAutoGen
2641 # This method is not supposed to be called by users of ModuleAutoGen. It's
2642 # only used by factory method __new__() to do real initialization work for an
2643 # object of ModuleAutoGen
2645 # @param Workspace EdkIIWorkspaceBuild object
2646 # @param ModuleFile The path of module file
2647 # @param Target Build target (DEBUG, RELEASE)
2648 # @param Toolchain Name of tool chain
2649 # @param Arch The arch the module supports
2650 # @param PlatformFile Platform meta-file
2652 def _Init(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2653 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2654 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2656 self
.Workspace
= Workspace
2657 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2659 self
.MetaFile
= ModuleFile
2660 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2661 # check if this module is employed by active platform
2662 if not self
.PlatformInfo
.ValidModule(self
.MetaFile
):
2663 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2664 % (self
.MetaFile
, Arch
))
2667 self
.SourceDir
= self
.MetaFile
.SubDir
2668 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2670 self
.SourceOverrideDir
= None
2671 # use overrided path defined in DSC file
2672 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2673 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2675 self
.ToolChain
= Toolchain
2676 self
.BuildTarget
= Target
2678 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2679 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2681 self
.IsMakeFileCreated
= False
2682 self
.IsCodeFileCreated
= False
2683 self
.IsAsBuiltInfCreated
= False
2684 self
.DepexGenerated
= False
2686 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2687 self
.BuildRuleOrder
= None
2692 self
._Version
= None
2693 self
._ModuleType
= None
2694 self
._ComponentType
= None
2695 self
._PcdIsDriver
= None
2696 self
._AutoGenVersion
= None
2697 self
._LibraryFlag
= None
2698 self
._CustomMakefile
= None
2701 self
._BuildDir
= None
2702 self
._OutputDir
= None
2703 self
._DebugDir
= None
2704 self
._MakeFileDir
= None
2706 self
._IncludePathList
= None
2707 self
._IncludePathLength
= 0
2708 self
._AutoGenFileList
= None
2709 self
._UnicodeFileList
= None
2710 self
._VfrFileList
= None
2711 self
._IdfFileList
= None
2712 self
._SourceFileList
= None
2713 self
._ObjectFileList
= None
2714 self
._BinaryFileList
= None
2716 self
._DependentPackageList
= None
2717 self
._DependentLibraryList
= None
2718 self
._LibraryAutoGenList
= None
2719 self
._DerivedPackageList
= None
2720 self
._ModulePcdList
= None
2721 self
._LibraryPcdList
= None
2722 self
._PcdComments
= sdict()
2723 self
._GuidList
= None
2724 self
._GuidsUsedByPcd
= None
2725 self
._GuidComments
= sdict()
2726 self
._ProtocolList
= None
2727 self
._ProtocolComments
= sdict()
2728 self
._PpiList
= None
2729 self
._PpiComments
= sdict()
2730 self
._DepexList
= None
2731 self
._DepexExpressionList
= None
2732 self
._BuildOption
= None
2733 self
._BuildOptionIncPathList
= None
2734 self
._BuildTargets
= None
2735 self
._IntroBuildTargetList
= None
2736 self
._FinalBuildTargetList
= None
2737 self
._FileTypes
= None
2738 self
._BuildRules
= None
2740 self
._TimeStampPath
= None
2742 self
.AutoGenDepSet
= set()
2745 ## The Modules referenced to this Library
2746 # Only Library has this attribute
2747 self
._ReferenceModules
= []
2749 ## Store the FixedAtBuild Pcds
2751 self
._FixedAtBuildPcds
= []
2756 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2758 # Get FixedAtBuild Pcds of this Module
2759 def _GetFixedAtBuildPcds(self
):
2760 if self
._FixedAtBuildPcds
:
2761 return self
._FixedAtBuildPcds
2762 for Pcd
in self
.ModulePcdList
:
2763 if Pcd
.Type
!= "FixedAtBuild":
2765 if Pcd
not in self
._FixedAtBuildPcds
:
2766 self
._FixedAtBuildPcds
.append(Pcd
)
2768 return self
._FixedAtBuildPcds
2770 def _GetUniqueBaseName(self
):
2771 BaseName
= self
.Name
2772 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2773 if Module
.MetaFile
== self
.MetaFile
:
2775 if Module
.Name
== self
.Name
:
2776 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2777 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2778 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2779 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2782 # Macros could be used in build_rule.txt (also Makefile)
2783 def _GetMacros(self
):
2784 if self
._Macro
== None:
2785 self
._Macro
= sdict()
2786 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2787 self
._Macro
["MODULE_NAME" ] = self
.Name
2788 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2789 self
._Macro
["MODULE_GUID" ] = self
.Guid
2790 self
._Macro
["MODULE_VERSION" ] = self
.Version
2791 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2792 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2793 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2794 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2795 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2797 self
._Macro
["BASE_NAME" ] = self
.Name
2799 self
._Macro
["ARCH" ] = self
.Arch
2800 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2801 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2802 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2803 self
._Macro
["TARGET" ] = self
.BuildTarget
2805 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2806 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2807 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2808 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2809 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2810 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2811 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2812 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2813 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2814 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2815 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2816 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2817 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2818 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2821 ## Return the module build data object
2822 def _GetModule(self
):
2823 if self
._Module
== None:
2824 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2827 ## Return the module name
2828 def _GetBaseName(self
):
2829 return self
.Module
.BaseName
2831 ## Return the module DxsFile if exist
2832 def _GetDxsFile(self
):
2833 return self
.Module
.DxsFile
2835 ## Return the module SourceOverridePath
2836 def _GetSourceOverridePath(self
):
2837 return self
.Module
.SourceOverridePath
2839 ## Return the module meta-file GUID
2842 # To build same module more than once, the module path with FILE_GUID overridden has
2843 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2844 # in DSC. The overridden GUID can be retrieved from file name
2846 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2848 # Length of GUID is 36
2850 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2851 return self
.Module
.Guid
2853 ## Return the module version
2854 def _GetVersion(self
):
2855 return self
.Module
.Version
2857 ## Return the module type
2858 def _GetModuleType(self
):
2859 return self
.Module
.ModuleType
2861 ## Return the component type (for Edk.x style of module)
2862 def _GetComponentType(self
):
2863 return self
.Module
.ComponentType
2865 ## Return the build type
2866 def _GetBuildType(self
):
2867 return self
.Module
.BuildType
2869 ## Return the PCD_IS_DRIVER setting
2870 def _GetPcdIsDriver(self
):
2871 return self
.Module
.PcdIsDriver
2873 ## Return the autogen version, i.e. module meta-file version
2874 def _GetAutoGenVersion(self
):
2875 return self
.Module
.AutoGenVersion
2877 ## Check if the module is library or not
2878 def _IsLibrary(self
):
2879 if self
._LibraryFlag
== None:
2880 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2881 self
._LibraryFlag
= True
2883 self
._LibraryFlag
= False
2884 return self
._LibraryFlag
2886 ## Check if the module is binary module or not
2887 def _IsBinaryModule(self
):
2888 return self
.Module
.IsBinaryModule
2890 ## Return the directory to store intermediate files of the module
2891 def _GetBuildDir(self
):
2892 if self
._BuildDir
== None:
2893 self
._BuildDir
= path
.join(
2894 self
.PlatformInfo
.BuildDir
,
2897 self
.MetaFile
.BaseName
2899 CreateDirectory(self
._BuildDir
)
2900 return self
._BuildDir
2902 ## Return the directory to store the intermediate object files of the mdoule
2903 def _GetOutputDir(self
):
2904 if self
._OutputDir
== None:
2905 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2906 CreateDirectory(self
._OutputDir
)
2907 return self
._OutputDir
2909 ## Return the directory to store auto-gened source files of the mdoule
2910 def _GetDebugDir(self
):
2911 if self
._DebugDir
== None:
2912 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2913 CreateDirectory(self
._DebugDir
)
2914 return self
._DebugDir
2916 ## Return the path of custom file
2917 def _GetCustomMakefile(self
):
2918 if self
._CustomMakefile
== None:
2919 self
._CustomMakefile
= {}
2920 for Type
in self
.Module
.CustomMakefile
:
2921 if Type
in gMakeTypeMap
:
2922 MakeType
= gMakeTypeMap
[Type
]
2925 if self
.SourceOverrideDir
!= None:
2926 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2927 if not os
.path
.exists(File
):
2928 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2930 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2931 self
._CustomMakefile
[MakeType
] = File
2932 return self
._CustomMakefile
2934 ## Return the directory of the makefile
2936 # @retval string The directory string of module's makefile
2938 def _GetMakeFileDir(self
):
2939 return self
.BuildDir
2941 ## Return build command string
2943 # @retval string Build command string
2945 def _GetBuildCommand(self
):
2946 return self
.PlatformInfo
.BuildCommand
2948 ## Get object list of all packages the module and its dependent libraries belong to
2950 # @retval list The list of package object
2952 def _GetDerivedPackageList(self
):
2954 for M
in [self
.Module
] + self
.DependentLibraryList
:
2955 for Package
in M
.Packages
:
2956 if Package
in PackageList
:
2958 PackageList
.append(Package
)
2961 ## Get the depex string
2963 # @return : a string contain all depex expresion.
2964 def _GetDepexExpresionString(self
):
2967 ## DPX_SOURCE IN Define section.
2968 if self
.Module
.DxsFile
:
2970 for M
in [self
.Module
] + self
.DependentLibraryList
:
2971 Filename
= M
.MetaFile
.Path
2972 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2973 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2974 for DepexExpresion
in DepexExpresionList
:
2975 for key
in DepexExpresion
.keys():
2976 Arch
, ModuleType
= key
2977 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
2978 # the type of build module is USER_DEFINED.
2979 # All different DEPEX section tags would be copied into the As Built INF file
2980 # and there would be separate DEPEX section tags
2981 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2982 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2983 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2985 if Arch
.upper() == TAB_ARCH_COMMON
or \
2986 (Arch
.upper() == self
.Arch
.upper() and \
2987 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2988 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2990 #the type of build module is USER_DEFINED.
2991 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2992 for Depex
in DepexList
:
2993 for key
in Depex
.keys():
2994 DepexStr
+= '[Depex.%s.%s]\n' % key
2995 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
2998 return '[Depex.%s]\n' % self
.Arch
3001 #the type of build module not is USER_DEFINED.
3003 for Depex
in DepexList
:
3008 for D
in Depex
.values():
3009 DepexStr
+= ' '.join([val
for val
in D
])
3010 Index
= DepexStr
.find('END')
3011 if Index
> -1 and Index
== len(DepexStr
) - 3:
3012 DepexStr
= DepexStr
[:-3]
3013 DepexStr
= DepexStr
.strip()
3016 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
3018 return '[Depex.%s]\n' % self
.Arch
3019 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
3021 ## Merge dependency expression
3023 # @retval list The token list of the dependency expression after parsed
3025 def _GetDepexTokenList(self
):
3026 if self
._DepexList
== None:
3027 self
._DepexList
= {}
3028 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3029 return self
._DepexList
3031 self
._DepexList
[self
.ModuleType
] = []
3033 for ModuleType
in self
._DepexList
:
3034 DepexList
= self
._DepexList
[ModuleType
]
3036 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3038 for M
in [self
.Module
] + self
.DependentLibraryList
:
3040 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
3042 DepexList
.append('AND')
3043 DepexList
.append('(')
3045 if DepexList
[-1] == 'END': # no need of a END at this time
3047 DepexList
.append(')')
3050 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
3051 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
3053 if len(DepexList
) > 0:
3054 EdkLogger
.verbose('')
3055 return self
._DepexList
3057 ## Merge dependency expression
3059 # @retval list The token list of the dependency expression after parsed
3061 def _GetDepexExpressionTokenList(self
):
3062 if self
._DepexExpressionList
== None:
3063 self
._DepexExpressionList
= {}
3064 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3065 return self
._DepexExpressionList
3067 self
._DepexExpressionList
[self
.ModuleType
] = ''
3069 for ModuleType
in self
._DepexExpressionList
:
3070 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
3072 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3074 for M
in [self
.Module
] + self
.DependentLibraryList
:
3076 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
3077 if DepexExpressionList
!= '':
3078 DepexExpressionList
+= ' AND '
3079 DepexExpressionList
+= '('
3080 DepexExpressionList
+= D
3081 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
3082 DepexExpressionList
+= ')'
3085 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
3086 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
3088 if len(DepexExpressionList
) > 0:
3089 EdkLogger
.verbose('')
3090 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
3091 return self
._DepexExpressionList
3093 # Get the tiano core user extension, it is contain dependent library.
3094 # @retval: a list contain tiano core userextension.
3096 def _GetTianoCoreUserExtensionList(self
):
3097 TianoCoreUserExtentionList
= []
3098 for M
in [self
.Module
] + self
.DependentLibraryList
:
3099 Filename
= M
.MetaFile
.Path
3100 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
3101 TianoCoreUserExtenList
= InfObj
.GetUserExtensionTianoCore()
3102 for TianoCoreUserExtent
in TianoCoreUserExtenList
:
3103 for Section
in TianoCoreUserExtent
.keys():
3104 ItemList
= Section
.split(TAB_SPLIT
)
3106 if len(ItemList
) == 4:
3108 if Arch
.upper() == TAB_ARCH_COMMON
or Arch
.upper() == self
.Arch
.upper():
3110 TianoCoreList
.extend([TAB_SECTION_START
+ Section
+ TAB_SECTION_END
])
3111 TianoCoreList
.extend(TianoCoreUserExtent
[Section
][:])
3112 TianoCoreList
.append('\n')
3113 TianoCoreUserExtentionList
.append(TianoCoreList
)
3115 return TianoCoreUserExtentionList
3117 ## Return the list of specification version required for the module
3119 # @retval list The list of specification defined in module file
3121 def _GetSpecification(self
):
3122 return self
.Module
.Specification
3124 ## Tool option for the module build
3126 # @param PlatformInfo The object of PlatformBuildInfo
3127 # @retval dict The dict containing valid options
3129 def _GetModuleBuildOption(self
):
3130 if self
._BuildOption
== None:
3131 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
3132 if self
.BuildRuleOrder
:
3133 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
3134 return self
._BuildOption
3136 ## Get include path list from tool option for the module build
3138 # @retval list The include path list
3140 def _GetBuildOptionIncPathList(self
):
3141 if self
._BuildOptionIncPathList
== None:
3143 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3144 # is the former use /I , the Latter used -I to specify include directories
3146 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
3147 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3148 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
3149 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3152 # New ToolChainFamily, don't known whether there is option to specify include directories
3154 self
._BuildOptionIncPathList
= []
3155 return self
._BuildOptionIncPathList
3157 BuildOptionIncPathList
= []
3158 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3161 FlagOption
= self
.BuildOption
[Tool
][Attr
]
3165 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
3166 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
3169 # RVCT may specify a list of directory seperated by commas
3172 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
3173 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3174 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
3177 # EDK II modules must not reference header files outside of the packages they depend on or
3178 # within the module's directory tree. Report error if violation.
3180 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
3181 for Path
in IncPathList
:
3182 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3183 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3184 EdkLogger
.error("build",
3187 File
=str(self
.MetaFile
))
3190 BuildOptionIncPathList
+= IncPathList
3192 self
._BuildOptionIncPathList
= BuildOptionIncPathList
3194 return self
._BuildOptionIncPathList
3196 ## Return a list of files which can be built from source
3198 # What kind of files can be built is determined by build rules in
3199 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3201 def _GetSourceFileList(self
):
3202 if self
._SourceFileList
== None:
3203 self
._SourceFileList
= []
3204 for F
in self
.Module
.Sources
:
3206 if F
.TagName
not in ("", "*", self
.ToolChain
):
3207 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3208 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
3210 # match tool chain family
3211 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
3214 "The file [%s] must be built by tools of [%s], " \
3215 "but current toolchain family is [%s]" \
3216 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
3219 # add the file path into search path list for file including
3220 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3221 self
.IncludePathList
.insert(0, F
.Dir
)
3222 self
._SourceFileList
.append(F
)
3224 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
3226 for F
in self
._SourceFileList
:
3227 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3228 return self
._SourceFileList
3230 def _MatchBuildRuleOrder(self
, FileList
):
3232 self
._GetModuleBuildOption
()
3233 for SingleFile
in FileList
:
3234 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3235 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3236 if key
in Order_Dict
:
3237 Order_Dict
[key
].append(SingleFile
.Ext
)
3239 Order_Dict
[key
] = [SingleFile
.Ext
]
3242 for F
in Order_Dict
:
3243 if len(Order_Dict
[F
]) > 1:
3244 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3245 for Ext
in Order_Dict
[F
][1:]:
3246 RemoveList
.append(F
+ Ext
)
3248 for item
in RemoveList
:
3249 FileList
.remove(item
)
3253 ## Return the list of unicode files
3254 def _GetUnicodeFileList(self
):
3255 if self
._UnicodeFileList
== None:
3256 if TAB_UNICODE_FILE
in self
.FileTypes
:
3257 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
3259 self
._UnicodeFileList
= []
3260 return self
._UnicodeFileList
3262 ## Return the list of vfr files
3263 def _GetVfrFileList(self
):
3264 if self
._VfrFileList
== None:
3265 if TAB_VFR_FILE
in self
.FileTypes
:
3266 self
._VfrFileList
= self
.FileTypes
[TAB_VFR_FILE
]
3268 self
._VfrFileList
= []
3269 return self
._VfrFileList
3271 ## Return the list of Image Definition files
3272 def _GetIdfFileList(self
):
3273 if self
._IdfFileList
== None:
3274 if TAB_IMAGE_FILE
in self
.FileTypes
:
3275 self
._IdfFileList
= self
.FileTypes
[TAB_IMAGE_FILE
]
3277 self
._IdfFileList
= []
3278 return self
._IdfFileList
3280 ## Return a list of files which can be built from binary
3282 # "Build" binary files are just to copy them to build directory.
3284 # @retval list The list of files which can be built later
3286 def _GetBinaryFiles(self
):
3287 if self
._BinaryFileList
== None:
3288 self
._BinaryFileList
= []
3289 for F
in self
.Module
.Binaries
:
3290 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
3292 self
._BinaryFileList
.append(F
)
3293 self
._ApplyBuildRule
(F
, F
.Type
)
3294 return self
._BinaryFileList
3296 def _GetBuildRules(self
):
3297 if self
._BuildRules
== None:
3299 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3300 for Type
in BuildRuleDatabase
.FileTypeList
:
3301 #first try getting build rule by BuildRuleFamily
3302 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3304 # build type is always module type, but ...
3305 if self
.ModuleType
!= self
.BuildType
:
3306 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3307 #second try getting build rule by ToolChainFamily
3309 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3311 # build type is always module type, but ...
3312 if self
.ModuleType
!= self
.BuildType
:
3313 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3316 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3317 BuildRules
[Type
] = RuleObject
3318 for Ext
in RuleObject
.SourceFileExtList
:
3319 BuildRules
[Ext
] = RuleObject
3320 self
._BuildRules
= BuildRules
3321 return self
._BuildRules
3323 def _ApplyBuildRule(self
, File
, FileType
):
3324 if self
._BuildTargets
== None:
3325 self
._IntroBuildTargetList
= set()
3326 self
._FinalBuildTargetList
= set()
3327 self
._BuildTargets
= {}
3328 self
._FileTypes
= {}
3330 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3331 if not os
.path
.exists(SubDirectory
):
3332 CreateDirectory(SubDirectory
)
3338 # Make sure to get build rule order value
3340 self
._GetModuleBuildOption
()
3342 while Index
< len(SourceList
):
3343 Source
= SourceList
[Index
]
3347 CreateDirectory(Source
.Dir
)
3349 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
3350 # Skip all files that are not binary libraries
3351 if not self
.IsLibrary
:
3353 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3354 elif FileType
in self
.BuildRules
:
3355 RuleObject
= self
.BuildRules
[FileType
]
3356 elif Source
.Ext
in self
.BuildRules
:
3357 RuleObject
= self
.BuildRules
[Source
.Ext
]
3359 # stop at no more rules
3361 self
._FinalBuildTargetList
.add(LastTarget
)
3364 FileType
= RuleObject
.SourceFileType
3365 if FileType
not in self
._FileTypes
:
3366 self
._FileTypes
[FileType
] = set()
3367 self
._FileTypes
[FileType
].add(Source
)
3369 # stop at STATIC_LIBRARY for library
3370 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3372 self
._FinalBuildTargetList
.add(LastTarget
)
3375 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3378 self
._FinalBuildTargetList
.add(LastTarget
)
3380 elif not Target
.Outputs
:
3381 # Only do build for target with outputs
3382 self
._FinalBuildTargetList
.add(Target
)
3384 if FileType
not in self
._BuildTargets
:
3385 self
._BuildTargets
[FileType
] = set()
3386 self
._BuildTargets
[FileType
].add(Target
)
3388 if not Source
.IsBinary
and Source
== File
:
3389 self
._IntroBuildTargetList
.add(Target
)
3391 # to avoid cyclic rule
3392 if FileType
in RuleChain
:
3395 RuleChain
.append(FileType
)
3396 SourceList
.extend(Target
.Outputs
)
3398 FileType
= TAB_UNKNOWN_FILE
3400 def _GetTargets(self
):
3401 if self
._BuildTargets
== None:
3402 self
._IntroBuildTargetList
= set()
3403 self
._FinalBuildTargetList
= set()
3404 self
._BuildTargets
= {}
3405 self
._FileTypes
= {}
3407 #TRICK: call _GetSourceFileList to apply build rule for source files
3408 if self
.SourceFileList
:
3411 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3412 if self
.BinaryFileList
:
3415 return self
._BuildTargets
3417 def _GetIntroTargetList(self
):
3419 return self
._IntroBuildTargetList
3421 def _GetFinalTargetList(self
):
3423 return self
._FinalBuildTargetList
3425 def _GetFileTypes(self
):
3427 return self
._FileTypes
3429 ## Get the list of package object the module depends on
3431 # @retval list The package object list
3433 def _GetDependentPackageList(self
):
3434 return self
.Module
.Packages
3436 ## Return the list of auto-generated code file
3438 # @retval list The list of auto-generated file
3440 def _GetAutoGenFileList(self
):
3441 UniStringAutoGenC
= True
3442 IdfStringAutoGenC
= True
3443 UniStringBinBuffer
= StringIO()
3444 IdfGenBinBuffer
= StringIO()
3445 if self
.BuildType
== 'UEFI_HII':
3446 UniStringAutoGenC
= False
3447 IdfStringAutoGenC
= False
3448 if self
._AutoGenFileList
== None:
3449 self
._AutoGenFileList
= {}
3450 AutoGenC
= TemplateString()
3451 AutoGenH
= TemplateString()
3452 StringH
= TemplateString()
3453 StringIdf
= TemplateString()
3454 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
, StringIdf
, IdfStringAutoGenC
, IdfGenBinBuffer
)
3456 # AutoGen.c is generated if there are library classes in inf, or there are object files
3458 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3459 or TAB_OBJECT_FILE
in self
.FileTypes
):
3460 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3461 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3462 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3463 if str(AutoGenH
) != "":
3464 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3465 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3466 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3467 if str(StringH
) != "":
3468 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3469 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3470 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3471 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
3472 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3473 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3474 AutoFile
.IsBinary
= True
3475 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3476 if UniStringBinBuffer
!= None:
3477 UniStringBinBuffer
.close()
3478 if str(StringIdf
) != "":
3479 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3480 self
._AutoGenFileList
[AutoFile
] = str(StringIdf
)
3481 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3482 if IdfGenBinBuffer
!= None and IdfGenBinBuffer
.getvalue() != "":
3483 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3484 self
._AutoGenFileList
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3485 AutoFile
.IsBinary
= True
3486 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3487 if IdfGenBinBuffer
!= None:
3488 IdfGenBinBuffer
.close()
3489 return self
._AutoGenFileList
3491 ## Return the list of library modules explicitly or implicityly used by this module
3492 def _GetLibraryList(self
):
3493 if self
._DependentLibraryList
== None:
3494 # only merge library classes and PCD for non-library module
3496 self
._DependentLibraryList
= []
3498 if self
.AutoGenVersion
< 0x00010005:
3499 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3501 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3502 return self
._DependentLibraryList
3505 def UpdateComments(Recver
, Src
):
3507 if Key
not in Recver
:
3509 Recver
[Key
].extend(Src
[Key
])
3510 ## Get the list of PCDs from current module
3512 # @retval list The list of PCD
3514 def _GetModulePcdList(self
):
3515 if self
._ModulePcdList
== None:
3516 # apply PCD settings from platform
3517 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3518 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3519 return self
._ModulePcdList
3521 ## Get the list of PCDs from dependent libraries
3523 # @retval list The list of PCD
3525 def _GetLibraryPcdList(self
):
3526 if self
._LibraryPcdList
== None:
3528 if not self
.IsLibrary
:
3529 # get PCDs from dependent libraries
3530 for Library
in self
.DependentLibraryList
:
3531 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3532 for Key
in Library
.Pcds
:
3533 # skip duplicated PCDs
3534 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3536 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3537 # apply PCD settings from platform
3538 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3540 self
._LibraryPcdList
= []
3541 return self
._LibraryPcdList
3543 ## Get the GUID value mapping
3545 # @retval dict The mapping between GUID cname and its value
3547 def _GetGuidList(self
):
3548 if self
._GuidList
== None:
3549 self
._GuidList
= sdict()
3550 self
._GuidList
.update(self
.Module
.Guids
)
3551 for Library
in self
.DependentLibraryList
:
3552 self
._GuidList
.update(Library
.Guids
)
3553 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3554 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3555 return self
._GuidList
3557 def GetGuidsUsedByPcd(self
):
3558 if self
._GuidsUsedByPcd
== None:
3559 self
._GuidsUsedByPcd
= sdict()
3560 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3561 for Library
in self
.DependentLibraryList
:
3562 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3563 return self
._GuidsUsedByPcd
3564 ## Get the protocol value mapping
3566 # @retval dict The mapping between protocol cname and its value
3568 def _GetProtocolList(self
):
3569 if self
._ProtocolList
== None:
3570 self
._ProtocolList
= sdict()
3571 self
._ProtocolList
.update(self
.Module
.Protocols
)
3572 for Library
in self
.DependentLibraryList
:
3573 self
._ProtocolList
.update(Library
.Protocols
)
3574 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3575 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3576 return self
._ProtocolList
3578 ## Get the PPI value mapping
3580 # @retval dict The mapping between PPI cname and its value
3582 def _GetPpiList(self
):
3583 if self
._PpiList
== None:
3584 self
._PpiList
= sdict()
3585 self
._PpiList
.update(self
.Module
.Ppis
)
3586 for Library
in self
.DependentLibraryList
:
3587 self
._PpiList
.update(Library
.Ppis
)
3588 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3589 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3590 return self
._PpiList
3592 ## Get the list of include search path
3594 # @retval list The list path
3596 def _GetIncludePathList(self
):
3597 if self
._IncludePathList
== None:
3598 self
._IncludePathList
= []
3599 if self
.AutoGenVersion
< 0x00010005:
3600 for Inc
in self
.Module
.Includes
:
3601 if Inc
not in self
._IncludePathList
:
3602 self
._IncludePathList
.append(Inc
)
3604 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3605 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3606 self
._IncludePathList
.append(Inc
)
3607 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3608 self
._IncludePathList
.append(self
.DebugDir
)
3610 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3611 self
._IncludePathList
.append(self
.DebugDir
)
3613 for Package
in self
.Module
.Packages
:
3614 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3615 if PackageDir
not in self
._IncludePathList
:
3616 self
._IncludePathList
.append(PackageDir
)
3617 IncludesList
= Package
.Includes
3618 if Package
._PrivateIncludes
:
3619 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3620 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3621 for Inc
in IncludesList
:
3622 if Inc
not in self
._IncludePathList
:
3623 self
._IncludePathList
.append(str(Inc
))
3624 return self
._IncludePathList
3626 def _GetIncludePathLength(self
):
3627 self
._IncludePathLength
= 0
3628 if self
._IncludePathList
:
3629 for inc
in self
._IncludePathList
:
3630 self
._IncludePathLength
+= len(' ' + inc
)
3631 return self
._IncludePathLength
3633 ## Get HII EX PCDs which maybe used by VFR
3635 # efivarstore used by VFR may relate with HII EX PCDs
3636 # Get the variable name and GUID from efivarstore and HII EX PCD
3637 # List the HII EX PCDs in As Built INF if both name and GUID match.
3639 # @retval list HII EX PCDs
3641 def _GetPcdsMaybeUsedByVfr(self
):
3642 if not self
.SourceFileList
:
3646 for SrcFile
in self
.SourceFileList
:
3647 if SrcFile
.Ext
.lower() != '.vfr':
3649 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3650 if not os
.path
.exists(Vfri
):
3652 VfriFile
= open(Vfri
, 'r')
3653 Content
= VfriFile
.read()
3655 Pos
= Content
.find('efivarstore')
3658 # Make sure 'efivarstore' is the start of efivarstore statement
3659 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3662 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3664 if Index
>= 0 and Content
[Index
] != ';':
3665 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3668 # 'efivarstore' must be followed by name and guid
3670 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3673 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3676 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3677 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3678 Pos
= Content
.find('efivarstore', Name
.end())
3682 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3683 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3685 for SkuName
in Pcd
.SkuInfoList
:
3686 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3687 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3688 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3691 Guid
= GuidStructureStringToGuidString(Value
)
3692 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3693 HiiExPcds
.append(Pcd
)
3698 def _GenOffsetBin(self
):
3700 for SourceFile
in self
.Module
.Sources
:
3701 if SourceFile
.Type
.upper() == ".VFR" :
3703 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3705 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3706 if SourceFile
.Type
.upper() == ".UNI" :
3708 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3710 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3712 if len(VfrUniBaseName
) == 0:
3714 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3715 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3716 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3717 if not VfrUniOffsetList
:
3720 OutputName
= '%sOffset.bin' % self
.Name
3721 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3724 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3726 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3728 # Use a instance of StringIO to cache data
3729 fStringIO
= StringIO('')
3731 for Item
in VfrUniOffsetList
:
3732 if (Item
[0].find("Strings") != -1):
3734 # UNI offset in image.
3736 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3738 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3739 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3740 fStringIO
.write(''.join(UniGuid
))
3741 UniValue
= pack ('Q', int (Item
[1], 16))
3742 fStringIO
.write (UniValue
)
3745 # VFR binary offset in image.
3747 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3749 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3750 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3751 fStringIO
.write(''.join(VfrGuid
))
3753 VfrValue
= pack ('Q', int (Item
[1], 16))
3754 fStringIO
.write (VfrValue
)
3756 # write data into file.
3759 fInputfile
.write (fStringIO
.getvalue())
3761 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3762 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3768 ## Create AsBuilt INF file the module
3770 def CreateAsBuiltInf(self
):
3771 if self
.IsAsBuiltInfCreated
:
3774 # Skip the following code for EDK I inf
3775 if self
.AutoGenVersion
< 0x00010005:
3778 # Skip the following code for libraries
3782 # Skip the following code for modules with no source files
3783 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3786 # Skip the following code for modules without any binary files
3787 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3790 ### TODO: How to handles mixed source and binary modules
3792 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3793 # Also find all packages that the DynamicEx PCDs depend on
3798 PcdTokenSpaceList
= []
3799 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3800 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3801 PatchablePcds
+= [Pcd
]
3802 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3803 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3806 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3807 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3808 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3810 GuidList
.update(self
.GuidList
)
3811 for TokenSpace
in self
.GetGuidsUsedByPcd():
3812 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3813 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3814 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3815 GuidList
.pop(TokenSpace
)
3816 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3817 for Package
in self
.DerivedPackageList
:
3818 if Package
in Packages
:
3820 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3822 for Index
in range(len(BeChecked
)):
3823 for Item
in CheckList
[Index
]:
3824 if Item
in BeChecked
[Index
]:
3825 Packages
+= [Package
]
3830 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3831 for Pkg
in self
.PlatformInfo
.PackageList
:
3834 for VfrPcd
in VfrPcds
:
3835 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3836 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3840 ModuleType
= self
.ModuleType
3841 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3842 ModuleType
= 'DXE_DRIVER'
3845 if self
.PcdIsDriver
!= '':
3846 DriverType
= self
.PcdIsDriver
3849 MDefs
= self
.Module
.Defines
3852 'module_name' : self
.Name
,
3853 'module_guid' : Guid
,
3854 'module_module_type' : ModuleType
,
3855 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3856 'pcd_is_driver_string' : [],
3857 'module_uefi_specification_version' : [],
3858 'module_pi_specification_version' : [],
3859 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3860 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3861 'module_constructor' : self
.Module
.ConstructorList
,
3862 'module_destructor' : self
.Module
.DestructorList
,
3863 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3864 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3865 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3866 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3867 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3868 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3869 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3870 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3871 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3872 'module_arch' : self
.Arch
,
3873 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3875 'patchablepcd_item' : [],
3877 'protocol_item' : [],
3881 'libraryclasses_item' : []
3884 if 'MODULE_UNI_FILE' in MDefs
:
3885 UNIFile
= os
.path
.join(self
.MetaFile
.Dir
, MDefs
['MODULE_UNI_FILE'])
3886 if os
.path
.isfile(UNIFile
):
3887 shutil
.copy2(UNIFile
, self
.OutputDir
)
3889 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3890 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3892 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3895 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3897 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3898 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3899 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3900 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3902 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3904 for Item
in self
.CodaTargetList
:
3905 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3906 if Item
.Target
.Ext
.lower() == '.aml':
3907 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3908 elif Item
.Target
.Ext
.lower() == '.acpi':
3909 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3910 elif Item
.Target
.Ext
.lower() == '.efi':
3911 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3913 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3914 if self
.DepexGenerated
:
3915 if self
.ModuleType
in ['PEIM']:
3916 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3917 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3918 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3919 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3920 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3922 Bin
= self
._GenOffsetBin
()
3924 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3926 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3928 if File
.lower().endswith('.pdb'):
3929 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3930 HeaderComments
= self
.Module
.HeaderComments
3932 for Index
in range(len(HeaderComments
)):
3933 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3934 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3937 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3938 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3941 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3942 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3943 (GuidList
, self
._GuidComments
, 'guid_item')
3945 for Item
in GenList
:
3946 for CName
in Item
[0]:
3948 if CName
in Item
[1]:
3949 Comments
= '\n '.join(Item
[1][CName
])
3952 Entry
= Comments
+ '\n ' + CName
3953 AsBuiltInfDict
[Item
[2]].append(Entry
)
3954 PatchList
= parsePcdInfoFromMapFile(
3955 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3956 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3959 for Pcd
in PatchablePcds
:
3960 TokenCName
= Pcd
.TokenCName
3961 for PcdItem
in GlobalData
.MixedPcd
:
3962 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3963 TokenCName
= PcdItem
[0]
3965 for PatchPcd
in PatchList
:
3966 if TokenCName
== PatchPcd
[0]:
3971 if Pcd
.DatumType
== 'BOOLEAN':
3972 BoolValue
= Pcd
.DefaultValue
.upper()
3973 if BoolValue
== 'TRUE':
3974 Pcd
.DefaultValue
= '1'
3975 elif BoolValue
== 'FALSE':
3976 Pcd
.DefaultValue
= '0'
3978 if Pcd
.DatumType
!= 'VOID*':
3979 HexFormat
= '0x%02x'
3980 if Pcd
.DatumType
== 'UINT16':
3981 HexFormat
= '0x%04x'
3982 elif Pcd
.DatumType
== 'UINT32':
3983 HexFormat
= '0x%08x'
3984 elif Pcd
.DatumType
== 'UINT64':
3985 HexFormat
= '0x%016x'
3986 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3988 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
3989 EdkLogger
.error("build", AUTOGEN_ERROR
,
3990 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3992 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3993 PcdValue
= Pcd
.DefaultValue
3994 if PcdValue
[0] != '{':
3996 if PcdValue
[0] == 'L':
3998 PcdValue
= PcdValue
.lstrip('L')
3999 PcdValue
= eval(PcdValue
)
4001 for Index
in range(0, len(PcdValue
)):
4003 CharVal
= ord(PcdValue
[Index
])
4004 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
4005 + '0x%02x' % (CharVal
>> 8) + ', '
4007 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
4010 Padding
= Padding
* 2
4011 ArraySize
= ArraySize
/ 2
4012 if ArraySize
< (len(PcdValue
) + 1):
4013 EdkLogger
.error("build", AUTOGEN_ERROR
,
4014 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4016 if ArraySize
> len(PcdValue
) + 1:
4017 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
4018 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
4019 elif len(PcdValue
.split(',')) <= ArraySize
:
4020 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
4023 EdkLogger
.error("build", AUTOGEN_ERROR
,
4024 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4026 PcdItem
= '%s.%s|%s|0x%X' % \
4027 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
4029 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4030 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
4032 PcdItem
= PcdComments
+ '\n ' + PcdItem
4033 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
4036 for Pcd
in Pcds
+ VfrPcds
:
4041 TokenCName
= Pcd
.TokenCName
4042 for PcdItem
in GlobalData
.MixedPcd
:
4043 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
4044 TokenCName
= PcdItem
[0]
4046 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
4047 for SkuName
in Pcd
.SkuInfoList
:
4048 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
4049 SkuId
= SkuInfo
.SkuId
4050 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
4054 # Don't generate duplicated HII PCD
4056 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
4059 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
4060 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4061 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
4065 for Index
, Comment
in enumerate(PcdCommentList
):
4066 for Usage
in UsageList
:
4067 if Comment
.find(Usage
) != -1:
4071 if UsageIndex
!= -1:
4072 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
4074 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
4075 PcdComments
= '\n '.join(PcdCommentList
)
4076 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
4078 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
4079 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
4080 for Item
in self
.BuildOption
:
4081 if 'FLAGS' in self
.BuildOption
[Item
]:
4082 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
4084 # Generated LibraryClasses section in comments.
4085 for Library
in self
.LibraryAutoGenList
:
4086 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
4088 # Generated UserExtensions TianoCore section.
4089 # All tianocore user extensions are copied.
4091 for TianoCore
in self
._GetTianoCoreUserExtensionList
():
4092 UserExtStr
+= '\n'.join(TianoCore
)
4093 ExtensionFile
= os
.path
.join(self
.MetaFile
.Dir
, TianoCore
[1])
4094 if os
.path
.isfile(ExtensionFile
):
4095 shutil
.copy2(ExtensionFile
, self
.OutputDir
)
4096 AsBuiltInfDict
['userextension_tianocore_item'] = UserExtStr
4098 # Generated depex expression section in comments.
4099 AsBuiltInfDict
['depexsection_item'] = ''
4100 DepexExpresion
= self
._GetDepexExpresionString
()
4102 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
4104 AsBuiltInf
= TemplateString()
4105 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
4107 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
4109 self
.IsAsBuiltInfCreated
= True
4111 ## Create makefile for the module and its dependent libraries
4113 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
4114 # dependent libraries will be created
4116 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
4117 # Ignore generating makefile when it is a binary module
4118 if self
.IsBinaryModule
:
4121 if self
.IsMakeFileCreated
:
4126 if not self
.IsLibrary
and CreateLibraryMakeFile
:
4127 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4128 LibraryAutoGen
.CreateMakeFile()
4130 if len(self
.CustomMakefile
) == 0:
4131 Makefile
= GenMake
.ModuleMakefile(self
)
4133 Makefile
= GenMake
.CustomMakefile(self
)
4134 if Makefile
.Generate():
4135 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
4136 (self
.Name
, self
.Arch
))
4138 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
4139 (self
.Name
, self
.Arch
))
4141 self
.CreateTimeStamp(Makefile
)
4142 self
.IsMakeFileCreated
= True
4144 def CopyBinaryFiles(self
):
4145 for File
in self
.Module
.Binaries
:
4147 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4148 CopyLongFilePath(SrcPath
, DstPath
)
4149 ## Create autogen code for the module and its dependent libraries
4151 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4152 # dependent libraries will be created
4154 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4155 if self
.IsCodeFileCreated
:
4160 # Need to generate PcdDatabase even PcdDriver is binarymodule
4161 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4162 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4164 if self
.IsBinaryModule
:
4166 self
.CopyBinaryFiles()
4169 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4170 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4171 LibraryAutoGen
.CreateCodeFile()
4174 IgoredAutoGenList
= []
4176 for File
in self
.AutoGenFileList
:
4177 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4178 #Ignore Edk AutoGen.c
4179 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
4182 AutoGenList
.append(str(File
))
4184 IgoredAutoGenList
.append(str(File
))
4186 # Skip the following code for EDK I inf
4187 if self
.AutoGenVersion
< 0x00010005:
4190 for ModuleType
in self
.DepexList
:
4191 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
4192 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
4195 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4196 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4198 if len(Dpx
.PostfixNotation
) <> 0:
4199 self
.DepexGenerated
= True
4201 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4202 AutoGenList
.append(str(DpxFile
))
4204 IgoredAutoGenList
.append(str(DpxFile
))
4206 if IgoredAutoGenList
== []:
4207 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4208 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4209 elif AutoGenList
== []:
4210 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4211 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4213 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4214 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4216 self
.IsCodeFileCreated
= True
4219 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4220 def _GetLibraryAutoGenList(self
):
4221 if self
._LibraryAutoGenList
== None:
4222 self
._LibraryAutoGenList
= []
4223 for Library
in self
.DependentLibraryList
:
4230 self
.PlatformInfo
.MetaFile
4232 if La
not in self
._LibraryAutoGenList
:
4233 self
._LibraryAutoGenList
.append(La
)
4234 for Lib
in La
.CodaTargetList
:
4235 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4236 return self
._LibraryAutoGenList
4238 ## Decide whether we can skip the ModuleAutoGen process
4239 # If any source file is newer than the modeule than we cannot skip
4242 if not os
.path
.exists(self
.GetTimeStampPath()):
4244 #last creation time of the module
4245 DstTimeStamp
= os
.stat(self
.GetTimeStampPath())[8]
4247 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4248 if SrcTimeStamp
> DstTimeStamp
:
4251 with
open(self
.GetTimeStampPath(),'r') as f
:
4253 source
= source
.rstrip('\n')
4254 if not os
.path
.exists(source
):
4256 if source
not in ModuleAutoGen
.TimeDict
:
4257 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4258 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4262 def GetTimeStampPath(self
):
4263 if self
._TimeStampPath
== None:
4264 self
._TimeStampPath
= os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')
4265 return self
._TimeStampPath
4266 def CreateTimeStamp(self
, Makefile
):
4270 FileSet
.add (self
.MetaFile
.Path
)
4272 for SourceFile
in self
.Module
.Sources
:
4273 FileSet
.add (SourceFile
.Path
)
4275 for Lib
in self
.DependentLibraryList
:
4276 FileSet
.add (Lib
.MetaFile
.Path
)
4278 for f
in self
.AutoGenDepSet
:
4279 FileSet
.add (f
.Path
)
4281 if os
.path
.exists (self
.GetTimeStampPath()):
4282 os
.remove (self
.GetTimeStampPath())
4283 with
open(self
.GetTimeStampPath(), 'w+') as file:
4287 Module
= property(_GetModule
)
4288 Name
= property(_GetBaseName
)
4289 Guid
= property(_GetGuid
)
4290 Version
= property(_GetVersion
)
4291 ModuleType
= property(_GetModuleType
)
4292 ComponentType
= property(_GetComponentType
)
4293 BuildType
= property(_GetBuildType
)
4294 PcdIsDriver
= property(_GetPcdIsDriver
)
4295 AutoGenVersion
= property(_GetAutoGenVersion
)
4296 Macros
= property(_GetMacros
)
4297 Specification
= property(_GetSpecification
)
4299 IsLibrary
= property(_IsLibrary
)
4300 IsBinaryModule
= property(_IsBinaryModule
)
4301 BuildDir
= property(_GetBuildDir
)
4302 OutputDir
= property(_GetOutputDir
)
4303 DebugDir
= property(_GetDebugDir
)
4304 MakeFileDir
= property(_GetMakeFileDir
)
4305 CustomMakefile
= property(_GetCustomMakefile
)
4307 IncludePathList
= property(_GetIncludePathList
)
4308 IncludePathLength
= property(_GetIncludePathLength
)
4309 AutoGenFileList
= property(_GetAutoGenFileList
)
4310 UnicodeFileList
= property(_GetUnicodeFileList
)
4311 VfrFileList
= property(_GetVfrFileList
)
4312 SourceFileList
= property(_GetSourceFileList
)
4313 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
4314 Targets
= property(_GetTargets
)
4315 IntroTargetList
= property(_GetIntroTargetList
)
4316 CodaTargetList
= property(_GetFinalTargetList
)
4317 FileTypes
= property(_GetFileTypes
)
4318 BuildRules
= property(_GetBuildRules
)
4319 IdfFileList
= property(_GetIdfFileList
)
4321 DependentPackageList
= property(_GetDependentPackageList
)
4322 DependentLibraryList
= property(_GetLibraryList
)
4323 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
4324 DerivedPackageList
= property(_GetDerivedPackageList
)
4326 ModulePcdList
= property(_GetModulePcdList
)
4327 LibraryPcdList
= property(_GetLibraryPcdList
)
4328 GuidList
= property(_GetGuidList
)
4329 ProtocolList
= property(_GetProtocolList
)
4330 PpiList
= property(_GetPpiList
)
4331 DepexList
= property(_GetDepexTokenList
)
4332 DxsFile
= property(_GetDxsFile
)
4333 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
4334 BuildOption
= property(_GetModuleBuildOption
)
4335 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
4336 BuildCommand
= property(_GetBuildCommand
)
4338 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
4340 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4341 if __name__
== '__main__':