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
:
2342 elif Key
in GlobalData
.MixedPcd
:
2343 for PcdItem
in GlobalData
.MixedPcd
[Key
]:
2345 ToPcd
= Pcds
[PcdItem
]
2349 self
._OverridePcd
(ToPcd
, PlatformModule
.Pcds
[Key
], Module
)
2350 return Pcds
.values()
2352 ## Resolve library names to library modules
2354 # (for Edk.x modules)
2356 # @param Module The module from which the library names will be resolved
2358 # @retval library_list The list of library modules
2360 def ResolveLibraryReference(self
, Module
):
2361 EdkLogger
.verbose("")
2362 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2363 LibraryConsumerList
= [Module
]
2365 # "CompilerStub" is a must for Edk modules
2366 if Module
.Libraries
:
2367 Module
.Libraries
.append("CompilerStub")
2369 while len(LibraryConsumerList
) > 0:
2370 M
= LibraryConsumerList
.pop()
2371 for LibraryName
in M
.Libraries
:
2372 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2374 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
2375 if LibraryName
.upper() == Key
.upper():
2376 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2379 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2380 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2383 if Library
not in LibraryList
:
2384 LibraryList
.append(Library
)
2385 LibraryConsumerList
.append(Library
)
2386 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2389 ## Calculate the priority value of the build option
2391 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2393 # @retval Value Priority value based on the priority list.
2395 def CalculatePriorityValue(self
, Key
):
2396 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2397 PriorityValue
= 0x11111
2399 PriorityValue
&= 0x01111
2400 if ToolChain
== "*":
2401 PriorityValue
&= 0x10111
2403 PriorityValue
&= 0x11011
2404 if CommandType
== "*":
2405 PriorityValue
&= 0x11101
2407 PriorityValue
&= 0x11110
2409 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2412 ## Expand * in build option key
2414 # @param Options Options to be expanded
2416 # @retval options Options expanded
2418 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2425 # Construct a list contain the build options which need override.
2429 # Key[0] -- tool family
2430 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2432 if (Key
[0] == self
.BuildRuleFamily
and
2433 (ModuleStyle
== None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2434 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2435 if Target
== self
.BuildTarget
or Target
== "*":
2436 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
2437 if Arch
== self
.Arch
or Arch
== "*":
2438 if Options
[Key
].startswith("="):
2439 if OverrideList
.get(Key
[1]) != None:
2440 OverrideList
.pop(Key
[1])
2441 OverrideList
[Key
[1]] = Options
[Key
]
2444 # Use the highest priority value.
2446 if (len(OverrideList
) >= 2):
2447 KeyList
= OverrideList
.keys()
2448 for Index
in range(len(KeyList
)):
2449 NowKey
= KeyList
[Index
]
2450 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2451 for Index1
in range(len(KeyList
) - Index
- 1):
2452 NextKey
= KeyList
[Index1
+ Index
+ 1]
2454 # Compare two Key, if one is included by another, choose the higher priority one
2456 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2457 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2458 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2459 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2460 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2461 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2462 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2463 if Options
.get((self
.BuildRuleFamily
, NextKey
)) != None:
2464 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2466 if Options
.get((self
.BuildRuleFamily
, NowKey
)) != None:
2467 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2470 if ModuleStyle
!= None and len (Key
) > 2:
2471 # Check Module style is EDK or EDKII.
2472 # Only append build option for the matched style module.
2473 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2475 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2478 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2479 # if tool chain family doesn't match, skip it
2480 if Tool
in self
.ToolDefinition
and Family
!= "":
2481 FamilyIsNull
= False
2482 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2483 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2485 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2488 # expand any wildcard
2489 if Target
== "*" or Target
== self
.BuildTarget
:
2490 if Tag
== "*" or Tag
== self
.ToolChain
:
2491 if Arch
== "*" or Arch
== self
.Arch
:
2492 if Tool
not in BuildOptions
:
2493 BuildOptions
[Tool
] = {}
2494 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2495 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2497 # append options for the same tool except PATH
2499 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2501 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2502 # Build Option Family has been checked, which need't to be checked again for family.
2503 if FamilyMatch
or FamilyIsNull
:
2507 if ModuleStyle
!= None and len (Key
) > 2:
2508 # Check Module style is EDK or EDKII.
2509 # Only append build option for the matched style module.
2510 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2512 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2515 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2516 # if tool chain family doesn't match, skip it
2517 if Tool
not in self
.ToolDefinition
or Family
== "":
2519 # option has been added before
2520 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2523 # expand any wildcard
2524 if Target
== "*" or Target
== self
.BuildTarget
:
2525 if Tag
== "*" or Tag
== self
.ToolChain
:
2526 if Arch
== "*" or Arch
== self
.Arch
:
2527 if Tool
not in BuildOptions
:
2528 BuildOptions
[Tool
] = {}
2529 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2530 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2532 # append options for the same tool except PATH
2534 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2536 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2539 ## Append build options in platform to a module
2541 # @param Module The module to which the build options will be appened
2543 # @retval options The options appended with build options in platform
2545 def ApplyBuildOption(self
, Module
):
2546 # Get the different options for the different style module
2547 if Module
.AutoGenVersion
< 0x00010005:
2548 PlatformOptions
= self
.EdkBuildOption
2549 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2551 PlatformOptions
= self
.EdkIIBuildOption
2552 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2553 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2554 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2555 if Module
in self
.Platform
.Modules
:
2556 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2557 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2559 PlatformModuleOptions
= {}
2561 BuildRuleOrder
= None
2562 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2563 for Tool
in Options
:
2564 for Attr
in Options
[Tool
]:
2565 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2566 BuildRuleOrder
= Options
[Tool
][Attr
]
2568 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2569 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2570 self
.ToolDefinition
.keys())
2572 for Tool
in AllTools
:
2573 if Tool
not in BuildOptions
:
2574 BuildOptions
[Tool
] = {}
2576 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2577 if Tool
not in Options
:
2579 for Attr
in Options
[Tool
]:
2580 Value
= Options
[Tool
][Attr
]
2582 # Do not generate it in Makefile
2584 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2586 if Attr
not in BuildOptions
[Tool
]:
2587 BuildOptions
[Tool
][Attr
] = ""
2588 # check if override is indicated
2589 if Value
.startswith('='):
2590 ToolPath
= Value
[1:]
2591 ToolPath
= mws
.handleWsMacro(ToolPath
)
2592 BuildOptions
[Tool
][Attr
] = ToolPath
2594 Value
= mws
.handleWsMacro(Value
)
2596 BuildOptions
[Tool
][Attr
] += " " + Value
2598 BuildOptions
[Tool
][Attr
] = Value
2599 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
!= None:
2601 # Override UNI flag only for EDK module.
2603 if 'BUILD' not in BuildOptions
:
2604 BuildOptions
['BUILD'] = {}
2605 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2606 return BuildOptions
, BuildRuleOrder
2608 Platform
= property(_GetPlatform
)
2609 Name
= property(_GetName
)
2610 Guid
= property(_GetGuid
)
2611 Version
= property(_GetVersion
)
2613 OutputDir
= property(_GetOutputDir
)
2614 BuildDir
= property(_GetBuildDir
)
2615 MakeFileDir
= property(_GetMakeFileDir
)
2616 FdfFile
= property(_GetFdfFile
)
2618 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2619 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2620 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2621 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2622 PackageList
= property(_GetPackageList
)
2624 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2625 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2626 ToolChainFamily
= property(_GetToolChainFamily
)
2627 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2628 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2629 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2630 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2632 BuildCommand
= property(_GetBuildCommand
)
2633 BuildRule
= property(_GetBuildRule
)
2634 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2635 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2636 GenFdsCommand
= property(_GenFdsCommand
)
2638 ## ModuleAutoGen class
2640 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2641 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2642 # to the [depex] section in module's inf file.
2644 class ModuleAutoGen(AutoGen
):
2645 ## Cache the timestamps of metafiles of every module in a class variable
2649 ## The real constructor of ModuleAutoGen
2651 # This method is not supposed to be called by users of ModuleAutoGen. It's
2652 # only used by factory method __new__() to do real initialization work for an
2653 # object of ModuleAutoGen
2655 # @param Workspace EdkIIWorkspaceBuild object
2656 # @param ModuleFile The path of module file
2657 # @param Target Build target (DEBUG, RELEASE)
2658 # @param Toolchain Name of tool chain
2659 # @param Arch The arch the module supports
2660 # @param PlatformFile Platform meta-file
2662 def _Init(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2663 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2664 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2666 self
.Workspace
= Workspace
2667 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2669 self
.MetaFile
= ModuleFile
2670 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2671 # check if this module is employed by active platform
2672 if not self
.PlatformInfo
.ValidModule(self
.MetaFile
):
2673 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2674 % (self
.MetaFile
, Arch
))
2677 self
.SourceDir
= self
.MetaFile
.SubDir
2678 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2680 self
.SourceOverrideDir
= None
2681 # use overrided path defined in DSC file
2682 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2683 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2685 self
.ToolChain
= Toolchain
2686 self
.BuildTarget
= Target
2688 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2689 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2691 self
.IsMakeFileCreated
= False
2692 self
.IsCodeFileCreated
= False
2693 self
.IsAsBuiltInfCreated
= False
2694 self
.DepexGenerated
= False
2696 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2697 self
.BuildRuleOrder
= None
2702 self
._Version
= None
2703 self
._ModuleType
= None
2704 self
._ComponentType
= None
2705 self
._PcdIsDriver
= None
2706 self
._AutoGenVersion
= None
2707 self
._LibraryFlag
= None
2708 self
._CustomMakefile
= None
2711 self
._BuildDir
= None
2712 self
._OutputDir
= None
2713 self
._DebugDir
= None
2714 self
._MakeFileDir
= None
2716 self
._IncludePathList
= None
2717 self
._IncludePathLength
= 0
2718 self
._AutoGenFileList
= None
2719 self
._UnicodeFileList
= None
2720 self
._VfrFileList
= None
2721 self
._IdfFileList
= None
2722 self
._SourceFileList
= None
2723 self
._ObjectFileList
= None
2724 self
._BinaryFileList
= None
2726 self
._DependentPackageList
= None
2727 self
._DependentLibraryList
= None
2728 self
._LibraryAutoGenList
= None
2729 self
._DerivedPackageList
= None
2730 self
._ModulePcdList
= None
2731 self
._LibraryPcdList
= None
2732 self
._PcdComments
= sdict()
2733 self
._GuidList
= None
2734 self
._GuidsUsedByPcd
= None
2735 self
._GuidComments
= sdict()
2736 self
._ProtocolList
= None
2737 self
._ProtocolComments
= sdict()
2738 self
._PpiList
= None
2739 self
._PpiComments
= sdict()
2740 self
._DepexList
= None
2741 self
._DepexExpressionList
= None
2742 self
._BuildOption
= None
2743 self
._BuildOptionIncPathList
= None
2744 self
._BuildTargets
= None
2745 self
._IntroBuildTargetList
= None
2746 self
._FinalBuildTargetList
= None
2747 self
._FileTypes
= None
2748 self
._BuildRules
= None
2750 self
._TimeStampPath
= None
2752 self
.AutoGenDepSet
= set()
2755 ## The Modules referenced to this Library
2756 # Only Library has this attribute
2757 self
._ReferenceModules
= []
2759 ## Store the FixedAtBuild Pcds
2761 self
._FixedAtBuildPcds
= []
2766 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2768 # Get FixedAtBuild Pcds of this Module
2769 def _GetFixedAtBuildPcds(self
):
2770 if self
._FixedAtBuildPcds
:
2771 return self
._FixedAtBuildPcds
2772 for Pcd
in self
.ModulePcdList
:
2773 if Pcd
.Type
!= "FixedAtBuild":
2775 if Pcd
not in self
._FixedAtBuildPcds
:
2776 self
._FixedAtBuildPcds
.append(Pcd
)
2778 return self
._FixedAtBuildPcds
2780 def _GetUniqueBaseName(self
):
2781 BaseName
= self
.Name
2782 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2783 if Module
.MetaFile
== self
.MetaFile
:
2785 if Module
.Name
== self
.Name
:
2786 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2787 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2788 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2789 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2792 # Macros could be used in build_rule.txt (also Makefile)
2793 def _GetMacros(self
):
2794 if self
._Macro
== None:
2795 self
._Macro
= sdict()
2796 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2797 self
._Macro
["MODULE_NAME" ] = self
.Name
2798 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2799 self
._Macro
["MODULE_GUID" ] = self
.Guid
2800 self
._Macro
["MODULE_VERSION" ] = self
.Version
2801 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2802 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2803 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2804 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2805 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2807 self
._Macro
["BASE_NAME" ] = self
.Name
2809 self
._Macro
["ARCH" ] = self
.Arch
2810 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2811 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2812 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2813 self
._Macro
["TARGET" ] = self
.BuildTarget
2815 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2816 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2817 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2818 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2819 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2820 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2821 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2822 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2823 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2824 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2825 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2826 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2827 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2828 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2831 ## Return the module build data object
2832 def _GetModule(self
):
2833 if self
._Module
== None:
2834 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2837 ## Return the module name
2838 def _GetBaseName(self
):
2839 return self
.Module
.BaseName
2841 ## Return the module DxsFile if exist
2842 def _GetDxsFile(self
):
2843 return self
.Module
.DxsFile
2845 ## Return the module SourceOverridePath
2846 def _GetSourceOverridePath(self
):
2847 return self
.Module
.SourceOverridePath
2849 ## Return the module meta-file GUID
2852 # To build same module more than once, the module path with FILE_GUID overridden has
2853 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2854 # in DSC. The overridden GUID can be retrieved from file name
2856 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2858 # Length of GUID is 36
2860 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2861 return self
.Module
.Guid
2863 ## Return the module version
2864 def _GetVersion(self
):
2865 return self
.Module
.Version
2867 ## Return the module type
2868 def _GetModuleType(self
):
2869 return self
.Module
.ModuleType
2871 ## Return the component type (for Edk.x style of module)
2872 def _GetComponentType(self
):
2873 return self
.Module
.ComponentType
2875 ## Return the build type
2876 def _GetBuildType(self
):
2877 return self
.Module
.BuildType
2879 ## Return the PCD_IS_DRIVER setting
2880 def _GetPcdIsDriver(self
):
2881 return self
.Module
.PcdIsDriver
2883 ## Return the autogen version, i.e. module meta-file version
2884 def _GetAutoGenVersion(self
):
2885 return self
.Module
.AutoGenVersion
2887 ## Check if the module is library or not
2888 def _IsLibrary(self
):
2889 if self
._LibraryFlag
== None:
2890 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2891 self
._LibraryFlag
= True
2893 self
._LibraryFlag
= False
2894 return self
._LibraryFlag
2896 ## Check if the module is binary module or not
2897 def _IsBinaryModule(self
):
2898 return self
.Module
.IsBinaryModule
2900 ## Return the directory to store intermediate files of the module
2901 def _GetBuildDir(self
):
2902 if self
._BuildDir
== None:
2903 self
._BuildDir
= path
.join(
2904 self
.PlatformInfo
.BuildDir
,
2907 self
.MetaFile
.BaseName
2909 CreateDirectory(self
._BuildDir
)
2910 return self
._BuildDir
2912 ## Return the directory to store the intermediate object files of the mdoule
2913 def _GetOutputDir(self
):
2914 if self
._OutputDir
== None:
2915 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2916 CreateDirectory(self
._OutputDir
)
2917 return self
._OutputDir
2919 ## Return the directory to store auto-gened source files of the mdoule
2920 def _GetDebugDir(self
):
2921 if self
._DebugDir
== None:
2922 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2923 CreateDirectory(self
._DebugDir
)
2924 return self
._DebugDir
2926 ## Return the path of custom file
2927 def _GetCustomMakefile(self
):
2928 if self
._CustomMakefile
== None:
2929 self
._CustomMakefile
= {}
2930 for Type
in self
.Module
.CustomMakefile
:
2931 if Type
in gMakeTypeMap
:
2932 MakeType
= gMakeTypeMap
[Type
]
2935 if self
.SourceOverrideDir
!= None:
2936 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2937 if not os
.path
.exists(File
):
2938 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2940 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2941 self
._CustomMakefile
[MakeType
] = File
2942 return self
._CustomMakefile
2944 ## Return the directory of the makefile
2946 # @retval string The directory string of module's makefile
2948 def _GetMakeFileDir(self
):
2949 return self
.BuildDir
2951 ## Return build command string
2953 # @retval string Build command string
2955 def _GetBuildCommand(self
):
2956 return self
.PlatformInfo
.BuildCommand
2958 ## Get object list of all packages the module and its dependent libraries belong to
2960 # @retval list The list of package object
2962 def _GetDerivedPackageList(self
):
2964 for M
in [self
.Module
] + self
.DependentLibraryList
:
2965 for Package
in M
.Packages
:
2966 if Package
in PackageList
:
2968 PackageList
.append(Package
)
2971 ## Get the depex string
2973 # @return : a string contain all depex expresion.
2974 def _GetDepexExpresionString(self
):
2977 ## DPX_SOURCE IN Define section.
2978 if self
.Module
.DxsFile
:
2980 for M
in [self
.Module
] + self
.DependentLibraryList
:
2981 Filename
= M
.MetaFile
.Path
2982 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2983 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2984 for DepexExpresion
in DepexExpresionList
:
2985 for key
in DepexExpresion
.keys():
2986 Arch
, ModuleType
= key
2987 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
2988 # the type of build module is USER_DEFINED.
2989 # All different DEPEX section tags would be copied into the As Built INF file
2990 # and there would be separate DEPEX section tags
2991 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2992 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2993 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2995 if Arch
.upper() == TAB_ARCH_COMMON
or \
2996 (Arch
.upper() == self
.Arch
.upper() and \
2997 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2998 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
3000 #the type of build module is USER_DEFINED.
3001 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
3002 for Depex
in DepexList
:
3003 for key
in Depex
.keys():
3004 DepexStr
+= '[Depex.%s.%s]\n' % key
3005 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
3008 return '[Depex.%s]\n' % self
.Arch
3011 #the type of build module not is USER_DEFINED.
3013 for Depex
in DepexList
:
3018 for D
in Depex
.values():
3019 DepexStr
+= ' '.join([val
for val
in D
])
3020 Index
= DepexStr
.find('END')
3021 if Index
> -1 and Index
== len(DepexStr
) - 3:
3022 DepexStr
= DepexStr
[:-3]
3023 DepexStr
= DepexStr
.strip()
3026 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
3028 return '[Depex.%s]\n' % self
.Arch
3029 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
3031 ## Merge dependency expression
3033 # @retval list The token list of the dependency expression after parsed
3035 def _GetDepexTokenList(self
):
3036 if self
._DepexList
== None:
3037 self
._DepexList
= {}
3038 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3039 return self
._DepexList
3041 self
._DepexList
[self
.ModuleType
] = []
3043 for ModuleType
in self
._DepexList
:
3044 DepexList
= self
._DepexList
[ModuleType
]
3046 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3048 for M
in [self
.Module
] + self
.DependentLibraryList
:
3050 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
3052 DepexList
.append('AND')
3053 DepexList
.append('(')
3055 if DepexList
[-1] == 'END': # no need of a END at this time
3057 DepexList
.append(')')
3060 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
3061 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
3063 if len(DepexList
) > 0:
3064 EdkLogger
.verbose('')
3065 return self
._DepexList
3067 ## Merge dependency expression
3069 # @retval list The token list of the dependency expression after parsed
3071 def _GetDepexExpressionTokenList(self
):
3072 if self
._DepexExpressionList
== None:
3073 self
._DepexExpressionList
= {}
3074 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3075 return self
._DepexExpressionList
3077 self
._DepexExpressionList
[self
.ModuleType
] = ''
3079 for ModuleType
in self
._DepexExpressionList
:
3080 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
3082 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3084 for M
in [self
.Module
] + self
.DependentLibraryList
:
3086 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
3087 if DepexExpressionList
!= '':
3088 DepexExpressionList
+= ' AND '
3089 DepexExpressionList
+= '('
3090 DepexExpressionList
+= D
3091 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
3092 DepexExpressionList
+= ')'
3095 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
3096 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
3098 if len(DepexExpressionList
) > 0:
3099 EdkLogger
.verbose('')
3100 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
3101 return self
._DepexExpressionList
3103 # Get the tiano core user extension, it is contain dependent library.
3104 # @retval: a list contain tiano core userextension.
3106 def _GetTianoCoreUserExtensionList(self
):
3107 TianoCoreUserExtentionList
= []
3108 for M
in [self
.Module
] + self
.DependentLibraryList
:
3109 Filename
= M
.MetaFile
.Path
3110 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
3111 TianoCoreUserExtenList
= InfObj
.GetUserExtensionTianoCore()
3112 for TianoCoreUserExtent
in TianoCoreUserExtenList
:
3113 for Section
in TianoCoreUserExtent
.keys():
3114 ItemList
= Section
.split(TAB_SPLIT
)
3116 if len(ItemList
) == 4:
3118 if Arch
.upper() == TAB_ARCH_COMMON
or Arch
.upper() == self
.Arch
.upper():
3120 TianoCoreList
.extend([TAB_SECTION_START
+ Section
+ TAB_SECTION_END
])
3121 TianoCoreList
.extend(TianoCoreUserExtent
[Section
][:])
3122 TianoCoreList
.append('\n')
3123 TianoCoreUserExtentionList
.append(TianoCoreList
)
3125 return TianoCoreUserExtentionList
3127 ## Return the list of specification version required for the module
3129 # @retval list The list of specification defined in module file
3131 def _GetSpecification(self
):
3132 return self
.Module
.Specification
3134 ## Tool option for the module build
3136 # @param PlatformInfo The object of PlatformBuildInfo
3137 # @retval dict The dict containing valid options
3139 def _GetModuleBuildOption(self
):
3140 if self
._BuildOption
== None:
3141 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
3142 if self
.BuildRuleOrder
:
3143 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
3144 return self
._BuildOption
3146 ## Get include path list from tool option for the module build
3148 # @retval list The include path list
3150 def _GetBuildOptionIncPathList(self
):
3151 if self
._BuildOptionIncPathList
== None:
3153 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3154 # is the former use /I , the Latter used -I to specify include directories
3156 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
3157 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3158 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
3159 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3162 # New ToolChainFamily, don't known whether there is option to specify include directories
3164 self
._BuildOptionIncPathList
= []
3165 return self
._BuildOptionIncPathList
3167 BuildOptionIncPathList
= []
3168 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3171 FlagOption
= self
.BuildOption
[Tool
][Attr
]
3175 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
3176 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
3179 # RVCT may specify a list of directory seperated by commas
3182 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
3183 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3184 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
3187 # EDK II modules must not reference header files outside of the packages they depend on or
3188 # within the module's directory tree. Report error if violation.
3190 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
3191 for Path
in IncPathList
:
3192 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3193 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3194 EdkLogger
.error("build",
3197 File
=str(self
.MetaFile
))
3200 BuildOptionIncPathList
+= IncPathList
3202 self
._BuildOptionIncPathList
= BuildOptionIncPathList
3204 return self
._BuildOptionIncPathList
3206 ## Return a list of files which can be built from source
3208 # What kind of files can be built is determined by build rules in
3209 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3211 def _GetSourceFileList(self
):
3212 if self
._SourceFileList
== None:
3213 self
._SourceFileList
= []
3214 for F
in self
.Module
.Sources
:
3216 if F
.TagName
not in ("", "*", self
.ToolChain
):
3217 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3218 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
3220 # match tool chain family
3221 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
3224 "The file [%s] must be built by tools of [%s], " \
3225 "but current toolchain family is [%s]" \
3226 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
3229 # add the file path into search path list for file including
3230 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3231 self
.IncludePathList
.insert(0, F
.Dir
)
3232 self
._SourceFileList
.append(F
)
3234 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
3236 for F
in self
._SourceFileList
:
3237 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3238 return self
._SourceFileList
3240 def _MatchBuildRuleOrder(self
, FileList
):
3242 self
._GetModuleBuildOption
()
3243 for SingleFile
in FileList
:
3244 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3245 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3246 if key
in Order_Dict
:
3247 Order_Dict
[key
].append(SingleFile
.Ext
)
3249 Order_Dict
[key
] = [SingleFile
.Ext
]
3252 for F
in Order_Dict
:
3253 if len(Order_Dict
[F
]) > 1:
3254 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3255 for Ext
in Order_Dict
[F
][1:]:
3256 RemoveList
.append(F
+ Ext
)
3258 for item
in RemoveList
:
3259 FileList
.remove(item
)
3263 ## Return the list of unicode files
3264 def _GetUnicodeFileList(self
):
3265 if self
._UnicodeFileList
== None:
3266 if TAB_UNICODE_FILE
in self
.FileTypes
:
3267 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
3269 self
._UnicodeFileList
= []
3270 return self
._UnicodeFileList
3272 ## Return the list of vfr files
3273 def _GetVfrFileList(self
):
3274 if self
._VfrFileList
== None:
3275 if TAB_VFR_FILE
in self
.FileTypes
:
3276 self
._VfrFileList
= self
.FileTypes
[TAB_VFR_FILE
]
3278 self
._VfrFileList
= []
3279 return self
._VfrFileList
3281 ## Return the list of Image Definition files
3282 def _GetIdfFileList(self
):
3283 if self
._IdfFileList
== None:
3284 if TAB_IMAGE_FILE
in self
.FileTypes
:
3285 self
._IdfFileList
= self
.FileTypes
[TAB_IMAGE_FILE
]
3287 self
._IdfFileList
= []
3288 return self
._IdfFileList
3290 ## Return a list of files which can be built from binary
3292 # "Build" binary files are just to copy them to build directory.
3294 # @retval list The list of files which can be built later
3296 def _GetBinaryFiles(self
):
3297 if self
._BinaryFileList
== None:
3298 self
._BinaryFileList
= []
3299 for F
in self
.Module
.Binaries
:
3300 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
3302 self
._BinaryFileList
.append(F
)
3303 self
._ApplyBuildRule
(F
, F
.Type
)
3304 return self
._BinaryFileList
3306 def _GetBuildRules(self
):
3307 if self
._BuildRules
== None:
3309 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3310 for Type
in BuildRuleDatabase
.FileTypeList
:
3311 #first try getting build rule by BuildRuleFamily
3312 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3314 # build type is always module type, but ...
3315 if self
.ModuleType
!= self
.BuildType
:
3316 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3317 #second try getting build rule by ToolChainFamily
3319 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3321 # build type is always module type, but ...
3322 if self
.ModuleType
!= self
.BuildType
:
3323 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3326 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3327 BuildRules
[Type
] = RuleObject
3328 for Ext
in RuleObject
.SourceFileExtList
:
3329 BuildRules
[Ext
] = RuleObject
3330 self
._BuildRules
= BuildRules
3331 return self
._BuildRules
3333 def _ApplyBuildRule(self
, File
, FileType
):
3334 if self
._BuildTargets
== None:
3335 self
._IntroBuildTargetList
= set()
3336 self
._FinalBuildTargetList
= set()
3337 self
._BuildTargets
= {}
3338 self
._FileTypes
= {}
3340 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3341 if not os
.path
.exists(SubDirectory
):
3342 CreateDirectory(SubDirectory
)
3348 # Make sure to get build rule order value
3350 self
._GetModuleBuildOption
()
3352 while Index
< len(SourceList
):
3353 Source
= SourceList
[Index
]
3357 CreateDirectory(Source
.Dir
)
3359 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
3360 # Skip all files that are not binary libraries
3361 if not self
.IsLibrary
:
3363 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3364 elif FileType
in self
.BuildRules
:
3365 RuleObject
= self
.BuildRules
[FileType
]
3366 elif Source
.Ext
in self
.BuildRules
:
3367 RuleObject
= self
.BuildRules
[Source
.Ext
]
3369 # stop at no more rules
3371 self
._FinalBuildTargetList
.add(LastTarget
)
3374 FileType
= RuleObject
.SourceFileType
3375 if FileType
not in self
._FileTypes
:
3376 self
._FileTypes
[FileType
] = set()
3377 self
._FileTypes
[FileType
].add(Source
)
3379 # stop at STATIC_LIBRARY for library
3380 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3382 self
._FinalBuildTargetList
.add(LastTarget
)
3385 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3388 self
._FinalBuildTargetList
.add(LastTarget
)
3390 elif not Target
.Outputs
:
3391 # Only do build for target with outputs
3392 self
._FinalBuildTargetList
.add(Target
)
3394 if FileType
not in self
._BuildTargets
:
3395 self
._BuildTargets
[FileType
] = set()
3396 self
._BuildTargets
[FileType
].add(Target
)
3398 if not Source
.IsBinary
and Source
== File
:
3399 self
._IntroBuildTargetList
.add(Target
)
3401 # to avoid cyclic rule
3402 if FileType
in RuleChain
:
3405 RuleChain
.append(FileType
)
3406 SourceList
.extend(Target
.Outputs
)
3408 FileType
= TAB_UNKNOWN_FILE
3410 def _GetTargets(self
):
3411 if self
._BuildTargets
== None:
3412 self
._IntroBuildTargetList
= set()
3413 self
._FinalBuildTargetList
= set()
3414 self
._BuildTargets
= {}
3415 self
._FileTypes
= {}
3417 #TRICK: call _GetSourceFileList to apply build rule for source files
3418 if self
.SourceFileList
:
3421 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3422 if self
.BinaryFileList
:
3425 return self
._BuildTargets
3427 def _GetIntroTargetList(self
):
3429 return self
._IntroBuildTargetList
3431 def _GetFinalTargetList(self
):
3433 return self
._FinalBuildTargetList
3435 def _GetFileTypes(self
):
3437 return self
._FileTypes
3439 ## Get the list of package object the module depends on
3441 # @retval list The package object list
3443 def _GetDependentPackageList(self
):
3444 return self
.Module
.Packages
3446 ## Return the list of auto-generated code file
3448 # @retval list The list of auto-generated file
3450 def _GetAutoGenFileList(self
):
3451 UniStringAutoGenC
= True
3452 IdfStringAutoGenC
= True
3453 UniStringBinBuffer
= StringIO()
3454 IdfGenBinBuffer
= StringIO()
3455 if self
.BuildType
== 'UEFI_HII':
3456 UniStringAutoGenC
= False
3457 IdfStringAutoGenC
= False
3458 if self
._AutoGenFileList
== None:
3459 self
._AutoGenFileList
= {}
3460 AutoGenC
= TemplateString()
3461 AutoGenH
= TemplateString()
3462 StringH
= TemplateString()
3463 StringIdf
= TemplateString()
3464 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
, StringIdf
, IdfStringAutoGenC
, IdfGenBinBuffer
)
3466 # AutoGen.c is generated if there are library classes in inf, or there are object files
3468 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3469 or TAB_OBJECT_FILE
in self
.FileTypes
):
3470 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3471 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3472 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3473 if str(AutoGenH
) != "":
3474 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3475 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3476 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3477 if str(StringH
) != "":
3478 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3479 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3480 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3481 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
3482 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3483 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3484 AutoFile
.IsBinary
= True
3485 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3486 if UniStringBinBuffer
!= None:
3487 UniStringBinBuffer
.close()
3488 if str(StringIdf
) != "":
3489 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3490 self
._AutoGenFileList
[AutoFile
] = str(StringIdf
)
3491 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3492 if IdfGenBinBuffer
!= None and IdfGenBinBuffer
.getvalue() != "":
3493 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3494 self
._AutoGenFileList
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3495 AutoFile
.IsBinary
= True
3496 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3497 if IdfGenBinBuffer
!= None:
3498 IdfGenBinBuffer
.close()
3499 return self
._AutoGenFileList
3501 ## Return the list of library modules explicitly or implicityly used by this module
3502 def _GetLibraryList(self
):
3503 if self
._DependentLibraryList
== None:
3504 # only merge library classes and PCD for non-library module
3506 self
._DependentLibraryList
= []
3508 if self
.AutoGenVersion
< 0x00010005:
3509 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3511 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3512 return self
._DependentLibraryList
3515 def UpdateComments(Recver
, Src
):
3517 if Key
not in Recver
:
3519 Recver
[Key
].extend(Src
[Key
])
3520 ## Get the list of PCDs from current module
3522 # @retval list The list of PCD
3524 def _GetModulePcdList(self
):
3525 if self
._ModulePcdList
== None:
3526 # apply PCD settings from platform
3527 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3528 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3529 return self
._ModulePcdList
3531 ## Get the list of PCDs from dependent libraries
3533 # @retval list The list of PCD
3535 def _GetLibraryPcdList(self
):
3536 if self
._LibraryPcdList
== None:
3538 if not self
.IsLibrary
:
3539 # get PCDs from dependent libraries
3540 for Library
in self
.DependentLibraryList
:
3541 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3542 for Key
in Library
.Pcds
:
3543 # skip duplicated PCDs
3544 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3546 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3547 # apply PCD settings from platform
3548 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3550 self
._LibraryPcdList
= []
3551 return self
._LibraryPcdList
3553 ## Get the GUID value mapping
3555 # @retval dict The mapping between GUID cname and its value
3557 def _GetGuidList(self
):
3558 if self
._GuidList
== None:
3559 self
._GuidList
= sdict()
3560 self
._GuidList
.update(self
.Module
.Guids
)
3561 for Library
in self
.DependentLibraryList
:
3562 self
._GuidList
.update(Library
.Guids
)
3563 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3564 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3565 return self
._GuidList
3567 def GetGuidsUsedByPcd(self
):
3568 if self
._GuidsUsedByPcd
== None:
3569 self
._GuidsUsedByPcd
= sdict()
3570 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3571 for Library
in self
.DependentLibraryList
:
3572 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3573 return self
._GuidsUsedByPcd
3574 ## Get the protocol value mapping
3576 # @retval dict The mapping between protocol cname and its value
3578 def _GetProtocolList(self
):
3579 if self
._ProtocolList
== None:
3580 self
._ProtocolList
= sdict()
3581 self
._ProtocolList
.update(self
.Module
.Protocols
)
3582 for Library
in self
.DependentLibraryList
:
3583 self
._ProtocolList
.update(Library
.Protocols
)
3584 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3585 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3586 return self
._ProtocolList
3588 ## Get the PPI value mapping
3590 # @retval dict The mapping between PPI cname and its value
3592 def _GetPpiList(self
):
3593 if self
._PpiList
== None:
3594 self
._PpiList
= sdict()
3595 self
._PpiList
.update(self
.Module
.Ppis
)
3596 for Library
in self
.DependentLibraryList
:
3597 self
._PpiList
.update(Library
.Ppis
)
3598 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3599 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3600 return self
._PpiList
3602 ## Get the list of include search path
3604 # @retval list The list path
3606 def _GetIncludePathList(self
):
3607 if self
._IncludePathList
== None:
3608 self
._IncludePathList
= []
3609 if self
.AutoGenVersion
< 0x00010005:
3610 for Inc
in self
.Module
.Includes
:
3611 if Inc
not in self
._IncludePathList
:
3612 self
._IncludePathList
.append(Inc
)
3614 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3615 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3616 self
._IncludePathList
.append(Inc
)
3617 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3618 self
._IncludePathList
.append(self
.DebugDir
)
3620 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3621 self
._IncludePathList
.append(self
.DebugDir
)
3623 for Package
in self
.Module
.Packages
:
3624 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3625 if PackageDir
not in self
._IncludePathList
:
3626 self
._IncludePathList
.append(PackageDir
)
3627 IncludesList
= Package
.Includes
3628 if Package
._PrivateIncludes
:
3629 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3630 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3631 for Inc
in IncludesList
:
3632 if Inc
not in self
._IncludePathList
:
3633 self
._IncludePathList
.append(str(Inc
))
3634 return self
._IncludePathList
3636 def _GetIncludePathLength(self
):
3637 self
._IncludePathLength
= 0
3638 if self
._IncludePathList
:
3639 for inc
in self
._IncludePathList
:
3640 self
._IncludePathLength
+= len(' ' + inc
)
3641 return self
._IncludePathLength
3643 ## Get HII EX PCDs which maybe used by VFR
3645 # efivarstore used by VFR may relate with HII EX PCDs
3646 # Get the variable name and GUID from efivarstore and HII EX PCD
3647 # List the HII EX PCDs in As Built INF if both name and GUID match.
3649 # @retval list HII EX PCDs
3651 def _GetPcdsMaybeUsedByVfr(self
):
3652 if not self
.SourceFileList
:
3656 for SrcFile
in self
.SourceFileList
:
3657 if SrcFile
.Ext
.lower() != '.vfr':
3659 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3660 if not os
.path
.exists(Vfri
):
3662 VfriFile
= open(Vfri
, 'r')
3663 Content
= VfriFile
.read()
3665 Pos
= Content
.find('efivarstore')
3668 # Make sure 'efivarstore' is the start of efivarstore statement
3669 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3672 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3674 if Index
>= 0 and Content
[Index
] != ';':
3675 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3678 # 'efivarstore' must be followed by name and guid
3680 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3683 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3686 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3687 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3688 Pos
= Content
.find('efivarstore', Name
.end())
3692 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3693 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3695 for SkuName
in Pcd
.SkuInfoList
:
3696 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3697 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3698 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3701 Guid
= GuidStructureStringToGuidString(Value
)
3702 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3703 HiiExPcds
.append(Pcd
)
3708 def _GenOffsetBin(self
):
3710 for SourceFile
in self
.Module
.Sources
:
3711 if SourceFile
.Type
.upper() == ".VFR" :
3713 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3715 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3716 if SourceFile
.Type
.upper() == ".UNI" :
3718 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3720 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3722 if len(VfrUniBaseName
) == 0:
3724 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3725 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3726 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3727 if not VfrUniOffsetList
:
3730 OutputName
= '%sOffset.bin' % self
.Name
3731 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3734 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3736 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3738 # Use a instance of StringIO to cache data
3739 fStringIO
= StringIO('')
3741 for Item
in VfrUniOffsetList
:
3742 if (Item
[0].find("Strings") != -1):
3744 # UNI offset in image.
3746 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3748 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3749 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3750 fStringIO
.write(''.join(UniGuid
))
3751 UniValue
= pack ('Q', int (Item
[1], 16))
3752 fStringIO
.write (UniValue
)
3755 # VFR binary offset in image.
3757 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3759 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3760 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3761 fStringIO
.write(''.join(VfrGuid
))
3763 VfrValue
= pack ('Q', int (Item
[1], 16))
3764 fStringIO
.write (VfrValue
)
3766 # write data into file.
3769 fInputfile
.write (fStringIO
.getvalue())
3771 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3772 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3778 ## Create AsBuilt INF file the module
3780 def CreateAsBuiltInf(self
):
3781 if self
.IsAsBuiltInfCreated
:
3784 # Skip the following code for EDK I inf
3785 if self
.AutoGenVersion
< 0x00010005:
3788 # Skip the following code for libraries
3792 # Skip the following code for modules with no source files
3793 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3796 # Skip the following code for modules without any binary files
3797 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3800 ### TODO: How to handles mixed source and binary modules
3802 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3803 # Also find all packages that the DynamicEx PCDs depend on
3808 PcdTokenSpaceList
= []
3809 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3810 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3811 PatchablePcds
+= [Pcd
]
3812 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3813 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3816 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3817 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3818 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3820 GuidList
.update(self
.GuidList
)
3821 for TokenSpace
in self
.GetGuidsUsedByPcd():
3822 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3823 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3824 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3825 GuidList
.pop(TokenSpace
)
3826 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3827 for Package
in self
.DerivedPackageList
:
3828 if Package
in Packages
:
3830 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3832 for Index
in range(len(BeChecked
)):
3833 for Item
in CheckList
[Index
]:
3834 if Item
in BeChecked
[Index
]:
3835 Packages
+= [Package
]
3840 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3841 for Pkg
in self
.PlatformInfo
.PackageList
:
3844 for VfrPcd
in VfrPcds
:
3845 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3846 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3850 ModuleType
= self
.ModuleType
3851 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3852 ModuleType
= 'DXE_DRIVER'
3855 if self
.PcdIsDriver
!= '':
3856 DriverType
= self
.PcdIsDriver
3859 MDefs
= self
.Module
.Defines
3862 'module_name' : self
.Name
,
3863 'module_guid' : Guid
,
3864 'module_module_type' : ModuleType
,
3865 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3866 'pcd_is_driver_string' : [],
3867 'module_uefi_specification_version' : [],
3868 'module_pi_specification_version' : [],
3869 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3870 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3871 'module_constructor' : self
.Module
.ConstructorList
,
3872 'module_destructor' : self
.Module
.DestructorList
,
3873 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3874 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3875 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3876 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3877 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3878 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3879 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3880 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3881 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3882 'module_arch' : self
.Arch
,
3883 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3885 'patchablepcd_item' : [],
3887 'protocol_item' : [],
3891 'libraryclasses_item' : []
3894 if 'MODULE_UNI_FILE' in MDefs
:
3895 UNIFile
= os
.path
.join(self
.MetaFile
.Dir
, MDefs
['MODULE_UNI_FILE'])
3896 if os
.path
.isfile(UNIFile
):
3897 shutil
.copy2(UNIFile
, self
.OutputDir
)
3899 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3900 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3902 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3905 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3907 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3908 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3909 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3910 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3912 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3914 for Item
in self
.CodaTargetList
:
3915 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3916 if Item
.Target
.Ext
.lower() == '.aml':
3917 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3918 elif Item
.Target
.Ext
.lower() == '.acpi':
3919 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3920 elif Item
.Target
.Ext
.lower() == '.efi':
3921 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3923 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3924 if self
.DepexGenerated
:
3925 if self
.ModuleType
in ['PEIM']:
3926 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3927 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3928 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3929 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3930 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3932 Bin
= self
._GenOffsetBin
()
3934 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3936 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3938 if File
.lower().endswith('.pdb'):
3939 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3940 HeaderComments
= self
.Module
.HeaderComments
3942 for Index
in range(len(HeaderComments
)):
3943 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3944 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3947 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3948 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3951 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3952 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3953 (GuidList
, self
._GuidComments
, 'guid_item')
3955 for Item
in GenList
:
3956 for CName
in Item
[0]:
3958 if CName
in Item
[1]:
3959 Comments
= '\n '.join(Item
[1][CName
])
3962 Entry
= Comments
+ '\n ' + CName
3963 AsBuiltInfDict
[Item
[2]].append(Entry
)
3964 PatchList
= parsePcdInfoFromMapFile(
3965 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3966 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3969 for Pcd
in PatchablePcds
:
3970 TokenCName
= Pcd
.TokenCName
3971 for PcdItem
in GlobalData
.MixedPcd
:
3972 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3973 TokenCName
= PcdItem
[0]
3975 for PatchPcd
in PatchList
:
3976 if TokenCName
== PatchPcd
[0]:
3981 if Pcd
.DatumType
== 'BOOLEAN':
3982 BoolValue
= Pcd
.DefaultValue
.upper()
3983 if BoolValue
== 'TRUE':
3984 Pcd
.DefaultValue
= '1'
3985 elif BoolValue
== 'FALSE':
3986 Pcd
.DefaultValue
= '0'
3988 if Pcd
.DatumType
!= 'VOID*':
3989 HexFormat
= '0x%02x'
3990 if Pcd
.DatumType
== 'UINT16':
3991 HexFormat
= '0x%04x'
3992 elif Pcd
.DatumType
== 'UINT32':
3993 HexFormat
= '0x%08x'
3994 elif Pcd
.DatumType
== 'UINT64':
3995 HexFormat
= '0x%016x'
3996 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3998 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
3999 EdkLogger
.error("build", AUTOGEN_ERROR
,
4000 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4002 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
4003 PcdValue
= Pcd
.DefaultValue
4004 if PcdValue
[0] != '{':
4006 if PcdValue
[0] == 'L':
4008 PcdValue
= PcdValue
.lstrip('L')
4009 PcdValue
= eval(PcdValue
)
4011 for Index
in range(0, len(PcdValue
)):
4013 CharVal
= ord(PcdValue
[Index
])
4014 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
4015 + '0x%02x' % (CharVal
>> 8) + ', '
4017 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
4020 Padding
= Padding
* 2
4021 ArraySize
= ArraySize
/ 2
4022 if ArraySize
< (len(PcdValue
) + 1):
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 if ArraySize
> len(PcdValue
) + 1:
4027 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
4028 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
4029 elif len(PcdValue
.split(',')) <= ArraySize
:
4030 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
4033 EdkLogger
.error("build", AUTOGEN_ERROR
,
4034 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4036 PcdItem
= '%s.%s|%s|0x%X' % \
4037 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
4039 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4040 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
4042 PcdItem
= PcdComments
+ '\n ' + PcdItem
4043 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
4046 for Pcd
in Pcds
+ VfrPcds
:
4051 TokenCName
= Pcd
.TokenCName
4052 for PcdItem
in GlobalData
.MixedPcd
:
4053 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
4054 TokenCName
= PcdItem
[0]
4056 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
4057 for SkuName
in Pcd
.SkuInfoList
:
4058 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
4059 SkuId
= SkuInfo
.SkuId
4060 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
4064 # Don't generate duplicated HII PCD
4066 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
4069 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
4070 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4071 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
4075 for Index
, Comment
in enumerate(PcdCommentList
):
4076 for Usage
in UsageList
:
4077 if Comment
.find(Usage
) != -1:
4081 if UsageIndex
!= -1:
4082 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
4084 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
4085 PcdComments
= '\n '.join(PcdCommentList
)
4086 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
4088 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
4089 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
4090 for Item
in self
.BuildOption
:
4091 if 'FLAGS' in self
.BuildOption
[Item
]:
4092 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
4094 # Generated LibraryClasses section in comments.
4095 for Library
in self
.LibraryAutoGenList
:
4096 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
4098 # Generated UserExtensions TianoCore section.
4099 # All tianocore user extensions are copied.
4101 for TianoCore
in self
._GetTianoCoreUserExtensionList
():
4102 UserExtStr
+= '\n'.join(TianoCore
)
4103 ExtensionFile
= os
.path
.join(self
.MetaFile
.Dir
, TianoCore
[1])
4104 if os
.path
.isfile(ExtensionFile
):
4105 shutil
.copy2(ExtensionFile
, self
.OutputDir
)
4106 AsBuiltInfDict
['userextension_tianocore_item'] = UserExtStr
4108 # Generated depex expression section in comments.
4109 AsBuiltInfDict
['depexsection_item'] = ''
4110 DepexExpresion
= self
._GetDepexExpresionString
()
4112 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
4114 AsBuiltInf
= TemplateString()
4115 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
4117 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
4119 self
.IsAsBuiltInfCreated
= True
4121 ## Create makefile for the module and its dependent libraries
4123 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
4124 # dependent libraries will be created
4126 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
4127 # Ignore generating makefile when it is a binary module
4128 if self
.IsBinaryModule
:
4131 if self
.IsMakeFileCreated
:
4136 if not self
.IsLibrary
and CreateLibraryMakeFile
:
4137 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4138 LibraryAutoGen
.CreateMakeFile()
4140 if len(self
.CustomMakefile
) == 0:
4141 Makefile
= GenMake
.ModuleMakefile(self
)
4143 Makefile
= GenMake
.CustomMakefile(self
)
4144 if Makefile
.Generate():
4145 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
4146 (self
.Name
, self
.Arch
))
4148 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
4149 (self
.Name
, self
.Arch
))
4151 self
.CreateTimeStamp(Makefile
)
4152 self
.IsMakeFileCreated
= True
4154 def CopyBinaryFiles(self
):
4155 for File
in self
.Module
.Binaries
:
4157 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4158 CopyLongFilePath(SrcPath
, DstPath
)
4159 ## Create autogen code for the module and its dependent libraries
4161 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4162 # dependent libraries will be created
4164 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4165 if self
.IsCodeFileCreated
:
4170 # Need to generate PcdDatabase even PcdDriver is binarymodule
4171 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4172 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4174 if self
.IsBinaryModule
:
4176 self
.CopyBinaryFiles()
4179 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4180 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4181 LibraryAutoGen
.CreateCodeFile()
4184 IgoredAutoGenList
= []
4186 for File
in self
.AutoGenFileList
:
4187 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4188 #Ignore Edk AutoGen.c
4189 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
4192 AutoGenList
.append(str(File
))
4194 IgoredAutoGenList
.append(str(File
))
4196 # Skip the following code for EDK I inf
4197 if self
.AutoGenVersion
< 0x00010005:
4200 for ModuleType
in self
.DepexList
:
4201 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
4202 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
4205 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4206 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4208 if len(Dpx
.PostfixNotation
) <> 0:
4209 self
.DepexGenerated
= True
4211 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4212 AutoGenList
.append(str(DpxFile
))
4214 IgoredAutoGenList
.append(str(DpxFile
))
4216 if IgoredAutoGenList
== []:
4217 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4218 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4219 elif AutoGenList
== []:
4220 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4221 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4223 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4224 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4226 self
.IsCodeFileCreated
= True
4229 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4230 def _GetLibraryAutoGenList(self
):
4231 if self
._LibraryAutoGenList
== None:
4232 self
._LibraryAutoGenList
= []
4233 for Library
in self
.DependentLibraryList
:
4240 self
.PlatformInfo
.MetaFile
4242 if La
not in self
._LibraryAutoGenList
:
4243 self
._LibraryAutoGenList
.append(La
)
4244 for Lib
in La
.CodaTargetList
:
4245 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4246 return self
._LibraryAutoGenList
4248 ## Decide whether we can skip the ModuleAutoGen process
4249 # If any source file is newer than the modeule than we cannot skip
4252 if not os
.path
.exists(self
.GetTimeStampPath()):
4254 #last creation time of the module
4255 DstTimeStamp
= os
.stat(self
.GetTimeStampPath())[8]
4257 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4258 if SrcTimeStamp
> DstTimeStamp
:
4261 with
open(self
.GetTimeStampPath(),'r') as f
:
4263 source
= source
.rstrip('\n')
4264 if not os
.path
.exists(source
):
4266 if source
not in ModuleAutoGen
.TimeDict
:
4267 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4268 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4272 def GetTimeStampPath(self
):
4273 if self
._TimeStampPath
== None:
4274 self
._TimeStampPath
= os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')
4275 return self
._TimeStampPath
4276 def CreateTimeStamp(self
, Makefile
):
4280 FileSet
.add (self
.MetaFile
.Path
)
4282 for SourceFile
in self
.Module
.Sources
:
4283 FileSet
.add (SourceFile
.Path
)
4285 for Lib
in self
.DependentLibraryList
:
4286 FileSet
.add (Lib
.MetaFile
.Path
)
4288 for f
in self
.AutoGenDepSet
:
4289 FileSet
.add (f
.Path
)
4291 if os
.path
.exists (self
.GetTimeStampPath()):
4292 os
.remove (self
.GetTimeStampPath())
4293 with
open(self
.GetTimeStampPath(), 'w+') as file:
4297 Module
= property(_GetModule
)
4298 Name
= property(_GetBaseName
)
4299 Guid
= property(_GetGuid
)
4300 Version
= property(_GetVersion
)
4301 ModuleType
= property(_GetModuleType
)
4302 ComponentType
= property(_GetComponentType
)
4303 BuildType
= property(_GetBuildType
)
4304 PcdIsDriver
= property(_GetPcdIsDriver
)
4305 AutoGenVersion
= property(_GetAutoGenVersion
)
4306 Macros
= property(_GetMacros
)
4307 Specification
= property(_GetSpecification
)
4309 IsLibrary
= property(_IsLibrary
)
4310 IsBinaryModule
= property(_IsBinaryModule
)
4311 BuildDir
= property(_GetBuildDir
)
4312 OutputDir
= property(_GetOutputDir
)
4313 DebugDir
= property(_GetDebugDir
)
4314 MakeFileDir
= property(_GetMakeFileDir
)
4315 CustomMakefile
= property(_GetCustomMakefile
)
4317 IncludePathList
= property(_GetIncludePathList
)
4318 IncludePathLength
= property(_GetIncludePathLength
)
4319 AutoGenFileList
= property(_GetAutoGenFileList
)
4320 UnicodeFileList
= property(_GetUnicodeFileList
)
4321 VfrFileList
= property(_GetVfrFileList
)
4322 SourceFileList
= property(_GetSourceFileList
)
4323 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
4324 Targets
= property(_GetTargets
)
4325 IntroTargetList
= property(_GetIntroTargetList
)
4326 CodaTargetList
= property(_GetFinalTargetList
)
4327 FileTypes
= property(_GetFileTypes
)
4328 BuildRules
= property(_GetBuildRules
)
4329 IdfFileList
= property(_GetIdfFileList
)
4331 DependentPackageList
= property(_GetDependentPackageList
)
4332 DependentLibraryList
= property(_GetLibraryList
)
4333 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
4334 DerivedPackageList
= property(_GetDerivedPackageList
)
4336 ModulePcdList
= property(_GetModulePcdList
)
4337 LibraryPcdList
= property(_GetLibraryPcdList
)
4338 GuidList
= property(_GetGuidList
)
4339 ProtocolList
= property(_GetProtocolList
)
4340 PpiList
= property(_GetPpiList
)
4341 DepexList
= property(_GetDepexTokenList
)
4342 DxsFile
= property(_GetDxsFile
)
4343 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
4344 BuildOption
= property(_GetModuleBuildOption
)
4345 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
4346 BuildCommand
= property(_GetBuildCommand
)
4348 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
4350 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4351 if __name__
== '__main__':