2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 import Common
.LongFilePathOs
as os
18 import os
.path
as path
25 from StringIO
import StringIO
27 from StrGather
import *
28 from BuildEngine
import BuildRule
30 from Common
.LongFilePathSupport
import CopyLongFilePath
31 from Common
.BuildToolError
import *
32 from Common
.DataType
import *
33 from Common
.Misc
import *
34 from Common
.String
import *
35 import Common
.GlobalData
as GlobalData
36 from GenFds
.FdfParser
import *
37 from CommonDataClass
.CommonClass
import SkuInfoClass
38 from Workspace
.BuildClassObject
import *
39 from GenPatchPcdTable
.GenPatchPcdTable
import parsePcdInfoFromMapFile
40 import Common
.VpdInfoFile
as VpdInfoFile
41 from GenPcdDb
import CreatePcdDatabaseCode
42 from Workspace
.MetaFileCommentParser
import UsageList
43 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
44 import InfSectionParser
47 ## Regular expression for splitting Dependency Expression string into tokens
48 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
51 # Match name = variable
53 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
55 # The format of guid in efivarstore statement likes following and must be correct:
56 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
58 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
60 ## Mapping Makefile type
61 gMakeTypeMap
= {"MSFT":"nmake", "GCC":"gmake"}
64 ## Build rule configuration file
65 gDefaultBuildRuleFile
= 'build_rule.txt'
67 ## Tools definition configuration file
68 gDefaultToolsDefFile
= 'tools_def.txt'
70 ## Build rule default version
71 AutoGenReqBuildRuleVerNum
= "0.1"
73 ## default file name for AutoGen
74 gAutoGenCodeFileName
= "AutoGen.c"
75 gAutoGenHeaderFileName
= "AutoGen.h"
76 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
77 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
78 gAutoGenDepexFileName
= "%(module_name)s.depex"
79 gAutoGenImageDefFileName
= "%(module_name)sImgDefs.h"
80 gAutoGenIdfFileName
= "%(module_name)sIdf.hpk"
81 gInfSpecVersion
= "0x00010017"
84 # Template string to generic AsBuilt INF
86 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
92 INF_VERSION = ${module_inf_version}
93 BASE_NAME = ${module_name}
94 FILE_GUID = ${module_guid}
95 MODULE_TYPE = ${module_module_type}${BEGIN}
96 VERSION_STRING = ${module_version_string}${END}${BEGIN}
97 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
98 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
99 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
100 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
101 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
102 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
103 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
104 SHADOW = ${module_shadow}${END}${BEGIN}
105 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
106 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
107 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
108 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
109 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
110 SPEC = ${module_spec}${END}${BEGIN}
111 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
112 MODULE_UNI_FILE = ${module_uni_file}${END}
114 [Packages.${module_arch}]${BEGIN}
115 ${package_item}${END}
117 [Binaries.${module_arch}]${BEGIN}
120 [PatchPcd.${module_arch}]${BEGIN}
124 [Protocols.${module_arch}]${BEGIN}
128 [Ppis.${module_arch}]${BEGIN}
132 [Guids.${module_arch}]${BEGIN}
136 [PcdEx.${module_arch}]${BEGIN}
140 [LibraryClasses.${module_arch}]
141 ## @LIB_INSTANCES${BEGIN}
142 # ${libraryclasses_item}${END}
148 [BuildOptions.${module_arch}]
150 ## ${flags_item}${END}
153 ## Base class for AutoGen
155 # This class just implements the cache mechanism of AutoGen objects.
157 class AutoGen(object):
158 # database to maintain the objects of xxxAutoGen
159 _CACHE_
= {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}
163 # @param Class class object of real AutoGen class
164 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
165 # @param Workspace Workspace directory or WorkspaceAutoGen object
166 # @param MetaFile The path of meta file
167 # @param Target Build target
168 # @param Toolchain Tool chain name
169 # @param Arch Target arch
170 # @param *args The specific class related parameters
171 # @param **kwargs The specific class related dict parameters
173 def __new__(Class
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
174 # check if the object has been created
175 Key
= (Target
, Toolchain
)
176 if Key
not in Class
._CACHE
_ or Arch
not in Class
._CACHE
_[Key
] \
177 or MetaFile
not in Class
._CACHE
_[Key
][Arch
]:
178 AutoGenObject
= super(AutoGen
, Class
).__new
__(Class
)
179 # call real constructor
180 if not AutoGenObject
._Init
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
182 if Key
not in Class
._CACHE
_:
183 Class
._CACHE
_[Key
] = {}
184 if Arch
not in Class
._CACHE
_[Key
]:
185 Class
._CACHE
_[Key
][Arch
] = {}
186 Class
._CACHE
_[Key
][Arch
][MetaFile
] = AutoGenObject
188 AutoGenObject
= Class
._CACHE
_[Key
][Arch
][MetaFile
]
194 # The file path of platform file will be used to represent hash value of this object
196 # @retval int Hash value of the file path of platform file
199 return hash(self
.MetaFile
)
203 # The file path of platform file will be used to represent this object
205 # @retval string String of platform file path
208 return str(self
.MetaFile
)
211 def __eq__(self
, Other
):
212 return Other
and self
.MetaFile
== Other
214 ## Workspace AutoGen class
216 # This class is used mainly to control the whole platform build for different
217 # architecture. This class will generate top level makefile.
219 class WorkspaceAutoGen(AutoGen
):
220 ## Real constructor of WorkspaceAutoGen
222 # This method behaves the same as __init__ except that it needs explicit invoke
223 # (in super class's __new__ method)
225 # @param WorkspaceDir Root directory of workspace
226 # @param ActivePlatform Meta-file of active platform
227 # @param Target Build target
228 # @param Toolchain Tool chain name
229 # @param ArchList List of architecture of current build
230 # @param MetaFileDb Database containing meta-files
231 # @param BuildConfig Configuration of build
232 # @param ToolDefinition Tool chain definitions
233 # @param FlashDefinitionFile File of flash definition
234 # @param Fds FD list to be generated
235 # @param Fvs FV list to be generated
236 # @param Caps Capsule list to be generated
237 # @param SkuId SKU id from command line
239 def _Init(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
240 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
241 Progress
=None, BuildModule
=None):
248 self
.BuildDatabase
= MetaFileDb
249 self
.MetaFile
= ActivePlatform
250 self
.WorkspaceDir
= WorkspaceDir
251 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, 'COMMON', Target
, Toolchain
]
252 GlobalData
.gActivePlatform
= self
.Platform
253 self
.BuildTarget
= Target
254 self
.ToolChain
= Toolchain
255 self
.ArchList
= ArchList
257 self
.UniFlag
= UniFlag
259 self
.TargetTxt
= BuildConfig
260 self
.ToolDef
= ToolDefinition
261 self
.FdfFile
= FlashDefinitionFile
262 self
.FdTargetList
= Fds
263 self
.FvTargetList
= Fvs
264 self
.CapTargetList
= Caps
265 self
.AutoGenObjectList
= []
267 # there's many relative directory operations, so ...
268 os
.chdir(self
.WorkspaceDir
)
273 if not self
.ArchList
:
274 ArchList
= set(self
.Platform
.SupArchList
)
276 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
278 EdkLogger
.error("build", PARAMETER_INVALID
,
279 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
280 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
281 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
282 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
283 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
284 self
.ArchList
= tuple(ArchList
)
286 # Validate build target
287 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
288 EdkLogger
.error("build", PARAMETER_INVALID
,
289 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
290 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
293 # parse FDF file to get PCDs in it, if any
295 self
.FdfFile
= self
.Platform
.FlashDefinition
299 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
300 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
301 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
303 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
305 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
308 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
310 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
313 Progress
.Start("\nProcessing meta-data")
317 # Mark now build in AutoGen Phase
319 GlobalData
.gAutoGenPhase
= True
320 Fdf
= FdfParser(self
.FdfFile
.Path
)
322 GlobalData
.gFdfParser
= Fdf
323 GlobalData
.gAutoGenPhase
= False
324 PcdSet
= Fdf
.Profile
.PcdDict
325 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
326 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
327 for FdRegion
in FdDict
.RegionList
:
328 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
329 if int(FdRegion
.Offset
) % 8 != 0:
330 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
331 ModuleList
= Fdf
.Profile
.InfList
332 self
.FdfProfile
= Fdf
.Profile
333 for fvname
in self
.FvTargetList
:
334 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
335 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
336 "No such an FV in FDF file: %s" % fvname
)
338 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
339 # but the path (self.MetaFile.Path) is the real path
340 for key
in self
.FdfProfile
.InfDict
:
344 for Arch
in self
.ArchList
:
345 Platform_cache
[Arch
] = self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
346 MetaFile_cache
[Arch
] = []
347 for Pkey
in Platform_cache
[Arch
].Modules
.keys():
348 MetaFile_cache
[Arch
].append(Platform_cache
[Arch
].Modules
[Pkey
].MetaFile
)
349 for Inf
in self
.FdfProfile
.InfDict
[key
]:
350 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
351 for Arch
in self
.ArchList
:
352 if ModuleFile
in MetaFile_cache
[Arch
]:
355 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
356 if not ModuleData
.IsBinaryModule
:
357 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
360 for Arch
in self
.ArchList
:
362 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
364 for Pkey
in Platform
.Modules
.keys():
365 MetaFileList
.append(Platform
.Modules
[Pkey
].MetaFile
)
366 for Inf
in self
.FdfProfile
.InfDict
[key
]:
367 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
368 if ModuleFile
in MetaFileList
:
370 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
371 if not ModuleData
.IsBinaryModule
:
372 EdkLogger
.error('build', PARSER_ERROR
, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile
)
377 self
.FdfProfile
= None
378 if self
.FdTargetList
:
379 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
380 self
.FdTargetList
= []
381 if self
.FvTargetList
:
382 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
383 self
.FvTargetList
= []
384 if self
.CapTargetList
:
385 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
386 self
.CapTargetList
= []
388 # apply SKU and inject PCDs from Flash Definition file
389 for Arch
in self
.ArchList
:
390 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
394 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
395 if GlobalData
.BuildOptionPcd
:
396 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
397 if type(pcd
) is tuple:
399 (pcdname
, pcdvalue
) = pcd
.split('=')
401 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
403 (TokenSpaceGuidCName
, TokenCName
) = pcdname
.split('.')
407 TokenSpaceGuidCName
= ''
408 HasTokenSpace
= False
409 TokenSpaceGuidCNameList
= []
413 for package
in PGen
.PackageList
:
414 for key
in package
.Pcds
:
415 PcdItem
= package
.Pcds
[key
]
417 if (PcdItem
.TokenCName
, PcdItem
.TokenSpaceGuidCName
) == (TokenCName
, TokenSpaceGuidCName
):
418 PcdDatumType
= PcdItem
.DatumType
419 NewValue
= self
._BuildOptionPcdValueFormat
(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
422 if PcdItem
.TokenCName
== TokenCName
:
423 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
424 if len (TokenSpaceGuidCNameList
) < 1:
425 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
426 PcdDatumType
= PcdItem
.DatumType
427 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
428 NewValue
= self
._BuildOptionPcdValueFormat
(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
434 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
437 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, NewValue
)
441 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, TokenCName
))
443 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (TokenCName
))
445 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
446 if BuildData
.Arch
!= Arch
:
448 if BuildData
.MetaFile
.Ext
== '.dec':
450 for key
in BuildData
.Pcds
:
451 PcdItem
= BuildData
.Pcds
[key
]
452 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
):
453 PcdItem
.DefaultValue
= NewValue
455 if (TokenCName
, TokenSpaceGuidCName
) in PcdSet
:
456 PcdSet
[(TokenCName
, TokenSpaceGuidCName
)] = NewValue
458 SourcePcdDict
= {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}
459 BinaryPcdDict
= {'DynamicEx':[], 'PatchableInModule':[]}
460 SourcePcdDict_Keys
= SourcePcdDict
.keys()
461 BinaryPcdDict_Keys
= BinaryPcdDict
.keys()
463 # generate the SourcePcdDict and BinaryPcdDict
464 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
465 if BuildData
.Arch
!= Arch
:
467 if BuildData
.MetaFile
.Ext
== '.inf':
468 for key
in BuildData
.Pcds
:
469 if BuildData
.Pcds
[key
].Pending
:
470 if key
in Platform
.Pcds
:
471 PcdInPlatform
= Platform
.Pcds
[key
]
472 if PcdInPlatform
.Type
not in [None, '']:
473 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
475 if BuildData
.MetaFile
in Platform
.Modules
:
476 PlatformModule
= Platform
.Modules
[str(BuildData
.MetaFile
)]
477 if key
in PlatformModule
.Pcds
:
478 PcdInPlatform
= PlatformModule
.Pcds
[key
]
479 if PcdInPlatform
.Type
not in [None, '']:
480 BuildData
.Pcds
[key
].Type
= PcdInPlatform
.Type
482 if 'DynamicEx' in BuildData
.Pcds
[key
].Type
:
483 if BuildData
.IsBinaryModule
:
484 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['DynamicEx']:
485 BinaryPcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
487 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['DynamicEx']:
488 SourcePcdDict
['DynamicEx'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
490 elif 'PatchableInModule' in BuildData
.Pcds
[key
].Type
:
491 if BuildData
.MetaFile
.Ext
== '.inf':
492 if BuildData
.IsBinaryModule
:
493 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in BinaryPcdDict
['PatchableInModule']:
494 BinaryPcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
496 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['PatchableInModule']:
497 SourcePcdDict
['PatchableInModule'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
499 elif 'Dynamic' in BuildData
.Pcds
[key
].Type
:
500 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['Dynamic']:
501 SourcePcdDict
['Dynamic'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
502 elif 'FixedAtBuild' in BuildData
.Pcds
[key
].Type
:
503 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) not in SourcePcdDict
['FixedAtBuild']:
504 SourcePcdDict
['FixedAtBuild'].append((BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
))
508 # A PCD can only use one type for all source modules
510 for i
in SourcePcdDict_Keys
:
511 for j
in SourcePcdDict_Keys
:
513 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(SourcePcdDict
[j
])))
514 if len(IntersectionList
) > 0:
518 "Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i
, j
),
519 ExtraData
="%s" % '\n\t'.join([str(P
[1]+'.'+P
[0]) for P
in IntersectionList
])
525 # intersection the BinaryPCD for Mixed PCD
527 for i
in BinaryPcdDict_Keys
:
528 for j
in BinaryPcdDict_Keys
:
530 IntersectionList
= list(set(BinaryPcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
531 for item
in IntersectionList
:
532 NewPcd1
= (item
[0] + '_' + i
, item
[1])
533 NewPcd2
= (item
[0] + '_' + j
, item
[1])
534 if item
not in GlobalData
.MixedPcd
:
535 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
537 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
538 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
539 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
540 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
545 # intersection the SourcePCD and BinaryPCD for Mixed PCD
547 for i
in SourcePcdDict_Keys
:
548 for j
in BinaryPcdDict_Keys
:
550 IntersectionList
= list(set(SourcePcdDict
[i
]).intersection(set(BinaryPcdDict
[j
])))
551 for item
in IntersectionList
:
552 NewPcd1
= (item
[0] + '_' + i
, item
[1])
553 NewPcd2
= (item
[0] + '_' + j
, item
[1])
554 if item
not in GlobalData
.MixedPcd
:
555 GlobalData
.MixedPcd
[item
] = [NewPcd1
, NewPcd2
]
557 if NewPcd1
not in GlobalData
.MixedPcd
[item
]:
558 GlobalData
.MixedPcd
[item
].append(NewPcd1
)
559 if NewPcd2
not in GlobalData
.MixedPcd
[item
]:
560 GlobalData
.MixedPcd
[item
].append(NewPcd2
)
564 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
565 if BuildData
.Arch
!= Arch
:
567 for key
in BuildData
.Pcds
:
568 for SinglePcd
in GlobalData
.MixedPcd
:
569 if (BuildData
.Pcds
[key
].TokenCName
, BuildData
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
570 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
571 Pcd_Type
= item
[0].split('_')[-1]
572 if (Pcd_Type
== BuildData
.Pcds
[key
].Type
) or (Pcd_Type
== TAB_PCDS_DYNAMIC_EX
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicExPcd
) or \
573 (Pcd_Type
== TAB_PCDS_DYNAMIC
and BuildData
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
574 Value
= BuildData
.Pcds
[key
]
575 Value
.TokenCName
= BuildData
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
577 newkey
= (Value
.TokenCName
, key
[1])
579 newkey
= (Value
.TokenCName
, key
[1], key
[2])
580 del BuildData
.Pcds
[key
]
581 BuildData
.Pcds
[newkey
] = Value
589 # handle the mixed pcd in FDF file
591 if key
in GlobalData
.MixedPcd
:
594 for item
in GlobalData
.MixedPcd
[key
]:
597 #Collect package set information from INF of FDF
599 for Inf
in ModuleList
:
600 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
601 if ModuleFile
in Platform
.Modules
:
603 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
604 PkgSet
.update(ModuleData
.Packages
)
605 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
608 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
609 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
611 Platform
.SkuName
= self
.SkuId
612 for Name
, Guid
in PcdSet
:
613 if (Name
, Guid
) not in DecPcds
:
617 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
618 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
619 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
622 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
623 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
624 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
625 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
626 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
628 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
632 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
633 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
634 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
637 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
639 # Explicitly collect platform's dynamic PCDs
641 Pa
.CollectPlatformDynamicPcds()
642 Pa
.CollectFixedAtBuildPcds()
643 self
.AutoGenObjectList
.append(Pa
)
646 # Check PCDs token value conflict in each DEC file.
648 self
._CheckAllPcdsTokenValueConflict
()
651 # Check PCD type and definition between DSC and DEC
653 self
._CheckPcdDefineAndType
()
656 # self._CheckDuplicateInFV(Fdf)
658 self
._BuildDir
= None
660 self
._MakeFileDir
= None
661 self
._BuildCommand
= None
664 # Create BuildOptions Macro & PCD metafile.
666 content
= 'gCommandLineDefines: '
667 content
+= str(GlobalData
.gCommandLineDefines
)
668 content
+= os
.linesep
669 content
+= 'BuildOptionPcd: '
670 content
+= str(GlobalData
.BuildOptionPcd
)
671 SaveFileOnChange(os
.path
.join(self
.BuildDir
, 'BuildOptions'), content
, False)
674 # Get set of workspace metafiles
676 AllWorkSpaceMetaFiles
= self
._GetMetaFiles
(Target
, Toolchain
, Arch
)
679 # Retrieve latest modified time of all metafiles
682 for f
in AllWorkSpaceMetaFiles
:
683 if os
.stat(f
)[8] > SrcTimeStamp
:
684 SrcTimeStamp
= os
.stat(f
)[8]
685 self
._SrcTimeStamp
= SrcTimeStamp
688 # Write metafile list to build directory
690 AutoGenFilePath
= os
.path
.join(self
.BuildDir
, 'AutoGen')
691 if os
.path
.exists (AutoGenFilePath
):
692 os
.remove(AutoGenFilePath
)
693 if not os
.path
.exists(self
.BuildDir
):
694 os
.makedirs(self
.BuildDir
)
695 with
open(os
.path
.join(self
.BuildDir
, 'AutoGen'), 'w+') as file:
696 for f
in AllWorkSpaceMetaFiles
:
700 def _BuildOptionPcdValueFormat(self
, TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, Value
):
701 if PcdDatumType
== 'VOID*':
702 if Value
.startswith('L'):
704 EdkLogger
.error('build', OPTION_VALUE_INVALID
, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
705 Value
= Value
[0] + '"' + Value
[1:] + '"'
706 elif Value
.startswith('B'):
708 EdkLogger
.error('build', OPTION_VALUE_INVALID
, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
712 EdkLogger
.error('build', OPTION_VALUE_INVALID
, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
713 Value
= '"' + Value
+ '"'
715 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, Value
)
717 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
718 if PcdDatumType
== 'BOOLEAN':
719 Value
= Value
.upper()
720 if Value
== 'TRUE' or Value
== '1':
722 elif Value
== 'FALSE' or Value
== '0':
726 def _GetMetaFiles(self
, Target
, Toolchain
, Arch
):
727 AllWorkSpaceMetaFiles
= set()
732 AllWorkSpaceMetaFiles
.add (self
.FdfFile
.Path
)
734 FdfFiles
= GlobalData
.gFdfParser
.GetAllIncludedFile()
736 AllWorkSpaceMetaFiles
.add (f
.FileName
)
740 AllWorkSpaceMetaFiles
.add(self
.MetaFile
.Path
)
743 # add build_rule.txt & tools_def.txt
745 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultBuildRuleFile
))
746 AllWorkSpaceMetaFiles
.add(os
.path
.join(GlobalData
.gConfDirectory
, gDefaultToolsDefFile
))
748 # add BuildOption metafile
750 AllWorkSpaceMetaFiles
.add(os
.path
.join(self
.BuildDir
, 'BuildOptions'))
752 for Arch
in self
.ArchList
:
753 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
754 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
759 for Package
in PGen
.PackageList
:
760 AllWorkSpaceMetaFiles
.add(Package
.MetaFile
.Path
)
765 for filePath
in Platform
._RawData
.IncludedFiles
:
766 AllWorkSpaceMetaFiles
.add(filePath
.Path
)
768 return AllWorkSpaceMetaFiles
770 ## _CheckDuplicateInFV() method
772 # Check whether there is duplicate modules/files exist in FV section.
773 # The check base on the file GUID;
775 def _CheckDuplicateInFV(self
, Fdf
):
776 for Fv
in Fdf
.Profile
.FvDict
:
778 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
779 if FfsFile
.InfFileName
and FfsFile
.NameGuid
== None:
784 for Pa
in self
.AutoGenObjectList
:
787 for Module
in Pa
.ModuleAutoGenList
:
788 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
790 if not Module
.Guid
.upper() in _GuidDict
.keys():
791 _GuidDict
[Module
.Guid
.upper()] = FfsFile
794 EdkLogger
.error("build",
796 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
797 FfsFile
.CurrentLineContent
,
798 _GuidDict
[Module
.Guid
.upper()].CurrentLineNum
,
799 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
800 Module
.Guid
.upper()),
801 ExtraData
=self
.FdfFile
)
803 # Some INF files not have entity in DSC file.
806 if FfsFile
.InfFileName
.find('$') == -1:
807 InfPath
= NormPath(FfsFile
.InfFileName
)
808 if not os
.path
.exists(InfPath
):
809 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
811 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
813 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
814 # BuildObject from one of AutoGenObjectList is enough.
816 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, 'COMMON', self
.BuildTarget
, self
.ToolChain
]
817 if not InfObj
.Guid
.upper() in _GuidDict
.keys():
818 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
820 EdkLogger
.error("build",
822 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
823 FfsFile
.CurrentLineContent
,
824 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
825 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
826 InfObj
.Guid
.upper()),
827 ExtraData
=self
.FdfFile
)
830 if FfsFile
.NameGuid
!= None:
831 _CheckPCDAsGuidPattern
= re
.compile("^PCD\(.+\..+\)$")
834 # If the NameGuid reference a PCD name.
835 # The style must match: PCD(xxxx.yyy)
837 if _CheckPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
839 # Replace the PCD value.
841 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
843 for Pa
in self
.AutoGenObjectList
:
845 for PcdItem
in Pa
.AllPcdList
:
846 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
848 # First convert from CFormatGuid to GUID string
850 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
852 if not _PcdGuidString
:
854 # Then try Byte array.
856 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
858 if not _PcdGuidString
:
860 # Not Byte array or CFormat GUID, raise error.
862 EdkLogger
.error("build",
864 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
865 ExtraData
=self
.FdfFile
)
867 if not _PcdGuidString
.upper() in _GuidDict
.keys():
868 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
872 EdkLogger
.error("build",
874 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
875 FfsFile
.CurrentLineContent
,
876 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
877 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
878 FfsFile
.NameGuid
.upper()),
879 ExtraData
=self
.FdfFile
)
881 if not FfsFile
.NameGuid
.upper() in _GuidDict
.keys():
882 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
885 # Two raw file GUID conflict.
887 EdkLogger
.error("build",
889 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
890 FfsFile
.CurrentLineContent
,
891 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
892 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
893 FfsFile
.NameGuid
.upper()),
894 ExtraData
=self
.FdfFile
)
897 def _CheckPcdDefineAndType(self
):
899 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
900 "Dynamic", #"DynamicHii", "DynamicVpd",
901 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
904 # This dict store PCDs which are not used by any modules with specified arches
906 for Pa
in self
.AutoGenObjectList
:
907 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
908 for Pcd
in Pa
.Platform
.Pcds
:
909 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
911 # If no PCD type, this PCD comes from FDF
915 # Try to remove Hii and Vpd suffix
916 if PcdType
.startswith("DynamicEx"):
917 PcdType
= "DynamicEx"
918 elif PcdType
.startswith("Dynamic"):
921 for Package
in Pa
.PackageList
:
922 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
923 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
925 for Type
in PcdTypeList
:
926 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
930 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
931 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
936 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
938 for Pcd
in UnusedPcd
:
941 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
942 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
943 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
948 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
950 ## Return the directory to store FV files
952 if self
._FvDir
== None:
953 self
._FvDir
= path
.join(self
.BuildDir
, 'FV')
956 ## Return the directory to store all intermediate and final files built
957 def _GetBuildDir(self
):
958 return self
.AutoGenObjectList
[0].BuildDir
960 ## Return the build output directory platform specifies
961 def _GetOutputDir(self
):
962 return self
.Platform
.OutputDirectory
964 ## Return platform name
966 return self
.Platform
.PlatformName
968 ## Return meta-file GUID
970 return self
.Platform
.Guid
972 ## Return platform version
973 def _GetVersion(self
):
974 return self
.Platform
.Version
976 ## Return paths of tools
977 def _GetToolDefinition(self
):
978 return self
.AutoGenObjectList
[0].ToolDefinition
980 ## Return directory of platform makefile
982 # @retval string Makefile directory
984 def _GetMakeFileDir(self
):
985 if self
._MakeFileDir
== None:
986 self
._MakeFileDir
= self
.BuildDir
987 return self
._MakeFileDir
989 ## Return build command string
991 # @retval string Build command string
993 def _GetBuildCommand(self
):
994 if self
._BuildCommand
== None:
995 # BuildCommand should be all the same. So just get one from platform AutoGen
996 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
997 return self
._BuildCommand
999 ## Check the PCDs token value conflict in each DEC file.
1001 # Will cause build break and raise error message while two PCDs conflict.
1005 def _CheckAllPcdsTokenValueConflict(self
):
1006 for Pa
in self
.AutoGenObjectList
:
1007 for Package
in Pa
.PackageList
:
1008 PcdList
= Package
.Pcds
.values()
1009 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
1011 while (Count
< len(PcdList
) - 1) :
1012 Item
= PcdList
[Count
]
1013 ItemNext
= PcdList
[Count
+ 1]
1015 # Make sure in the same token space the TokenValue should be unique
1017 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
1018 SameTokenValuePcdList
= []
1019 SameTokenValuePcdList
.append(Item
)
1020 SameTokenValuePcdList
.append(ItemNext
)
1021 RemainPcdListLength
= len(PcdList
) - Count
- 2
1022 for ValueSameCount
in range(RemainPcdListLength
):
1023 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
1024 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
1028 # Sort same token value PCD list with TokenGuid and TokenCName
1030 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1031 SameTokenValuePcdListCount
= 0
1032 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
1034 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
1035 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
1037 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
1038 for PcdItem
in GlobalData
.MixedPcd
:
1039 if (TemListItem
.TokenCName
, TemListItem
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
] or \
1040 (TemListItemNext
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1046 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
1047 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
1050 SameTokenValuePcdListCount
+= 1
1051 Count
+= SameTokenValuePcdListCount
1054 PcdList
= Package
.Pcds
.values()
1055 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
1057 while (Count
< len(PcdList
) - 1) :
1058 Item
= PcdList
[Count
]
1059 ItemNext
= PcdList
[Count
+ 1]
1061 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
1063 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
1067 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
1068 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
1072 ## Generate fds command
1073 def _GenFdsCommand(self
):
1074 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
1076 ## Create makefile for the platform and modules in it
1078 # @param CreateDepsMakeFile Flag indicating if the makefile for
1079 # modules will be created as well
1081 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
1082 if CreateDepsMakeFile
:
1083 for Pa
in self
.AutoGenObjectList
:
1084 Pa
.CreateMakeFile(CreateDepsMakeFile
)
1086 ## Create autogen code for platform and modules
1088 # Since there's no autogen code for platform, this method will do nothing
1089 # if CreateModuleCodeFile is set to False.
1091 # @param CreateDepsCodeFile Flag indicating if creating module's
1092 # autogen code file or not
1094 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
1095 if not CreateDepsCodeFile
:
1097 for Pa
in self
.AutoGenObjectList
:
1098 Pa
.CreateCodeFile(CreateDepsCodeFile
)
1100 ## Create AsBuilt INF file the platform
1102 def CreateAsBuiltInf(self
):
1105 Name
= property(_GetName
)
1106 Guid
= property(_GetGuid
)
1107 Version
= property(_GetVersion
)
1108 OutputDir
= property(_GetOutputDir
)
1110 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
1112 BuildDir
= property(_GetBuildDir
)
1113 FvDir
= property(_GetFvDir
)
1114 MakeFileDir
= property(_GetMakeFileDir
)
1115 BuildCommand
= property(_GetBuildCommand
)
1116 GenFdsCommand
= property(_GenFdsCommand
)
1118 ## AutoGen class for platform
1120 # PlatformAutoGen class will process the original information in platform
1121 # file in order to generate makefile for platform.
1123 class PlatformAutoGen(AutoGen
):
1125 # Used to store all PCDs for both PEI and DXE phase, in order to generate
1126 # correct PCD database
1129 _NonDynaPcdList_
= []
1133 # The priority list while override build option
1135 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
1136 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1137 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1138 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1139 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1140 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1141 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1142 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1143 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1144 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1145 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1146 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1147 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1148 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1149 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1150 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1152 ## The real constructor of PlatformAutoGen
1154 # This method is not supposed to be called by users of PlatformAutoGen. It's
1155 # only used by factory method __new__() to do real initialization work for an
1156 # object of PlatformAutoGen
1158 # @param Workspace WorkspaceAutoGen object
1159 # @param PlatformFile Platform file (DSC file)
1160 # @param Target Build target (DEBUG, RELEASE)
1161 # @param Toolchain Name of tool chain
1162 # @param Arch arch of the platform supports
1164 def _Init(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
1165 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
1166 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
1168 self
.MetaFile
= PlatformFile
1169 self
.Workspace
= Workspace
1170 self
.WorkspaceDir
= Workspace
.WorkspaceDir
1171 self
.ToolChain
= Toolchain
1172 self
.BuildTarget
= Target
1174 self
.SourceDir
= PlatformFile
.SubDir
1175 self
.SourceOverrideDir
= None
1176 self
.FdTargetList
= self
.Workspace
.FdTargetList
1177 self
.FvTargetList
= self
.Workspace
.FvTargetList
1178 self
.AllPcdList
= []
1179 # get the original module/package/platform objects
1180 self
.BuildDatabase
= Workspace
.BuildDatabase
1182 # flag indicating if the makefile/C-code file has been created or not
1183 self
.IsMakeFileCreated
= False
1184 self
.IsCodeFileCreated
= False
1186 self
._Platform
= None
1189 self
._Version
= None
1191 self
._BuildRule
= None
1192 self
._SourceDir
= None
1193 self
._BuildDir
= None
1194 self
._OutputDir
= None
1196 self
._MakeFileDir
= None
1197 self
._FdfFile
= None
1199 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
1200 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1201 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1202 self
._NonDynamicPcdDict
= {}
1204 self
._ToolDefinitions
= None
1205 self
._ToolDefFile
= None # toolcode : tool path
1206 self
._ToolChainFamily
= None
1207 self
._BuildRuleFamily
= None
1208 self
._BuildOption
= None # toolcode : option
1209 self
._EdkBuildOption
= None # edktoolcode : option
1210 self
._EdkIIBuildOption
= None # edkiitoolcode : option
1211 self
._PackageList
= None
1212 self
._ModuleAutoGenList
= None
1213 self
._LibraryAutoGenList
= None
1214 self
._BuildCommand
= None
1215 self
._AsBuildInfList
= []
1216 self
._AsBuildModuleList
= []
1217 if GlobalData
.gFdfParser
!= None:
1218 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
1219 for Inf
in self
._AsBuildInfList
:
1220 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
1221 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1222 if not M
.IsSupportedArch
:
1224 self
._AsBuildModuleList
.append(InfClass
)
1225 # get library/modules for build
1226 self
.LibraryBuildDirectoryList
= []
1227 self
.ModuleBuildDirectoryList
= []
1231 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
1233 ## Create autogen code for platform and modules
1235 # Since there's no autogen code for platform, this method will do nothing
1236 # if CreateModuleCodeFile is set to False.
1238 # @param CreateModuleCodeFile Flag indicating if creating module's
1239 # autogen code file or not
1241 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
1242 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1243 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
1246 for Ma
in self
.ModuleAutoGenList
:
1247 Ma
.CreateCodeFile(True)
1249 # don't do this twice
1250 self
.IsCodeFileCreated
= True
1252 ## Generate Fds Command
1253 def _GenFdsCommand(self
):
1254 return self
.Workspace
.GenFdsCommand
1256 ## Create makefile for the platform and mdoules in it
1258 # @param CreateModuleMakeFile Flag indicating if the makefile for
1259 # modules will be created as well
1261 def CreateMakeFile(self
, CreateModuleMakeFile
=False):
1262 if CreateModuleMakeFile
:
1263 for ModuleFile
in self
.Platform
.Modules
:
1264 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
1265 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1266 Ma
.CreateMakeFile(True)
1267 #Ma.CreateAsBuiltInf()
1269 # no need to create makefile for the platform more than once
1270 if self
.IsMakeFileCreated
:
1273 # create library/module build dirs for platform
1274 Makefile
= GenMake
.PlatformMakefile(self
)
1275 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1276 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1278 self
.IsMakeFileCreated
= True
1280 ## Deal with Shared FixedAtBuild Pcds
1282 def CollectFixedAtBuildPcds(self
):
1283 for LibAuto
in self
.LibraryAutoGenList
:
1284 FixedAtBuildPcds
= {}
1285 ShareFixedAtBuildPcdsSameValue
= {}
1286 for Module
in LibAuto
._ReferenceModules
:
1287 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
1288 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1289 if key
not in FixedAtBuildPcds
:
1290 ShareFixedAtBuildPcdsSameValue
[key
] = True
1291 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
1293 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
1294 ShareFixedAtBuildPcdsSameValue
[key
] = False
1295 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1296 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1297 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1300 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
1301 if DscPcd
.Type
!= "FixedAtBuild":
1303 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1304 LibAuto
.ConstPcd
[key
] = Pcd
.DefaultValue
1306 ## Collect dynamic PCDs
1308 # Gather dynamic PCDs list from each module and their settings from platform
1309 # This interface should be invoked explicitly when platform action is created.
1311 def CollectPlatformDynamicPcds(self
):
1312 # Override the platform Pcd's value by build option
1313 if GlobalData
.BuildOptionPcd
:
1314 for key
in self
.Platform
.Pcds
:
1315 PlatformPcd
= self
.Platform
.Pcds
[key
]
1316 for PcdItem
in GlobalData
.BuildOptionPcd
:
1317 if (PlatformPcd
.TokenSpaceGuidCName
, PlatformPcd
.TokenCName
) == (PcdItem
[0], PcdItem
[1]):
1318 PlatformPcd
.DefaultValue
= PcdItem
[2]
1319 if PlatformPcd
.SkuInfoList
:
1320 Sku
= PlatformPcd
.SkuInfoList
[PlatformPcd
.SkuInfoList
.keys()[0]]
1321 Sku
.DefaultValue
= PcdItem
[2]
1324 for key
in self
.Platform
.Pcds
:
1325 for SinglePcd
in GlobalData
.MixedPcd
:
1326 if (self
.Platform
.Pcds
[key
].TokenCName
, self
.Platform
.Pcds
[key
].TokenSpaceGuidCName
) == SinglePcd
:
1327 for item
in GlobalData
.MixedPcd
[SinglePcd
]:
1328 Pcd_Type
= item
[0].split('_')[-1]
1329 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 \
1330 (Pcd_Type
== TAB_PCDS_DYNAMIC
and self
.Platform
.Pcds
[key
].Type
in GenC
.gDynamicPcd
):
1331 Value
= self
.Platform
.Pcds
[key
]
1332 Value
.TokenCName
= self
.Platform
.Pcds
[key
].TokenCName
+ '_' + Pcd_Type
1334 newkey
= (Value
.TokenCName
, key
[1])
1336 newkey
= (Value
.TokenCName
, key
[1], key
[2])
1337 del self
.Platform
.Pcds
[key
]
1338 self
.Platform
.Pcds
[newkey
] = Value
1346 # for gathering error information
1347 NoDatumTypePcdList
= set()
1349 self
._GuidValue
= {}
1351 for InfName
in self
._AsBuildInfList
:
1352 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1353 FdfModuleList
.append(os
.path
.normpath(InfName
))
1354 for F
in self
.Platform
.Modules
.keys():
1355 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1356 #GuidValue.update(M.Guids)
1358 self
.Platform
.Modules
[F
].M
= M
1360 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1361 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1362 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1363 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1365 # Check the PCD from Binary INF or Source INF
1366 if M
.IsBinaryModule
== True:
1367 PcdFromModule
.IsFromBinaryInf
= True
1369 # Check the PCD from DSC or not
1370 if (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
.keys():
1371 PcdFromModule
.IsFromDsc
= True
1373 PcdFromModule
.IsFromDsc
= False
1374 if PcdFromModule
.Type
in GenC
.gDynamicPcd
or PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1375 if F
.Path
not in FdfModuleList
:
1376 # If one of the Source built modules listed in the DSC is not listed
1377 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1378 # access method (it is only listed in the DEC file that declares the
1379 # PCD as PcdsDynamic), then build tool will report warning message
1380 # notify the PI that they are attempting to build a module that must
1381 # be included in a flash image in order to be functional. These Dynamic
1382 # PCD will not be added into the Database unless it is used by other
1383 # modules that are included in the FDF file.
1384 if PcdFromModule
.Type
in GenC
.gDynamicPcd
and \
1385 PcdFromModule
.IsFromBinaryInf
== False:
1386 # Print warning message to let the developer make a determine.
1387 if PcdFromModule
not in PcdNotInDb
:
1388 PcdNotInDb
.append(PcdFromModule
)
1390 # If one of the Source built modules listed in the DSC is not listed in
1391 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1392 # access method (it is only listed in the DEC file that declares the
1393 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1394 # PCD to the Platform's PCD Database.
1395 if PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1396 if PcdFromModule
not in PcdNotInDb
:
1397 PcdNotInDb
.append(PcdFromModule
)
1400 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1401 # it should be stored in Pcd PEI database, If a dynamic only
1402 # used by DXE module, it should be stored in DXE PCD database.
1403 # The default Phase is DXE
1405 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1406 PcdFromModule
.Phase
= "PEI"
1407 if PcdFromModule
not in self
._DynaPcdList
_:
1408 self
._DynaPcdList
_.append(PcdFromModule
)
1409 elif PcdFromModule
.Phase
== 'PEI':
1410 # overwrite any the same PCD existing, if Phase is PEI
1411 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1412 self
._DynaPcdList
_[Index
] = PcdFromModule
1413 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1414 self
._NonDynaPcdList
_.append(PcdFromModule
)
1415 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1416 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1417 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1418 #The PCD from Binary INF will override the same one from source INF
1419 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1420 PcdFromModule
.Pending
= False
1421 self
._NonDynaPcdList
_.append (PcdFromModule
)
1422 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1424 for ModuleInf
in self
.Platform
.Modules
.keys():
1425 DscModuleList
.append (os
.path
.normpath(ModuleInf
.Path
))
1426 # add the PCD from modules that listed in FDF but not in DSC to Database
1427 for InfName
in FdfModuleList
:
1428 if InfName
not in DscModuleList
:
1429 InfClass
= PathClass(InfName
)
1430 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1431 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1432 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1433 # For binary module, if in current arch, we need to list the PCDs into database.
1434 if not M
.IsSupportedArch
:
1436 # Override the module PCD setting by platform setting
1437 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1438 for PcdFromModule
in ModulePcdList
:
1439 PcdFromModule
.IsFromBinaryInf
= True
1440 PcdFromModule
.IsFromDsc
= False
1441 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1442 if PcdFromModule
.Type
not in GenC
.gDynamicExPcd
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1443 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1445 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1446 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1447 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1448 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1449 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1450 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1451 PcdFromModule
.Phase
= "PEI"
1452 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1453 self
._DynaPcdList
_.append(PcdFromModule
)
1454 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1455 self
._NonDynaPcdList
_.append(PcdFromModule
)
1456 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1457 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1458 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1459 # module & DXE module at a same time.
1460 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1461 # INF file as DynamicEx.
1462 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1463 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1464 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1465 for PcdFromModule
in self
._NonDynaPcdList
_:
1466 # If a PCD is not listed in the DSC file, but binary INF files used by
1467 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1468 # section, AND all source INF files used by this platform the build
1469 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1470 # section, then the tools must NOT add the PCD to the Platform's PCD
1471 # Database; the build must assign the access method for this PCD as
1472 # PcdsPatchableInModule.
1473 if PcdFromModule
not in self
._DynaPcdList
_:
1475 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1476 if PcdFromModule
.IsFromDsc
== False and \
1477 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1478 PcdFromModule
.IsFromBinaryInf
== True and \
1479 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1480 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1481 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1483 # print out error information and break the build, if error found
1484 if len(NoDatumTypePcdList
) > 0:
1485 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1486 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1488 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1489 % NoDatumTypePcdListString
)
1490 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1491 self
._DynamicPcdList
= self
._DynaPcdList
_
1493 # Sort dynamic PCD list to:
1494 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1495 # try to be put header of dynamicd List
1496 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1498 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1500 UnicodePcdArray
= []
1504 VpdFile
= VpdInfoFile
.VpdInfoFile()
1505 NeedProcessVpdMapFile
= False
1507 for pcd
in self
.Platform
.Pcds
.keys():
1508 if pcd
not in self
._PlatformPcds
.keys():
1509 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1511 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1512 for Pcd
in self
._DynamicPcdList
:
1513 # just pick the a value to determine whether is unicode string type
1514 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1515 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1517 PcdValue
= Sku
.DefaultValue
1518 if Pcd
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1519 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1520 UnicodePcdArray
.append(Pcd
)
1521 elif len(Sku
.VariableName
) > 0:
1522 # if found HII type PCD then insert to right of UnicodeIndex
1523 HiiPcdArray
.append(Pcd
)
1525 OtherPcdArray
.append(Pcd
)
1526 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1527 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1529 PlatformPcds
= self
._PlatformPcds
.keys()
1532 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1534 for PcdKey
in PlatformPcds
:
1535 Pcd
= self
._PlatformPcds
[PcdKey
]
1536 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1537 PcdKey
in VpdPcdDict
:
1538 Pcd
= VpdPcdDict
[PcdKey
]
1539 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1540 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1541 PcdValue
= Sku
.DefaultValue
1543 PcdValue
= Pcd
.DefaultValue
1544 if Sku
.VpdOffset
!= '*':
1545 if PcdValue
.startswith("{"):
1547 elif PcdValue
.startswith("L"):
1552 VpdOffset
= int(Sku
.VpdOffset
)
1555 VpdOffset
= int(Sku
.VpdOffset
, 16)
1557 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1558 if VpdOffset
% Alignment
!= 0:
1559 if PcdValue
.startswith("{"):
1560 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1562 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1563 VpdFile
.Add(Pcd
, Sku
.VpdOffset
)
1564 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1565 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1566 NeedProcessVpdMapFile
= True
1567 if self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== '':
1568 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1569 "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.")
1573 # Fix the PCDs define in VPD PCD section that never referenced by module.
1574 # An example is PCD for signature usage.
1576 for DscPcd
in PlatformPcds
:
1577 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1578 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1579 if not (self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== ''):
1581 for VpdPcd
in VpdFile
._VpdArray
.keys():
1582 # This PCD has been referenced by module
1583 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1584 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1587 # Not found, it should be signature
1589 # just pick the a value to determine whether is unicode string type
1590 for (SkuName
,Sku
) in DscPcdEntry
.SkuInfoList
.items():
1591 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1593 # Need to iterate DEC pcd information to get the value & datumtype
1594 for eachDec
in self
.PackageList
:
1595 for DecPcd
in eachDec
.Pcds
:
1596 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1597 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1598 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1599 # Print warning message to let the developer make a determine.
1600 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1601 File
=self
.MetaFile
, \
1602 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1603 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1605 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1606 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1607 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1608 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1609 # Only fix the value while no value provided in DSC file.
1610 if (Sku
.DefaultValue
== "" or Sku
.DefaultValue
==None):
1611 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1613 if DscPcdEntry
not in self
._DynamicPcdList
:
1614 self
._DynamicPcdList
.append(DscPcdEntry
)
1615 # Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]
1616 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1617 PcdValue
= Sku
.DefaultValue
1619 PcdValue
= DscPcdEntry
.DefaultValue
1620 if Sku
.VpdOffset
!= '*':
1621 if PcdValue
.startswith("{"):
1623 elif PcdValue
.startswith("L"):
1628 VpdOffset
= int(Sku
.VpdOffset
)
1631 VpdOffset
= int(Sku
.VpdOffset
, 16)
1633 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1634 if VpdOffset
% Alignment
!= 0:
1635 if PcdValue
.startswith("{"):
1636 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1638 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1639 VpdFile
.Add(DscPcdEntry
, Sku
.VpdOffset
)
1640 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1641 NeedProcessVpdMapFile
= True
1642 if DscPcdEntry
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1643 UnicodePcdArray
.append(DscPcdEntry
)
1644 elif len(Sku
.VariableName
) > 0:
1645 HiiPcdArray
.append(DscPcdEntry
)
1647 OtherPcdArray
.append(DscPcdEntry
)
1649 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1653 if (self
.Platform
.FlashDefinition
== None or self
.Platform
.FlashDefinition
== '') and \
1654 VpdFile
.GetCount() != 0:
1655 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1656 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1658 if VpdFile
.GetCount() != 0:
1659 FvPath
= os
.path
.join(self
.BuildDir
, "FV")
1660 if not os
.path
.exists(FvPath
):
1664 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1666 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1668 if VpdFile
.Write(VpdFilePath
):
1669 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1671 for ToolDef
in self
.ToolDefinition
.values():
1672 if ToolDef
.has_key("GUID") and ToolDef
["GUID"] == self
.Platform
.VpdToolGuid
:
1673 if not ToolDef
.has_key("PATH"):
1674 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1675 BPDGToolName
= ToolDef
["PATH"]
1677 # Call third party GUID BPDG tool.
1678 if BPDGToolName
!= None:
1679 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1681 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.")
1683 # Process VPD map file generated by third party BPDG tool
1684 if NeedProcessVpdMapFile
:
1685 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1686 if os
.path
.exists(VpdMapFilePath
):
1687 VpdFile
.Read(VpdMapFilePath
)
1690 for Pcd
in self
._DynamicPcdList
:
1691 # just pick the a value to determine whether is unicode string type
1693 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1694 if Sku
.VpdOffset
== "*":
1695 Sku
.VpdOffset
= VpdFile
.GetOffset(Pcd
)[i
].strip()
1698 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1700 # Delete the DynamicPcdList At the last time enter into this function
1701 del self
._DynamicPcdList
[:]
1702 self
._DynamicPcdList
.extend(UnicodePcdArray
)
1703 self
._DynamicPcdList
.extend(HiiPcdArray
)
1704 self
._DynamicPcdList
.extend(OtherPcdArray
)
1705 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1707 ## Return the platform build data object
1708 def _GetPlatform(self
):
1709 if self
._Platform
== None:
1710 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1711 return self
._Platform
1713 ## Return platform name
1715 return self
.Platform
.PlatformName
1717 ## Return the meta file GUID
1719 return self
.Platform
.Guid
1721 ## Return the platform version
1722 def _GetVersion(self
):
1723 return self
.Platform
.Version
1725 ## Return the FDF file name
1726 def _GetFdfFile(self
):
1727 if self
._FdfFile
== None:
1728 if self
.Workspace
.FdfFile
!= "":
1729 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1732 return self
._FdfFile
1734 ## Return the build output directory platform specifies
1735 def _GetOutputDir(self
):
1736 return self
.Platform
.OutputDirectory
1738 ## Return the directory to store all intermediate and final files built
1739 def _GetBuildDir(self
):
1740 if self
._BuildDir
== None:
1741 if os
.path
.isabs(self
.OutputDir
):
1742 self
._BuildDir
= path
.join(
1743 path
.abspath(self
.OutputDir
),
1744 self
.BuildTarget
+ "_" + self
.ToolChain
,
1747 self
._BuildDir
= path
.join(
1750 self
.BuildTarget
+ "_" + self
.ToolChain
,
1752 return self
._BuildDir
1754 ## Return directory of platform makefile
1756 # @retval string Makefile directory
1758 def _GetMakeFileDir(self
):
1759 if self
._MakeFileDir
== None:
1760 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1761 return self
._MakeFileDir
1763 ## Return build command string
1765 # @retval string Build command string
1767 def _GetBuildCommand(self
):
1768 if self
._BuildCommand
== None:
1769 self
._BuildCommand
= []
1770 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1771 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1772 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1773 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1775 self
._BuildCommand
+= SplitOption(NewOption
)
1776 return self
._BuildCommand
1778 ## Get tool chain definition
1780 # Get each tool defition for given tool chain from tools_def.txt and platform
1782 def _GetToolDefinition(self
):
1783 if self
._ToolDefinitions
== None:
1784 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1785 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1786 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1787 ExtraData
="[%s]" % self
.MetaFile
)
1788 self
._ToolDefinitions
= {}
1790 for Def
in ToolDefinition
:
1791 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1792 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1795 Value
= ToolDefinition
[Def
]
1796 # don't record the DLL
1798 DllPathList
.add(Value
)
1801 if Tool
not in self
._ToolDefinitions
:
1802 self
._ToolDefinitions
[Tool
] = {}
1803 self
._ToolDefinitions
[Tool
][Attr
] = Value
1807 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1808 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1809 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1810 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1812 for Tool
in self
._ToolDefinitions
:
1813 for Attr
in self
._ToolDefinitions
[Tool
]:
1814 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1815 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1816 # check if override is indicated
1817 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1818 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1821 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1823 Value
= self
.BuildOption
[Tool
][Attr
]
1826 # Don't put MAKE definition in the file
1830 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1832 # Don't put MAKE definition in the file
1837 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1840 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1841 for DllPath
in DllPathList
:
1842 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1843 os
.environ
["MAKE_FLAGS"] = MakeFlags
1845 return self
._ToolDefinitions
1847 ## Return the paths of tools
1848 def _GetToolDefFile(self
):
1849 if self
._ToolDefFile
== None:
1850 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1851 return self
._ToolDefFile
1853 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1854 def _GetToolChainFamily(self
):
1855 if self
._ToolChainFamily
== None:
1856 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1857 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1858 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1859 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1860 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1862 self
._ToolChainFamily
= "MSFT"
1864 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1865 return self
._ToolChainFamily
1867 def _GetBuildRuleFamily(self
):
1868 if self
._BuildRuleFamily
== None:
1869 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1870 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1871 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1872 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1873 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1875 self
._BuildRuleFamily
= "MSFT"
1877 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1878 return self
._BuildRuleFamily
1880 ## Return the build options specific for all modules in this platform
1881 def _GetBuildOptions(self
):
1882 if self
._BuildOption
== None:
1883 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1884 return self
._BuildOption
1886 ## Return the build options specific for EDK modules in this platform
1887 def _GetEdkBuildOptions(self
):
1888 if self
._EdkBuildOption
== None:
1889 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1890 return self
._EdkBuildOption
1892 ## Return the build options specific for EDKII modules in this platform
1893 def _GetEdkIIBuildOptions(self
):
1894 if self
._EdkIIBuildOption
== None:
1895 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1896 return self
._EdkIIBuildOption
1898 ## Parse build_rule.txt in Conf Directory.
1900 # @retval BuildRule object
1902 def _GetBuildRule(self
):
1903 if self
._BuildRule
== None:
1904 BuildRuleFile
= None
1905 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1906 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1907 if BuildRuleFile
in [None, '']:
1908 BuildRuleFile
= gDefaultBuildRuleFile
1909 self
._BuildRule
= BuildRule(BuildRuleFile
)
1910 if self
._BuildRule
._FileVersion
== "":
1911 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
1913 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1914 # If Build Rule's version is less than the version number required by the tools, halting the build.
1915 EdkLogger
.error("build", AUTOGEN_ERROR
,
1916 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])"\
1917 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1919 return self
._BuildRule
1921 ## Summarize the packages used by modules in this platform
1922 def _GetPackageList(self
):
1923 if self
._PackageList
== None:
1924 self
._PackageList
= set()
1925 for La
in self
.LibraryAutoGenList
:
1926 self
._PackageList
.update(La
.DependentPackageList
)
1927 for Ma
in self
.ModuleAutoGenList
:
1928 self
._PackageList
.update(Ma
.DependentPackageList
)
1929 #Collect package set information from INF of FDF
1931 for ModuleFile
in self
._AsBuildModuleList
:
1932 if ModuleFile
in self
.Platform
.Modules
:
1934 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1935 PkgSet
.update(ModuleData
.Packages
)
1936 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
1937 return self
._PackageList
1939 def _GetNonDynamicPcdDict(self
):
1940 if self
._NonDynamicPcdDict
:
1941 return self
._NonDynamicPcdDict
1942 for Pcd
in self
.NonDynamicPcdList
:
1943 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
1944 return self
._NonDynamicPcdDict
1946 ## Get list of non-dynamic PCDs
1947 def _GetNonDynamicPcdList(self
):
1948 if self
._NonDynamicPcdList
== None:
1949 self
.CollectPlatformDynamicPcds()
1950 return self
._NonDynamicPcdList
1952 ## Get list of dynamic PCDs
1953 def _GetDynamicPcdList(self
):
1954 if self
._DynamicPcdList
== None:
1955 self
.CollectPlatformDynamicPcds()
1956 return self
._DynamicPcdList
1958 ## Generate Token Number for all PCD
1959 def _GetPcdTokenNumbers(self
):
1960 if self
._PcdTokenNumber
== None:
1961 self
._PcdTokenNumber
= sdict()
1964 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1968 # TokenNumber 0 ~ 10
1970 # TokeNumber 11 ~ 20
1972 for Pcd
in self
.DynamicPcdList
:
1973 if Pcd
.Phase
== "PEI":
1974 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1975 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1976 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1979 for Pcd
in self
.DynamicPcdList
:
1980 if Pcd
.Phase
== "PEI":
1981 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1982 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1983 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1986 for Pcd
in self
.DynamicPcdList
:
1987 if Pcd
.Phase
== "DXE":
1988 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1989 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1990 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1993 for Pcd
in self
.DynamicPcdList
:
1994 if Pcd
.Phase
== "DXE":
1995 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1996 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1997 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2000 for Pcd
in self
.NonDynamicPcdList
:
2001 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
2003 return self
._PcdTokenNumber
2005 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
2006 def _GetAutoGenObjectList(self
):
2007 self
._ModuleAutoGenList
= []
2008 self
._LibraryAutoGenList
= []
2009 for ModuleFile
in self
.Platform
.Modules
:
2018 if Ma
not in self
._ModuleAutoGenList
:
2019 self
._ModuleAutoGenList
.append(Ma
)
2020 for La
in Ma
.LibraryAutoGenList
:
2021 if La
not in self
._LibraryAutoGenList
:
2022 self
._LibraryAutoGenList
.append(La
)
2023 if Ma
not in La
._ReferenceModules
:
2024 La
._ReferenceModules
.append(Ma
)
2026 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
2027 def _GetModuleAutoGenList(self
):
2028 if self
._ModuleAutoGenList
== None:
2029 self
._GetAutoGenObjectList
()
2030 return self
._ModuleAutoGenList
2032 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
2033 def _GetLibraryAutoGenList(self
):
2034 if self
._LibraryAutoGenList
== None:
2035 self
._GetAutoGenObjectList
()
2036 return self
._LibraryAutoGenList
2038 ## Test if a module is supported by the platform
2040 # An error will be raised directly if the module or its arch is not supported
2041 # by the platform or current configuration
2043 def ValidModule(self
, Module
):
2044 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
2045 or Module
in self
._AsBuildModuleList
2047 ## Resolve the library classes in a module to library instances
2049 # This method will not only resolve library classes but also sort the library
2050 # instances according to the dependency-ship.
2052 # @param Module The module from which the library classes will be resolved
2054 # @retval library_list List of library instances sorted
2056 def ApplyLibraryInstance(self
, Module
):
2057 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
2058 if str(Module
) not in self
.Platform
.Modules
:
2061 ModuleType
= Module
.ModuleType
2063 # for overridding library instances with module specific setting
2064 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2066 # add forced library instances (specified under LibraryClasses sections)
2068 # If a module has a MODULE_TYPE of USER_DEFINED,
2069 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
2071 if Module
.ModuleType
!= SUP_MODULE_USER_DEFINED
:
2072 for LibraryClass
in self
.Platform
.LibraryClasses
.GetKeys():
2073 if LibraryClass
.startswith("NULL") and self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]:
2074 Module
.LibraryClasses
[LibraryClass
] = self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]
2076 # add forced library instances (specified in module overrides)
2077 for LibraryClass
in PlatformModule
.LibraryClasses
:
2078 if LibraryClass
.startswith("NULL"):
2079 Module
.LibraryClasses
[LibraryClass
] = PlatformModule
.LibraryClasses
[LibraryClass
]
2082 LibraryConsumerList
= [Module
]
2084 ConsumedByList
= sdict()
2085 LibraryInstance
= sdict()
2087 EdkLogger
.verbose("")
2088 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2089 while len(LibraryConsumerList
) > 0:
2090 M
= LibraryConsumerList
.pop()
2091 for LibraryClassName
in M
.LibraryClasses
:
2092 if LibraryClassName
not in LibraryInstance
:
2093 # override library instance for this module
2094 if LibraryClassName
in PlatformModule
.LibraryClasses
:
2095 LibraryPath
= PlatformModule
.LibraryClasses
[LibraryClassName
]
2097 LibraryPath
= self
.Platform
.LibraryClasses
[LibraryClassName
, ModuleType
]
2098 if LibraryPath
== None or LibraryPath
== "":
2099 LibraryPath
= M
.LibraryClasses
[LibraryClassName
]
2100 if LibraryPath
== None or LibraryPath
== "":
2101 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
2102 "Instance of library class [%s] is not found" % LibraryClassName
,
2104 ExtraData
="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M
), self
.Arch
, str(Module
)))
2106 LibraryModule
= self
.BuildDatabase
[LibraryPath
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2107 # for those forced library instance (NULL library), add a fake library class
2108 if LibraryClassName
.startswith("NULL"):
2109 LibraryModule
.LibraryClass
.append(LibraryClassObject(LibraryClassName
, [ModuleType
]))
2110 elif LibraryModule
.LibraryClass
== None \
2111 or len(LibraryModule
.LibraryClass
) == 0 \
2112 or (ModuleType
!= 'USER_DEFINED'
2113 and ModuleType
not in LibraryModule
.LibraryClass
[0].SupModList
):
2114 # only USER_DEFINED can link against any library instance despite of its SupModList
2115 EdkLogger
.error("build", OPTION_MISSING
,
2116 "Module type [%s] is not supported by library instance [%s]" \
2117 % (ModuleType
, LibraryPath
), File
=self
.MetaFile
,
2118 ExtraData
="consumed by [%s]" % str(Module
))
2120 LibraryInstance
[LibraryClassName
] = LibraryModule
2121 LibraryConsumerList
.append(LibraryModule
)
2122 EdkLogger
.verbose("\t" + str(LibraryClassName
) + " : " + str(LibraryModule
))
2124 LibraryModule
= LibraryInstance
[LibraryClassName
]
2126 if LibraryModule
== None:
2129 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
2130 Constructor
.append(LibraryModule
)
2132 if LibraryModule
not in ConsumedByList
:
2133 ConsumedByList
[LibraryModule
] = []
2134 # don't add current module itself to consumer list
2136 if M
in ConsumedByList
[LibraryModule
]:
2138 ConsumedByList
[LibraryModule
].append(M
)
2140 # Initialize the sorted output list to the empty set
2142 SortedLibraryList
= []
2144 # Q <- Set of all nodes with no incoming edges
2146 LibraryList
= [] #LibraryInstance.values()
2148 for LibraryClassName
in LibraryInstance
:
2149 M
= LibraryInstance
[LibraryClassName
]
2150 LibraryList
.append(M
)
2151 if ConsumedByList
[M
] == []:
2155 # start the DAG algorithm
2159 while Q
== [] and EdgeRemoved
:
2161 # for each node Item with a Constructor
2162 for Item
in LibraryList
:
2163 if Item
not in Constructor
:
2165 # for each Node without a constructor with an edge e from Item to Node
2166 for Node
in ConsumedByList
[Item
]:
2167 if Node
in Constructor
:
2169 # remove edge e from the graph if Node has no constructor
2170 ConsumedByList
[Item
].remove(Node
)
2172 if ConsumedByList
[Item
] == []:
2173 # insert Item into Q
2178 # DAG is done if there's no more incoming edge for all nodes
2182 # remove node from Q
2185 SortedLibraryList
.append(Node
)
2187 # for each node Item with an edge e from Node to Item do
2188 for Item
in LibraryList
:
2189 if Node
not in ConsumedByList
[Item
]:
2191 # remove edge e from the graph
2192 ConsumedByList
[Item
].remove(Node
)
2194 if ConsumedByList
[Item
] != []:
2196 # insert Item into Q, if Item has no other incoming edges
2200 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
2202 for Item
in LibraryList
:
2203 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
2204 ErrorMessage
= "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]])
2205 EdkLogger
.error("build", BUILD_ERROR
, 'Library [%s] with constructors has a cycle' % str(Item
),
2206 ExtraData
=ErrorMessage
, File
=self
.MetaFile
)
2207 if Item
not in SortedLibraryList
:
2208 SortedLibraryList
.append(Item
)
2211 # Build the list of constructor and destructir names
2212 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
2214 SortedLibraryList
.reverse()
2215 return SortedLibraryList
2218 ## Override PCD setting (type, value, ...)
2220 # @param ToPcd The PCD to be overrided
2221 # @param FromPcd The PCD overrideing from
2223 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
=""):
2225 # in case there's PCDs coming from FDF file, which have no type given.
2226 # at this point, ToPcd.Type has the type found from dependent
2229 TokenCName
= ToPcd
.TokenCName
2230 for PcdItem
in GlobalData
.MixedPcd
:
2231 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2232 TokenCName
= PcdItem
[0]
2235 if GlobalData
.BuildOptionPcd
:
2236 for pcd
in GlobalData
.BuildOptionPcd
:
2237 if (FromPcd
.TokenSpaceGuidCName
, FromPcd
.TokenCName
) == (pcd
[0], pcd
[1]):
2238 FromPcd
.DefaultValue
= pcd
[2]
2240 if ToPcd
.Pending
and FromPcd
.Type
not in [None, '']:
2241 ToPcd
.Type
= FromPcd
.Type
2242 elif (ToPcd
.Type
not in [None, '']) and (FromPcd
.Type
not in [None, ''])\
2243 and (ToPcd
.Type
!= FromPcd
.Type
) and (ToPcd
.Type
in FromPcd
.Type
):
2244 if ToPcd
.Type
.strip() == "DynamicEx":
2245 ToPcd
.Type
= FromPcd
.Type
2246 elif ToPcd
.Type
not in [None, ''] and FromPcd
.Type
not in [None, ''] \
2247 and ToPcd
.Type
!= FromPcd
.Type
:
2248 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
2249 ExtraData
="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
2250 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
2251 ToPcd
.Type
, Module
, FromPcd
.Type
),
2254 if FromPcd
.MaxDatumSize
not in [None, '']:
2255 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2256 if FromPcd
.DefaultValue
not in [None, '']:
2257 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
2258 if FromPcd
.TokenValue
not in [None, '']:
2259 ToPcd
.TokenValue
= FromPcd
.TokenValue
2260 if FromPcd
.MaxDatumSize
not in [None, '']:
2261 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
2262 if FromPcd
.DatumType
not in [None, '']:
2263 ToPcd
.DatumType
= FromPcd
.DatumType
2264 if FromPcd
.SkuInfoList
not in [None, '', []]:
2265 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
2267 # check the validation of datum
2268 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
2270 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
2271 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2272 ToPcd
.validateranges
= FromPcd
.validateranges
2273 ToPcd
.validlists
= FromPcd
.validlists
2274 ToPcd
.expressions
= FromPcd
.expressions
2276 if ToPcd
.DatumType
== "VOID*" and ToPcd
.MaxDatumSize
in ['', None]:
2277 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
2278 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
2279 Value
= ToPcd
.DefaultValue
2280 if Value
in [None, '']:
2281 ToPcd
.MaxDatumSize
= '1'
2282 elif Value
[0] == 'L':
2283 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
2284 elif Value
[0] == '{':
2285 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
2287 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
2289 # apply default SKU for dynamic PCDS if specified one is not available
2290 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_LIST
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_LIST
) \
2291 and ToPcd
.SkuInfoList
in [None, {}, '']:
2292 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
2293 SkuName
= self
.Platform
.SkuName
2296 ToPcd
.SkuInfoList
= {
2297 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
], '', '', '', '', '', ToPcd
.DefaultValue
)
2300 ## Apply PCD setting defined platform to a module
2302 # @param Module The module from which the PCD setting will be overrided
2304 # @retval PCD_list The list PCDs with settings from platform
2306 def ApplyPcdSetting(self
, Module
, Pcds
):
2307 # for each PCD in module
2308 for Name
, Guid
in Pcds
:
2309 PcdInModule
= Pcds
[Name
, Guid
]
2310 # find out the PCD setting in platform
2311 if (Name
, Guid
) in self
.Platform
.Pcds
:
2312 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2314 PcdInPlatform
= None
2315 # then override the settings if any
2316 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
)
2317 # resolve the VariableGuid value
2318 for SkuId
in PcdInModule
.SkuInfoList
:
2319 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2320 if Sku
.VariableGuid
== '': continue
2321 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
2322 if Sku
.VariableGuidValue
== None:
2323 PackageList
= "\n\t".join([str(P
) for P
in self
.PackageList
])
2326 RESOURCE_NOT_AVAILABLE
,
2327 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2328 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2329 % (Guid
, Name
, str(Module
)),
2333 # override PCD settings with module specific setting
2334 if Module
in self
.Platform
.Modules
:
2335 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2336 for Key
in PlatformModule
.Pcds
:
2338 self
._OverridePcd
(Pcds
[Key
], PlatformModule
.Pcds
[Key
], Module
)
2339 return Pcds
.values()
2341 ## Resolve library names to library modules
2343 # (for Edk.x modules)
2345 # @param Module The module from which the library names will be resolved
2347 # @retval library_list The list of library modules
2349 def ResolveLibraryReference(self
, Module
):
2350 EdkLogger
.verbose("")
2351 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2352 LibraryConsumerList
= [Module
]
2354 # "CompilerStub" is a must for Edk modules
2355 if Module
.Libraries
:
2356 Module
.Libraries
.append("CompilerStub")
2358 while len(LibraryConsumerList
) > 0:
2359 M
= LibraryConsumerList
.pop()
2360 for LibraryName
in M
.Libraries
:
2361 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2363 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
2364 if LibraryName
.upper() == Key
.upper():
2365 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2368 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2369 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2372 if Library
not in LibraryList
:
2373 LibraryList
.append(Library
)
2374 LibraryConsumerList
.append(Library
)
2375 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2378 ## Calculate the priority value of the build option
2380 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2382 # @retval Value Priority value based on the priority list.
2384 def CalculatePriorityValue(self
, Key
):
2385 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2386 PriorityValue
= 0x11111
2388 PriorityValue
&= 0x01111
2389 if ToolChain
== "*":
2390 PriorityValue
&= 0x10111
2392 PriorityValue
&= 0x11011
2393 if CommandType
== "*":
2394 PriorityValue
&= 0x11101
2396 PriorityValue
&= 0x11110
2398 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2401 ## Expand * in build option key
2403 # @param Options Options to be expanded
2405 # @retval options Options expanded
2407 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2414 # Construct a list contain the build options which need override.
2418 # Key[0] -- tool family
2419 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2421 if (Key
[0] == self
.BuildRuleFamily
and
2422 (ModuleStyle
== None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2423 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2424 if Target
== self
.BuildTarget
or Target
== "*":
2425 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
2426 if Arch
== self
.Arch
or Arch
== "*":
2427 if Options
[Key
].startswith("="):
2428 if OverrideList
.get(Key
[1]) != None:
2429 OverrideList
.pop(Key
[1])
2430 OverrideList
[Key
[1]] = Options
[Key
]
2433 # Use the highest priority value.
2435 if (len(OverrideList
) >= 2):
2436 KeyList
= OverrideList
.keys()
2437 for Index
in range(len(KeyList
)):
2438 NowKey
= KeyList
[Index
]
2439 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2440 for Index1
in range(len(KeyList
) - Index
- 1):
2441 NextKey
= KeyList
[Index1
+ Index
+ 1]
2443 # Compare two Key, if one is included by another, choose the higher priority one
2445 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2446 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2447 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2448 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2449 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2450 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2451 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2452 if Options
.get((self
.BuildRuleFamily
, NextKey
)) != None:
2453 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2455 if Options
.get((self
.BuildRuleFamily
, NowKey
)) != None:
2456 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2459 if ModuleStyle
!= None and len (Key
) > 2:
2460 # Check Module style is EDK or EDKII.
2461 # Only append build option for the matched style module.
2462 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2464 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2467 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2468 # if tool chain family doesn't match, skip it
2469 if Tool
in self
.ToolDefinition
and Family
!= "":
2470 FamilyIsNull
= False
2471 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2472 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2474 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2477 # expand any wildcard
2478 if Target
== "*" or Target
== self
.BuildTarget
:
2479 if Tag
== "*" or Tag
== self
.ToolChain
:
2480 if Arch
== "*" or Arch
== self
.Arch
:
2481 if Tool
not in BuildOptions
:
2482 BuildOptions
[Tool
] = {}
2483 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2484 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2486 # append options for the same tool except PATH
2488 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2490 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2491 # Build Option Family has been checked, which need't to be checked again for family.
2492 if FamilyMatch
or FamilyIsNull
:
2496 if ModuleStyle
!= None and len (Key
) > 2:
2497 # Check Module style is EDK or EDKII.
2498 # Only append build option for the matched style module.
2499 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2501 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2504 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2505 # if tool chain family doesn't match, skip it
2506 if Tool
not in self
.ToolDefinition
or Family
== "":
2508 # option has been added before
2509 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2512 # expand any wildcard
2513 if Target
== "*" or Target
== self
.BuildTarget
:
2514 if Tag
== "*" or Tag
== self
.ToolChain
:
2515 if Arch
== "*" or Arch
== self
.Arch
:
2516 if Tool
not in BuildOptions
:
2517 BuildOptions
[Tool
] = {}
2518 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2519 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2521 # append options for the same tool except PATH
2523 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2525 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2528 ## Append build options in platform to a module
2530 # @param Module The module to which the build options will be appened
2532 # @retval options The options appended with build options in platform
2534 def ApplyBuildOption(self
, Module
):
2535 # Get the different options for the different style module
2536 if Module
.AutoGenVersion
< 0x00010005:
2537 PlatformOptions
= self
.EdkBuildOption
2538 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2540 PlatformOptions
= self
.EdkIIBuildOption
2541 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2542 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2543 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2544 if Module
in self
.Platform
.Modules
:
2545 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2546 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2548 PlatformModuleOptions
= {}
2550 BuildRuleOrder
= None
2551 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2552 for Tool
in Options
:
2553 for Attr
in Options
[Tool
]:
2554 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2555 BuildRuleOrder
= Options
[Tool
][Attr
]
2557 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2558 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2559 self
.ToolDefinition
.keys())
2561 for Tool
in AllTools
:
2562 if Tool
not in BuildOptions
:
2563 BuildOptions
[Tool
] = {}
2565 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2566 if Tool
not in Options
:
2568 for Attr
in Options
[Tool
]:
2569 Value
= Options
[Tool
][Attr
]
2571 # Do not generate it in Makefile
2573 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2575 if Attr
not in BuildOptions
[Tool
]:
2576 BuildOptions
[Tool
][Attr
] = ""
2577 # check if override is indicated
2578 if Value
.startswith('='):
2579 ToolPath
= Value
[1:]
2580 ToolPath
= mws
.handleWsMacro(ToolPath
)
2581 BuildOptions
[Tool
][Attr
] = ToolPath
2583 Value
= mws
.handleWsMacro(Value
)
2585 BuildOptions
[Tool
][Attr
] += " " + Value
2587 BuildOptions
[Tool
][Attr
] = Value
2588 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
!= None:
2590 # Override UNI flag only for EDK module.
2592 if 'BUILD' not in BuildOptions
:
2593 BuildOptions
['BUILD'] = {}
2594 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2595 return BuildOptions
, BuildRuleOrder
2597 Platform
= property(_GetPlatform
)
2598 Name
= property(_GetName
)
2599 Guid
= property(_GetGuid
)
2600 Version
= property(_GetVersion
)
2602 OutputDir
= property(_GetOutputDir
)
2603 BuildDir
= property(_GetBuildDir
)
2604 MakeFileDir
= property(_GetMakeFileDir
)
2605 FdfFile
= property(_GetFdfFile
)
2607 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2608 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2609 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2610 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2611 PackageList
= property(_GetPackageList
)
2613 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2614 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2615 ToolChainFamily
= property(_GetToolChainFamily
)
2616 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2617 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2618 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2619 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2621 BuildCommand
= property(_GetBuildCommand
)
2622 BuildRule
= property(_GetBuildRule
)
2623 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2624 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2625 GenFdsCommand
= property(_GenFdsCommand
)
2627 ## ModuleAutoGen class
2629 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2630 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2631 # to the [depex] section in module's inf file.
2633 class ModuleAutoGen(AutoGen
):
2634 ## Cache the timestamps of metafiles of every module in a class variable
2638 ## The real constructor of ModuleAutoGen
2640 # This method is not supposed to be called by users of ModuleAutoGen. It's
2641 # only used by factory method __new__() to do real initialization work for an
2642 # object of ModuleAutoGen
2644 # @param Workspace EdkIIWorkspaceBuild object
2645 # @param ModuleFile The path of module file
2646 # @param Target Build target (DEBUG, RELEASE)
2647 # @param Toolchain Name of tool chain
2648 # @param Arch The arch the module supports
2649 # @param PlatformFile Platform meta-file
2651 def _Init(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2652 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2653 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2655 self
.Workspace
= Workspace
2656 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2658 self
.MetaFile
= ModuleFile
2659 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2660 # check if this module is employed by active platform
2661 if not self
.PlatformInfo
.ValidModule(self
.MetaFile
):
2662 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2663 % (self
.MetaFile
, Arch
))
2666 self
.SourceDir
= self
.MetaFile
.SubDir
2667 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2669 self
.SourceOverrideDir
= None
2670 # use overrided path defined in DSC file
2671 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2672 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2674 self
.ToolChain
= Toolchain
2675 self
.BuildTarget
= Target
2677 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2678 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2680 self
.IsMakeFileCreated
= False
2681 self
.IsCodeFileCreated
= False
2682 self
.IsAsBuiltInfCreated
= False
2683 self
.DepexGenerated
= False
2685 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2686 self
.BuildRuleOrder
= None
2691 self
._Version
= None
2692 self
._ModuleType
= None
2693 self
._ComponentType
= None
2694 self
._PcdIsDriver
= None
2695 self
._AutoGenVersion
= None
2696 self
._LibraryFlag
= None
2697 self
._CustomMakefile
= None
2700 self
._BuildDir
= None
2701 self
._OutputDir
= None
2702 self
._DebugDir
= None
2703 self
._MakeFileDir
= None
2705 self
._IncludePathList
= None
2706 self
._IncludePathLength
= 0
2707 self
._AutoGenFileList
= None
2708 self
._UnicodeFileList
= None
2709 self
._VfrFileList
= None
2710 self
._IdfFileList
= None
2711 self
._SourceFileList
= None
2712 self
._ObjectFileList
= None
2713 self
._BinaryFileList
= None
2715 self
._DependentPackageList
= None
2716 self
._DependentLibraryList
= None
2717 self
._LibraryAutoGenList
= None
2718 self
._DerivedPackageList
= None
2719 self
._ModulePcdList
= None
2720 self
._LibraryPcdList
= None
2721 self
._PcdComments
= sdict()
2722 self
._GuidList
= None
2723 self
._GuidsUsedByPcd
= None
2724 self
._GuidComments
= sdict()
2725 self
._ProtocolList
= None
2726 self
._ProtocolComments
= sdict()
2727 self
._PpiList
= None
2728 self
._PpiComments
= sdict()
2729 self
._DepexList
= None
2730 self
._DepexExpressionList
= None
2731 self
._BuildOption
= None
2732 self
._BuildOptionIncPathList
= None
2733 self
._BuildTargets
= None
2734 self
._IntroBuildTargetList
= None
2735 self
._FinalBuildTargetList
= None
2736 self
._FileTypes
= None
2737 self
._BuildRules
= None
2739 self
._TimeStampPath
= None
2741 self
.AutoGenDepSet
= set()
2744 ## The Modules referenced to this Library
2745 # Only Library has this attribute
2746 self
._ReferenceModules
= []
2748 ## Store the FixedAtBuild Pcds
2750 self
._FixedAtBuildPcds
= []
2755 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2757 # Get FixedAtBuild Pcds of this Module
2758 def _GetFixedAtBuildPcds(self
):
2759 if self
._FixedAtBuildPcds
:
2760 return self
._FixedAtBuildPcds
2761 for Pcd
in self
.ModulePcdList
:
2762 if Pcd
.Type
!= "FixedAtBuild":
2764 if Pcd
not in self
._FixedAtBuildPcds
:
2765 self
._FixedAtBuildPcds
.append(Pcd
)
2767 return self
._FixedAtBuildPcds
2769 def _GetUniqueBaseName(self
):
2770 BaseName
= self
.Name
2771 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2772 if Module
.MetaFile
== self
.MetaFile
:
2774 if Module
.Name
== self
.Name
:
2775 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2776 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2777 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2778 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2781 # Macros could be used in build_rule.txt (also Makefile)
2782 def _GetMacros(self
):
2783 if self
._Macro
== None:
2784 self
._Macro
= sdict()
2785 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2786 self
._Macro
["MODULE_NAME" ] = self
.Name
2787 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2788 self
._Macro
["MODULE_GUID" ] = self
.Guid
2789 self
._Macro
["MODULE_VERSION" ] = self
.Version
2790 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2791 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2792 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2793 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2794 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2796 self
._Macro
["BASE_NAME" ] = self
.Name
2798 self
._Macro
["ARCH" ] = self
.Arch
2799 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2800 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2801 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2802 self
._Macro
["TARGET" ] = self
.BuildTarget
2804 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2805 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2806 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2807 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2808 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2809 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2810 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2811 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2812 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2813 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2814 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2815 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2816 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2817 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2820 ## Return the module build data object
2821 def _GetModule(self
):
2822 if self
._Module
== None:
2823 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2826 ## Return the module name
2827 def _GetBaseName(self
):
2828 return self
.Module
.BaseName
2830 ## Return the module DxsFile if exist
2831 def _GetDxsFile(self
):
2832 return self
.Module
.DxsFile
2834 ## Return the module SourceOverridePath
2835 def _GetSourceOverridePath(self
):
2836 return self
.Module
.SourceOverridePath
2838 ## Return the module meta-file GUID
2841 # To build same module more than once, the module path with FILE_GUID overridden has
2842 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2843 # in DSC. The overridden GUID can be retrieved from file name
2845 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2847 # Length of GUID is 36
2849 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2850 return self
.Module
.Guid
2852 ## Return the module version
2853 def _GetVersion(self
):
2854 return self
.Module
.Version
2856 ## Return the module type
2857 def _GetModuleType(self
):
2858 return self
.Module
.ModuleType
2860 ## Return the component type (for Edk.x style of module)
2861 def _GetComponentType(self
):
2862 return self
.Module
.ComponentType
2864 ## Return the build type
2865 def _GetBuildType(self
):
2866 return self
.Module
.BuildType
2868 ## Return the PCD_IS_DRIVER setting
2869 def _GetPcdIsDriver(self
):
2870 return self
.Module
.PcdIsDriver
2872 ## Return the autogen version, i.e. module meta-file version
2873 def _GetAutoGenVersion(self
):
2874 return self
.Module
.AutoGenVersion
2876 ## Check if the module is library or not
2877 def _IsLibrary(self
):
2878 if self
._LibraryFlag
== None:
2879 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2880 self
._LibraryFlag
= True
2882 self
._LibraryFlag
= False
2883 return self
._LibraryFlag
2885 ## Check if the module is binary module or not
2886 def _IsBinaryModule(self
):
2887 return self
.Module
.IsBinaryModule
2889 ## Return the directory to store intermediate files of the module
2890 def _GetBuildDir(self
):
2891 if self
._BuildDir
== None:
2892 self
._BuildDir
= path
.join(
2893 self
.PlatformInfo
.BuildDir
,
2896 self
.MetaFile
.BaseName
2898 CreateDirectory(self
._BuildDir
)
2899 return self
._BuildDir
2901 ## Return the directory to store the intermediate object files of the mdoule
2902 def _GetOutputDir(self
):
2903 if self
._OutputDir
== None:
2904 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2905 CreateDirectory(self
._OutputDir
)
2906 return self
._OutputDir
2908 ## Return the directory to store auto-gened source files of the mdoule
2909 def _GetDebugDir(self
):
2910 if self
._DebugDir
== None:
2911 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2912 CreateDirectory(self
._DebugDir
)
2913 return self
._DebugDir
2915 ## Return the path of custom file
2916 def _GetCustomMakefile(self
):
2917 if self
._CustomMakefile
== None:
2918 self
._CustomMakefile
= {}
2919 for Type
in self
.Module
.CustomMakefile
:
2920 if Type
in gMakeTypeMap
:
2921 MakeType
= gMakeTypeMap
[Type
]
2924 if self
.SourceOverrideDir
!= None:
2925 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2926 if not os
.path
.exists(File
):
2927 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2929 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2930 self
._CustomMakefile
[MakeType
] = File
2931 return self
._CustomMakefile
2933 ## Return the directory of the makefile
2935 # @retval string The directory string of module's makefile
2937 def _GetMakeFileDir(self
):
2938 return self
.BuildDir
2940 ## Return build command string
2942 # @retval string Build command string
2944 def _GetBuildCommand(self
):
2945 return self
.PlatformInfo
.BuildCommand
2947 ## Get object list of all packages the module and its dependent libraries belong to
2949 # @retval list The list of package object
2951 def _GetDerivedPackageList(self
):
2953 for M
in [self
.Module
] + self
.DependentLibraryList
:
2954 for Package
in M
.Packages
:
2955 if Package
in PackageList
:
2957 PackageList
.append(Package
)
2960 ## Get the depex string
2962 # @return : a string contain all depex expresion.
2963 def _GetDepexExpresionString(self
):
2966 ## DPX_SOURCE IN Define section.
2967 if self
.Module
.DxsFile
:
2969 for M
in [self
.Module
] + self
.DependentLibraryList
:
2970 Filename
= M
.MetaFile
.Path
2971 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2972 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2973 for DepexExpresion
in DepexExpresionList
:
2974 for key
in DepexExpresion
.keys():
2975 Arch
, ModuleType
= key
2976 DepexExpr
= [x
for x
in DepexExpresion
[key
] if not str(x
).startswith('#')]
2977 # the type of build module is USER_DEFINED.
2978 # All different DEPEX section tags would be copied into the As Built INF file
2979 # and there would be separate DEPEX section tags
2980 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2981 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2982 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2984 if Arch
.upper() == TAB_ARCH_COMMON
or \
2985 (Arch
.upper() == self
.Arch
.upper() and \
2986 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2987 DepexList
.append({(Arch
, ModuleType
): DepexExpr
})
2989 #the type of build module is USER_DEFINED.
2990 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2991 for Depex
in DepexList
:
2992 for key
in Depex
.keys():
2993 DepexStr
+= '[Depex.%s.%s]\n' % key
2994 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
2997 return '[Depex.%s]\n' % self
.Arch
3000 #the type of build module not is USER_DEFINED.
3002 for Depex
in DepexList
:
3007 for D
in Depex
.values():
3008 DepexStr
+= ' '.join([val
for val
in D
])
3009 Index
= DepexStr
.find('END')
3010 if Index
> -1 and Index
== len(DepexStr
) - 3:
3011 DepexStr
= DepexStr
[:-3]
3012 DepexStr
= DepexStr
.strip()
3015 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
3017 return '[Depex.%s]\n' % self
.Arch
3018 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
3020 ## Merge dependency expression
3022 # @retval list The token list of the dependency expression after parsed
3024 def _GetDepexTokenList(self
):
3025 if self
._DepexList
== None:
3026 self
._DepexList
= {}
3027 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3028 return self
._DepexList
3030 self
._DepexList
[self
.ModuleType
] = []
3032 for ModuleType
in self
._DepexList
:
3033 DepexList
= self
._DepexList
[ModuleType
]
3035 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3037 for M
in [self
.Module
] + self
.DependentLibraryList
:
3039 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
3041 DepexList
.append('AND')
3042 DepexList
.append('(')
3044 if DepexList
[-1] == 'END': # no need of a END at this time
3046 DepexList
.append(')')
3049 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
3050 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
3052 if len(DepexList
) > 0:
3053 EdkLogger
.verbose('')
3054 return self
._DepexList
3056 ## Merge dependency expression
3058 # @retval list The token list of the dependency expression after parsed
3060 def _GetDepexExpressionTokenList(self
):
3061 if self
._DepexExpressionList
== None:
3062 self
._DepexExpressionList
= {}
3063 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
3064 return self
._DepexExpressionList
3066 self
._DepexExpressionList
[self
.ModuleType
] = ''
3068 for ModuleType
in self
._DepexExpressionList
:
3069 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
3071 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3073 for M
in [self
.Module
] + self
.DependentLibraryList
:
3075 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
3076 if DepexExpressionList
!= '':
3077 DepexExpressionList
+= ' AND '
3078 DepexExpressionList
+= '('
3079 DepexExpressionList
+= D
3080 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
3081 DepexExpressionList
+= ')'
3084 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
3085 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
3087 if len(DepexExpressionList
) > 0:
3088 EdkLogger
.verbose('')
3089 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
3090 return self
._DepexExpressionList
3092 ## Return the list of specification version required for the module
3094 # @retval list The list of specification defined in module file
3096 def _GetSpecification(self
):
3097 return self
.Module
.Specification
3099 ## Tool option for the module build
3101 # @param PlatformInfo The object of PlatformBuildInfo
3102 # @retval dict The dict containing valid options
3104 def _GetModuleBuildOption(self
):
3105 if self
._BuildOption
== None:
3106 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
3107 if self
.BuildRuleOrder
:
3108 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
3109 return self
._BuildOption
3111 ## Get include path list from tool option for the module build
3113 # @retval list The include path list
3115 def _GetBuildOptionIncPathList(self
):
3116 if self
._BuildOptionIncPathList
== None:
3118 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3119 # is the former use /I , the Latter used -I to specify include directories
3121 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
3122 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3123 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
3124 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
3127 # New ToolChainFamily, don't known whether there is option to specify include directories
3129 self
._BuildOptionIncPathList
= []
3130 return self
._BuildOptionIncPathList
3132 BuildOptionIncPathList
= []
3133 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3136 FlagOption
= self
.BuildOption
[Tool
][Attr
]
3140 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
3141 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
3144 # RVCT may specify a list of directory seperated by commas
3147 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
3148 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
3149 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
3152 # EDK II modules must not reference header files outside of the packages they depend on or
3153 # within the module's directory tree. Report error if violation.
3155 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
3156 for Path
in IncPathList
:
3157 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
3158 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
3159 EdkLogger
.error("build",
3162 File
=str(self
.MetaFile
))
3165 BuildOptionIncPathList
+= IncPathList
3167 self
._BuildOptionIncPathList
= BuildOptionIncPathList
3169 return self
._BuildOptionIncPathList
3171 ## Return a list of files which can be built from source
3173 # What kind of files can be built is determined by build rules in
3174 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3176 def _GetSourceFileList(self
):
3177 if self
._SourceFileList
== None:
3178 self
._SourceFileList
= []
3179 for F
in self
.Module
.Sources
:
3181 if F
.TagName
not in ("", "*", self
.ToolChain
):
3182 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
3183 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
3185 # match tool chain family
3186 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
3189 "The file [%s] must be built by tools of [%s], " \
3190 "but current toolchain family is [%s]" \
3191 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
3194 # add the file path into search path list for file including
3195 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
3196 self
.IncludePathList
.insert(0, F
.Dir
)
3197 self
._SourceFileList
.append(F
)
3199 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
3201 for F
in self
._SourceFileList
:
3202 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
3203 return self
._SourceFileList
3205 def _MatchBuildRuleOrder(self
, FileList
):
3207 self
._GetModuleBuildOption
()
3208 for SingleFile
in FileList
:
3209 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
3210 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
3211 if key
in Order_Dict
:
3212 Order_Dict
[key
].append(SingleFile
.Ext
)
3214 Order_Dict
[key
] = [SingleFile
.Ext
]
3217 for F
in Order_Dict
:
3218 if len(Order_Dict
[F
]) > 1:
3219 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
3220 for Ext
in Order_Dict
[F
][1:]:
3221 RemoveList
.append(F
+ Ext
)
3223 for item
in RemoveList
:
3224 FileList
.remove(item
)
3228 ## Return the list of unicode files
3229 def _GetUnicodeFileList(self
):
3230 if self
._UnicodeFileList
== None:
3231 if TAB_UNICODE_FILE
in self
.FileTypes
:
3232 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
3234 self
._UnicodeFileList
= []
3235 return self
._UnicodeFileList
3237 ## Return the list of vfr files
3238 def _GetVfrFileList(self
):
3239 if self
._VfrFileList
== None:
3240 if TAB_VFR_FILE
in self
.FileTypes
:
3241 self
._VfrFileList
= self
.FileTypes
[TAB_VFR_FILE
]
3243 self
._VfrFileList
= []
3244 return self
._VfrFileList
3246 ## Return the list of Image Definition files
3247 def _GetIdfFileList(self
):
3248 if self
._IdfFileList
== None:
3249 if TAB_IMAGE_FILE
in self
.FileTypes
:
3250 self
._IdfFileList
= self
.FileTypes
[TAB_IMAGE_FILE
]
3252 self
._IdfFileList
= []
3253 return self
._IdfFileList
3255 ## Return a list of files which can be built from binary
3257 # "Build" binary files are just to copy them to build directory.
3259 # @retval list The list of files which can be built later
3261 def _GetBinaryFiles(self
):
3262 if self
._BinaryFileList
== None:
3263 self
._BinaryFileList
= []
3264 for F
in self
.Module
.Binaries
:
3265 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
3267 self
._BinaryFileList
.append(F
)
3268 self
._ApplyBuildRule
(F
, F
.Type
)
3269 return self
._BinaryFileList
3271 def _GetBuildRules(self
):
3272 if self
._BuildRules
== None:
3274 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
3275 for Type
in BuildRuleDatabase
.FileTypeList
:
3276 #first try getting build rule by BuildRuleFamily
3277 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
3279 # build type is always module type, but ...
3280 if self
.ModuleType
!= self
.BuildType
:
3281 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
3282 #second try getting build rule by ToolChainFamily
3284 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
3286 # build type is always module type, but ...
3287 if self
.ModuleType
!= self
.BuildType
:
3288 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
3291 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
3292 BuildRules
[Type
] = RuleObject
3293 for Ext
in RuleObject
.SourceFileExtList
:
3294 BuildRules
[Ext
] = RuleObject
3295 self
._BuildRules
= BuildRules
3296 return self
._BuildRules
3298 def _ApplyBuildRule(self
, File
, FileType
):
3299 if self
._BuildTargets
== None:
3300 self
._IntroBuildTargetList
= set()
3301 self
._FinalBuildTargetList
= set()
3302 self
._BuildTargets
= {}
3303 self
._FileTypes
= {}
3305 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
3306 if not os
.path
.exists(SubDirectory
):
3307 CreateDirectory(SubDirectory
)
3313 # Make sure to get build rule order value
3315 self
._GetModuleBuildOption
()
3317 while Index
< len(SourceList
):
3318 Source
= SourceList
[Index
]
3322 CreateDirectory(Source
.Dir
)
3324 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
3325 # Skip all files that are not binary libraries
3326 if not self
.IsLibrary
:
3328 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
3329 elif FileType
in self
.BuildRules
:
3330 RuleObject
= self
.BuildRules
[FileType
]
3331 elif Source
.Ext
in self
.BuildRules
:
3332 RuleObject
= self
.BuildRules
[Source
.Ext
]
3334 # stop at no more rules
3336 self
._FinalBuildTargetList
.add(LastTarget
)
3339 FileType
= RuleObject
.SourceFileType
3340 if FileType
not in self
._FileTypes
:
3341 self
._FileTypes
[FileType
] = set()
3342 self
._FileTypes
[FileType
].add(Source
)
3344 # stop at STATIC_LIBRARY for library
3345 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3347 self
._FinalBuildTargetList
.add(LastTarget
)
3350 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3353 self
._FinalBuildTargetList
.add(LastTarget
)
3355 elif not Target
.Outputs
:
3356 # Only do build for target with outputs
3357 self
._FinalBuildTargetList
.add(Target
)
3359 if FileType
not in self
._BuildTargets
:
3360 self
._BuildTargets
[FileType
] = set()
3361 self
._BuildTargets
[FileType
].add(Target
)
3363 if not Source
.IsBinary
and Source
== File
:
3364 self
._IntroBuildTargetList
.add(Target
)
3366 # to avoid cyclic rule
3367 if FileType
in RuleChain
:
3370 RuleChain
.append(FileType
)
3371 SourceList
.extend(Target
.Outputs
)
3373 FileType
= TAB_UNKNOWN_FILE
3375 def _GetTargets(self
):
3376 if self
._BuildTargets
== None:
3377 self
._IntroBuildTargetList
= set()
3378 self
._FinalBuildTargetList
= set()
3379 self
._BuildTargets
= {}
3380 self
._FileTypes
= {}
3382 #TRICK: call _GetSourceFileList to apply build rule for source files
3383 if self
.SourceFileList
:
3386 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3387 if self
.BinaryFileList
:
3390 return self
._BuildTargets
3392 def _GetIntroTargetList(self
):
3394 return self
._IntroBuildTargetList
3396 def _GetFinalTargetList(self
):
3398 return self
._FinalBuildTargetList
3400 def _GetFileTypes(self
):
3402 return self
._FileTypes
3404 ## Get the list of package object the module depends on
3406 # @retval list The package object list
3408 def _GetDependentPackageList(self
):
3409 return self
.Module
.Packages
3411 ## Return the list of auto-generated code file
3413 # @retval list The list of auto-generated file
3415 def _GetAutoGenFileList(self
):
3416 UniStringAutoGenC
= True
3417 IdfStringAutoGenC
= True
3418 UniStringBinBuffer
= StringIO()
3419 IdfGenBinBuffer
= StringIO()
3420 if self
.BuildType
== 'UEFI_HII':
3421 UniStringAutoGenC
= False
3422 IdfStringAutoGenC
= False
3423 if self
._AutoGenFileList
== None:
3424 self
._AutoGenFileList
= {}
3425 AutoGenC
= TemplateString()
3426 AutoGenH
= TemplateString()
3427 StringH
= TemplateString()
3428 StringIdf
= TemplateString()
3429 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
, StringIdf
, IdfStringAutoGenC
, IdfGenBinBuffer
)
3431 # AutoGen.c is generated if there are library classes in inf, or there are object files
3433 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3434 or TAB_OBJECT_FILE
in self
.FileTypes
):
3435 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3436 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3437 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3438 if str(AutoGenH
) != "":
3439 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3440 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3441 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3442 if str(StringH
) != "":
3443 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3444 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3445 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3446 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
3447 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3448 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3449 AutoFile
.IsBinary
= True
3450 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3451 if UniStringBinBuffer
!= None:
3452 UniStringBinBuffer
.close()
3453 if str(StringIdf
) != "":
3454 AutoFile
= PathClass(gAutoGenImageDefFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3455 self
._AutoGenFileList
[AutoFile
] = str(StringIdf
)
3456 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3457 if IdfGenBinBuffer
!= None and IdfGenBinBuffer
.getvalue() != "":
3458 AutoFile
= PathClass(gAutoGenIdfFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3459 self
._AutoGenFileList
[AutoFile
] = IdfGenBinBuffer
.getvalue()
3460 AutoFile
.IsBinary
= True
3461 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3462 if IdfGenBinBuffer
!= None:
3463 IdfGenBinBuffer
.close()
3464 return self
._AutoGenFileList
3466 ## Return the list of library modules explicitly or implicityly used by this module
3467 def _GetLibraryList(self
):
3468 if self
._DependentLibraryList
== None:
3469 # only merge library classes and PCD for non-library module
3471 self
._DependentLibraryList
= []
3473 if self
.AutoGenVersion
< 0x00010005:
3474 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3476 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3477 return self
._DependentLibraryList
3480 def UpdateComments(Recver
, Src
):
3482 if Key
not in Recver
:
3484 Recver
[Key
].extend(Src
[Key
])
3485 ## Get the list of PCDs from current module
3487 # @retval list The list of PCD
3489 def _GetModulePcdList(self
):
3490 if self
._ModulePcdList
== None:
3491 # apply PCD settings from platform
3492 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3493 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3494 return self
._ModulePcdList
3496 ## Get the list of PCDs from dependent libraries
3498 # @retval list The list of PCD
3500 def _GetLibraryPcdList(self
):
3501 if self
._LibraryPcdList
== None:
3503 if not self
.IsLibrary
:
3504 # get PCDs from dependent libraries
3505 for Library
in self
.DependentLibraryList
:
3506 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3507 for Key
in Library
.Pcds
:
3508 # skip duplicated PCDs
3509 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3511 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3512 # apply PCD settings from platform
3513 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3515 self
._LibraryPcdList
= []
3516 return self
._LibraryPcdList
3518 ## Get the GUID value mapping
3520 # @retval dict The mapping between GUID cname and its value
3522 def _GetGuidList(self
):
3523 if self
._GuidList
== None:
3524 self
._GuidList
= sdict()
3525 self
._GuidList
.update(self
.Module
.Guids
)
3526 for Library
in self
.DependentLibraryList
:
3527 self
._GuidList
.update(Library
.Guids
)
3528 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3529 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3530 return self
._GuidList
3532 def GetGuidsUsedByPcd(self
):
3533 if self
._GuidsUsedByPcd
== None:
3534 self
._GuidsUsedByPcd
= sdict()
3535 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3536 for Library
in self
.DependentLibraryList
:
3537 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3538 return self
._GuidsUsedByPcd
3539 ## Get the protocol value mapping
3541 # @retval dict The mapping between protocol cname and its value
3543 def _GetProtocolList(self
):
3544 if self
._ProtocolList
== None:
3545 self
._ProtocolList
= sdict()
3546 self
._ProtocolList
.update(self
.Module
.Protocols
)
3547 for Library
in self
.DependentLibraryList
:
3548 self
._ProtocolList
.update(Library
.Protocols
)
3549 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3550 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3551 return self
._ProtocolList
3553 ## Get the PPI value mapping
3555 # @retval dict The mapping between PPI cname and its value
3557 def _GetPpiList(self
):
3558 if self
._PpiList
== None:
3559 self
._PpiList
= sdict()
3560 self
._PpiList
.update(self
.Module
.Ppis
)
3561 for Library
in self
.DependentLibraryList
:
3562 self
._PpiList
.update(Library
.Ppis
)
3563 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3564 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3565 return self
._PpiList
3567 ## Get the list of include search path
3569 # @retval list The list path
3571 def _GetIncludePathList(self
):
3572 if self
._IncludePathList
== None:
3573 self
._IncludePathList
= []
3574 if self
.AutoGenVersion
< 0x00010005:
3575 for Inc
in self
.Module
.Includes
:
3576 if Inc
not in self
._IncludePathList
:
3577 self
._IncludePathList
.append(Inc
)
3579 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3580 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3581 self
._IncludePathList
.append(Inc
)
3582 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3583 self
._IncludePathList
.append(self
.DebugDir
)
3585 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3586 self
._IncludePathList
.append(self
.DebugDir
)
3588 for Package
in self
.Module
.Packages
:
3589 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3590 if PackageDir
not in self
._IncludePathList
:
3591 self
._IncludePathList
.append(PackageDir
)
3592 IncludesList
= Package
.Includes
3593 if Package
._PrivateIncludes
:
3594 if not self
.MetaFile
.Path
.startswith(PackageDir
):
3595 IncludesList
= list(set(Package
.Includes
).difference(set(Package
._PrivateIncludes
)))
3596 for Inc
in IncludesList
:
3597 if Inc
not in self
._IncludePathList
:
3598 self
._IncludePathList
.append(str(Inc
))
3599 return self
._IncludePathList
3601 def _GetIncludePathLength(self
):
3602 self
._IncludePathLength
= 0
3603 if self
._IncludePathList
:
3604 for inc
in self
._IncludePathList
:
3605 self
._IncludePathLength
+= len(' ' + inc
)
3606 return self
._IncludePathLength
3608 ## Get HII EX PCDs which maybe used by VFR
3610 # efivarstore used by VFR may relate with HII EX PCDs
3611 # Get the variable name and GUID from efivarstore and HII EX PCD
3612 # List the HII EX PCDs in As Built INF if both name and GUID match.
3614 # @retval list HII EX PCDs
3616 def _GetPcdsMaybeUsedByVfr(self
):
3617 if not self
.SourceFileList
:
3621 for SrcFile
in self
.SourceFileList
:
3622 if SrcFile
.Ext
.lower() != '.vfr':
3624 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3625 if not os
.path
.exists(Vfri
):
3627 VfriFile
= open(Vfri
, 'r')
3628 Content
= VfriFile
.read()
3630 Pos
= Content
.find('efivarstore')
3633 # Make sure 'efivarstore' is the start of efivarstore statement
3634 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3637 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3639 if Index
>= 0 and Content
[Index
] != ';':
3640 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3643 # 'efivarstore' must be followed by name and guid
3645 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3648 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3651 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3652 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3653 Pos
= Content
.find('efivarstore', Name
.end())
3657 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3658 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3660 for SkuName
in Pcd
.SkuInfoList
:
3661 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3662 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3663 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
, self
.MetaFile
.Path
)
3666 Guid
= GuidStructureStringToGuidString(Value
)
3667 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3668 HiiExPcds
.append(Pcd
)
3673 def _GenOffsetBin(self
):
3675 for SourceFile
in self
.Module
.Sources
:
3676 if SourceFile
.Type
.upper() == ".VFR" :
3678 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3680 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3681 if SourceFile
.Type
.upper() == ".UNI" :
3683 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3685 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3687 if len(VfrUniBaseName
) == 0:
3689 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3690 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3691 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3692 if not VfrUniOffsetList
:
3695 OutputName
= '%sOffset.bin' % self
.Name
3696 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3699 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3701 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3703 # Use a instance of StringIO to cache data
3704 fStringIO
= StringIO('')
3706 for Item
in VfrUniOffsetList
:
3707 if (Item
[0].find("Strings") != -1):
3709 # UNI offset in image.
3711 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3713 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3714 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3715 fStringIO
.write(''.join(UniGuid
))
3716 UniValue
= pack ('Q', int (Item
[1], 16))
3717 fStringIO
.write (UniValue
)
3720 # VFR binary offset in image.
3722 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3724 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3725 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3726 fStringIO
.write(''.join(VfrGuid
))
3728 VfrValue
= pack ('Q', int (Item
[1], 16))
3729 fStringIO
.write (VfrValue
)
3731 # write data into file.
3734 fInputfile
.write (fStringIO
.getvalue())
3736 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3737 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3743 ## Create AsBuilt INF file the module
3745 def CreateAsBuiltInf(self
):
3746 if self
.IsAsBuiltInfCreated
:
3749 # Skip the following code for EDK I inf
3750 if self
.AutoGenVersion
< 0x00010005:
3753 # Skip the following code for libraries
3757 # Skip the following code for modules with no source files
3758 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3761 # Skip the following code for modules without any binary files
3762 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3765 ### TODO: How to handles mixed source and binary modules
3767 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3768 # Also find all packages that the DynamicEx PCDs depend on
3773 PcdTokenSpaceList
= []
3774 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3775 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3776 PatchablePcds
+= [Pcd
]
3777 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3778 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3781 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3782 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3783 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3785 GuidList
.update(self
.GuidList
)
3786 for TokenSpace
in self
.GetGuidsUsedByPcd():
3787 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3788 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3789 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3790 GuidList
.pop(TokenSpace
)
3791 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3792 for Package
in self
.DerivedPackageList
:
3793 if Package
in Packages
:
3795 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3797 for Index
in range(len(BeChecked
)):
3798 for Item
in CheckList
[Index
]:
3799 if Item
in BeChecked
[Index
]:
3800 Packages
+= [Package
]
3805 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3806 for Pkg
in self
.PlatformInfo
.PackageList
:
3809 for VfrPcd
in VfrPcds
:
3810 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3811 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3815 ModuleType
= self
.ModuleType
3816 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3817 ModuleType
= 'DXE_DRIVER'
3820 if self
.PcdIsDriver
!= '':
3821 DriverType
= self
.PcdIsDriver
3824 MDefs
= self
.Module
.Defines
3827 'module_name' : self
.Name
,
3828 'module_guid' : Guid
,
3829 'module_module_type' : ModuleType
,
3830 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3831 'pcd_is_driver_string' : [],
3832 'module_uefi_specification_version' : [],
3833 'module_pi_specification_version' : [],
3834 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3835 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3836 'module_constructor' : self
.Module
.ConstructorList
,
3837 'module_destructor' : self
.Module
.DestructorList
,
3838 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3839 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3840 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3841 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3842 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3843 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3844 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3845 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3846 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3847 'module_arch' : self
.Arch
,
3848 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3850 'patchablepcd_item' : [],
3852 'protocol_item' : [],
3856 'libraryclasses_item' : []
3859 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3860 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3862 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3865 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3867 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3868 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3869 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3870 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3872 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3874 for Item
in self
.CodaTargetList
:
3875 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3876 if Item
.Target
.Ext
.lower() == '.aml':
3877 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3878 elif Item
.Target
.Ext
.lower() == '.acpi':
3879 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3880 elif Item
.Target
.Ext
.lower() == '.efi':
3881 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3883 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3884 if self
.DepexGenerated
:
3885 if self
.ModuleType
in ['PEIM']:
3886 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3887 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3888 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3889 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3890 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3892 Bin
= self
._GenOffsetBin
()
3894 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3896 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3898 if File
.lower().endswith('.pdb'):
3899 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3900 HeaderComments
= self
.Module
.HeaderComments
3902 for Index
in range(len(HeaderComments
)):
3903 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3904 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3907 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3908 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3911 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3912 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3913 (GuidList
, self
._GuidComments
, 'guid_item')
3915 for Item
in GenList
:
3916 for CName
in Item
[0]:
3918 if CName
in Item
[1]:
3919 Comments
= '\n '.join(Item
[1][CName
])
3922 Entry
= Comments
+ '\n ' + CName
3923 AsBuiltInfDict
[Item
[2]].append(Entry
)
3924 PatchList
= parsePcdInfoFromMapFile(
3925 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3926 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3929 for Pcd
in PatchablePcds
:
3930 TokenCName
= Pcd
.TokenCName
3931 for PcdItem
in GlobalData
.MixedPcd
:
3932 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
3933 TokenCName
= PcdItem
[0]
3935 for PatchPcd
in PatchList
:
3936 if TokenCName
== PatchPcd
[0]:
3941 if Pcd
.DatumType
== 'BOOLEAN':
3942 BoolValue
= Pcd
.DefaultValue
.upper()
3943 if BoolValue
== 'TRUE':
3944 Pcd
.DefaultValue
= '1'
3945 elif BoolValue
== 'FALSE':
3946 Pcd
.DefaultValue
= '0'
3948 if Pcd
.DatumType
!= 'VOID*':
3949 HexFormat
= '0x%02x'
3950 if Pcd
.DatumType
== 'UINT16':
3951 HexFormat
= '0x%04x'
3952 elif Pcd
.DatumType
== 'UINT32':
3953 HexFormat
= '0x%08x'
3954 elif Pcd
.DatumType
== 'UINT64':
3955 HexFormat
= '0x%016x'
3956 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3958 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
3959 EdkLogger
.error("build", AUTOGEN_ERROR
,
3960 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3962 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3963 PcdValue
= Pcd
.DefaultValue
3964 if PcdValue
[0] != '{':
3966 if PcdValue
[0] == 'L':
3968 PcdValue
= PcdValue
.lstrip('L')
3969 PcdValue
= eval(PcdValue
)
3971 for Index
in range(0, len(PcdValue
)):
3973 CharVal
= ord(PcdValue
[Index
])
3974 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3975 + '0x%02x' % (CharVal
>> 8) + ', '
3977 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3980 Padding
= Padding
* 2
3981 ArraySize
= ArraySize
/ 2
3982 if ArraySize
< (len(PcdValue
) + 1):
3983 EdkLogger
.error("build", AUTOGEN_ERROR
,
3984 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3986 if ArraySize
> len(PcdValue
) + 1:
3987 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3988 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3989 elif len(PcdValue
.split(',')) <= ArraySize
:
3990 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3993 EdkLogger
.error("build", AUTOGEN_ERROR
,
3994 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
)
3996 PcdItem
= '%s.%s|%s|0x%X' % \
3997 (Pcd
.TokenSpaceGuidCName
, TokenCName
, PcdValue
, PatchPcd
[1])
3999 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4000 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
4002 PcdItem
= PcdComments
+ '\n ' + PcdItem
4003 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
4006 for Pcd
in Pcds
+ VfrPcds
:
4011 TokenCName
= Pcd
.TokenCName
4012 for PcdItem
in GlobalData
.MixedPcd
:
4013 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
4014 TokenCName
= PcdItem
[0]
4016 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
4017 for SkuName
in Pcd
.SkuInfoList
:
4018 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
4019 SkuId
= SkuInfo
.SkuId
4020 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
4024 # Don't generate duplicated HII PCD
4026 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
4029 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
4030 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
4031 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
4035 for Index
, Comment
in enumerate(PcdCommentList
):
4036 for Usage
in UsageList
:
4037 if Comment
.find(Usage
) != -1:
4041 if UsageIndex
!= -1:
4042 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
4044 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
4045 PcdComments
= '\n '.join(PcdCommentList
)
4046 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + TokenCName
4048 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
4049 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
4050 for Item
in self
.BuildOption
:
4051 if 'FLAGS' in self
.BuildOption
[Item
]:
4052 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
4054 # Generated LibraryClasses section in comments.
4055 for Library
in self
.LibraryAutoGenList
:
4056 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
4058 # Generated depex expression section in comments.
4059 AsBuiltInfDict
['depexsection_item'] = ''
4060 DepexExpresion
= self
._GetDepexExpresionString
()
4062 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
4064 AsBuiltInf
= TemplateString()
4065 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
4067 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
4069 self
.IsAsBuiltInfCreated
= True
4071 ## Create makefile for the module and its dependent libraries
4073 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
4074 # dependent libraries will be created
4076 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
4077 # Ignore generating makefile when it is a binary module
4078 if self
.IsBinaryModule
:
4081 if self
.IsMakeFileCreated
:
4086 if not self
.IsLibrary
and CreateLibraryMakeFile
:
4087 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4088 LibraryAutoGen
.CreateMakeFile()
4090 if len(self
.CustomMakefile
) == 0:
4091 Makefile
= GenMake
.ModuleMakefile(self
)
4093 Makefile
= GenMake
.CustomMakefile(self
)
4094 if Makefile
.Generate():
4095 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
4096 (self
.Name
, self
.Arch
))
4098 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
4099 (self
.Name
, self
.Arch
))
4101 self
.CreateTimeStamp(Makefile
)
4102 self
.IsMakeFileCreated
= True
4104 def CopyBinaryFiles(self
):
4105 for File
in self
.Module
.Binaries
:
4107 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
4108 CopyLongFilePath(SrcPath
, DstPath
)
4109 ## Create autogen code for the module and its dependent libraries
4111 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4112 # dependent libraries will be created
4114 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
4115 if self
.IsCodeFileCreated
:
4120 # Need to generate PcdDatabase even PcdDriver is binarymodule
4121 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
4122 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
4124 if self
.IsBinaryModule
:
4126 self
.CopyBinaryFiles()
4129 if not self
.IsLibrary
and CreateLibraryCodeFile
:
4130 for LibraryAutoGen
in self
.LibraryAutoGenList
:
4131 LibraryAutoGen
.CreateCodeFile()
4134 IgoredAutoGenList
= []
4136 for File
in self
.AutoGenFileList
:
4137 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
4138 #Ignore Edk AutoGen.c
4139 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
4142 AutoGenList
.append(str(File
))
4144 IgoredAutoGenList
.append(str(File
))
4146 # Skip the following code for EDK I inf
4147 if self
.AutoGenVersion
< 0x00010005:
4150 for ModuleType
in self
.DepexList
:
4151 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
4152 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
4155 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
4156 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
4158 if len(Dpx
.PostfixNotation
) <> 0:
4159 self
.DepexGenerated
= True
4161 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
4162 AutoGenList
.append(str(DpxFile
))
4164 IgoredAutoGenList
.append(str(DpxFile
))
4166 if IgoredAutoGenList
== []:
4167 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
4168 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
4169 elif AutoGenList
== []:
4170 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
4171 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4173 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
4174 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
4176 self
.IsCodeFileCreated
= True
4179 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4180 def _GetLibraryAutoGenList(self
):
4181 if self
._LibraryAutoGenList
== None:
4182 self
._LibraryAutoGenList
= []
4183 for Library
in self
.DependentLibraryList
:
4190 self
.PlatformInfo
.MetaFile
4192 if La
not in self
._LibraryAutoGenList
:
4193 self
._LibraryAutoGenList
.append(La
)
4194 for Lib
in La
.CodaTargetList
:
4195 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
4196 return self
._LibraryAutoGenList
4198 ## Decide whether we can skip the ModuleAutoGen process
4199 # If any source file is newer than the modeule than we cannot skip
4202 if not os
.path
.exists(self
.GetTimeStampPath()):
4204 #last creation time of the module
4205 DstTimeStamp
= os
.stat(self
.GetTimeStampPath())[8]
4207 SrcTimeStamp
= self
.Workspace
._SrcTimeStamp
4208 if SrcTimeStamp
> DstTimeStamp
:
4211 with
open(self
.GetTimeStampPath(),'r') as f
:
4213 source
= source
.rstrip('\n')
4214 if source
not in ModuleAutoGen
.TimeDict
:
4215 ModuleAutoGen
.TimeDict
[source
] = os
.stat(source
)[8]
4216 if ModuleAutoGen
.TimeDict
[source
] > DstTimeStamp
:
4220 def GetTimeStampPath(self
):
4221 if self
._TimeStampPath
== None:
4222 self
._TimeStampPath
= os
.path
.join(self
.MakeFileDir
, 'AutoGenTimeStamp')
4223 return self
._TimeStampPath
4224 def CreateTimeStamp(self
, Makefile
):
4228 FileSet
.add (self
.MetaFile
.Path
)
4230 for SourceFile
in self
.Module
.Sources
:
4231 FileSet
.add (SourceFile
.Path
)
4233 for Lib
in self
.DependentLibraryList
:
4234 FileSet
.add (Lib
.MetaFile
.Path
)
4236 for f
in self
.AutoGenDepSet
:
4237 FileSet
.add (f
.Path
)
4239 if os
.path
.exists (self
.GetTimeStampPath()):
4240 os
.remove (self
.GetTimeStampPath())
4241 with
open(self
.GetTimeStampPath(), 'w+') as file:
4245 Module
= property(_GetModule
)
4246 Name
= property(_GetBaseName
)
4247 Guid
= property(_GetGuid
)
4248 Version
= property(_GetVersion
)
4249 ModuleType
= property(_GetModuleType
)
4250 ComponentType
= property(_GetComponentType
)
4251 BuildType
= property(_GetBuildType
)
4252 PcdIsDriver
= property(_GetPcdIsDriver
)
4253 AutoGenVersion
= property(_GetAutoGenVersion
)
4254 Macros
= property(_GetMacros
)
4255 Specification
= property(_GetSpecification
)
4257 IsLibrary
= property(_IsLibrary
)
4258 IsBinaryModule
= property(_IsBinaryModule
)
4259 BuildDir
= property(_GetBuildDir
)
4260 OutputDir
= property(_GetOutputDir
)
4261 DebugDir
= property(_GetDebugDir
)
4262 MakeFileDir
= property(_GetMakeFileDir
)
4263 CustomMakefile
= property(_GetCustomMakefile
)
4265 IncludePathList
= property(_GetIncludePathList
)
4266 IncludePathLength
= property(_GetIncludePathLength
)
4267 AutoGenFileList
= property(_GetAutoGenFileList
)
4268 UnicodeFileList
= property(_GetUnicodeFileList
)
4269 VfrFileList
= property(_GetVfrFileList
)
4270 SourceFileList
= property(_GetSourceFileList
)
4271 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
4272 Targets
= property(_GetTargets
)
4273 IntroTargetList
= property(_GetIntroTargetList
)
4274 CodaTargetList
= property(_GetFinalTargetList
)
4275 FileTypes
= property(_GetFileTypes
)
4276 BuildRules
= property(_GetBuildRules
)
4277 IdfFileList
= property(_GetIdfFileList
)
4279 DependentPackageList
= property(_GetDependentPackageList
)
4280 DependentLibraryList
= property(_GetLibraryList
)
4281 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
4282 DerivedPackageList
= property(_GetDerivedPackageList
)
4284 ModulePcdList
= property(_GetModulePcdList
)
4285 LibraryPcdList
= property(_GetLibraryPcdList
)
4286 GuidList
= property(_GetGuidList
)
4287 ProtocolList
= property(_GetProtocolList
)
4288 PpiList
= property(_GetPpiList
)
4289 DepexList
= property(_GetDepexTokenList
)
4290 DxsFile
= property(_GetDxsFile
)
4291 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
4292 BuildOption
= property(_GetModuleBuildOption
)
4293 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
4294 BuildCommand
= property(_GetBuildCommand
)
4296 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
4298 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4299 if __name__
== '__main__':