2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2016, 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
46 ## Regular expression for splitting Dependency Expression string into tokens
47 gDepexTokenPattern
= re
.compile("(\(|\)|\w+| \S+\.inf)")
50 # Match name = variable
52 gEfiVarStoreNamePattern
= re
.compile("\s*name\s*=\s*(\w+)")
54 # The format of guid in efivarstore statement likes following and must be correct:
55 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
57 gEfiVarStoreGuidPattern
= re
.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
59 ## Mapping Makefile type
60 gMakeTypeMap
= {"MSFT":"nmake", "GCC":"gmake"}
63 ## Build rule configuration file
64 gDefaultBuildRuleFile
= 'Conf/build_rule.txt'
66 ## Build rule default version
67 AutoGenReqBuildRuleVerNum
= "0.1"
69 ## default file name for AutoGen
70 gAutoGenCodeFileName
= "AutoGen.c"
71 gAutoGenHeaderFileName
= "AutoGen.h"
72 gAutoGenStringFileName
= "%(module_name)sStrDefs.h"
73 gAutoGenStringFormFileName
= "%(module_name)sStrDefs.hpk"
74 gAutoGenDepexFileName
= "%(module_name)s.depex"
76 gInfSpecVersion
= "0x00010017"
79 # Template string to generic AsBuilt INF
81 gAsBuiltInfHeaderString
= TemplateString("""${header_comments}
87 INF_VERSION = ${module_inf_version}
88 BASE_NAME = ${module_name}
89 FILE_GUID = ${module_guid}
90 MODULE_TYPE = ${module_module_type}${BEGIN}
91 VERSION_STRING = ${module_version_string}${END}${BEGIN}
92 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
93 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
94 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
95 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
96 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
97 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
98 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
99 SHADOW = ${module_shadow}${END}${BEGIN}
100 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
101 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
102 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
103 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
104 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
105 SPEC = ${module_spec}${END}${BEGIN}
106 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
107 MODULE_UNI_FILE = ${module_uni_file}${END}
109 [Packages.${module_arch}]${BEGIN}
110 ${package_item}${END}
112 [Binaries.${module_arch}]${BEGIN}
115 [PatchPcd.${module_arch}]${BEGIN}
119 [Protocols.${module_arch}]${BEGIN}
123 [Ppis.${module_arch}]${BEGIN}
127 [Guids.${module_arch}]${BEGIN}
131 [PcdEx.${module_arch}]${BEGIN}
135 [LibraryClasses.${module_arch}]
136 ## @LIB_INSTANCES${BEGIN}
137 # ${libraryclasses_item}${END}
143 [BuildOptions.${module_arch}]
145 ## ${flags_item}${END}
148 ## Base class for AutoGen
150 # This class just implements the cache mechanism of AutoGen objects.
152 class AutoGen(object):
153 # database to maintain the objects of xxxAutoGen
154 _CACHE_
= {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}
158 # @param Class class object of real AutoGen class
159 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
160 # @param Workspace Workspace directory or WorkspaceAutoGen object
161 # @param MetaFile The path of meta file
162 # @param Target Build target
163 # @param Toolchain Tool chain name
164 # @param Arch Target arch
165 # @param *args The specific class related parameters
166 # @param **kwargs The specific class related dict parameters
168 def __new__(Class
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
169 # check if the object has been created
170 Key
= (Target
, Toolchain
)
171 if Key
not in Class
._CACHE
_ or Arch
not in Class
._CACHE
_[Key
] \
172 or MetaFile
not in Class
._CACHE
_[Key
][Arch
]:
173 AutoGenObject
= super(AutoGen
, Class
).__new
__(Class
)
174 # call real constructor
175 if not AutoGenObject
._Init
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
177 if Key
not in Class
._CACHE
_:
178 Class
._CACHE
_[Key
] = {}
179 if Arch
not in Class
._CACHE
_[Key
]:
180 Class
._CACHE
_[Key
][Arch
] = {}
181 Class
._CACHE
_[Key
][Arch
][MetaFile
] = AutoGenObject
183 AutoGenObject
= Class
._CACHE
_[Key
][Arch
][MetaFile
]
189 # The file path of platform file will be used to represent hash value of this object
191 # @retval int Hash value of the file path of platform file
194 return hash(self
.MetaFile
)
198 # The file path of platform file will be used to represent this object
200 # @retval string String of platform file path
203 return str(self
.MetaFile
)
206 def __eq__(self
, Other
):
207 return Other
and self
.MetaFile
== Other
209 ## Workspace AutoGen class
211 # This class is used mainly to control the whole platform build for different
212 # architecture. This class will generate top level makefile.
214 class WorkspaceAutoGen(AutoGen
):
215 ## Real constructor of WorkspaceAutoGen
217 # This method behaves the same as __init__ except that it needs explicit invoke
218 # (in super class's __new__ method)
220 # @param WorkspaceDir Root directory of workspace
221 # @param ActivePlatform Meta-file of active platform
222 # @param Target Build target
223 # @param Toolchain Tool chain name
224 # @param ArchList List of architecture of current build
225 # @param MetaFileDb Database containing meta-files
226 # @param BuildConfig Configuration of build
227 # @param ToolDefinition Tool chain definitions
228 # @param FlashDefinitionFile File of flash definition
229 # @param Fds FD list to be generated
230 # @param Fvs FV list to be generated
231 # @param Caps Capsule list to be generated
232 # @param SkuId SKU id from command line
234 def _Init(self
, WorkspaceDir
, ActivePlatform
, Target
, Toolchain
, ArchList
, MetaFileDb
,
235 BuildConfig
, ToolDefinition
, FlashDefinitionFile
='', Fds
=None, Fvs
=None, Caps
=None, SkuId
='', UniFlag
=None,
236 Progress
=None, BuildModule
=None):
243 self
.BuildDatabase
= MetaFileDb
244 self
.MetaFile
= ActivePlatform
245 self
.WorkspaceDir
= WorkspaceDir
246 self
.Platform
= self
.BuildDatabase
[self
.MetaFile
, 'COMMON', Target
, Toolchain
]
247 GlobalData
.gActivePlatform
= self
.Platform
248 self
.BuildTarget
= Target
249 self
.ToolChain
= Toolchain
250 self
.ArchList
= ArchList
252 self
.UniFlag
= UniFlag
254 self
.TargetTxt
= BuildConfig
255 self
.ToolDef
= ToolDefinition
256 self
.FdfFile
= FlashDefinitionFile
257 self
.FdTargetList
= Fds
258 self
.FvTargetList
= Fvs
259 self
.CapTargetList
= Caps
260 self
.AutoGenObjectList
= []
262 # there's many relative directory operations, so ...
263 os
.chdir(self
.WorkspaceDir
)
268 if not self
.ArchList
:
269 ArchList
= set(self
.Platform
.SupArchList
)
271 ArchList
= set(self
.ArchList
) & set(self
.Platform
.SupArchList
)
273 EdkLogger
.error("build", PARAMETER_INVALID
,
274 ExtraData
= "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self
.Platform
.SupArchList
)))
275 elif self
.ArchList
and len(ArchList
) != len(self
.ArchList
):
276 SkippedArchList
= set(self
.ArchList
).symmetric_difference(set(self
.Platform
.SupArchList
))
277 EdkLogger
.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
278 % (" ".join(SkippedArchList
), " ".join(self
.Platform
.SupArchList
)))
279 self
.ArchList
= tuple(ArchList
)
281 # Validate build target
282 if self
.BuildTarget
not in self
.Platform
.BuildTargets
:
283 EdkLogger
.error("build", PARAMETER_INVALID
,
284 ExtraData
="Build target [%s] is not supported by the platform. [Valid target: %s]"
285 % (self
.BuildTarget
, " ".join(self
.Platform
.BuildTargets
)))
288 # parse FDF file to get PCDs in it, if any
290 self
.FdfFile
= self
.Platform
.FlashDefinition
294 EdkLogger
.info('%-16s = %s' % ("Architecture(s)", ' '.join(self
.ArchList
)))
295 EdkLogger
.info('%-16s = %s' % ("Build target", self
.BuildTarget
))
296 EdkLogger
.info('%-16s = %s' % ("Toolchain", self
.ToolChain
))
298 EdkLogger
.info('\n%-24s = %s' % ("Active Platform", self
.Platform
))
300 EdkLogger
.info('%-24s = %s' % ("Active Module", BuildModule
))
303 EdkLogger
.info('%-24s = %s' % ("Flash Image Definition", self
.FdfFile
))
305 EdkLogger
.verbose("\nFLASH_DEFINITION = %s" % self
.FdfFile
)
308 Progress
.Start("\nProcessing meta-data")
312 # Mark now build in AutoGen Phase
314 GlobalData
.gAutoGenPhase
= True
315 Fdf
= FdfParser(self
.FdfFile
.Path
)
317 GlobalData
.gFdfParser
= Fdf
318 GlobalData
.gAutoGenPhase
= False
319 PcdSet
= Fdf
.Profile
.PcdDict
320 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
321 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
322 for FdRegion
in FdDict
.RegionList
:
323 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
324 if int(FdRegion
.Offset
) % 8 != 0:
325 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
326 ModuleList
= Fdf
.Profile
.InfList
327 self
.FdfProfile
= Fdf
.Profile
328 for fvname
in self
.FvTargetList
:
329 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
330 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
331 "No such an FV in FDF file: %s" % fvname
)
335 self
.FdfProfile
= None
336 if self
.FdTargetList
:
337 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
338 self
.FdTargetList
= []
339 if self
.FvTargetList
:
340 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
341 self
.FvTargetList
= []
342 if self
.CapTargetList
:
343 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
344 self
.CapTargetList
= []
346 # apply SKU and inject PCDs from Flash Definition file
347 for Arch
in self
.ArchList
:
348 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
352 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
353 if GlobalData
.BuildOptionPcd
:
354 for i
, pcd
in enumerate(GlobalData
.BuildOptionPcd
):
355 if type(pcd
) is tuple:
357 (pcdname
, pcdvalue
) = pcd
.split('=')
359 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
361 (TokenSpaceGuidCName
, TokenCName
) = pcdname
.split('.')
365 TokenSpaceGuidCName
= ''
366 HasTokenSpace
= False
367 TokenSpaceGuidCNameList
= []
371 for package
in PGen
.PackageList
:
372 for key
in package
.Pcds
:
373 PcdItem
= package
.Pcds
[key
]
375 if (PcdItem
.TokenCName
, PcdItem
.TokenSpaceGuidCName
) == (TokenCName
, TokenSpaceGuidCName
):
376 PcdDatumType
= PcdItem
.DatumType
377 NewValue
= self
._BuildOptionPcdValueFormat
(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
380 if PcdItem
.TokenCName
== TokenCName
:
381 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
382 if len (TokenSpaceGuidCNameList
) < 1:
383 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
384 PcdDatumType
= PcdItem
.DatumType
385 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
386 NewValue
= self
._BuildOptionPcdValueFormat
(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
392 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
395 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, NewValue
)
399 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, TokenCName
))
401 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (TokenCName
))
403 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
404 if BuildData
.Arch
!= Arch
:
406 if BuildData
.MetaFile
.Ext
== '.dec':
408 for key
in BuildData
.Pcds
:
409 PcdItem
= BuildData
.Pcds
[key
]
410 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
):
411 PcdItem
.DefaultValue
= NewValue
413 if (TokenCName
, TokenSpaceGuidCName
) in PcdSet
:
414 PcdSet
[(TokenCName
, TokenSpaceGuidCName
)] = NewValue
416 #Collect package set information from INF of FDF
418 for Inf
in ModuleList
:
419 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
420 if ModuleFile
in Platform
.Modules
:
422 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
423 PkgSet
.update(ModuleData
.Packages
)
424 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
427 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
428 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
430 Platform
.SkuName
= self
.SkuId
431 for Name
, Guid
in PcdSet
:
432 if (Name
, Guid
) not in DecPcds
:
436 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
437 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
438 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
441 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
442 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
443 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
444 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
445 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
447 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
451 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
452 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
453 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
456 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
458 # Explicitly collect platform's dynamic PCDs
460 Pa
.CollectPlatformDynamicPcds()
461 Pa
.CollectFixedAtBuildPcds()
462 self
.AutoGenObjectList
.append(Pa
)
465 # Check PCDs token value conflict in each DEC file.
467 self
._CheckAllPcdsTokenValueConflict
()
470 # Check PCD type and definition between DSC and DEC
472 self
._CheckPcdDefineAndType
()
475 # self._CheckDuplicateInFV(Fdf)
477 self
._BuildDir
= None
479 self
._MakeFileDir
= None
480 self
._BuildCommand
= None
484 def _BuildOptionPcdValueFormat(self
, TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, Value
):
485 if PcdDatumType
== 'VOID*':
486 if Value
.startswith('L'):
488 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"{...}"')
489 Value
= Value
[0] + '"' + Value
[1:] + '"'
490 elif Value
.startswith('B'):
492 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"{...}"')
496 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"{...}"')
497 Value
= '"' + Value
+ '"'
499 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, Value
)
501 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
502 if PcdDatumType
== 'BOOLEAN':
503 Value
= Value
.upper()
504 if Value
== 'TRUE' or Value
== '1':
506 elif Value
== 'FALSE' or Value
== '0':
510 ## _CheckDuplicateInFV() method
512 # Check whether there is duplicate modules/files exist in FV section.
513 # The check base on the file GUID;
515 def _CheckDuplicateInFV(self
, Fdf
):
516 for Fv
in Fdf
.Profile
.FvDict
:
518 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
519 if FfsFile
.InfFileName
and FfsFile
.NameGuid
== None:
524 for Pa
in self
.AutoGenObjectList
:
527 for Module
in Pa
.ModuleAutoGenList
:
528 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
530 if not Module
.Guid
.upper() in _GuidDict
.keys():
531 _GuidDict
[Module
.Guid
.upper()] = FfsFile
534 EdkLogger
.error("build",
536 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
537 FfsFile
.CurrentLineContent
,
538 _GuidDict
[Module
.Guid
.upper()].CurrentLineNum
,
539 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
540 Module
.Guid
.upper()),
541 ExtraData
=self
.FdfFile
)
543 # Some INF files not have entity in DSC file.
546 if FfsFile
.InfFileName
.find('$') == -1:
547 InfPath
= NormPath(FfsFile
.InfFileName
)
548 if not os
.path
.exists(InfPath
):
549 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
551 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
553 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
554 # BuildObject from one of AutoGenObjectList is enough.
556 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, 'COMMON', self
.BuildTarget
, self
.ToolChain
]
557 if not InfObj
.Guid
.upper() in _GuidDict
.keys():
558 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
560 EdkLogger
.error("build",
562 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
563 FfsFile
.CurrentLineContent
,
564 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
565 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
566 InfObj
.Guid
.upper()),
567 ExtraData
=self
.FdfFile
)
570 if FfsFile
.NameGuid
!= None:
571 _CheckPCDAsGuidPattern
= re
.compile("^PCD\(.+\..+\)$")
574 # If the NameGuid reference a PCD name.
575 # The style must match: PCD(xxxx.yyy)
577 if _CheckPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
579 # Replace the PCD value.
581 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
583 for Pa
in self
.AutoGenObjectList
:
585 for PcdItem
in Pa
.AllPcdList
:
586 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
588 # First convert from CFormatGuid to GUID string
590 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
592 if not _PcdGuidString
:
594 # Then try Byte array.
596 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
598 if not _PcdGuidString
:
600 # Not Byte array or CFormat GUID, raise error.
602 EdkLogger
.error("build",
604 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
605 ExtraData
=self
.FdfFile
)
607 if not _PcdGuidString
.upper() in _GuidDict
.keys():
608 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
612 EdkLogger
.error("build",
614 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
615 FfsFile
.CurrentLineContent
,
616 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
617 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
618 FfsFile
.NameGuid
.upper()),
619 ExtraData
=self
.FdfFile
)
621 if not FfsFile
.NameGuid
.upper() in _GuidDict
.keys():
622 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
625 # Two raw file GUID conflict.
627 EdkLogger
.error("build",
629 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
630 FfsFile
.CurrentLineContent
,
631 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
632 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
633 FfsFile
.NameGuid
.upper()),
634 ExtraData
=self
.FdfFile
)
637 def _CheckPcdDefineAndType(self
):
639 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
640 "Dynamic", #"DynamicHii", "DynamicVpd",
641 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
644 # This dict store PCDs which are not used by any modules with specified arches
646 for Pa
in self
.AutoGenObjectList
:
647 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
648 for Pcd
in Pa
.Platform
.Pcds
:
649 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
651 # If no PCD type, this PCD comes from FDF
655 # Try to remove Hii and Vpd suffix
656 if PcdType
.startswith("DynamicEx"):
657 PcdType
= "DynamicEx"
658 elif PcdType
.startswith("Dynamic"):
661 for Package
in Pa
.PackageList
:
662 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
663 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
665 for Type
in PcdTypeList
:
666 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
670 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
671 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
676 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
678 for Pcd
in UnusedPcd
:
681 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
682 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
683 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
688 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
690 ## Return the directory to store FV files
692 if self
._FvDir
== None:
693 self
._FvDir
= path
.join(self
.BuildDir
, 'FV')
696 ## Return the directory to store all intermediate and final files built
697 def _GetBuildDir(self
):
698 return self
.AutoGenObjectList
[0].BuildDir
700 ## Return the build output directory platform specifies
701 def _GetOutputDir(self
):
702 return self
.Platform
.OutputDirectory
704 ## Return platform name
706 return self
.Platform
.PlatformName
708 ## Return meta-file GUID
710 return self
.Platform
.Guid
712 ## Return platform version
713 def _GetVersion(self
):
714 return self
.Platform
.Version
716 ## Return paths of tools
717 def _GetToolDefinition(self
):
718 return self
.AutoGenObjectList
[0].ToolDefinition
720 ## Return directory of platform makefile
722 # @retval string Makefile directory
724 def _GetMakeFileDir(self
):
725 if self
._MakeFileDir
== None:
726 self
._MakeFileDir
= self
.BuildDir
727 return self
._MakeFileDir
729 ## Return build command string
731 # @retval string Build command string
733 def _GetBuildCommand(self
):
734 if self
._BuildCommand
== None:
735 # BuildCommand should be all the same. So just get one from platform AutoGen
736 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
737 return self
._BuildCommand
739 ## Check the PCDs token value conflict in each DEC file.
741 # Will cause build break and raise error message while two PCDs conflict.
745 def _CheckAllPcdsTokenValueConflict(self
):
746 for Pa
in self
.AutoGenObjectList
:
747 for Package
in Pa
.PackageList
:
748 PcdList
= Package
.Pcds
.values()
749 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
751 while (Count
< len(PcdList
) - 1) :
752 Item
= PcdList
[Count
]
753 ItemNext
= PcdList
[Count
+ 1]
755 # Make sure in the same token space the TokenValue should be unique
757 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
758 SameTokenValuePcdList
= []
759 SameTokenValuePcdList
.append(Item
)
760 SameTokenValuePcdList
.append(ItemNext
)
761 RemainPcdListLength
= len(PcdList
) - Count
- 2
762 for ValueSameCount
in range(RemainPcdListLength
):
763 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
764 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
768 # Sort same token value PCD list with TokenGuid and TokenCName
770 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
771 SameTokenValuePcdListCount
= 0
772 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
773 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
774 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
776 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
780 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
781 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
784 SameTokenValuePcdListCount
+= 1
785 Count
+= SameTokenValuePcdListCount
788 PcdList
= Package
.Pcds
.values()
789 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
791 while (Count
< len(PcdList
) - 1) :
792 Item
= PcdList
[Count
]
793 ItemNext
= PcdList
[Count
+ 1]
795 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
797 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
801 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
802 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
806 ## Generate fds command
807 def _GenFdsCommand(self
):
808 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
810 ## Create makefile for the platform and modules in it
812 # @param CreateDepsMakeFile Flag indicating if the makefile for
813 # modules will be created as well
815 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
816 if CreateDepsMakeFile
:
817 for Pa
in self
.AutoGenObjectList
:
818 Pa
.CreateMakeFile(CreateDepsMakeFile
)
820 ## Create autogen code for platform and modules
822 # Since there's no autogen code for platform, this method will do nothing
823 # if CreateModuleCodeFile is set to False.
825 # @param CreateDepsCodeFile Flag indicating if creating module's
826 # autogen code file or not
828 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
829 if not CreateDepsCodeFile
:
831 for Pa
in self
.AutoGenObjectList
:
832 Pa
.CreateCodeFile(CreateDepsCodeFile
)
834 ## Create AsBuilt INF file the platform
836 def CreateAsBuiltInf(self
):
839 Name
= property(_GetName
)
840 Guid
= property(_GetGuid
)
841 Version
= property(_GetVersion
)
842 OutputDir
= property(_GetOutputDir
)
844 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
846 BuildDir
= property(_GetBuildDir
)
847 FvDir
= property(_GetFvDir
)
848 MakeFileDir
= property(_GetMakeFileDir
)
849 BuildCommand
= property(_GetBuildCommand
)
850 GenFdsCommand
= property(_GenFdsCommand
)
852 ## AutoGen class for platform
854 # PlatformAutoGen class will process the original information in platform
855 # file in order to generate makefile for platform.
857 class PlatformAutoGen(AutoGen
):
859 # Used to store all PCDs for both PEI and DXE phase, in order to generate
860 # correct PCD database
863 _NonDynaPcdList_
= []
867 # The priority list while override build option
869 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
870 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
871 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
872 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
873 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
874 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
875 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
876 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
877 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
878 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
879 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
880 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
881 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
882 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
883 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
884 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
886 ## The real constructor of PlatformAutoGen
888 # This method is not supposed to be called by users of PlatformAutoGen. It's
889 # only used by factory method __new__() to do real initialization work for an
890 # object of PlatformAutoGen
892 # @param Workspace WorkspaceAutoGen object
893 # @param PlatformFile Platform file (DSC file)
894 # @param Target Build target (DEBUG, RELEASE)
895 # @param Toolchain Name of tool chain
896 # @param Arch arch of the platform supports
898 def _Init(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
899 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
900 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
902 self
.MetaFile
= PlatformFile
903 self
.Workspace
= Workspace
904 self
.WorkspaceDir
= Workspace
.WorkspaceDir
905 self
.ToolChain
= Toolchain
906 self
.BuildTarget
= Target
908 self
.SourceDir
= PlatformFile
.SubDir
909 self
.SourceOverrideDir
= None
910 self
.FdTargetList
= self
.Workspace
.FdTargetList
911 self
.FvTargetList
= self
.Workspace
.FvTargetList
913 # get the original module/package/platform objects
914 self
.BuildDatabase
= Workspace
.BuildDatabase
916 # flag indicating if the makefile/C-code file has been created or not
917 self
.IsMakeFileCreated
= False
918 self
.IsCodeFileCreated
= False
920 self
._Platform
= None
925 self
._BuildRule
= None
926 self
._SourceDir
= None
927 self
._BuildDir
= None
928 self
._OutputDir
= None
930 self
._MakeFileDir
= None
933 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
934 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
935 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
936 self
._NonDynamicPcdDict
= {}
938 self
._ToolDefinitions
= None
939 self
._ToolDefFile
= None # toolcode : tool path
940 self
._ToolChainFamily
= None
941 self
._BuildRuleFamily
= None
942 self
._BuildOption
= None # toolcode : option
943 self
._EdkBuildOption
= None # edktoolcode : option
944 self
._EdkIIBuildOption
= None # edkiitoolcode : option
945 self
._PackageList
= None
946 self
._ModuleAutoGenList
= None
947 self
._LibraryAutoGenList
= None
948 self
._BuildCommand
= None
949 self
._AsBuildInfList
= []
950 self
._AsBuildModuleList
= []
951 if GlobalData
.gFdfParser
!= None:
952 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
953 for Inf
in self
._AsBuildInfList
:
954 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
955 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
956 if not M
.IsSupportedArch
:
958 self
._AsBuildModuleList
.append(InfClass
)
959 # get library/modules for build
960 self
.LibraryBuildDirectoryList
= []
961 self
.ModuleBuildDirectoryList
= []
965 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
967 ## Create autogen code for platform and modules
969 # Since there's no autogen code for platform, this method will do nothing
970 # if CreateModuleCodeFile is set to False.
972 # @param CreateModuleCodeFile Flag indicating if creating module's
973 # autogen code file or not
975 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
976 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
977 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
980 for Ma
in self
.ModuleAutoGenList
:
981 Ma
.CreateCodeFile(True)
983 # don't do this twice
984 self
.IsCodeFileCreated
= True
986 ## Generate Fds Command
987 def _GenFdsCommand(self
):
988 return self
.Workspace
.GenFdsCommand
990 ## Create makefile for the platform and mdoules in it
992 # @param CreateModuleMakeFile Flag indicating if the makefile for
993 # modules will be created as well
995 def CreateMakeFile(self
, CreateModuleMakeFile
=False):
996 if CreateModuleMakeFile
:
997 for ModuleFile
in self
.Platform
.Modules
:
998 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
999 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1000 Ma
.CreateMakeFile(True)
1001 #Ma.CreateAsBuiltInf()
1003 # no need to create makefile for the platform more than once
1004 if self
.IsMakeFileCreated
:
1007 # create library/module build dirs for platform
1008 Makefile
= GenMake
.PlatformMakefile(self
)
1009 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1010 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1012 self
.IsMakeFileCreated
= True
1014 ## Deal with Shared FixedAtBuild Pcds
1016 def CollectFixedAtBuildPcds(self
):
1017 for LibAuto
in self
.LibraryAutoGenList
:
1018 FixedAtBuildPcds
= {}
1019 ShareFixedAtBuildPcdsSameValue
= {}
1020 for Module
in LibAuto
._ReferenceModules
:
1021 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
1022 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1023 if key
not in FixedAtBuildPcds
:
1024 ShareFixedAtBuildPcdsSameValue
[key
] = True
1025 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
1027 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
1028 ShareFixedAtBuildPcdsSameValue
[key
] = False
1029 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1030 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1031 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1034 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
1035 if DscPcd
.Type
!= "FixedAtBuild":
1037 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1038 LibAuto
.ConstPcd
[key
] = Pcd
.DefaultValue
1040 ## Collect dynamic PCDs
1042 # Gather dynamic PCDs list from each module and their settings from platform
1043 # This interface should be invoked explicitly when platform action is created.
1045 def CollectPlatformDynamicPcds(self
):
1046 # Override the platform Pcd's value by build option
1047 if GlobalData
.BuildOptionPcd
:
1048 for key
in self
.Platform
.Pcds
:
1049 PlatformPcd
= self
.Platform
.Pcds
[key
]
1050 for PcdItem
in GlobalData
.BuildOptionPcd
:
1051 if (PlatformPcd
.TokenSpaceGuidCName
, PlatformPcd
.TokenCName
) == (PcdItem
[0], PcdItem
[1]):
1052 PlatformPcd
.DefaultValue
= PcdItem
[2]
1053 if PlatformPcd
.SkuInfoList
:
1054 Sku
= PlatformPcd
.SkuInfoList
[PlatformPcd
.SkuInfoList
.keys()[0]]
1055 Sku
.DefaultValue
= PcdItem
[2]
1058 # for gathering error information
1059 NoDatumTypePcdList
= set()
1061 self
._GuidValue
= {}
1063 for InfName
in self
._AsBuildInfList
:
1064 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1065 FdfModuleList
.append(os
.path
.normpath(InfName
))
1066 for F
in self
.Platform
.Modules
.keys():
1067 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1068 #GuidValue.update(M.Guids)
1070 self
.Platform
.Modules
[F
].M
= M
1072 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1073 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1074 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1075 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1077 # Check the PCD from Binary INF or Source INF
1078 if M
.IsBinaryModule
== True:
1079 PcdFromModule
.IsFromBinaryInf
= True
1081 # Check the PCD from DSC or not
1082 if (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
.keys():
1083 PcdFromModule
.IsFromDsc
= True
1085 PcdFromModule
.IsFromDsc
= False
1086 if PcdFromModule
.Type
in GenC
.gDynamicPcd
or PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1087 if F
.Path
not in FdfModuleList
:
1088 # If one of the Source built modules listed in the DSC is not listed
1089 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1090 # access method (it is only listed in the DEC file that declares the
1091 # PCD as PcdsDynamic), then build tool will report warning message
1092 # notify the PI that they are attempting to build a module that must
1093 # be included in a flash image in order to be functional. These Dynamic
1094 # PCD will not be added into the Database unless it is used by other
1095 # modules that are included in the FDF file.
1096 if PcdFromModule
.Type
in GenC
.gDynamicPcd
and \
1097 PcdFromModule
.IsFromBinaryInf
== False:
1098 # Print warning message to let the developer make a determine.
1099 if PcdFromModule
not in PcdNotInDb
:
1100 PcdNotInDb
.append(PcdFromModule
)
1102 # If one of the Source built modules listed in the DSC is not listed in
1103 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1104 # access method (it is only listed in the DEC file that declares the
1105 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1106 # PCD to the Platform's PCD Database.
1107 if PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1108 if PcdFromModule
not in PcdNotInDb
:
1109 PcdNotInDb
.append(PcdFromModule
)
1112 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1113 # it should be stored in Pcd PEI database, If a dynamic only
1114 # used by DXE module, it should be stored in DXE PCD database.
1115 # The default Phase is DXE
1117 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1118 PcdFromModule
.Phase
= "PEI"
1119 if PcdFromModule
not in self
._DynaPcdList
_:
1120 self
._DynaPcdList
_.append(PcdFromModule
)
1121 elif PcdFromModule
.Phase
== 'PEI':
1122 # overwrite any the same PCD existing, if Phase is PEI
1123 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1124 self
._DynaPcdList
_[Index
] = PcdFromModule
1125 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1126 self
._NonDynaPcdList
_.append(PcdFromModule
)
1127 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1128 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1129 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1130 #The PCD from Binary INF will override the same one from source INF
1131 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1132 PcdFromModule
.Pending
= False
1133 self
._NonDynaPcdList
_.append (PcdFromModule
)
1134 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1136 for ModuleInf
in self
.Platform
.Modules
.keys():
1137 DscModuleList
.append (os
.path
.normpath(ModuleInf
.Path
))
1138 # add the PCD from modules that listed in FDF but not in DSC to Database
1139 for InfName
in FdfModuleList
:
1140 if InfName
not in DscModuleList
:
1141 InfClass
= PathClass(InfName
)
1142 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1143 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1144 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1145 # For binary module, if in current arch, we need to list the PCDs into database.
1146 if not M
.IsSupportedArch
:
1148 # Override the module PCD setting by platform setting
1149 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1150 for PcdFromModule
in ModulePcdList
:
1151 PcdFromModule
.IsFromBinaryInf
= True
1152 PcdFromModule
.IsFromDsc
= False
1153 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1154 if PcdFromModule
.Type
not in GenC
.gDynamicExPcd
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1155 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1157 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1158 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1159 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1160 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1161 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1162 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1163 PcdFromModule
.Phase
= "PEI"
1164 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1165 self
._DynaPcdList
_.append(PcdFromModule
)
1166 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1167 self
._NonDynaPcdList
_.append(PcdFromModule
)
1168 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1169 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1170 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1171 # module & DXE module at a same time.
1172 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1173 # INF file as DynamicEx.
1174 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1175 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1176 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1177 for PcdFromModule
in self
._NonDynaPcdList
_:
1178 # If a PCD is not listed in the DSC file, but binary INF files used by
1179 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1180 # section, AND all source INF files used by this platform the build
1181 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1182 # section, then the tools must NOT add the PCD to the Platform's PCD
1183 # Database; the build must assign the access method for this PCD as
1184 # PcdsPatchableInModule.
1185 if PcdFromModule
not in self
._DynaPcdList
_:
1187 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1188 if PcdFromModule
.IsFromDsc
== False and \
1189 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1190 PcdFromModule
.IsFromBinaryInf
== True and \
1191 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1192 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1193 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1195 # print out error information and break the build, if error found
1196 if len(NoDatumTypePcdList
) > 0:
1197 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1198 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1200 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1201 % NoDatumTypePcdListString
)
1202 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1203 self
._DynamicPcdList
= self
._DynaPcdList
_
1205 # Sort dynamic PCD list to:
1206 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1207 # try to be put header of dynamicd List
1208 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1210 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1212 UnicodePcdArray
= []
1216 VpdFile
= VpdInfoFile
.VpdInfoFile()
1217 NeedProcessVpdMapFile
= False
1219 for pcd
in self
.Platform
.Pcds
.keys():
1220 if pcd
not in self
._PlatformPcds
.keys():
1221 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
1223 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1224 for Pcd
in self
._DynamicPcdList
:
1225 # just pick the a value to determine whether is unicode string type
1226 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1227 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1229 PcdValue
= Sku
.DefaultValue
1230 if Pcd
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1231 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1232 UnicodePcdArray
.append(Pcd
)
1233 elif len(Sku
.VariableName
) > 0:
1234 # if found HII type PCD then insert to right of UnicodeIndex
1235 HiiPcdArray
.append(Pcd
)
1237 OtherPcdArray
.append(Pcd
)
1238 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1239 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1241 PlatformPcds
= self
._PlatformPcds
.keys()
1244 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1246 for PcdKey
in PlatformPcds
:
1247 Pcd
= self
._PlatformPcds
[PcdKey
]
1248 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1249 PcdKey
in VpdPcdDict
:
1250 Pcd
= VpdPcdDict
[PcdKey
]
1251 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1252 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1253 PcdValue
= Sku
.DefaultValue
1255 PcdValue
= Pcd
.DefaultValue
1256 if Sku
.VpdOffset
!= '*':
1257 if PcdValue
.startswith("{"):
1259 elif PcdValue
.startswith("L"):
1264 VpdOffset
= int(Sku
.VpdOffset
)
1267 VpdOffset
= int(Sku
.VpdOffset
, 16)
1269 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1270 if VpdOffset
% Alignment
!= 0:
1271 if PcdValue
.startswith("{"):
1272 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1274 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1275 VpdFile
.Add(Pcd
, Sku
.VpdOffset
)
1276 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1277 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1278 NeedProcessVpdMapFile
= True
1279 if self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== '':
1280 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1281 "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.")
1285 # Fix the PCDs define in VPD PCD section that never referenced by module.
1286 # An example is PCD for signature usage.
1288 for DscPcd
in PlatformPcds
:
1289 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
1290 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1291 if not (self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== ''):
1293 for VpdPcd
in VpdFile
._VpdArray
.keys():
1294 # This PCD has been referenced by module
1295 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1296 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1299 # Not found, it should be signature
1301 # just pick the a value to determine whether is unicode string type
1302 for (SkuName
,Sku
) in DscPcdEntry
.SkuInfoList
.items():
1303 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1305 # Need to iterate DEC pcd information to get the value & datumtype
1306 for eachDec
in self
.PackageList
:
1307 for DecPcd
in eachDec
.Pcds
:
1308 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1309 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1310 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1311 # Print warning message to let the developer make a determine.
1312 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1313 File
=self
.MetaFile
, \
1314 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1315 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1317 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1318 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1319 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1320 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1321 # Only fix the value while no value provided in DSC file.
1322 if (Sku
.DefaultValue
== "" or Sku
.DefaultValue
==None):
1323 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1325 if DscPcdEntry
not in self
._DynamicPcdList
:
1326 self
._DynamicPcdList
.append(DscPcdEntry
)
1327 # Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]
1328 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1329 PcdValue
= Sku
.DefaultValue
1331 PcdValue
= DscPcdEntry
.DefaultValue
1332 if Sku
.VpdOffset
!= '*':
1333 if PcdValue
.startswith("{"):
1335 elif PcdValue
.startswith("L"):
1340 VpdOffset
= int(Sku
.VpdOffset
)
1343 VpdOffset
= int(Sku
.VpdOffset
, 16)
1345 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1346 if VpdOffset
% Alignment
!= 0:
1347 if PcdValue
.startswith("{"):
1348 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1350 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1351 VpdFile
.Add(DscPcdEntry
, Sku
.VpdOffset
)
1352 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1353 NeedProcessVpdMapFile
= True
1354 if DscPcdEntry
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1355 UnicodePcdArray
.append(DscPcdEntry
)
1356 elif len(Sku
.VariableName
) > 0:
1357 HiiPcdArray
.append(DscPcdEntry
)
1359 OtherPcdArray
.append(DscPcdEntry
)
1361 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1365 if (self
.Platform
.FlashDefinition
== None or self
.Platform
.FlashDefinition
== '') and \
1366 VpdFile
.GetCount() != 0:
1367 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1368 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1370 if VpdFile
.GetCount() != 0:
1371 FvPath
= os
.path
.join(self
.BuildDir
, "FV")
1372 if not os
.path
.exists(FvPath
):
1376 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1378 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1380 if VpdFile
.Write(VpdFilePath
):
1381 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1383 for ToolDef
in self
.ToolDefinition
.values():
1384 if ToolDef
.has_key("GUID") and ToolDef
["GUID"] == self
.Platform
.VpdToolGuid
:
1385 if not ToolDef
.has_key("PATH"):
1386 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1387 BPDGToolName
= ToolDef
["PATH"]
1389 # Call third party GUID BPDG tool.
1390 if BPDGToolName
!= None:
1391 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1393 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.")
1395 # Process VPD map file generated by third party BPDG tool
1396 if NeedProcessVpdMapFile
:
1397 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1398 if os
.path
.exists(VpdMapFilePath
):
1399 VpdFile
.Read(VpdMapFilePath
)
1402 for Pcd
in self
._DynamicPcdList
:
1403 # just pick the a value to determine whether is unicode string type
1405 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1406 if Sku
.VpdOffset
== "*":
1407 Sku
.VpdOffset
= VpdFile
.GetOffset(Pcd
)[i
].strip()
1410 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1412 # Delete the DynamicPcdList At the last time enter into this function
1413 del self
._DynamicPcdList
[:]
1414 self
._DynamicPcdList
.extend(UnicodePcdArray
)
1415 self
._DynamicPcdList
.extend(HiiPcdArray
)
1416 self
._DynamicPcdList
.extend(OtherPcdArray
)
1417 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1419 ## Return the platform build data object
1420 def _GetPlatform(self
):
1421 if self
._Platform
== None:
1422 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1423 return self
._Platform
1425 ## Return platform name
1427 return self
.Platform
.PlatformName
1429 ## Return the meta file GUID
1431 return self
.Platform
.Guid
1433 ## Return the platform version
1434 def _GetVersion(self
):
1435 return self
.Platform
.Version
1437 ## Return the FDF file name
1438 def _GetFdfFile(self
):
1439 if self
._FdfFile
== None:
1440 if self
.Workspace
.FdfFile
!= "":
1441 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1444 return self
._FdfFile
1446 ## Return the build output directory platform specifies
1447 def _GetOutputDir(self
):
1448 return self
.Platform
.OutputDirectory
1450 ## Return the directory to store all intermediate and final files built
1451 def _GetBuildDir(self
):
1452 if self
._BuildDir
== None:
1453 if os
.path
.isabs(self
.OutputDir
):
1454 self
._BuildDir
= path
.join(
1455 path
.abspath(self
.OutputDir
),
1456 self
.BuildTarget
+ "_" + self
.ToolChain
,
1459 self
._BuildDir
= path
.join(
1462 self
.BuildTarget
+ "_" + self
.ToolChain
,
1464 return self
._BuildDir
1466 ## Return directory of platform makefile
1468 # @retval string Makefile directory
1470 def _GetMakeFileDir(self
):
1471 if self
._MakeFileDir
== None:
1472 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1473 return self
._MakeFileDir
1475 ## Return build command string
1477 # @retval string Build command string
1479 def _GetBuildCommand(self
):
1480 if self
._BuildCommand
== None:
1481 self
._BuildCommand
= []
1482 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1483 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1484 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1485 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1487 self
._BuildCommand
+= SplitOption(NewOption
)
1488 return self
._BuildCommand
1490 ## Get tool chain definition
1492 # Get each tool defition for given tool chain from tools_def.txt and platform
1494 def _GetToolDefinition(self
):
1495 if self
._ToolDefinitions
== None:
1496 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1497 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1498 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1499 ExtraData
="[%s]" % self
.MetaFile
)
1500 self
._ToolDefinitions
= {}
1502 for Def
in ToolDefinition
:
1503 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1504 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1507 Value
= ToolDefinition
[Def
]
1508 # don't record the DLL
1510 DllPathList
.add(Value
)
1513 if Tool
not in self
._ToolDefinitions
:
1514 self
._ToolDefinitions
[Tool
] = {}
1515 self
._ToolDefinitions
[Tool
][Attr
] = Value
1519 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1520 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1521 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1522 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1524 for Tool
in self
._ToolDefinitions
:
1525 for Attr
in self
._ToolDefinitions
[Tool
]:
1526 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1527 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1528 # check if override is indicated
1529 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1530 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1532 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1535 # Don't put MAKE definition in the file
1539 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1541 # Don't put MAKE definition in the file
1546 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1549 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1550 for DllPath
in DllPathList
:
1551 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1552 os
.environ
["MAKE_FLAGS"] = MakeFlags
1554 return self
._ToolDefinitions
1556 ## Return the paths of tools
1557 def _GetToolDefFile(self
):
1558 if self
._ToolDefFile
== None:
1559 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1560 return self
._ToolDefFile
1562 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1563 def _GetToolChainFamily(self
):
1564 if self
._ToolChainFamily
== None:
1565 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1566 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1567 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1568 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1569 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1571 self
._ToolChainFamily
= "MSFT"
1573 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1574 return self
._ToolChainFamily
1576 def _GetBuildRuleFamily(self
):
1577 if self
._BuildRuleFamily
== None:
1578 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1579 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1580 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1581 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1582 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1584 self
._BuildRuleFamily
= "MSFT"
1586 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1587 return self
._BuildRuleFamily
1589 ## Return the build options specific for all modules in this platform
1590 def _GetBuildOptions(self
):
1591 if self
._BuildOption
== None:
1592 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1593 return self
._BuildOption
1595 ## Return the build options specific for EDK modules in this platform
1596 def _GetEdkBuildOptions(self
):
1597 if self
._EdkBuildOption
== None:
1598 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1599 return self
._EdkBuildOption
1601 ## Return the build options specific for EDKII modules in this platform
1602 def _GetEdkIIBuildOptions(self
):
1603 if self
._EdkIIBuildOption
== None:
1604 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1605 return self
._EdkIIBuildOption
1607 ## Parse build_rule.txt in Conf Directory.
1609 # @retval BuildRule object
1611 def _GetBuildRule(self
):
1612 if self
._BuildRule
== None:
1613 BuildRuleFile
= None
1614 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1615 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1616 if BuildRuleFile
in [None, '']:
1617 BuildRuleFile
= gDefaultBuildRuleFile
1618 self
._BuildRule
= BuildRule(BuildRuleFile
)
1619 if self
._BuildRule
._FileVersion
== "":
1620 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
1622 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1623 # If Build Rule's version is less than the version number required by the tools, halting the build.
1624 EdkLogger
.error("build", AUTOGEN_ERROR
,
1625 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])"\
1626 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1628 return self
._BuildRule
1630 ## Summarize the packages used by modules in this platform
1631 def _GetPackageList(self
):
1632 if self
._PackageList
== None:
1633 self
._PackageList
= set()
1634 for La
in self
.LibraryAutoGenList
:
1635 self
._PackageList
.update(La
.DependentPackageList
)
1636 for Ma
in self
.ModuleAutoGenList
:
1637 self
._PackageList
.update(Ma
.DependentPackageList
)
1638 #Collect package set information from INF of FDF
1640 for ModuleFile
in self
._AsBuildModuleList
:
1641 if ModuleFile
in self
.Platform
.Modules
:
1643 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1644 PkgSet
.update(ModuleData
.Packages
)
1645 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
1646 return self
._PackageList
1648 def _GetNonDynamicPcdDict(self
):
1649 if self
._NonDynamicPcdDict
:
1650 return self
._NonDynamicPcdDict
1651 for Pcd
in self
.NonDynamicPcdList
:
1652 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
1653 return self
._NonDynamicPcdDict
1655 ## Get list of non-dynamic PCDs
1656 def _GetNonDynamicPcdList(self
):
1657 if self
._NonDynamicPcdList
== None:
1658 self
.CollectPlatformDynamicPcds()
1659 return self
._NonDynamicPcdList
1661 ## Get list of dynamic PCDs
1662 def _GetDynamicPcdList(self
):
1663 if self
._DynamicPcdList
== None:
1664 self
.CollectPlatformDynamicPcds()
1665 return self
._DynamicPcdList
1667 ## Generate Token Number for all PCD
1668 def _GetPcdTokenNumbers(self
):
1669 if self
._PcdTokenNumber
== None:
1670 self
._PcdTokenNumber
= sdict()
1673 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1677 # TokenNumber 0 ~ 10
1679 # TokeNumber 11 ~ 20
1681 for Pcd
in self
.DynamicPcdList
:
1682 if Pcd
.Phase
== "PEI":
1683 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1684 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1685 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1688 for Pcd
in self
.DynamicPcdList
:
1689 if Pcd
.Phase
== "PEI":
1690 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1691 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1692 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1695 for Pcd
in self
.DynamicPcdList
:
1696 if Pcd
.Phase
== "DXE":
1697 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1698 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1699 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1702 for Pcd
in self
.DynamicPcdList
:
1703 if Pcd
.Phase
== "DXE":
1704 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1705 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1706 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1709 for Pcd
in self
.NonDynamicPcdList
:
1710 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1712 return self
._PcdTokenNumber
1714 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
1715 def _GetAutoGenObjectList(self
):
1716 self
._ModuleAutoGenList
= []
1717 self
._LibraryAutoGenList
= []
1718 for ModuleFile
in self
.Platform
.Modules
:
1727 if Ma
not in self
._ModuleAutoGenList
:
1728 self
._ModuleAutoGenList
.append(Ma
)
1729 for La
in Ma
.LibraryAutoGenList
:
1730 if La
not in self
._LibraryAutoGenList
:
1731 self
._LibraryAutoGenList
.append(La
)
1732 if Ma
not in La
._ReferenceModules
:
1733 La
._ReferenceModules
.append(Ma
)
1735 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
1736 def _GetModuleAutoGenList(self
):
1737 if self
._ModuleAutoGenList
== None:
1738 self
._GetAutoGenObjectList
()
1739 return self
._ModuleAutoGenList
1741 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
1742 def _GetLibraryAutoGenList(self
):
1743 if self
._LibraryAutoGenList
== None:
1744 self
._GetAutoGenObjectList
()
1745 return self
._LibraryAutoGenList
1747 ## Test if a module is supported by the platform
1749 # An error will be raised directly if the module or its arch is not supported
1750 # by the platform or current configuration
1752 def ValidModule(self
, Module
):
1753 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
1754 or Module
in self
._AsBuildModuleList
1756 ## Resolve the library classes in a module to library instances
1758 # This method will not only resolve library classes but also sort the library
1759 # instances according to the dependency-ship.
1761 # @param Module The module from which the library classes will be resolved
1763 # @retval library_list List of library instances sorted
1765 def ApplyLibraryInstance(self
, Module
):
1766 ModuleType
= Module
.ModuleType
1768 # for overridding library instances with module specific setting
1769 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
1771 # add forced library instances (specified under LibraryClasses sections)
1773 # If a module has a MODULE_TYPE of USER_DEFINED,
1774 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
1776 if Module
.ModuleType
!= SUP_MODULE_USER_DEFINED
:
1777 for LibraryClass
in self
.Platform
.LibraryClasses
.GetKeys():
1778 if LibraryClass
.startswith("NULL") and self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]:
1779 Module
.LibraryClasses
[LibraryClass
] = self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]
1781 # add forced library instances (specified in module overrides)
1782 for LibraryClass
in PlatformModule
.LibraryClasses
:
1783 if LibraryClass
.startswith("NULL"):
1784 Module
.LibraryClasses
[LibraryClass
] = PlatformModule
.LibraryClasses
[LibraryClass
]
1787 LibraryConsumerList
= [Module
]
1789 ConsumedByList
= sdict()
1790 LibraryInstance
= sdict()
1792 EdkLogger
.verbose("")
1793 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
1794 while len(LibraryConsumerList
) > 0:
1795 M
= LibraryConsumerList
.pop()
1796 for LibraryClassName
in M
.LibraryClasses
:
1797 if LibraryClassName
not in LibraryInstance
:
1798 # override library instance for this module
1799 if LibraryClassName
in PlatformModule
.LibraryClasses
:
1800 LibraryPath
= PlatformModule
.LibraryClasses
[LibraryClassName
]
1802 LibraryPath
= self
.Platform
.LibraryClasses
[LibraryClassName
, ModuleType
]
1803 if LibraryPath
== None or LibraryPath
== "":
1804 LibraryPath
= M
.LibraryClasses
[LibraryClassName
]
1805 if LibraryPath
== None or LibraryPath
== "":
1806 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
1807 "Instance of library class [%s] is not found" % LibraryClassName
,
1809 ExtraData
="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M
), self
.Arch
, str(Module
)))
1811 LibraryModule
= self
.BuildDatabase
[LibraryPath
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1812 # for those forced library instance (NULL library), add a fake library class
1813 if LibraryClassName
.startswith("NULL"):
1814 LibraryModule
.LibraryClass
.append(LibraryClassObject(LibraryClassName
, [ModuleType
]))
1815 elif LibraryModule
.LibraryClass
== None \
1816 or len(LibraryModule
.LibraryClass
) == 0 \
1817 or (ModuleType
!= 'USER_DEFINED'
1818 and ModuleType
not in LibraryModule
.LibraryClass
[0].SupModList
):
1819 # only USER_DEFINED can link against any library instance despite of its SupModList
1820 EdkLogger
.error("build", OPTION_MISSING
,
1821 "Module type [%s] is not supported by library instance [%s]" \
1822 % (ModuleType
, LibraryPath
), File
=self
.MetaFile
,
1823 ExtraData
="consumed by [%s]" % str(Module
))
1825 LibraryInstance
[LibraryClassName
] = LibraryModule
1826 LibraryConsumerList
.append(LibraryModule
)
1827 EdkLogger
.verbose("\t" + str(LibraryClassName
) + " : " + str(LibraryModule
))
1829 LibraryModule
= LibraryInstance
[LibraryClassName
]
1831 if LibraryModule
== None:
1834 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
1835 Constructor
.append(LibraryModule
)
1837 if LibraryModule
not in ConsumedByList
:
1838 ConsumedByList
[LibraryModule
] = []
1839 # don't add current module itself to consumer list
1841 if M
in ConsumedByList
[LibraryModule
]:
1843 ConsumedByList
[LibraryModule
].append(M
)
1845 # Initialize the sorted output list to the empty set
1847 SortedLibraryList
= []
1849 # Q <- Set of all nodes with no incoming edges
1851 LibraryList
= [] #LibraryInstance.values()
1853 for LibraryClassName
in LibraryInstance
:
1854 M
= LibraryInstance
[LibraryClassName
]
1855 LibraryList
.append(M
)
1856 if ConsumedByList
[M
] == []:
1860 # start the DAG algorithm
1864 while Q
== [] and EdgeRemoved
:
1866 # for each node Item with a Constructor
1867 for Item
in LibraryList
:
1868 if Item
not in Constructor
:
1870 # for each Node without a constructor with an edge e from Item to Node
1871 for Node
in ConsumedByList
[Item
]:
1872 if Node
in Constructor
:
1874 # remove edge e from the graph if Node has no constructor
1875 ConsumedByList
[Item
].remove(Node
)
1877 if ConsumedByList
[Item
] == []:
1878 # insert Item into Q
1883 # DAG is done if there's no more incoming edge for all nodes
1887 # remove node from Q
1890 SortedLibraryList
.append(Node
)
1892 # for each node Item with an edge e from Node to Item do
1893 for Item
in LibraryList
:
1894 if Node
not in ConsumedByList
[Item
]:
1896 # remove edge e from the graph
1897 ConsumedByList
[Item
].remove(Node
)
1899 if ConsumedByList
[Item
] != []:
1901 # insert Item into Q, if Item has no other incoming edges
1905 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
1907 for Item
in LibraryList
:
1908 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
1909 ErrorMessage
= "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]])
1910 EdkLogger
.error("build", BUILD_ERROR
, 'Library [%s] with constructors has a cycle' % str(Item
),
1911 ExtraData
=ErrorMessage
, File
=self
.MetaFile
)
1912 if Item
not in SortedLibraryList
:
1913 SortedLibraryList
.append(Item
)
1916 # Build the list of constructor and destructir names
1917 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
1919 SortedLibraryList
.reverse()
1920 return SortedLibraryList
1923 ## Override PCD setting (type, value, ...)
1925 # @param ToPcd The PCD to be overrided
1926 # @param FromPcd The PCD overrideing from
1928 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
=""):
1930 # in case there's PCDs coming from FDF file, which have no type given.
1931 # at this point, ToPcd.Type has the type found from dependent
1935 if ToPcd
.Pending
and FromPcd
.Type
not in [None, '']:
1936 ToPcd
.Type
= FromPcd
.Type
1937 elif (ToPcd
.Type
not in [None, '']) and (FromPcd
.Type
not in [None, ''])\
1938 and (ToPcd
.Type
!= FromPcd
.Type
) and (ToPcd
.Type
in FromPcd
.Type
):
1939 if ToPcd
.Type
.strip() == "DynamicEx":
1940 ToPcd
.Type
= FromPcd
.Type
1941 elif ToPcd
.Type
not in [None, ''] and FromPcd
.Type
not in [None, ''] \
1942 and ToPcd
.Type
!= FromPcd
.Type
:
1943 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
1944 ExtraData
="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
1945 % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
,
1946 ToPcd
.Type
, Module
, FromPcd
.Type
),
1949 if FromPcd
.MaxDatumSize
not in [None, '']:
1950 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
1951 if FromPcd
.DefaultValue
not in [None, '']:
1952 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
1953 if FromPcd
.TokenValue
not in [None, '']:
1954 ToPcd
.TokenValue
= FromPcd
.TokenValue
1955 if FromPcd
.MaxDatumSize
not in [None, '']:
1956 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
1957 if FromPcd
.DatumType
not in [None, '']:
1958 ToPcd
.DatumType
= FromPcd
.DatumType
1959 if FromPcd
.SkuInfoList
not in [None, '', []]:
1960 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
1962 # check the validation of datum
1963 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
1965 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
1966 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
))
1967 ToPcd
.validateranges
= FromPcd
.validateranges
1968 ToPcd
.validlists
= FromPcd
.validlists
1969 ToPcd
.expressions
= FromPcd
.expressions
1971 if ToPcd
.DatumType
== "VOID*" and ToPcd
.MaxDatumSize
in ['', None]:
1972 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
1973 % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
))
1974 Value
= ToPcd
.DefaultValue
1975 if Value
in [None, '']:
1976 ToPcd
.MaxDatumSize
= '1'
1977 elif Value
[0] == 'L':
1978 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
1979 elif Value
[0] == '{':
1980 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
1982 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
1984 # apply default SKU for dynamic PCDS if specified one is not available
1985 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_LIST
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_LIST
) \
1986 and ToPcd
.SkuInfoList
in [None, {}, '']:
1987 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
1988 SkuName
= self
.Platform
.SkuName
1991 ToPcd
.SkuInfoList
= {
1992 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
], '', '', '', '', '', ToPcd
.DefaultValue
)
1995 ## Apply PCD setting defined platform to a module
1997 # @param Module The module from which the PCD setting will be overrided
1999 # @retval PCD_list The list PCDs with settings from platform
2001 def ApplyPcdSetting(self
, Module
, Pcds
):
2002 # for each PCD in module
2003 for Name
, Guid
in Pcds
:
2004 PcdInModule
= Pcds
[Name
, Guid
]
2005 # find out the PCD setting in platform
2006 if (Name
, Guid
) in self
.Platform
.Pcds
:
2007 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2009 PcdInPlatform
= None
2010 # then override the settings if any
2011 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
)
2012 # resolve the VariableGuid value
2013 for SkuId
in PcdInModule
.SkuInfoList
:
2014 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2015 if Sku
.VariableGuid
== '': continue
2016 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
)
2017 if Sku
.VariableGuidValue
== None:
2018 PackageList
= "\n\t".join([str(P
) for P
in self
.PackageList
])
2021 RESOURCE_NOT_AVAILABLE
,
2022 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2023 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2024 % (Guid
, Name
, str(Module
)),
2028 # override PCD settings with module specific setting
2029 if Module
in self
.Platform
.Modules
:
2030 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2031 for Key
in PlatformModule
.Pcds
:
2033 self
._OverridePcd
(Pcds
[Key
], PlatformModule
.Pcds
[Key
], Module
)
2034 return Pcds
.values()
2036 ## Resolve library names to library modules
2038 # (for Edk.x modules)
2040 # @param Module The module from which the library names will be resolved
2042 # @retval library_list The list of library modules
2044 def ResolveLibraryReference(self
, Module
):
2045 EdkLogger
.verbose("")
2046 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2047 LibraryConsumerList
= [Module
]
2049 # "CompilerStub" is a must for Edk modules
2050 if Module
.Libraries
:
2051 Module
.Libraries
.append("CompilerStub")
2053 while len(LibraryConsumerList
) > 0:
2054 M
= LibraryConsumerList
.pop()
2055 for LibraryName
in M
.Libraries
:
2056 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2058 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
2059 if LibraryName
.upper() == Key
.upper():
2060 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2063 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2064 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2067 if Library
not in LibraryList
:
2068 LibraryList
.append(Library
)
2069 LibraryConsumerList
.append(Library
)
2070 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2073 ## Calculate the priority value of the build option
2075 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2077 # @retval Value Priority value based on the priority list.
2079 def CalculatePriorityValue(self
, Key
):
2080 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2081 PriorityValue
= 0x11111
2083 PriorityValue
&= 0x01111
2084 if ToolChain
== "*":
2085 PriorityValue
&= 0x10111
2087 PriorityValue
&= 0x11011
2088 if CommandType
== "*":
2089 PriorityValue
&= 0x11101
2091 PriorityValue
&= 0x11110
2093 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2096 ## Expand * in build option key
2098 # @param Options Options to be expanded
2100 # @retval options Options expanded
2102 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2109 # Construct a list contain the build options which need override.
2113 # Key[0] -- tool family
2114 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2116 if (Key
[0] == self
.BuildRuleFamily
and
2117 (ModuleStyle
== None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2118 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2119 if Target
== self
.BuildTarget
or Target
== "*":
2120 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
2121 if Arch
== self
.Arch
or Arch
== "*":
2122 if Options
[Key
].startswith("="):
2123 if OverrideList
.get(Key
[1]) != None:
2124 OverrideList
.pop(Key
[1])
2125 OverrideList
[Key
[1]] = Options
[Key
]
2128 # Use the highest priority value.
2130 if (len(OverrideList
) >= 2):
2131 KeyList
= OverrideList
.keys()
2132 for Index
in range(len(KeyList
)):
2133 NowKey
= KeyList
[Index
]
2134 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2135 for Index1
in range(len(KeyList
) - Index
- 1):
2136 NextKey
= KeyList
[Index1
+ Index
+ 1]
2138 # Compare two Key, if one is included by another, choose the higher priority one
2140 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2141 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2142 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2143 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2144 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2145 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2146 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2147 if Options
.get((self
.BuildRuleFamily
, NextKey
)) != None:
2148 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2150 if Options
.get((self
.BuildRuleFamily
, NowKey
)) != None:
2151 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2154 if ModuleStyle
!= None and len (Key
) > 2:
2155 # Check Module style is EDK or EDKII.
2156 # Only append build option for the matched style module.
2157 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2159 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2162 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2163 # if tool chain family doesn't match, skip it
2164 if Tool
in self
.ToolDefinition
and Family
!= "":
2165 FamilyIsNull
= False
2166 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2167 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2169 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2172 # expand any wildcard
2173 if Target
== "*" or Target
== self
.BuildTarget
:
2174 if Tag
== "*" or Tag
== self
.ToolChain
:
2175 if Arch
== "*" or Arch
== self
.Arch
:
2176 if Tool
not in BuildOptions
:
2177 BuildOptions
[Tool
] = {}
2178 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2179 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2181 # append options for the same tool
2182 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2183 # Build Option Family has been checked, which need't to be checked again for family.
2184 if FamilyMatch
or FamilyIsNull
:
2188 if ModuleStyle
!= None and len (Key
) > 2:
2189 # Check Module style is EDK or EDKII.
2190 # Only append build option for the matched style module.
2191 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2193 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2196 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2197 # if tool chain family doesn't match, skip it
2198 if Tool
not in self
.ToolDefinition
or Family
== "":
2200 # option has been added before
2201 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2204 # expand any wildcard
2205 if Target
== "*" or Target
== self
.BuildTarget
:
2206 if Tag
== "*" or Tag
== self
.ToolChain
:
2207 if Arch
== "*" or Arch
== self
.Arch
:
2208 if Tool
not in BuildOptions
:
2209 BuildOptions
[Tool
] = {}
2210 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2211 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2213 # append options for the same tool
2214 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2217 ## Append build options in platform to a module
2219 # @param Module The module to which the build options will be appened
2221 # @retval options The options appended with build options in platform
2223 def ApplyBuildOption(self
, Module
):
2224 # Get the different options for the different style module
2225 if Module
.AutoGenVersion
< 0x00010005:
2226 PlatformOptions
= self
.EdkBuildOption
2227 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2229 PlatformOptions
= self
.EdkIIBuildOption
2230 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2231 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2232 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2233 if Module
in self
.Platform
.Modules
:
2234 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2235 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2237 PlatformModuleOptions
= {}
2239 BuildRuleOrder
= None
2240 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2241 for Tool
in Options
:
2242 for Attr
in Options
[Tool
]:
2243 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2244 BuildRuleOrder
= Options
[Tool
][Attr
]
2246 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2247 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2248 self
.ToolDefinition
.keys())
2250 for Tool
in AllTools
:
2251 if Tool
not in BuildOptions
:
2252 BuildOptions
[Tool
] = {}
2254 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2255 if Tool
not in Options
:
2257 for Attr
in Options
[Tool
]:
2258 Value
= Options
[Tool
][Attr
]
2260 # Do not generate it in Makefile
2262 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2264 if Attr
not in BuildOptions
[Tool
]:
2265 BuildOptions
[Tool
][Attr
] = ""
2266 # check if override is indicated
2267 if Value
.startswith('='):
2268 ToolPath
= Value
[1:]
2269 ToolPath
= mws
.handleWsMacro(ToolPath
)
2270 BuildOptions
[Tool
][Attr
] = ToolPath
2272 Value
= mws
.handleWsMacro(Value
)
2273 BuildOptions
[Tool
][Attr
] += " " + Value
2274 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
!= None:
2276 # Override UNI flag only for EDK module.
2278 if 'BUILD' not in BuildOptions
:
2279 BuildOptions
['BUILD'] = {}
2280 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2281 return BuildOptions
, BuildRuleOrder
2283 Platform
= property(_GetPlatform
)
2284 Name
= property(_GetName
)
2285 Guid
= property(_GetGuid
)
2286 Version
= property(_GetVersion
)
2288 OutputDir
= property(_GetOutputDir
)
2289 BuildDir
= property(_GetBuildDir
)
2290 MakeFileDir
= property(_GetMakeFileDir
)
2291 FdfFile
= property(_GetFdfFile
)
2293 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2294 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2295 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2296 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2297 PackageList
= property(_GetPackageList
)
2299 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2300 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2301 ToolChainFamily
= property(_GetToolChainFamily
)
2302 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2303 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2304 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2305 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2307 BuildCommand
= property(_GetBuildCommand
)
2308 BuildRule
= property(_GetBuildRule
)
2309 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2310 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2311 GenFdsCommand
= property(_GenFdsCommand
)
2313 ## ModuleAutoGen class
2315 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2316 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2317 # to the [depex] section in module's inf file.
2319 class ModuleAutoGen(AutoGen
):
2320 ## The real constructor of ModuleAutoGen
2322 # This method is not supposed to be called by users of ModuleAutoGen. It's
2323 # only used by factory method __new__() to do real initialization work for an
2324 # object of ModuleAutoGen
2326 # @param Workspace EdkIIWorkspaceBuild object
2327 # @param ModuleFile The path of module file
2328 # @param Target Build target (DEBUG, RELEASE)
2329 # @param Toolchain Name of tool chain
2330 # @param Arch The arch the module supports
2331 # @param PlatformFile Platform meta-file
2333 def _Init(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2334 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2335 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2337 self
.Workspace
= Workspace
2338 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2340 self
.MetaFile
= ModuleFile
2341 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2342 # check if this module is employed by active platform
2343 if not self
.PlatformInfo
.ValidModule(self
.MetaFile
):
2344 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2345 % (self
.MetaFile
, Arch
))
2348 self
.SourceDir
= self
.MetaFile
.SubDir
2349 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2351 self
.SourceOverrideDir
= None
2352 # use overrided path defined in DSC file
2353 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2354 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2356 self
.ToolChain
= Toolchain
2357 self
.BuildTarget
= Target
2359 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2360 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2362 self
.IsMakeFileCreated
= False
2363 self
.IsCodeFileCreated
= False
2364 self
.IsAsBuiltInfCreated
= False
2365 self
.DepexGenerated
= False
2367 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2368 self
.BuildRuleOrder
= None
2373 self
._Version
= None
2374 self
._ModuleType
= None
2375 self
._ComponentType
= None
2376 self
._PcdIsDriver
= None
2377 self
._AutoGenVersion
= None
2378 self
._LibraryFlag
= None
2379 self
._CustomMakefile
= None
2382 self
._BuildDir
= None
2383 self
._OutputDir
= None
2384 self
._DebugDir
= None
2385 self
._MakeFileDir
= None
2387 self
._IncludePathList
= None
2388 self
._IncludePathLength
= 0
2389 self
._AutoGenFileList
= None
2390 self
._UnicodeFileList
= None
2391 self
._SourceFileList
= None
2392 self
._ObjectFileList
= None
2393 self
._BinaryFileList
= None
2395 self
._DependentPackageList
= None
2396 self
._DependentLibraryList
= None
2397 self
._LibraryAutoGenList
= None
2398 self
._DerivedPackageList
= None
2399 self
._ModulePcdList
= None
2400 self
._LibraryPcdList
= None
2401 self
._PcdComments
= sdict()
2402 self
._GuidList
= None
2403 self
._GuidsUsedByPcd
= None
2404 self
._GuidComments
= sdict()
2405 self
._ProtocolList
= None
2406 self
._ProtocolComments
= sdict()
2407 self
._PpiList
= None
2408 self
._PpiComments
= sdict()
2409 self
._DepexList
= None
2410 self
._DepexExpressionList
= None
2411 self
._BuildOption
= None
2412 self
._BuildOptionIncPathList
= None
2413 self
._BuildTargets
= None
2414 self
._IntroBuildTargetList
= None
2415 self
._FinalBuildTargetList
= None
2416 self
._FileTypes
= None
2417 self
._BuildRules
= None
2419 ## The Modules referenced to this Library
2420 # Only Library has this attribute
2421 self
._ReferenceModules
= []
2423 ## Store the FixedAtBuild Pcds
2425 self
._FixedAtBuildPcds
= []
2430 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2432 # Get FixedAtBuild Pcds of this Module
2433 def _GetFixedAtBuildPcds(self
):
2434 if self
._FixedAtBuildPcds
:
2435 return self
._FixedAtBuildPcds
2436 for Pcd
in self
.ModulePcdList
:
2438 if not (Pcd
.Pending
== False and Pcd
.Type
== "FixedAtBuild"):
2440 elif Pcd
.Type
!= "FixedAtBuild":
2442 if Pcd
not in self
._FixedAtBuildPcds
:
2443 self
._FixedAtBuildPcds
.append(Pcd
)
2445 return self
._FixedAtBuildPcds
2447 def _GetUniqueBaseName(self
):
2448 BaseName
= self
.Name
2449 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2450 if Module
.MetaFile
== self
.MetaFile
:
2452 if Module
.Name
== self
.Name
:
2453 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2454 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2455 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2456 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2459 # Macros could be used in build_rule.txt (also Makefile)
2460 def _GetMacros(self
):
2461 if self
._Macro
== None:
2462 self
._Macro
= sdict()
2463 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2464 self
._Macro
["MODULE_NAME" ] = self
.Name
2465 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2466 self
._Macro
["MODULE_GUID" ] = self
.Guid
2467 self
._Macro
["MODULE_VERSION" ] = self
.Version
2468 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2469 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2470 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2471 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2472 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2474 self
._Macro
["BASE_NAME" ] = self
.Name
2476 self
._Macro
["ARCH" ] = self
.Arch
2477 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2478 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2479 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2480 self
._Macro
["TARGET" ] = self
.BuildTarget
2482 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2483 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2484 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2485 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2486 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2487 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2488 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2489 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2490 self
._Macro
["PLATFORM_NAME" ] = self
.PlatformInfo
.Name
2491 self
._Macro
["PLATFORM_GUID" ] = self
.PlatformInfo
.Guid
2492 self
._Macro
["PLATFORM_VERSION" ] = self
.PlatformInfo
.Version
2493 self
._Macro
["PLATFORM_RELATIVE_DIR" ] = self
.PlatformInfo
.SourceDir
2494 self
._Macro
["PLATFORM_DIR" ] = mws
.join(self
.WorkspaceDir
, self
.PlatformInfo
.SourceDir
)
2495 self
._Macro
["PLATFORM_OUTPUT_DIR" ] = self
.PlatformInfo
.OutputDir
2498 ## Return the module build data object
2499 def _GetModule(self
):
2500 if self
._Module
== None:
2501 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2504 ## Return the module name
2505 def _GetBaseName(self
):
2506 return self
.Module
.BaseName
2508 ## Return the module DxsFile if exist
2509 def _GetDxsFile(self
):
2510 return self
.Module
.DxsFile
2512 ## Return the module SourceOverridePath
2513 def _GetSourceOverridePath(self
):
2514 return self
.Module
.SourceOverridePath
2516 ## Return the module meta-file GUID
2519 # To build same module more than once, the module path with FILE_GUID overridden has
2520 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2521 # in DSC. The overridden GUID can be retrieved from file name
2523 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2525 # Length of GUID is 36
2527 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2528 return self
.Module
.Guid
2530 ## Return the module version
2531 def _GetVersion(self
):
2532 return self
.Module
.Version
2534 ## Return the module type
2535 def _GetModuleType(self
):
2536 return self
.Module
.ModuleType
2538 ## Return the component type (for Edk.x style of module)
2539 def _GetComponentType(self
):
2540 return self
.Module
.ComponentType
2542 ## Return the build type
2543 def _GetBuildType(self
):
2544 return self
.Module
.BuildType
2546 ## Return the PCD_IS_DRIVER setting
2547 def _GetPcdIsDriver(self
):
2548 return self
.Module
.PcdIsDriver
2550 ## Return the autogen version, i.e. module meta-file version
2551 def _GetAutoGenVersion(self
):
2552 return self
.Module
.AutoGenVersion
2554 ## Check if the module is library or not
2555 def _IsLibrary(self
):
2556 if self
._LibraryFlag
== None:
2557 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2558 self
._LibraryFlag
= True
2560 self
._LibraryFlag
= False
2561 return self
._LibraryFlag
2563 ## Check if the module is binary module or not
2564 def _IsBinaryModule(self
):
2565 return self
.Module
.IsBinaryModule
2567 ## Return the directory to store intermediate files of the module
2568 def _GetBuildDir(self
):
2569 if self
._BuildDir
== None:
2570 self
._BuildDir
= path
.join(
2571 self
.PlatformInfo
.BuildDir
,
2574 self
.MetaFile
.BaseName
2576 CreateDirectory(self
._BuildDir
)
2577 return self
._BuildDir
2579 ## Return the directory to store the intermediate object files of the mdoule
2580 def _GetOutputDir(self
):
2581 if self
._OutputDir
== None:
2582 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2583 CreateDirectory(self
._OutputDir
)
2584 return self
._OutputDir
2586 ## Return the directory to store auto-gened source files of the mdoule
2587 def _GetDebugDir(self
):
2588 if self
._DebugDir
== None:
2589 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2590 CreateDirectory(self
._DebugDir
)
2591 return self
._DebugDir
2593 ## Return the path of custom file
2594 def _GetCustomMakefile(self
):
2595 if self
._CustomMakefile
== None:
2596 self
._CustomMakefile
= {}
2597 for Type
in self
.Module
.CustomMakefile
:
2598 if Type
in gMakeTypeMap
:
2599 MakeType
= gMakeTypeMap
[Type
]
2602 if self
.SourceOverrideDir
!= None:
2603 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2604 if not os
.path
.exists(File
):
2605 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2607 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2608 self
._CustomMakefile
[MakeType
] = File
2609 return self
._CustomMakefile
2611 ## Return the directory of the makefile
2613 # @retval string The directory string of module's makefile
2615 def _GetMakeFileDir(self
):
2616 return self
.BuildDir
2618 ## Return build command string
2620 # @retval string Build command string
2622 def _GetBuildCommand(self
):
2623 return self
.PlatformInfo
.BuildCommand
2625 ## Get object list of all packages the module and its dependent libraries belong to
2627 # @retval list The list of package object
2629 def _GetDerivedPackageList(self
):
2631 for M
in [self
.Module
] + self
.DependentLibraryList
:
2632 for Package
in M
.Packages
:
2633 if Package
in PackageList
:
2635 PackageList
.append(Package
)
2638 ## Get the depex string
2640 # @return : a string contain all depex expresion.
2641 def _GetDepexExpresionString(self
):
2644 ## DPX_SOURCE IN Define section.
2645 if self
.Module
.DxsFile
:
2647 for M
in [self
.Module
] + self
.DependentLibraryList
:
2648 Filename
= M
.MetaFile
.Path
2649 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2650 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2651 for DepexExpresion
in DepexExpresionList
:
2652 for key
in DepexExpresion
.keys():
2653 Arch
, ModuleType
= key
2654 # the type of build module is USER_DEFINED.
2655 # All different DEPEX section tags would be copied into the As Built INF file
2656 # and there would be separate DEPEX section tags
2657 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2658 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2659 DepexList
.append({(Arch
, ModuleType
): DepexExpresion
[key
][:]})
2661 if Arch
.upper() == TAB_ARCH_COMMON
or \
2662 (Arch
.upper() == self
.Arch
.upper() and \
2663 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2664 DepexList
.append({(Arch
, ModuleType
): DepexExpresion
[key
][:]})
2666 #the type of build module is USER_DEFINED.
2667 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2668 for Depex
in DepexList
:
2669 for key
in Depex
.keys():
2670 DepexStr
+= '[Depex.%s.%s]\n' % key
2671 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
2674 return '[Depex.%s]\n' % self
.Arch
2677 #the type of build module not is USER_DEFINED.
2679 for Depex
in DepexList
:
2684 for D
in Depex
.values():
2685 DepexStr
+= ' '.join([val
for val
in D
])
2686 Index
= DepexStr
.find('END')
2687 if Index
> -1 and Index
== len(DepexStr
) - 3:
2688 DepexStr
= DepexStr
[:-3]
2689 DepexStr
= DepexStr
.strip()
2692 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
2694 return '[Depex.%s]\n' % self
.Arch
2695 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
2697 ## Merge dependency expression
2699 # @retval list The token list of the dependency expression after parsed
2701 def _GetDepexTokenList(self
):
2702 if self
._DepexList
== None:
2703 self
._DepexList
= {}
2704 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2705 return self
._DepexList
2707 self
._DepexList
[self
.ModuleType
] = []
2709 for ModuleType
in self
._DepexList
:
2710 DepexList
= self
._DepexList
[ModuleType
]
2712 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2714 for M
in [self
.Module
] + self
.DependentLibraryList
:
2716 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
2718 DepexList
.append('AND')
2719 DepexList
.append('(')
2721 if DepexList
[-1] == 'END': # no need of a END at this time
2723 DepexList
.append(')')
2726 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
2727 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
2729 if len(DepexList
) > 0:
2730 EdkLogger
.verbose('')
2731 return self
._DepexList
2733 ## Merge dependency expression
2735 # @retval list The token list of the dependency expression after parsed
2737 def _GetDepexExpressionTokenList(self
):
2738 if self
._DepexExpressionList
== None:
2739 self
._DepexExpressionList
= {}
2740 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2741 return self
._DepexExpressionList
2743 self
._DepexExpressionList
[self
.ModuleType
] = ''
2745 for ModuleType
in self
._DepexExpressionList
:
2746 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
2748 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2750 for M
in [self
.Module
] + self
.DependentLibraryList
:
2752 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
2753 if DepexExpressionList
!= '':
2754 DepexExpressionList
+= ' AND '
2755 DepexExpressionList
+= '('
2756 DepexExpressionList
+= D
2757 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
2758 DepexExpressionList
+= ')'
2761 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
2762 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
2764 if len(DepexExpressionList
) > 0:
2765 EdkLogger
.verbose('')
2766 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
2767 return self
._DepexExpressionList
2769 ## Return the list of specification version required for the module
2771 # @retval list The list of specification defined in module file
2773 def _GetSpecification(self
):
2774 return self
.Module
.Specification
2776 ## Tool option for the module build
2778 # @param PlatformInfo The object of PlatformBuildInfo
2779 # @retval dict The dict containing valid options
2781 def _GetModuleBuildOption(self
):
2782 if self
._BuildOption
== None:
2783 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
2784 if self
.BuildRuleOrder
:
2785 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
2786 return self
._BuildOption
2788 ## Get include path list from tool option for the module build
2790 # @retval list The include path list
2792 def _GetBuildOptionIncPathList(self
):
2793 if self
._BuildOptionIncPathList
== None:
2795 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
2796 # is the former use /I , the Latter used -I to specify include directories
2798 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
2799 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
2800 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
2801 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
2804 # New ToolChainFamily, don't known whether there is option to specify include directories
2806 self
._BuildOptionIncPathList
= []
2807 return self
._BuildOptionIncPathList
2809 BuildOptionIncPathList
= []
2810 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
2813 FlagOption
= self
.BuildOption
[Tool
][Attr
]
2817 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
2818 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
2821 # RVCT may specify a list of directory seperated by commas
2824 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
2825 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
2826 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
2829 # EDK II modules must not reference header files outside of the packages they depend on or
2830 # within the module's directory tree. Report error if violation.
2832 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
2833 for Path
in IncPathList
:
2834 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
2835 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
2836 EdkLogger
.error("build",
2839 File
=str(self
.MetaFile
))
2842 BuildOptionIncPathList
+= IncPathList
2844 self
._BuildOptionIncPathList
= BuildOptionIncPathList
2846 return self
._BuildOptionIncPathList
2848 ## Return a list of files which can be built from source
2850 # What kind of files can be built is determined by build rules in
2851 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
2853 def _GetSourceFileList(self
):
2854 if self
._SourceFileList
== None:
2855 self
._SourceFileList
= []
2856 for F
in self
.Module
.Sources
:
2858 if F
.TagName
not in ("", "*", self
.ToolChain
):
2859 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
2860 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
2862 # match tool chain family
2863 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
2866 "The file [%s] must be built by tools of [%s], " \
2867 "but current toolchain family is [%s]" \
2868 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
2871 # add the file path into search path list for file including
2872 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
2873 self
.IncludePathList
.insert(0, F
.Dir
)
2874 self
._SourceFileList
.append(F
)
2876 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
2878 for F
in self
._SourceFileList
:
2879 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
2880 return self
._SourceFileList
2882 def _MatchBuildRuleOrder(self
, FileList
):
2884 self
._GetModuleBuildOption
()
2885 for SingleFile
in FileList
:
2886 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
2887 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
2888 if key
in Order_Dict
:
2889 Order_Dict
[key
].append(SingleFile
.Ext
)
2891 Order_Dict
[key
] = [SingleFile
.Ext
]
2894 for F
in Order_Dict
:
2895 if len(Order_Dict
[F
]) > 1:
2896 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
2897 for Ext
in Order_Dict
[F
][1:]:
2898 RemoveList
.append(F
+ Ext
)
2900 for item
in RemoveList
:
2901 FileList
.remove(item
)
2905 ## Return the list of unicode files
2906 def _GetUnicodeFileList(self
):
2907 if self
._UnicodeFileList
== None:
2908 if TAB_UNICODE_FILE
in self
.FileTypes
:
2909 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
2911 self
._UnicodeFileList
= []
2912 return self
._UnicodeFileList
2914 ## Return a list of files which can be built from binary
2916 # "Build" binary files are just to copy them to build directory.
2918 # @retval list The list of files which can be built later
2920 def _GetBinaryFiles(self
):
2921 if self
._BinaryFileList
== None:
2922 self
._BinaryFileList
= []
2923 for F
in self
.Module
.Binaries
:
2924 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
2926 self
._BinaryFileList
.append(F
)
2927 self
._ApplyBuildRule
(F
, F
.Type
)
2928 return self
._BinaryFileList
2930 def _GetBuildRules(self
):
2931 if self
._BuildRules
== None:
2933 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
2934 for Type
in BuildRuleDatabase
.FileTypeList
:
2935 #first try getting build rule by BuildRuleFamily
2936 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
2938 # build type is always module type, but ...
2939 if self
.ModuleType
!= self
.BuildType
:
2940 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
2941 #second try getting build rule by ToolChainFamily
2943 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
2945 # build type is always module type, but ...
2946 if self
.ModuleType
!= self
.BuildType
:
2947 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
2950 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
2951 BuildRules
[Type
] = RuleObject
2952 for Ext
in RuleObject
.SourceFileExtList
:
2953 BuildRules
[Ext
] = RuleObject
2954 self
._BuildRules
= BuildRules
2955 return self
._BuildRules
2957 def _ApplyBuildRule(self
, File
, FileType
):
2958 if self
._BuildTargets
== None:
2959 self
._IntroBuildTargetList
= set()
2960 self
._FinalBuildTargetList
= set()
2961 self
._BuildTargets
= {}
2962 self
._FileTypes
= {}
2964 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
2965 if not os
.path
.exists(SubDirectory
):
2966 CreateDirectory(SubDirectory
)
2972 # Make sure to get build rule order value
2974 self
._GetModuleBuildOption
()
2976 while Index
< len(SourceList
):
2977 Source
= SourceList
[Index
]
2981 CreateDirectory(Source
.Dir
)
2983 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
2984 # Skip all files that are not binary libraries
2985 if not self
.IsLibrary
:
2987 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
2988 elif FileType
in self
.BuildRules
:
2989 RuleObject
= self
.BuildRules
[FileType
]
2990 elif Source
.Ext
in self
.BuildRules
:
2991 RuleObject
= self
.BuildRules
[Source
.Ext
]
2993 # stop at no more rules
2995 self
._FinalBuildTargetList
.add(LastTarget
)
2998 FileType
= RuleObject
.SourceFileType
2999 if FileType
not in self
._FileTypes
:
3000 self
._FileTypes
[FileType
] = set()
3001 self
._FileTypes
[FileType
].add(Source
)
3003 # stop at STATIC_LIBRARY for library
3004 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
3006 self
._FinalBuildTargetList
.add(LastTarget
)
3009 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
3012 self
._FinalBuildTargetList
.add(LastTarget
)
3014 elif not Target
.Outputs
:
3015 # Only do build for target with outputs
3016 self
._FinalBuildTargetList
.add(Target
)
3018 if FileType
not in self
._BuildTargets
:
3019 self
._BuildTargets
[FileType
] = set()
3020 self
._BuildTargets
[FileType
].add(Target
)
3022 if not Source
.IsBinary
and Source
== File
:
3023 self
._IntroBuildTargetList
.add(Target
)
3025 # to avoid cyclic rule
3026 if FileType
in RuleChain
:
3029 RuleChain
.append(FileType
)
3030 SourceList
.extend(Target
.Outputs
)
3032 FileType
= TAB_UNKNOWN_FILE
3034 def _GetTargets(self
):
3035 if self
._BuildTargets
== None:
3036 self
._IntroBuildTargetList
= set()
3037 self
._FinalBuildTargetList
= set()
3038 self
._BuildTargets
= {}
3039 self
._FileTypes
= {}
3041 #TRICK: call _GetSourceFileList to apply build rule for source files
3042 if self
.SourceFileList
:
3045 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3046 if self
.BinaryFileList
:
3049 return self
._BuildTargets
3051 def _GetIntroTargetList(self
):
3053 return self
._IntroBuildTargetList
3055 def _GetFinalTargetList(self
):
3057 return self
._FinalBuildTargetList
3059 def _GetFileTypes(self
):
3061 return self
._FileTypes
3063 ## Get the list of package object the module depends on
3065 # @retval list The package object list
3067 def _GetDependentPackageList(self
):
3068 return self
.Module
.Packages
3070 ## Return the list of auto-generated code file
3072 # @retval list The list of auto-generated file
3074 def _GetAutoGenFileList(self
):
3075 UniStringAutoGenC
= True
3076 UniStringBinBuffer
= StringIO()
3077 if self
.BuildType
== 'UEFI_HII':
3078 UniStringAutoGenC
= False
3079 if self
._AutoGenFileList
== None:
3080 self
._AutoGenFileList
= {}
3081 AutoGenC
= TemplateString()
3082 AutoGenH
= TemplateString()
3083 StringH
= TemplateString()
3084 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
)
3086 # AutoGen.c is generated if there are library classes in inf, or there are object files
3088 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3089 or TAB_OBJECT_FILE
in self
.FileTypes
):
3090 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3091 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3092 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3093 if str(AutoGenH
) != "":
3094 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3095 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3096 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3097 if str(StringH
) != "":
3098 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3099 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3100 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3101 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
3102 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3103 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3104 AutoFile
.IsBinary
= True
3105 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3106 if UniStringBinBuffer
!= None:
3107 UniStringBinBuffer
.close()
3108 return self
._AutoGenFileList
3110 ## Return the list of library modules explicitly or implicityly used by this module
3111 def _GetLibraryList(self
):
3112 if self
._DependentLibraryList
== None:
3113 # only merge library classes and PCD for non-library module
3115 self
._DependentLibraryList
= []
3117 if self
.AutoGenVersion
< 0x00010005:
3118 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3120 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3121 return self
._DependentLibraryList
3124 def UpdateComments(Recver
, Src
):
3126 if Key
not in Recver
:
3128 Recver
[Key
].extend(Src
[Key
])
3129 ## Get the list of PCDs from current module
3131 # @retval list The list of PCD
3133 def _GetModulePcdList(self
):
3134 if self
._ModulePcdList
== None:
3135 # apply PCD settings from platform
3136 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3137 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3138 return self
._ModulePcdList
3140 ## Get the list of PCDs from dependent libraries
3142 # @retval list The list of PCD
3144 def _GetLibraryPcdList(self
):
3145 if self
._LibraryPcdList
== None:
3147 if not self
.IsLibrary
:
3148 # get PCDs from dependent libraries
3149 for Library
in self
.DependentLibraryList
:
3150 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3151 for Key
in Library
.Pcds
:
3152 # skip duplicated PCDs
3153 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3155 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3156 # apply PCD settings from platform
3157 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3159 self
._LibraryPcdList
= []
3160 return self
._LibraryPcdList
3162 ## Get the GUID value mapping
3164 # @retval dict The mapping between GUID cname and its value
3166 def _GetGuidList(self
):
3167 if self
._GuidList
== None:
3168 self
._GuidList
= sdict()
3169 self
._GuidList
.update(self
.Module
.Guids
)
3170 for Library
in self
.DependentLibraryList
:
3171 self
._GuidList
.update(Library
.Guids
)
3172 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3173 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3174 return self
._GuidList
3176 def GetGuidsUsedByPcd(self
):
3177 if self
._GuidsUsedByPcd
== None:
3178 self
._GuidsUsedByPcd
= sdict()
3179 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3180 for Library
in self
.DependentLibraryList
:
3181 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3182 return self
._GuidsUsedByPcd
3183 ## Get the protocol value mapping
3185 # @retval dict The mapping between protocol cname and its value
3187 def _GetProtocolList(self
):
3188 if self
._ProtocolList
== None:
3189 self
._ProtocolList
= sdict()
3190 self
._ProtocolList
.update(self
.Module
.Protocols
)
3191 for Library
in self
.DependentLibraryList
:
3192 self
._ProtocolList
.update(Library
.Protocols
)
3193 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3194 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3195 return self
._ProtocolList
3197 ## Get the PPI value mapping
3199 # @retval dict The mapping between PPI cname and its value
3201 def _GetPpiList(self
):
3202 if self
._PpiList
== None:
3203 self
._PpiList
= sdict()
3204 self
._PpiList
.update(self
.Module
.Ppis
)
3205 for Library
in self
.DependentLibraryList
:
3206 self
._PpiList
.update(Library
.Ppis
)
3207 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3208 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3209 return self
._PpiList
3211 ## Get the list of include search path
3213 # @retval list The list path
3215 def _GetIncludePathList(self
):
3216 if self
._IncludePathList
== None:
3217 self
._IncludePathList
= []
3218 if self
.AutoGenVersion
< 0x00010005:
3219 for Inc
in self
.Module
.Includes
:
3220 if Inc
not in self
._IncludePathList
:
3221 self
._IncludePathList
.append(Inc
)
3223 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3224 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3225 self
._IncludePathList
.append(Inc
)
3226 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3227 self
._IncludePathList
.append(self
.DebugDir
)
3229 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3230 self
._IncludePathList
.append(self
.DebugDir
)
3232 for Package
in self
.Module
.Packages
:
3233 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3234 if PackageDir
not in self
._IncludePathList
:
3235 self
._IncludePathList
.append(PackageDir
)
3236 for Inc
in Package
.Includes
:
3237 if Inc
not in self
._IncludePathList
:
3238 self
._IncludePathList
.append(str(Inc
))
3239 return self
._IncludePathList
3241 def _GetIncludePathLength(self
):
3242 self
._IncludePathLength
= 0
3243 if self
._IncludePathList
:
3244 for inc
in self
._IncludePathList
:
3245 self
._IncludePathLength
+= len(' ' + inc
)
3246 return self
._IncludePathLength
3248 ## Get HII EX PCDs which maybe used by VFR
3250 # efivarstore used by VFR may relate with HII EX PCDs
3251 # Get the variable name and GUID from efivarstore and HII EX PCD
3252 # List the HII EX PCDs in As Built INF if both name and GUID match.
3254 # @retval list HII EX PCDs
3256 def _GetPcdsMaybeUsedByVfr(self
):
3257 if not self
.SourceFileList
:
3261 for SrcFile
in self
.SourceFileList
:
3262 if SrcFile
.Ext
.lower() != '.vfr':
3264 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3265 if not os
.path
.exists(Vfri
):
3267 VfriFile
= open(Vfri
, 'r')
3268 Content
= VfriFile
.read()
3270 Pos
= Content
.find('efivarstore')
3273 # Make sure 'efivarstore' is the start of efivarstore statement
3274 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3277 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3279 if Index
>= 0 and Content
[Index
] != ';':
3280 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3283 # 'efivarstore' must be followed by name and guid
3285 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3288 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3291 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3292 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3293 Pos
= Content
.find('efivarstore', Name
.end())
3297 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3298 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3300 for SkuName
in Pcd
.SkuInfoList
:
3301 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3302 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3303 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
)
3306 Guid
= GuidStructureStringToGuidString(Value
)
3307 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3308 HiiExPcds
.append(Pcd
)
3313 def _GenOffsetBin(self
):
3315 for SourceFile
in self
.Module
.Sources
:
3316 if SourceFile
.Type
.upper() == ".VFR" :
3318 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3320 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3321 if SourceFile
.Type
.upper() == ".UNI" :
3323 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3325 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3327 if len(VfrUniBaseName
) == 0:
3329 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3330 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3331 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3332 if not VfrUniOffsetList
:
3335 OutputName
= '%sOffset.bin' % self
.Name
3336 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3339 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3341 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3343 # Use a instance of StringIO to cache data
3344 fStringIO
= StringIO('')
3346 for Item
in VfrUniOffsetList
:
3347 if (Item
[0].find("Strings") != -1):
3349 # UNI offset in image.
3351 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3353 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3354 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3355 fStringIO
.write(''.join(UniGuid
))
3356 UniValue
= pack ('Q', int (Item
[1], 16))
3357 fStringIO
.write (UniValue
)
3360 # VFR binary offset in image.
3362 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3364 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3365 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3366 fStringIO
.write(''.join(VfrGuid
))
3368 VfrValue
= pack ('Q', int (Item
[1], 16))
3369 fStringIO
.write (VfrValue
)
3371 # write data into file.
3374 fInputfile
.write (fStringIO
.getvalue())
3376 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3377 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3383 ## Create AsBuilt INF file the module
3385 def CreateAsBuiltInf(self
):
3386 if self
.IsAsBuiltInfCreated
:
3389 # Skip the following code for EDK I inf
3390 if self
.AutoGenVersion
< 0x00010005:
3393 # Skip the following code for libraries
3397 # Skip the following code for modules with no source files
3398 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3401 # Skip the following code for modules without any binary files
3402 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3405 ### TODO: How to handles mixed source and binary modules
3407 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3408 # Also find all packages that the DynamicEx PCDs depend on
3413 PcdTokenSpaceList
= []
3414 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3415 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3416 PatchablePcds
[Pcd
.TokenCName
] = Pcd
3417 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3418 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3421 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3422 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3423 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3425 GuidList
.update(self
.GuidList
)
3426 for TokenSpace
in self
.GetGuidsUsedByPcd():
3427 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3428 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3429 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3430 GuidList
.pop(TokenSpace
)
3431 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3432 for Package
in self
.DerivedPackageList
:
3433 if Package
in Packages
:
3435 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3437 for Index
in range(len(BeChecked
)):
3438 for Item
in CheckList
[Index
]:
3439 if Item
in BeChecked
[Index
]:
3440 Packages
+= [Package
]
3445 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3446 for Pkg
in self
.PlatformInfo
.PackageList
:
3449 for VfrPcd
in VfrPcds
:
3450 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3451 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3455 ModuleType
= self
.ModuleType
3456 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3457 ModuleType
= 'DXE_DRIVER'
3460 if self
.PcdIsDriver
!= '':
3461 DriverType
= self
.PcdIsDriver
3464 MDefs
= self
.Module
.Defines
3467 'module_name' : self
.Name
,
3468 'module_guid' : Guid
,
3469 'module_module_type' : ModuleType
,
3470 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3471 'pcd_is_driver_string' : [],
3472 'module_uefi_specification_version' : [],
3473 'module_pi_specification_version' : [],
3474 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3475 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3476 'module_constructor' : self
.Module
.ConstructorList
,
3477 'module_destructor' : self
.Module
.DestructorList
,
3478 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3479 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3480 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3481 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3482 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3483 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3484 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3485 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3486 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3487 'module_arch' : self
.Arch
,
3488 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3490 'patchablepcd_item' : [],
3492 'protocol_item' : [],
3496 'libraryclasses_item' : []
3499 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3500 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3502 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3505 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3507 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3508 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3509 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3510 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3512 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3513 if self
.ModuleType
in ['BASE', 'USER_DEFINED']:
3514 for Item
in self
.CodaTargetList
:
3515 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3516 if Item
.Target
.Ext
.lower() == '.aml':
3517 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3518 elif Item
.Target
.Ext
.lower() == '.acpi':
3519 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3521 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3523 for Item
in self
.CodaTargetList
:
3524 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3525 if Item
.Target
.Ext
.lower() == '.efi':
3526 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3528 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3529 if self
.DepexGenerated
:
3530 if self
.ModuleType
in ['PEIM']:
3531 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3532 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3533 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3534 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3535 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3537 Bin
= self
._GenOffsetBin
()
3539 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3541 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3543 if File
.lower().endswith('.pdb'):
3544 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3545 HeaderComments
= self
.Module
.HeaderComments
3547 for Index
in range(len(HeaderComments
)):
3548 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3549 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3552 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3553 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3556 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3557 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3558 (GuidList
, self
._GuidComments
, 'guid_item')
3560 for Item
in GenList
:
3561 for CName
in Item
[0]:
3563 if CName
in Item
[1]:
3564 Comments
= '\n '.join(Item
[1][CName
])
3567 Entry
= Comments
+ '\n ' + CName
3568 AsBuiltInfDict
[Item
[2]].append(Entry
)
3569 PatchList
= parsePcdInfoFromMapFile(
3570 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3571 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3574 for PatchPcd
in PatchList
:
3575 if PatchPcd
[0] not in PatchablePcds
:
3577 Pcd
= PatchablePcds
[PatchPcd
[0]]
3579 if Pcd
.DatumType
!= 'VOID*':
3580 HexFormat
= '0x%02x'
3581 if Pcd
.DatumType
== 'UINT16':
3582 HexFormat
= '0x%04x'
3583 elif Pcd
.DatumType
== 'UINT32':
3584 HexFormat
= '0x%08x'
3585 elif Pcd
.DatumType
== 'UINT64':
3586 HexFormat
= '0x%016x'
3587 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3589 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
3590 EdkLogger
.error("build", AUTOGEN_ERROR
,
3591 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3593 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3594 PcdValue
= Pcd
.DefaultValue
3595 if PcdValue
[0] != '{':
3597 if PcdValue
[0] == 'L':
3599 PcdValue
= PcdValue
.lstrip('L')
3600 PcdValue
= eval(PcdValue
)
3602 for Index
in range(0, len(PcdValue
)):
3604 CharVal
= ord(PcdValue
[Index
])
3605 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3606 + '0x%02x' % (CharVal
>> 8) + ', '
3608 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3611 Padding
= Padding
* 2
3612 ArraySize
= ArraySize
/ 2
3613 if ArraySize
< (len(PcdValue
) + 1):
3614 EdkLogger
.error("build", AUTOGEN_ERROR
,
3615 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3617 if ArraySize
> len(PcdValue
) + 1:
3618 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3619 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3620 elif len(PcdValue
.split(',')) <= ArraySize
:
3621 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3624 EdkLogger
.error("build", AUTOGEN_ERROR
,
3625 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3627 PcdItem
= '%s.%s|%s|0x%X' % \
3628 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, PcdValue
, PatchPcd
[1])
3630 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3631 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
3633 PcdItem
= PcdComments
+ '\n ' + PcdItem
3634 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
3637 for Pcd
in Pcds
+ VfrPcds
:
3642 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
3643 for SkuName
in Pcd
.SkuInfoList
:
3644 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3645 SkuId
= SkuInfo
.SkuId
3646 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
3650 # Don't generate duplicated HII PCD
3652 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
3655 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
3656 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3657 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
3661 for Index
, Comment
in enumerate(PcdCommentList
):
3662 for Usage
in UsageList
:
3663 if Comment
.find(Usage
) != -1:
3667 if UsageIndex
!= -1:
3668 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
3670 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
3671 PcdComments
= '\n '.join(PcdCommentList
)
3672 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + Pcd
.TokenCName
3674 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
3675 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
3676 for Item
in self
.BuildOption
:
3677 if 'FLAGS' in self
.BuildOption
[Item
]:
3678 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
3680 # Generated LibraryClasses section in comments.
3681 for Library
in self
.LibraryAutoGenList
:
3682 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
3684 # Generated depex expression section in comments.
3685 AsBuiltInfDict
['depexsection_item'] = ''
3686 DepexExpresion
= self
._GetDepexExpresionString
()
3688 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
3690 AsBuiltInf
= TemplateString()
3691 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
3693 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
3695 self
.IsAsBuiltInfCreated
= True
3697 ## Create makefile for the module and its dependent libraries
3699 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
3700 # dependent libraries will be created
3702 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
3703 # Ignore generating makefile when it is a binary module
3704 if self
.IsBinaryModule
:
3707 if self
.IsMakeFileCreated
:
3710 if not self
.IsLibrary
and CreateLibraryMakeFile
:
3711 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3712 LibraryAutoGen
.CreateMakeFile()
3714 if len(self
.CustomMakefile
) == 0:
3715 Makefile
= GenMake
.ModuleMakefile(self
)
3717 Makefile
= GenMake
.CustomMakefile(self
)
3718 if Makefile
.Generate():
3719 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
3720 (self
.Name
, self
.Arch
))
3722 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
3723 (self
.Name
, self
.Arch
))
3725 self
.IsMakeFileCreated
= True
3727 def CopyBinaryFiles(self
):
3728 for File
in self
.Module
.Binaries
:
3730 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
3731 CopyLongFilePath(SrcPath
, DstPath
)
3732 ## Create autogen code for the module and its dependent libraries
3734 # @param CreateLibraryCodeFile Flag indicating if or not the code of
3735 # dependent libraries will be created
3737 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
3738 if self
.IsCodeFileCreated
:
3741 # Need to generate PcdDatabase even PcdDriver is binarymodule
3742 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
3743 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
3745 if self
.IsBinaryModule
:
3747 self
.CopyBinaryFiles()
3750 if not self
.IsLibrary
and CreateLibraryCodeFile
:
3751 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3752 LibraryAutoGen
.CreateCodeFile()
3755 IgoredAutoGenList
= []
3757 for File
in self
.AutoGenFileList
:
3758 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
3759 #Ignore Edk AutoGen.c
3760 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
3763 AutoGenList
.append(str(File
))
3765 IgoredAutoGenList
.append(str(File
))
3767 # Skip the following code for EDK I inf
3768 if self
.AutoGenVersion
< 0x00010005:
3771 for ModuleType
in self
.DepexList
:
3772 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
3773 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
3776 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
3777 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
3779 if len(Dpx
.PostfixNotation
) <> 0:
3780 self
.DepexGenerated
= True
3782 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
3783 AutoGenList
.append(str(DpxFile
))
3785 IgoredAutoGenList
.append(str(DpxFile
))
3787 if IgoredAutoGenList
== []:
3788 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
3789 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
3790 elif AutoGenList
== []:
3791 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
3792 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3794 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
3795 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3797 self
.IsCodeFileCreated
= True
3800 ## Summarize the ModuleAutoGen objects of all libraries used by this module
3801 def _GetLibraryAutoGenList(self
):
3802 if self
._LibraryAutoGenList
== None:
3803 self
._LibraryAutoGenList
= []
3804 for Library
in self
.DependentLibraryList
:
3811 self
.PlatformInfo
.MetaFile
3813 if La
not in self
._LibraryAutoGenList
:
3814 self
._LibraryAutoGenList
.append(La
)
3815 for Lib
in La
.CodaTargetList
:
3816 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
3817 return self
._LibraryAutoGenList
3819 Module
= property(_GetModule
)
3820 Name
= property(_GetBaseName
)
3821 Guid
= property(_GetGuid
)
3822 Version
= property(_GetVersion
)
3823 ModuleType
= property(_GetModuleType
)
3824 ComponentType
= property(_GetComponentType
)
3825 BuildType
= property(_GetBuildType
)
3826 PcdIsDriver
= property(_GetPcdIsDriver
)
3827 AutoGenVersion
= property(_GetAutoGenVersion
)
3828 Macros
= property(_GetMacros
)
3829 Specification
= property(_GetSpecification
)
3831 IsLibrary
= property(_IsLibrary
)
3832 IsBinaryModule
= property(_IsBinaryModule
)
3833 BuildDir
= property(_GetBuildDir
)
3834 OutputDir
= property(_GetOutputDir
)
3835 DebugDir
= property(_GetDebugDir
)
3836 MakeFileDir
= property(_GetMakeFileDir
)
3837 CustomMakefile
= property(_GetCustomMakefile
)
3839 IncludePathList
= property(_GetIncludePathList
)
3840 IncludePathLength
= property(_GetIncludePathLength
)
3841 AutoGenFileList
= property(_GetAutoGenFileList
)
3842 UnicodeFileList
= property(_GetUnicodeFileList
)
3843 SourceFileList
= property(_GetSourceFileList
)
3844 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
3845 Targets
= property(_GetTargets
)
3846 IntroTargetList
= property(_GetIntroTargetList
)
3847 CodaTargetList
= property(_GetFinalTargetList
)
3848 FileTypes
= property(_GetFileTypes
)
3849 BuildRules
= property(_GetBuildRules
)
3851 DependentPackageList
= property(_GetDependentPackageList
)
3852 DependentLibraryList
= property(_GetLibraryList
)
3853 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
3854 DerivedPackageList
= property(_GetDerivedPackageList
)
3856 ModulePcdList
= property(_GetModulePcdList
)
3857 LibraryPcdList
= property(_GetLibraryPcdList
)
3858 GuidList
= property(_GetGuidList
)
3859 ProtocolList
= property(_GetProtocolList
)
3860 PpiList
= property(_GetPpiList
)
3861 DepexList
= property(_GetDepexTokenList
)
3862 DxsFile
= property(_GetDxsFile
)
3863 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
3864 BuildOption
= property(_GetModuleBuildOption
)
3865 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
3866 BuildCommand
= property(_GetBuildCommand
)
3868 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
3870 # This acts like the main() function for the script, unless it is 'import'ed into another script.
3871 if __name__
== '__main__':