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
2703 self
._Version
= None
2704 self
._ModuleType
= None
2705 self
._ComponentType
= None
2706 self
._PcdIsDriver
= None
2707 self
._AutoGenVersion
= None
2708 self
._LibraryFlag
= None
2709 self
._CustomMakefile
= None
2712 self
._BuildDir
= None
2713 self
._OutputDir
= None
2714 self
._DebugDir
= None
2715 self
._MakeFileDir
= None
2717 self
._IncludePathList
= None
2718 self
._IncludePathLength
= 0
2719 self
._AutoGenFileList
= None
2720 self
._UnicodeFileList
= None
2721 self
._VfrFileList
= None
2722 self
._IdfFileList
= None
2723 self
._SourceFileList
= None
2724 self
._ObjectFileList
= None
2725 self
._BinaryFileList
= None
2727 self
._DependentPackageList
= None
2728 self
._DependentLibraryList
= None
2729 self
._LibraryAutoGenList
= None
2730 self
._DerivedPackageList
= None
2731 self
._ModulePcdList
= None
2732 self
._LibraryPcdList
= None
2733 self
._PcdComments
= sdict()
2734 self
._GuidList
= None
2735 self
._GuidsUsedByPcd
= None
2736 self
._GuidComments
= sdict()
2737 self
._ProtocolList
= None
2738 self
._ProtocolComments
= sdict()
2739 self
._PpiList
= None
2740 self
._PpiComments
= sdict()
2741 self
._DepexList
= None
2742 self
._DepexExpressionList
= None
2743 self
._BuildOption
= None
2744 self
._BuildOptionIncPathList
= None
2745 self
._BuildTargets
= None
2746 self
._IntroBuildTargetList
= None
2747 self
._FinalBuildTargetList
= None
2748 self
._FileTypes
= None
2749 self
._BuildRules
= None
2751 self
._TimeStampPath
= None
2753 self
.AutoGenDepSet
= set()
2756 ## The Modules referenced to this Library
2757 # Only Library has this attribute
2758 self
._ReferenceModules
= []
2760 ## Store the FixedAtBuild Pcds
2762 self
._FixedAtBuildPcds
= []
2767 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2769 # Get FixedAtBuild Pcds of this Module
2770 def _GetFixedAtBuildPcds(self
):
2771 if self
._FixedAtBuildPcds
:
2772 return self
._FixedAtBuildPcds
2773 for Pcd
in self
.ModulePcdList
:
2774 if Pcd
.Type
!= "FixedAtBuild":
2776 if Pcd
not in self
._FixedAtBuildPcds
:
2777 self
._FixedAtBuildPcds
.append(Pcd
)
2779 return self
._FixedAtBuildPcds
2781 def _GetUniqueBaseName(self
):
2782 BaseName
= self
.Name
2783 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2784 if Module
.MetaFile
== self
.MetaFile
:
2786 if Module
.Name
== self
.Name
:
2787 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2788 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2789 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2790 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2793 # Macros could be used in build_rule.txt (also Makefile)
2794 def _GetMacros(self
):
2795 if self
._Macro
== None:
2796 self
._Macro
= sdict()
2797 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2798 self
._Macro
["MODULE_NAME" ] = self
.Name
2799 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2800 self
._Macro
["MODULE_GUID" ] = self
.Guid
2801 self
._Macro
["MODULE_VERSION" ] = self
.Version
2802 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2803 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2804 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2805 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2806 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2808 self
._Macro
["BASE_NAME" ] = self
.Name
2810 self
._Macro
["ARCH" ] = self
.Arch
2811 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2812 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2813 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2814 self
._Macro
["TARGET" ] = self
.BuildTarget
2816 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2817 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2818 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2819 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2820 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2821 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2822 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2823 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2824 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2825 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2826 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2827 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2828 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2829 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2832 ## Return the module build data object
2833 def _GetModule(self
):
2834 if self
._Module
== None:
2835 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2838 ## Return the module name
2839 def _GetBaseName(self
):
2840 return self
.Module
.BaseName
2842 ## Return the module DxsFile if exist
2843 def _GetDxsFile(self
):
2844 return self
.Module
.DxsFile
2846 ## Return the module SourceOverridePath
2847 def _GetSourceOverridePath(self
):
2848 return self
.Module
.SourceOverridePath
2850 ## Return the module meta-file GUID
2853 # To build same module more than once, the module path with FILE_GUID overridden has
2854 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2855 # in DSC. The overridden GUID can be retrieved from file name
2857 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2859 # Length of GUID is 36
2861 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2862 return self
.Module
.Guid
2864 ## Return the module version
2865 def _GetVersion(self
):
2866 return self
.Module
.Version
2868 ## Return the module type
2869 def _GetModuleType(self
):
2870 return self
.Module
.ModuleType
2872 ## Return the component type (for Edk.x style of module)
2873 def _GetComponentType(self
):
2874 return self
.Module
.ComponentType
2876 ## Return the build type
2877 def _GetBuildType(self
):
2878 return self
.Module
.BuildType
2880 ## Return the PCD_IS_DRIVER setting
2881 def _GetPcdIsDriver(self
):
2882 return self
.Module
.PcdIsDriver
2884 ## Return the autogen version, i.e. module meta-file version
2885 def _GetAutoGenVersion(self
):
2886 return self
.Module
.AutoGenVersion
2888 ## Check if the module is library or not
2889 def _IsLibrary(self
):
2890 if self
._LibraryFlag
== None:
2891 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2892 self
._LibraryFlag
= True
2894 self
._LibraryFlag
= False
2895 return self
._LibraryFlag
2897 ## Check if the module is binary module or not
2898 def _IsBinaryModule(self
):
2899 return self
.Module
.IsBinaryModule
2901 ## Return the directory to store intermediate files of the module
2902 def _GetBuildDir(self
):
2903 if self
._BuildDir
== None:
2904 self
._BuildDir
= path
.join(
2905 self
.PlatformInfo
.BuildDir
,
2908 self
.MetaFile
.BaseName
2910 CreateDirectory(self
._BuildDir
)
2911 return self
._BuildDir
2913 ## Return the directory to store the intermediate object files of the mdoule
2914 def _GetOutputDir(self
):
2915 if self
._OutputDir
== None:
2916 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2917 CreateDirectory(self
._OutputDir
)
2918 return self
._OutputDir
2920 ## Return the directory to store auto-gened source files of the mdoule
2921 def _GetDebugDir(self
):
2922 if self
._DebugDir
== None:
2923 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2924 CreateDirectory(self
._DebugDir
)
2925 return self
._DebugDir
2927 ## Return the path of custom file
2928 def _GetCustomMakefile(self
):
2929 if self
._CustomMakefile
== None:
2930 self
._CustomMakefile
= {}
2931 for Type
in self
.Module
.CustomMakefile
:
2932 if Type
in gMakeTypeMap
:
2933 MakeType
= gMakeTypeMap
[Type
]
2936 if self
.SourceOverrideDir
!= None:
2937 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2938 if not os
.path
.exists(File
):
2939 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2941 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2942 self
._CustomMakefile
[MakeType
] = File
2943 return self
._CustomMakefile
2945 ## Return the directory of the makefile
2947 # @retval string The directory string of module's makefile
2949 def _GetMakeFileDir(self
):
2950 return self
.BuildDir
2952 ## Return build command string
2954 # @retval string Build command string
2956 def _GetBuildCommand(self
):
2957 return self
.PlatformInfo
.BuildCommand
2959 ## Get object list of all packages the module and its dependent libraries belong to
2961 # @retval list The list of package object
2963 def _GetDerivedPackageList(self
):
2965 for M
in [self
.Module
] + self
.DependentLibraryList
:
2966 for Package
in M
.Packages
:
2967 if Package
in PackageList
:
2969 PackageList
.append(Package
)
2972 ## Get the depex string
2974 # @return : a string contain all depex expresion.
2975 def _GetDepexExpresionString(self
):
2978 ## DPX_SOURCE IN Define section.
2979 if self
.Module
.DxsFile
:
2981 for M
in [self
.Module
] + self
.DependentLibraryList
:
2982 Filename
= M
.MetaFile
.Path
2983 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2984 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2985 for DepexExpresion
in DepexExpresionList
:
2986 for key
in DepexExpresion
.keys():
2987 Arch
, ModuleType
= key
2988 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
2989 # the type of build module is USER_DEFINED.
2990 # All different DEPEX section tags would be copied into the As Built INF file
2991 # and there would be separate DEPEX section tags
2992 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2993 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2994 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2996 if Arch
.upper() == TAB_ARCH_COMMON
or \
2997 (Arch
.upper() == self
.Arch
.upper() and \
2998 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2999 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
3001 #the type of build module is USER_DEFINED.
3002 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
3003 for Depex
in DepexList
:
3004 for key
in Depex
.keys():
3005 DepexStr
+= '[Depex.%s.%s]\n' % key
3006 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
3009 return '[Depex.%s]\n' % self
.Arch
3012 #the type of build module not is USER_DEFINED.
3014 for Depex
in DepexList
:
3019 for D
in Depex
.values():
3020 DepexStr
+= ' '.join([val
for val
in D
])
3021 Index
= DepexStr
.find('END')
3022 if Index
> -1 and Index
== len(DepexStr
) - 3:
3023 DepexStr
= DepexStr
[:-3]
3024 DepexStr
= DepexStr
.strip()
3027 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
3029 return '[Depex.%s]\n' % self
.Arch
3030 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
3032 ## Merge dependency expression
3034 # @retval list The token list of the dependency expression after parsed
3036 def _GetDepexTokenList(self
):
3037 if self
._DepexList
== None:
3038 self
._DepexList
= {}
3039 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3040 return self
._DepexList
3042 self
._DepexList
[self
.ModuleType
] = []
3044 for ModuleType
in self
._DepexList
:
3045 DepexList
= self
._DepexList
[ModuleType
]
3047 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3049 for M
in [self
.Module
] + self
.DependentLibraryList
:
3051 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
3053 DepexList
.append('AND')
3054 DepexList
.append('(')
3056 if DepexList
[-1] == 'END': # no need of a END at this time
3058 DepexList
.append(')')
3061 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
3062 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
3064 if len(DepexList
) > 0:
3065 EdkLogger
.verbose('')
3066 return self
._DepexList
3068 ## Merge dependency expression
3070 # @retval list The token list of the dependency expression after parsed
3072 def _GetDepexExpressionTokenList(self
):
3073 if self
._DepexExpressionList
== None:
3074 self
._DepexExpressionList
= {}
3075 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3076 return self
._DepexExpressionList
3078 self
._DepexExpressionList
[self
.ModuleType
] = ''
3080 for ModuleType
in self
._DepexExpressionList
:
3081 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
3083 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3085 for M
in [self
.Module
] + self
.DependentLibraryList
:
3087 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
3088 if DepexExpressionList
!= '':
3089 DepexExpressionList
+= ' AND '
3090 DepexExpressionList
+= '('
3091 DepexExpressionList
+= D
3092 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
3093 DepexExpressionList
+= ')'
3096 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
3097 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
3099 if len(DepexExpressionList
) > 0:
3100 EdkLogger
.verbose('')
3101 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
3102 return self
._DepexExpressionList
3104 # Get the tiano core user extension, it is contain dependent library.
3105 # @retval: a list contain tiano core userextension.
3107 def _GetTianoCoreUserExtensionList(self
):
3108 TianoCoreUserExtentionList
= []
3109 for M
in [self
.Module
] + self
.DependentLibraryList
:
3110 Filename
= M
.MetaFile
.Path
3111 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
3112 TianoCoreUserExtenList
= InfObj
.GetUserExtensionTianoCore()
3113 for TianoCoreUserExtent
in TianoCoreUserExtenList
:
3114 for Section
in TianoCoreUserExtent
.keys():
3115 ItemList
= Section
.split(TAB_SPLIT
)
3117 if len(ItemList
) == 4:
3119 if Arch
.upper() == TAB_ARCH_COMMON
or Arch
.upper() == self
.Arch
.upper():
3121 TianoCoreList
.extend([TAB_SECTION_START
+ Section
+ TAB_SECTION_END
])
3122 TianoCoreList
.extend(TianoCoreUserExtent
[Section
][:])
3123 TianoCoreList
.append('\n')
3124 TianoCoreUserExtentionList
.append(TianoCoreList
)
3126 return TianoCoreUserExtentionList
3128 ## Return the list of specification version required for the module
3130 # @retval list The list of specification defined in module file
3132 def _GetSpecification(self
):
3133 return self
.Module
.Specification
3135 ## Tool option for the module build
3137 # @param PlatformInfo The object of PlatformBuildInfo
3138 # @retval dict The dict containing valid options
3140 def _GetModuleBuildOption(self
):
3141 if self
._BuildOption
== None:
3142 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
3143 if self
.BuildRuleOrder
:
3144 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
3145 return self
._BuildOption
3147 ## Get include path list from tool option for the module build
3149 # @retval list The include path list
3151 def _GetBuildOptionIncPathList(self
):
3152 if self
._BuildOptionIncPathList
== None:
3154 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3155 # is the former use /I , the Latter used -I to specify include directories
3157 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
3158 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3159 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
3160 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3163 # New ToolChainFamily, don't known whether there is option to specify include directories
3165 self
._BuildOptionIncPathList
= []
3166 return self
._BuildOptionIncPathList
3168 BuildOptionIncPathList
= []
3169 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3172 FlagOption
= self
.BuildOption
[Tool
][Attr
]
3176 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
3177 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
3180 # RVCT may specify a list of directory seperated by commas
3183 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
3184 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3185 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
3188 # EDK II modules must not reference header files outside of the packages they depend on or
3189 # within the module's directory tree. Report error if violation.
3191 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
3192 for Path
in IncPathList
:
3193 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3194 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3195 EdkLogger
.error("build",
3198 File
=str(self
.MetaFile
))
3201 BuildOptionIncPathList
+= IncPathList
3203 self
._BuildOptionIncPathList
= BuildOptionIncPathList
3205 return self
._BuildOptionIncPathList
3207 ## Return a list of files which can be built from source
3209 # What kind of files can be built is determined by build rules in
3210 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3212 def _GetSourceFileList(self
):
3213 if self
._SourceFileList
== None:
3214 self
._SourceFileList
= []
3215 for F
in self
.Module
.Sources
:
3217 if F
.TagName
not in ("", "*", self
.ToolChain
):
3218 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3219 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
3221 # match tool chain family
3222 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
3225 "The file [%s] must be built by tools of [%s], " \
3226 "but current toolchain family is [%s]" \
3227 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
3230 # add the file path into search path list for file including
3231 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3232 self
.IncludePathList
.insert(0, F
.Dir
)
3233 self
._SourceFileList
.append(F
)
3235 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
3237 for F
in self
._SourceFileList
:
3238 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3239 return self
._SourceFileList
3241 def _MatchBuildRuleOrder(self
, FileList
):
3243 self
._GetModuleBuildOption
()
3244 for SingleFile
in FileList
:
3245 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3246 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3247 if key
in Order_Dict
:
3248 Order_Dict
[key
].append(SingleFile
.Ext
)
3250 Order_Dict
[key
] = [SingleFile
.Ext
]
3253 for F
in Order_Dict
:
3254 if len(Order_Dict
[F
]) > 1:
3255 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3256 for Ext
in Order_Dict
[F
][1:]:
3257 RemoveList
.append(F
+ Ext
)
3259 for item
in RemoveList
:
3260 FileList
.remove(item
)
3264 ## Return the list of unicode files
3265 def _GetUnicodeFileList(self
):
3266 if self
._UnicodeFileList
== None:
3267 if TAB_UNICODE_FILE
in self
.FileTypes
:
3268 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
3270 self
._UnicodeFileList
= []
3271 return self
._UnicodeFileList
3273 ## Return the list of vfr files
3274 def _GetVfrFileList(self
):
3275 if self
._VfrFileList
== None:
3276 if TAB_VFR_FILE
in self
.FileTypes
:
3277 self
._VfrFileList
= self
.FileTypes
[TAB_VFR_FILE
]
3279 self
._VfrFileList
= []
3280 return self
._VfrFileList
3282 ## Return the list of Image Definition files
3283 def _GetIdfFileList(self
):
3284 if self
._IdfFileList
== None:
3285 if TAB_IMAGE_FILE
in self
.FileTypes
:
3286 self
._IdfFileList
= self
.FileTypes
[TAB_IMAGE_FILE
]
3288 self
._IdfFileList
= []
3289 return self
._IdfFileList
3291 ## Return a list of files which can be built from binary
3293 # "Build" binary files are just to copy them to build directory.
3295 # @retval list The list of files which can be built later
3297 def _GetBinaryFiles(self
):
3298 if self
._BinaryFileList
== None:
3299 self
._BinaryFileList
= []
3300 for F
in self
.Module
.Binaries
:
3301 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
3303 self
._BinaryFileList
.append(F
)
3304 self
._ApplyBuildRule
(F
, F
.Type
)
3305 return self
._BinaryFileList
3307 def _GetBuildRules(self
):
3308 if self
._BuildRules
== None:
3310 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3311 for Type
in BuildRuleDatabase
.FileTypeList
:
3312 #first try getting build rule by BuildRuleFamily
3313 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3315 # build type is always module type, but ...
3316 if self
.ModuleType
!= self
.BuildType
:
3317 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3318 #second try getting build rule by ToolChainFamily
3320 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3322 # build type is always module type, but ...
3323 if self
.ModuleType
!= self
.BuildType
:
3324 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3327 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3328 BuildRules
[Type
] = RuleObject
3329 for Ext
in RuleObject
.SourceFileExtList
:
3330 BuildRules
[Ext
] = RuleObject
3331 self
._BuildRules
= BuildRules
3332 return self
._BuildRules
3334 def _ApplyBuildRule(self
, File
, FileType
):
3335 if self
._BuildTargets
== None:
3336 self
._IntroBuildTargetList
= set()
3337 self
._FinalBuildTargetList
= set()
3338 self
._BuildTargets
= {}
3339 self
._FileTypes
= {}
3341 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3342 if not os
.path
.exists(SubDirectory
):
3343 CreateDirectory(SubDirectory
)
3349 # Make sure to get build rule order value
3351 self
._GetModuleBuildOption
()
3353 while Index
< len(SourceList
):
3354 Source
= SourceList
[Index
]
3358 CreateDirectory(Source
.Dir
)
3360 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
3361 # Skip all files that are not binary libraries
3362 if not self
.IsLibrary
:
3364 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3365 elif FileType
in self
.BuildRules
:
3366 RuleObject
= self
.BuildRules
[FileType
]
3367 elif Source
.Ext
in self
.BuildRules
:
3368 RuleObject
= self
.BuildRules
[Source
.Ext
]
3370 # stop at no more rules
3372 self
._FinalBuildTargetList
.add(LastTarget
)
3375 FileType
= RuleObject
.SourceFileType
3376 if FileType
not in self
._FileTypes
:
3377 self
._FileTypes
[FileType
] = set()
3378 self
._FileTypes
[FileType
].add(Source
)
3380 # stop at STATIC_LIBRARY for library
3381 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3383 self
._FinalBuildTargetList
.add(LastTarget
)
3386 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3389 self
._FinalBuildTargetList
.add(LastTarget
)
3391 elif not Target
.Outputs
:
3392 # Only do build for target with outputs
3393 self
._FinalBuildTargetList
.add(Target
)
3395 if FileType
not in self
._BuildTargets
:
3396 self
._BuildTargets
[FileType
] = set()
3397 self
._BuildTargets
[FileType
].add(Target
)
3399 if not Source
.IsBinary
and Source
== File
:
3400 self
._IntroBuildTargetList
.add(Target
)
3402 # to avoid cyclic rule
3403 if FileType
in RuleChain
:
3406 RuleChain
.append(FileType
)
3407 SourceList
.extend(Target
.Outputs
)
3409 FileType
= TAB_UNKNOWN_FILE
3411 def _GetTargets(self
):
3412 if self
._BuildTargets
== None:
3413 self
._IntroBuildTargetList
= set()
3414 self
._FinalBuildTargetList
= set()
3415 self
._BuildTargets
= {}
3416 self
._FileTypes
= {}
3418 #TRICK: call _GetSourceFileList to apply build rule for source files
3419 if self
.SourceFileList
:
3422 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3423 if self
.BinaryFileList
:
3426 return self
._BuildTargets
3428 def _GetIntroTargetList(self
):
3430 return self
._IntroBuildTargetList
3432 def _GetFinalTargetList(self
):
3434 return self
._FinalBuildTargetList
3436 def _GetFileTypes(self
):
3438 return self
._FileTypes
3440 ## Get the list of package object the module depends on
3442 # @retval list The package object list
3444 def _GetDependentPackageList(self
):
3445 return self
.Module
.Packages
3447 ## Return the list of auto-generated code file
3449 # @retval list The list of auto-generated file
3451 def _GetAutoGenFileList(self
):
3452 UniStringAutoGenC
= True
3453 IdfStringAutoGenC
= True
3454 UniStringBinBuffer
= StringIO()
3455 IdfGenBinBuffer
= StringIO()
3456 if self
.BuildType
== 'UEFI_HII':
3457 UniStringAutoGenC
= False
3458 IdfStringAutoGenC
= False
3459 if self
._AutoGenFileList
== None:
3460 self
._AutoGenFileList
= {}
3461 AutoGenC
= TemplateString()
3462 AutoGenH
= TemplateString()
3463 StringH
= TemplateString()
3464 StringIdf
= TemplateString()
3465 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
, StringIdf
, IdfStringAutoGenC
, IdfGenBinBuffer
)
3467 # AutoGen.c is generated if there are library classes in inf, or there are object files
3469 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3470 or TAB_OBJECT_FILE
in self
.FileTypes
):
3471 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3472 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3473 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3474 if str(AutoGenH
) != "":
3475 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3476 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3477 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3478 if str(StringH
) != "":
3479 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3480 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3481 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3482 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
3483 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3484 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3485 AutoFile
.IsBinary
= True
3486 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3487 if UniStringBinBuffer
!= None:
3488 UniStringBinBuffer
.close()
3489 if str(StringIdf
) != "":
3490 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3491 self
._AutoGenFileList
[AutoFile
] = str(StringIdf
)
3492 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3493 if IdfGenBinBuffer
!= None and IdfGenBinBuffer
.getvalue() != "":
3494 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3495 self
._AutoGenFileList
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3496 AutoFile
.IsBinary
= True
3497 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3498 if IdfGenBinBuffer
!= None:
3499 IdfGenBinBuffer
.close()
3500 return self
._AutoGenFileList
3502 ## Return the list of library modules explicitly or implicityly used by this module
3503 def _GetLibraryList(self
):
3504 if self
._DependentLibraryList
== None:
3505 # only merge library classes and PCD for non-library module
3507 self
._DependentLibraryList
= []
3509 if self
.AutoGenVersion
< 0x00010005:
3510 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3512 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3513 return self
._DependentLibraryList
3516 def UpdateComments(Recver
, Src
):
3518 if Key
not in Recver
:
3520 Recver
[Key
].extend(Src
[Key
])
3521 ## Get the list of PCDs from current module
3523 # @retval list The list of PCD
3525 def _GetModulePcdList(self
):
3526 if self
._ModulePcdList
== None:
3527 # apply PCD settings from platform
3528 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3529 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3530 return self
._ModulePcdList
3532 ## Get the list of PCDs from dependent libraries
3534 # @retval list The list of PCD
3536 def _GetLibraryPcdList(self
):
3537 if self
._LibraryPcdList
== None:
3539 if not self
.IsLibrary
:
3540 # get PCDs from dependent libraries
3541 for Library
in self
.DependentLibraryList
:
3542 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3543 for Key
in Library
.Pcds
:
3544 # skip duplicated PCDs
3545 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3547 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3548 # apply PCD settings from platform
3549 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3551 self
._LibraryPcdList
= []
3552 return self
._LibraryPcdList
3554 ## Get the GUID value mapping
3556 # @retval dict The mapping between GUID cname and its value
3558 def _GetGuidList(self
):
3559 if self
._GuidList
== None:
3560 self
._GuidList
= sdict()
3561 self
._GuidList
.update(self
.Module
.Guids
)
3562 for Library
in self
.DependentLibraryList
:
3563 self
._GuidList
.update(Library
.Guids
)
3564 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3565 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3566 return self
._GuidList
3568 def GetGuidsUsedByPcd(self
):
3569 if self
._GuidsUsedByPcd
== None:
3570 self
._GuidsUsedByPcd
= sdict()
3571 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3572 for Library
in self
.DependentLibraryList
:
3573 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3574 return self
._GuidsUsedByPcd
3575 ## Get the protocol value mapping
3577 # @retval dict The mapping between protocol cname and its value
3579 def _GetProtocolList(self
):
3580 if self
._ProtocolList
== None:
3581 self
._ProtocolList
= sdict()
3582 self
._ProtocolList
.update(self
.Module
.Protocols
)
3583 for Library
in self
.DependentLibraryList
:
3584 self
._ProtocolList
.update(Library
.Protocols
)
3585 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3586 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3587 return self
._ProtocolList
3589 ## Get the PPI value mapping
3591 # @retval dict The mapping between PPI cname and its value
3593 def _GetPpiList(self
):
3594 if self
._PpiList
== None:
3595 self
._PpiList
= sdict()
3596 self
._PpiList
.update(self
.Module
.Ppis
)
3597 for Library
in self
.DependentLibraryList
:
3598 self
._PpiList
.update(Library
.Ppis
)
3599 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3600 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3601 return self
._PpiList
3603 ## Get the list of include search path
3605 # @retval list The list path
3607 def _GetIncludePathList(self
):
3608 if self
._IncludePathList
== None:
3609 self
._IncludePathList
= []
3610 if self
.AutoGenVersion
< 0x00010005:
3611 for Inc
in self
.Module
.Includes
:
3612 if Inc
not in self
._IncludePathList
:
3613 self
._IncludePathList
.append(Inc
)
3615 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3616 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3617 self
._IncludePathList
.append(Inc
)
3618 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3619 self
._IncludePathList
.append(self
.DebugDir
)
3621 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3622 self
._IncludePathList
.append(self
.DebugDir
)
3624 for Package
in self
.Module
.Packages
:
3625 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3626 if PackageDir
not in self
._IncludePathList
:
3627 self
._IncludePathList
.append(PackageDir
)
3628 IncludesList
= Package
.Includes
3629 if Package
._PrivateIncludes
:
3630 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3631 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3632 for Inc
in IncludesList
:
3633 if Inc
not in self
._IncludePathList
:
3634 self
._IncludePathList
.append(str(Inc
))
3635 return self
._IncludePathList
3637 def _GetIncludePathLength(self
):
3638 self
._IncludePathLength
= 0
3639 if self
._IncludePathList
:
3640 for inc
in self
._IncludePathList
:
3641 self
._IncludePathLength
+= len(' ' + inc
)
3642 return self
._IncludePathLength
3644 ## Get HII EX PCDs which maybe used by VFR
3646 # efivarstore used by VFR may relate with HII EX PCDs
3647 # Get the variable name and GUID from efivarstore and HII EX PCD
3648 # List the HII EX PCDs in As Built INF if both name and GUID match.
3650 # @retval list HII EX PCDs
3652 def _GetPcdsMaybeUsedByVfr(self
):
3653 if not self
.SourceFileList
:
3657 for SrcFile
in self
.SourceFileList
:
3658 if SrcFile
.Ext
.lower() != '.vfr':
3660 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3661 if not os
.path
.exists(Vfri
):
3663 VfriFile
= open(Vfri
, 'r')
3664 Content
= VfriFile
.read()
3666 Pos
= Content
.find('efivarstore')
3669 # Make sure 'efivarstore' is the start of efivarstore statement
3670 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3673 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3675 if Index
>= 0 and Content
[Index
] != ';':
3676 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3679 # 'efivarstore' must be followed by name and guid
3681 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3684 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3687 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3688 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3689 Pos
= Content
.find('efivarstore', Name
.end())
3693 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3694 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3696 for SkuName
in Pcd
.SkuInfoList
:
3697 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3698 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3699 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3702 Guid
= GuidStructureStringToGuidString(Value
)
3703 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3704 HiiExPcds
.append(Pcd
)
3709 def _GenOffsetBin(self
):
3711 for SourceFile
in self
.Module
.Sources
:
3712 if SourceFile
.Type
.upper() == ".VFR" :
3714 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3716 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3717 if SourceFile
.Type
.upper() == ".UNI" :
3719 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3721 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3723 if len(VfrUniBaseName
) == 0:
3725 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3726 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3727 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3728 if not VfrUniOffsetList
:
3731 OutputName
= '%sOffset.bin' % self
.Name
3732 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3735 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3737 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3739 # Use a instance of StringIO to cache data
3740 fStringIO
= StringIO('')
3742 for Item
in VfrUniOffsetList
:
3743 if (Item
[0].find("Strings") != -1):
3745 # UNI offset in image.
3747 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3749 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3750 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3751 fStringIO
.write(''.join(UniGuid
))
3752 UniValue
= pack ('Q', int (Item
[1], 16))
3753 fStringIO
.write (UniValue
)
3756 # VFR binary offset in image.
3758 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3760 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3761 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3762 fStringIO
.write(''.join(VfrGuid
))
3764 VfrValue
= pack ('Q', int (Item
[1], 16))
3765 fStringIO
.write (VfrValue
)
3767 # write data into file.
3770 fInputfile
.write (fStringIO
.getvalue())
3772 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3773 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3779 ## Create AsBuilt INF file the module
3781 def CreateAsBuiltInf(self
):
3782 if self
.IsAsBuiltInfCreated
:
3785 # Skip the following code for EDK I inf
3786 if self
.AutoGenVersion
< 0x00010005:
3789 # Skip the following code for libraries
3793 # Skip the following code for modules with no source files
3794 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3797 # Skip the following code for modules without any binary files
3798 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3801 ### TODO: How to handles mixed source and binary modules
3803 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3804 # Also find all packages that the DynamicEx PCDs depend on
3809 PcdTokenSpaceList
= []
3810 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3811 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3812 PatchablePcds
+= [Pcd
]
3813 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3814 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3817 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3818 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3819 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3821 GuidList
.update(self
.GuidList
)
3822 for TokenSpace
in self
.GetGuidsUsedByPcd():
3823 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3824 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3825 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3826 GuidList
.pop(TokenSpace
)
3827 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3828 for Package
in self
.DerivedPackageList
:
3829 if Package
in Packages
:
3831 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3833 for Index
in range(len(BeChecked
)):
3834 for Item
in CheckList
[Index
]:
3835 if Item
in BeChecked
[Index
]:
3836 Packages
+= [Package
]
3841 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3842 for Pkg
in self
.PlatformInfo
.PackageList
:
3845 for VfrPcd
in VfrPcds
:
3846 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3847 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3851 ModuleType
= self
.ModuleType
3852 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3853 ModuleType
= 'DXE_DRIVER'
3856 if self
.PcdIsDriver
!= '':
3857 DriverType
= self
.PcdIsDriver
3860 MDefs
= self
.Module
.Defines
3863 'module_name' : self
.Name
,
3864 'module_guid' : Guid
,
3865 'module_module_type' : ModuleType
,
3866 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3867 'pcd_is_driver_string' : [],
3868 'module_uefi_specification_version' : [],
3869 'module_pi_specification_version' : [],
3870 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3871 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3872 'module_constructor' : self
.Module
.ConstructorList
,
3873 'module_destructor' : self
.Module
.DestructorList
,
3874 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3875 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3876 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3877 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3878 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3879 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3880 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3881 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3882 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3883 'module_arch' : self
.Arch
,
3884 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3886 'patchablepcd_item' : [],
3888 'protocol_item' : [],
3892 'libraryclasses_item' : []
3895 if 'MODULE_UNI_FILE' in MDefs
:
3896 UNIFile
= os
.path
.join(self
.MetaFile
.Dir
, MDefs
['MODULE_UNI_FILE'])
3897 if os
.path
.isfile(UNIFile
):
3898 shutil
.copy2(UNIFile
, self
.OutputDir
)
3900 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3901 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3903 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3906 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3908 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3909 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3910 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3911 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3913 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3915 for Item
in self
.CodaTargetList
:
3916 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3917 if Item
.Target
.Ext
.lower() == '.aml':
3918 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3919 elif Item
.Target
.Ext
.lower() == '.acpi':
3920 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3921 elif Item
.Target
.Ext
.lower() == '.efi':
3922 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3924 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3925 if self
.DepexGenerated
:
3926 if self
.ModuleType
in ['PEIM']:
3927 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3928 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3929 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3930 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3931 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3933 Bin
= self
._GenOffsetBin
()
3935 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3937 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3939 if File
.lower().endswith('.pdb'):
3940 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3941 HeaderComments
= self
.Module
.HeaderComments
3943 for Index
in range(len(HeaderComments
)):
3944 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3945 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3948 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3949 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3952 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3953 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3954 (GuidList
, self
._GuidComments
, 'guid_item')
3956 for Item
in GenList
:
3957 for CName
in Item
[0]:
3959 if CName
in Item
[1]:
3960 Comments
= '\n '.join(Item
[1][CName
])
3963 Entry
= Comments
+ '\n ' + CName
3964 AsBuiltInfDict
[Item
[2]].append(Entry
)
3965 PatchList
= parsePcdInfoFromMapFile(
3966 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3967 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3970 for Pcd
in PatchablePcds
:
3971 TokenCName
= Pcd
.TokenCName
3972 for PcdItem
in GlobalData
.MixedPcd
:
3973 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3974 TokenCName
= PcdItem
[0]
3976 for PatchPcd
in PatchList
:
3977 if TokenCName
== PatchPcd
[0]:
3982 if Pcd
.DatumType
== 'BOOLEAN':
3983 BoolValue
= Pcd
.DefaultValue
.upper()
3984 if BoolValue
== 'TRUE':
3985 Pcd
.DefaultValue
= '1'
3986 elif BoolValue
== 'FALSE':
3987 Pcd
.DefaultValue
= '0'
3989 if Pcd
.DatumType
!= 'VOID*':
3990 HexFormat
= '0x%02x'
3991 if Pcd
.DatumType
== 'UINT16':
3992 HexFormat
= '0x%04x'
3993 elif Pcd
.DatumType
== 'UINT32':
3994 HexFormat
= '0x%08x'
3995 elif Pcd
.DatumType
== 'UINT64':
3996 HexFormat
= '0x%016x'
3997 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3999 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
4000 EdkLogger
.error("build", AUTOGEN_ERROR
,
4001 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4003 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
4004 PcdValue
= Pcd
.DefaultValue
4005 if PcdValue
[0] != '{':
4007 if PcdValue
[0] == 'L':
4009 PcdValue
= PcdValue
.lstrip('L')
4010 PcdValue
= eval(PcdValue
)
4012 for Index
in range(0, len(PcdValue
)):
4014 CharVal
= ord(PcdValue
[Index
])
4015 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
4016 + '0x%02x' % (CharVal
>> 8) + ', '
4018 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
4021 Padding
= Padding
* 2
4022 ArraySize
= ArraySize
/ 2
4023 if ArraySize
< (len(PcdValue
) + 1):
4024 EdkLogger
.error("build", AUTOGEN_ERROR
,
4025 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4027 if ArraySize
> len(PcdValue
) + 1:
4028 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
4029 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
4030 elif len(PcdValue
.split(',')) <= ArraySize
:
4031 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
4034 EdkLogger
.error("build", AUTOGEN_ERROR
,
4035 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
4037 PcdItem
= '%s.%s|%s|0x%X' % \
4038 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
4040 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4041 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
4043 PcdItem
= PcdComments
+ '\n ' + PcdItem
4044 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
4047 for Pcd
in Pcds
+ VfrPcds
:
4052 TokenCName
= Pcd
.TokenCName
4053 for PcdItem
in GlobalData
.MixedPcd
:
4054 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
4055 TokenCName
= PcdItem
[0]
4057 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
4058 for SkuName
in Pcd
.SkuInfoList
:
4059 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
4060 SkuId
= SkuInfo
.SkuId
4061 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
4065 # Don't generate duplicated HII PCD
4067 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
4070 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
4071 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4072 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
4076 for Index
, Comment
in enumerate(PcdCommentList
):
4077 for Usage
in UsageList
:
4078 if Comment
.find(Usage
) != -1:
4082 if UsageIndex
!= -1:
4083 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
4085 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
4086 PcdComments
= '\n '.join(PcdCommentList
)
4087 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
4089 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
4090 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
4091 for Item
in self
.BuildOption
:
4092 if 'FLAGS' in self
.BuildOption
[Item
]:
4093 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
4095 # Generated LibraryClasses section in comments.
4096 for Library
in self
.LibraryAutoGenList
:
4097 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
4099 # Generated UserExtensions TianoCore section.
4100 # All tianocore user extensions are copied.
4102 for TianoCore
in self
._GetTianoCoreUserExtensionList
():
4103 UserExtStr
+= '\n'.join(TianoCore
)
4104 ExtensionFile
= os
.path
.join(self
.MetaFile
.Dir
, TianoCore
[1])
4105 if os
.path
.isfile(ExtensionFile
):
4106 shutil
.copy2(ExtensionFile
, self
.OutputDir
)
4107 AsBuiltInfDict
['userextension_tianocore_item'] = UserExtStr
4109 # Generated depex expression section in comments.
4110 AsBuiltInfDict
['depexsection_item'] = ''
4111 DepexExpresion
= self
._GetDepexExpresionString
()
4113 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
4115 AsBuiltInf
= TemplateString()
4116 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
4118 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
4120 self
.IsAsBuiltInfCreated
= True
4122 ## Create makefile for the module and its dependent libraries
4124 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
4125 # dependent libraries will be created
4127 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
4128 # Ignore generating makefile when it is a binary module
4129 if self
.IsBinaryModule
:
4132 if self
.IsMakeFileCreated
:
4137 if not self
.IsLibrary
and CreateLibraryMakeFile
:
4138 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4139 LibraryAutoGen
.CreateMakeFile()
4141 if len(self
.CustomMakefile
) == 0:
4142 Makefile
= GenMake
.ModuleMakefile(self
)
4144 Makefile
= GenMake
.CustomMakefile(self
)
4145 if Makefile
.Generate():
4146 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
4147 (self
.Name
, self
.Arch
))
4149 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
4150 (self
.Name
, self
.Arch
))
4152 self
.CreateTimeStamp(Makefile
)
4153 self
.IsMakeFileCreated
= True
4155 def CopyBinaryFiles(self
):
4156 for File
in self
.Module
.Binaries
:
4158 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4159 CopyLongFilePath(SrcPath
, DstPath
)
4160 ## Create autogen code for the module and its dependent libraries
4162 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4163 # dependent libraries will be created
4165 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4166 if self
.IsCodeFileCreated
:
4171 # Need to generate PcdDatabase even PcdDriver is binarymodule
4172 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4173 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4175 if self
.IsBinaryModule
:
4177 self
.CopyBinaryFiles()
4180 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4181 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4182 LibraryAutoGen
.CreateCodeFile()
4185 IgoredAutoGenList
= []
4187 for File
in self
.AutoGenFileList
:
4188 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4189 #Ignore Edk AutoGen.c
4190 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
4193 AutoGenList
.append(str(File
))
4195 IgoredAutoGenList
.append(str(File
))
4197 # Skip the following code for EDK I inf
4198 if self
.AutoGenVersion
< 0x00010005:
4201 for ModuleType
in self
.DepexList
:
4202 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
4203 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
4206 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4207 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4209 if len(Dpx
.PostfixNotation
) <> 0:
4210 self
.DepexGenerated
= True
4212 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4213 AutoGenList
.append(str(DpxFile
))
4215 IgoredAutoGenList
.append(str(DpxFile
))
4217 if IgoredAutoGenList
== []:
4218 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4219 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4220 elif AutoGenList
== []:
4221 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4222 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4224 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4225 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4227 self
.IsCodeFileCreated
= True
4230 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4231 def _GetLibraryAutoGenList(self
):
4232 if self
._LibraryAutoGenList
== None:
4233 self
._LibraryAutoGenList
= []
4234 for Library
in self
.DependentLibraryList
:
4241 self
.PlatformInfo
.MetaFile
4243 if La
not in self
._LibraryAutoGenList
:
4244 self
._LibraryAutoGenList
.append(La
)
4245 for Lib
in La
.CodaTargetList
:
4246 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4247 return self
._LibraryAutoGenList
4249 ## Decide whether we can skip the ModuleAutoGen process
4250 # If any source file is newer than the modeule than we cannot skip
4253 if not os
.path
.exists(self
.GetTimeStampPath()):
4255 #last creation time of the module
4256 DstTimeStamp
= os
.stat(self
.GetTimeStampPath())[8]
4258 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4259 if SrcTimeStamp
> DstTimeStamp
:
4262 with
open(self
.GetTimeStampPath(),'r') as f
:
4264 source
= source
.rstrip('\n')
4265 if not os
.path
.exists(source
):
4267 if source
not in ModuleAutoGen
.TimeDict
:
4268 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4269 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4273 def GetTimeStampPath(self
):
4274 if self
._TimeStampPath
== None:
4275 self
._TimeStampPath
= os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')
4276 return self
._TimeStampPath
4277 def CreateTimeStamp(self
, Makefile
):
4281 FileSet
.add (self
.MetaFile
.Path
)
4283 for SourceFile
in self
.Module
.Sources
:
4284 FileSet
.add (SourceFile
.Path
)
4286 for Lib
in self
.DependentLibraryList
:
4287 FileSet
.add (Lib
.MetaFile
.Path
)
4289 for f
in self
.AutoGenDepSet
:
4290 FileSet
.add (f
.Path
)
4292 if os
.path
.exists (self
.GetTimeStampPath()):
4293 os
.remove (self
.GetTimeStampPath())
4294 with
open(self
.GetTimeStampPath(), 'w+') as file:
4298 Module
= property(_GetModule
)
4299 Name
= property(_GetBaseName
)
4300 Guid
= property(_GetGuid
)
4301 Version
= property(_GetVersion
)
4302 ModuleType
= property(_GetModuleType
)
4303 ComponentType
= property(_GetComponentType
)
4304 BuildType
= property(_GetBuildType
)
4305 PcdIsDriver
= property(_GetPcdIsDriver
)
4306 AutoGenVersion
= property(_GetAutoGenVersion
)
4307 Macros
= property(_GetMacros
)
4308 Specification
= property(_GetSpecification
)
4310 IsLibrary
= property(_IsLibrary
)
4311 IsBinaryModule
= property(_IsBinaryModule
)
4312 BuildDir
= property(_GetBuildDir
)
4313 OutputDir
= property(_GetOutputDir
)
4314 DebugDir
= property(_GetDebugDir
)
4315 MakeFileDir
= property(_GetMakeFileDir
)
4316 CustomMakefile
= property(_GetCustomMakefile
)
4318 IncludePathList
= property(_GetIncludePathList
)
4319 IncludePathLength
= property(_GetIncludePathLength
)
4320 AutoGenFileList
= property(_GetAutoGenFileList
)
4321 UnicodeFileList
= property(_GetUnicodeFileList
)
4322 VfrFileList
= property(_GetVfrFileList
)
4323 SourceFileList
= property(_GetSourceFileList
)
4324 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
4325 Targets
= property(_GetTargets
)
4326 IntroTargetList
= property(_GetIntroTargetList
)
4327 CodaTargetList
= property(_GetFinalTargetList
)
4328 FileTypes
= property(_GetFileTypes
)
4329 BuildRules
= property(_GetBuildRules
)
4330 IdfFileList
= property(_GetIdfFileList
)
4332 DependentPackageList
= property(_GetDependentPackageList
)
4333 DependentLibraryList
= property(_GetLibraryList
)
4334 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
4335 DerivedPackageList
= property(_GetDerivedPackageList
)
4337 ModulePcdList
= property(_GetModulePcdList
)
4338 LibraryPcdList
= property(_GetLibraryPcdList
)
4339 GuidList
= property(_GetGuidList
)
4340 ProtocolList
= property(_GetProtocolList
)
4341 PpiList
= property(_GetPpiList
)
4342 DepexList
= property(_GetDepexTokenList
)
4343 DxsFile
= property(_GetDxsFile
)
4344 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
4345 BuildOption
= property(_GetModuleBuildOption
)
4346 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
4347 BuildCommand
= property(_GetBuildCommand
)
4349 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
4351 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4352 if __name__
== '__main__':