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 (pcdname
, pcdvalue
) = pcd
.split('=')
357 EdkLogger
.error('build', AUTOGEN_ERROR
, "No Value specified for the PCD %s." % (pcdname
))
359 (TokenSpaceGuidCName
, TokenCName
) = pcdname
.split('.')
363 TokenSpaceGuidCName
= ''
364 HasTokenSpace
= False
365 TokenSpaceGuidCNameList
= []
369 for package
in PGen
.PackageList
:
370 for key
in package
.Pcds
:
371 PcdItem
= package
.Pcds
[key
]
373 if (PcdItem
.TokenCName
, PcdItem
.TokenSpaceGuidCName
) == (TokenCName
, TokenSpaceGuidCName
):
374 PcdDatumType
= PcdItem
.DatumType
375 NewValue
= self
._BuildOptionPcdValueFormat
(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
378 if PcdItem
.TokenCName
== TokenCName
:
379 if not PcdItem
.TokenSpaceGuidCName
in TokenSpaceGuidCNameList
:
380 if len (TokenSpaceGuidCNameList
) < 1:
381 TokenSpaceGuidCNameList
.append(PcdItem
.TokenSpaceGuidCName
)
382 PcdDatumType
= PcdItem
.DatumType
383 TokenSpaceGuidCName
= PcdItem
.TokenSpaceGuidCName
384 NewValue
= self
._BuildOptionPcdValueFormat
(TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, pcdvalue
)
390 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName
, PcdItem
.TokenSpaceGuidCName
, TokenSpaceGuidCNameList
[0])
393 GlobalData
.BuildOptionPcd
[i
] = (TokenSpaceGuidCName
, TokenCName
, NewValue
)
397 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName
, TokenCName
))
399 EdkLogger
.error('build', AUTOGEN_ERROR
, "The Pcd %s is not found in the DEC file." % (TokenCName
))
401 for BuildData
in PGen
.BuildDatabase
._CACHE
_.values():
402 if BuildData
.Arch
!= Arch
:
404 if BuildData
.MetaFile
.Ext
== '.dec':
406 for key
in BuildData
.Pcds
:
407 PcdItem
= BuildData
.Pcds
[key
]
408 if (TokenSpaceGuidCName
, TokenCName
) == (PcdItem
.TokenSpaceGuidCName
, PcdItem
.TokenCName
):
409 PcdItem
.DefaultValue
= NewValue
411 if (TokenCName
, TokenSpaceGuidCName
) in PcdSet
:
412 PcdSet
[(TokenCName
, TokenSpaceGuidCName
)] = NewValue
414 #Collect package set information from INF of FDF
416 for Inf
in ModuleList
:
417 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
418 if ModuleFile
in Platform
.Modules
:
420 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
421 PkgSet
.update(ModuleData
.Packages
)
422 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
425 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
426 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
428 Platform
.SkuName
= self
.SkuId
429 for Name
, Guid
in PcdSet
:
430 if (Name
, Guid
) not in DecPcds
:
434 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
435 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
436 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
439 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
440 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
441 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
442 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
443 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
445 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
449 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
450 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
451 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
454 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
456 # Explicitly collect platform's dynamic PCDs
458 Pa
.CollectPlatformDynamicPcds()
459 Pa
.CollectFixedAtBuildPcds()
460 self
.AutoGenObjectList
.append(Pa
)
463 # Check PCDs token value conflict in each DEC file.
465 self
._CheckAllPcdsTokenValueConflict
()
468 # Check PCD type and definition between DSC and DEC
470 self
._CheckPcdDefineAndType
()
473 # self._CheckDuplicateInFV(Fdf)
475 self
._BuildDir
= None
477 self
._MakeFileDir
= None
478 self
._BuildCommand
= None
482 def _BuildOptionPcdValueFormat(self
, TokenSpaceGuidCName
, TokenCName
, PcdDatumType
, Value
):
483 if PcdDatumType
== 'VOID*':
484 if Value
.startswith('L'):
486 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"{...}"')
487 Value
= Value
[0] + '"' + Value
[1:] + '"'
488 elif Value
.startswith('B'):
490 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"{...}"')
494 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"{...}"')
495 Value
= '"' + Value
+ '"'
497 IsValid
, Cause
= CheckPcdDatum(PcdDatumType
, Value
)
499 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, ExtraData
="%s.%s" % (TokenSpaceGuidCName
, TokenCName
))
500 if PcdDatumType
== 'BOOLEAN':
501 Value
= Value
.upper()
502 if Value
== 'TRUE' or Value
== '1':
504 elif Value
== 'FALSE' or Value
== '0':
508 ## _CheckDuplicateInFV() method
510 # Check whether there is duplicate modules/files exist in FV section.
511 # The check base on the file GUID;
513 def _CheckDuplicateInFV(self
, Fdf
):
514 for Fv
in Fdf
.Profile
.FvDict
:
516 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
517 if FfsFile
.InfFileName
and FfsFile
.NameGuid
== None:
522 for Pa
in self
.AutoGenObjectList
:
525 for Module
in Pa
.ModuleAutoGenList
:
526 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
528 if not Module
.Guid
.upper() in _GuidDict
.keys():
529 _GuidDict
[Module
.Guid
.upper()] = FfsFile
532 EdkLogger
.error("build",
534 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
535 FfsFile
.CurrentLineContent
,
536 _GuidDict
[Module
.Guid
.upper()].CurrentLineNum
,
537 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
538 Module
.Guid
.upper()),
539 ExtraData
=self
.FdfFile
)
541 # Some INF files not have entity in DSC file.
544 if FfsFile
.InfFileName
.find('$') == -1:
545 InfPath
= NormPath(FfsFile
.InfFileName
)
546 if not os
.path
.exists(InfPath
):
547 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
549 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
551 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
552 # BuildObject from one of AutoGenObjectList is enough.
554 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, 'COMMON', self
.BuildTarget
, self
.ToolChain
]
555 if not InfObj
.Guid
.upper() in _GuidDict
.keys():
556 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
558 EdkLogger
.error("build",
560 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
561 FfsFile
.CurrentLineContent
,
562 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
563 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
564 InfObj
.Guid
.upper()),
565 ExtraData
=self
.FdfFile
)
568 if FfsFile
.NameGuid
!= None:
569 _CheckPCDAsGuidPattern
= re
.compile("^PCD\(.+\..+\)$")
572 # If the NameGuid reference a PCD name.
573 # The style must match: PCD(xxxx.yyy)
575 if _CheckPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
577 # Replace the PCD value.
579 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
581 for Pa
in self
.AutoGenObjectList
:
583 for PcdItem
in Pa
.AllPcdList
:
584 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
586 # First convert from CFormatGuid to GUID string
588 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
590 if not _PcdGuidString
:
592 # Then try Byte array.
594 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
596 if not _PcdGuidString
:
598 # Not Byte array or CFormat GUID, raise error.
600 EdkLogger
.error("build",
602 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
603 ExtraData
=self
.FdfFile
)
605 if not _PcdGuidString
.upper() in _GuidDict
.keys():
606 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
610 EdkLogger
.error("build",
612 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
613 FfsFile
.CurrentLineContent
,
614 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
615 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
616 FfsFile
.NameGuid
.upper()),
617 ExtraData
=self
.FdfFile
)
619 if not FfsFile
.NameGuid
.upper() in _GuidDict
.keys():
620 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
623 # Two raw file GUID conflict.
625 EdkLogger
.error("build",
627 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
628 FfsFile
.CurrentLineContent
,
629 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
630 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
631 FfsFile
.NameGuid
.upper()),
632 ExtraData
=self
.FdfFile
)
635 def _CheckPcdDefineAndType(self
):
637 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
638 "Dynamic", #"DynamicHii", "DynamicVpd",
639 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
642 # This dict store PCDs which are not used by any modules with specified arches
644 for Pa
in self
.AutoGenObjectList
:
645 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
646 for Pcd
in Pa
.Platform
.Pcds
:
647 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
649 # If no PCD type, this PCD comes from FDF
653 # Try to remove Hii and Vpd suffix
654 if PcdType
.startswith("DynamicEx"):
655 PcdType
= "DynamicEx"
656 elif PcdType
.startswith("Dynamic"):
659 for Package
in Pa
.PackageList
:
660 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
661 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
663 for Type
in PcdTypeList
:
664 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
668 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
669 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
674 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
676 for Pcd
in UnusedPcd
:
679 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
680 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
681 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
686 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
688 ## Return the directory to store FV files
690 if self
._FvDir
== None:
691 self
._FvDir
= path
.join(self
.BuildDir
, 'FV')
694 ## Return the directory to store all intermediate and final files built
695 def _GetBuildDir(self
):
696 return self
.AutoGenObjectList
[0].BuildDir
698 ## Return the build output directory platform specifies
699 def _GetOutputDir(self
):
700 return self
.Platform
.OutputDirectory
702 ## Return platform name
704 return self
.Platform
.PlatformName
706 ## Return meta-file GUID
708 return self
.Platform
.Guid
710 ## Return platform version
711 def _GetVersion(self
):
712 return self
.Platform
.Version
714 ## Return paths of tools
715 def _GetToolDefinition(self
):
716 return self
.AutoGenObjectList
[0].ToolDefinition
718 ## Return directory of platform makefile
720 # @retval string Makefile directory
722 def _GetMakeFileDir(self
):
723 if self
._MakeFileDir
== None:
724 self
._MakeFileDir
= self
.BuildDir
725 return self
._MakeFileDir
727 ## Return build command string
729 # @retval string Build command string
731 def _GetBuildCommand(self
):
732 if self
._BuildCommand
== None:
733 # BuildCommand should be all the same. So just get one from platform AutoGen
734 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
735 return self
._BuildCommand
737 ## Check the PCDs token value conflict in each DEC file.
739 # Will cause build break and raise error message while two PCDs conflict.
743 def _CheckAllPcdsTokenValueConflict(self
):
744 for Pa
in self
.AutoGenObjectList
:
745 for Package
in Pa
.PackageList
:
746 PcdList
= Package
.Pcds
.values()
747 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
749 while (Count
< len(PcdList
) - 1) :
750 Item
= PcdList
[Count
]
751 ItemNext
= PcdList
[Count
+ 1]
753 # Make sure in the same token space the TokenValue should be unique
755 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
756 SameTokenValuePcdList
= []
757 SameTokenValuePcdList
.append(Item
)
758 SameTokenValuePcdList
.append(ItemNext
)
759 RemainPcdListLength
= len(PcdList
) - Count
- 2
760 for ValueSameCount
in range(RemainPcdListLength
):
761 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
762 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
766 # Sort same token value PCD list with TokenGuid and TokenCName
768 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
769 SameTokenValuePcdListCount
= 0
770 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
771 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
772 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
774 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
778 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
779 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
782 SameTokenValuePcdListCount
+= 1
783 Count
+= SameTokenValuePcdListCount
786 PcdList
= Package
.Pcds
.values()
787 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
789 while (Count
< len(PcdList
) - 1) :
790 Item
= PcdList
[Count
]
791 ItemNext
= PcdList
[Count
+ 1]
793 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
795 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
799 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
800 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
804 ## Generate fds command
805 def _GenFdsCommand(self
):
806 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
808 ## Create makefile for the platform and modules in it
810 # @param CreateDepsMakeFile Flag indicating if the makefile for
811 # modules will be created as well
813 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
814 if CreateDepsMakeFile
:
815 for Pa
in self
.AutoGenObjectList
:
816 Pa
.CreateMakeFile(CreateDepsMakeFile
)
818 ## Create autogen code for platform and modules
820 # Since there's no autogen code for platform, this method will do nothing
821 # if CreateModuleCodeFile is set to False.
823 # @param CreateDepsCodeFile Flag indicating if creating module's
824 # autogen code file or not
826 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
827 if not CreateDepsCodeFile
:
829 for Pa
in self
.AutoGenObjectList
:
830 Pa
.CreateCodeFile(CreateDepsCodeFile
)
832 ## Create AsBuilt INF file the platform
834 def CreateAsBuiltInf(self
):
837 Name
= property(_GetName
)
838 Guid
= property(_GetGuid
)
839 Version
= property(_GetVersion
)
840 OutputDir
= property(_GetOutputDir
)
842 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
844 BuildDir
= property(_GetBuildDir
)
845 FvDir
= property(_GetFvDir
)
846 MakeFileDir
= property(_GetMakeFileDir
)
847 BuildCommand
= property(_GetBuildCommand
)
848 GenFdsCommand
= property(_GenFdsCommand
)
850 ## AutoGen class for platform
852 # PlatformAutoGen class will process the original information in platform
853 # file in order to generate makefile for platform.
855 class PlatformAutoGen(AutoGen
):
857 # Used to store all PCDs for both PEI and DXE phase, in order to generate
858 # correct PCD database
861 _NonDynaPcdList_
= []
864 # The priority list while override build option
866 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
867 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
868 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
869 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
870 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
871 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
872 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
873 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
874 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
875 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
876 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
877 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
878 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
879 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
880 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
881 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
883 ## The real constructor of PlatformAutoGen
885 # This method is not supposed to be called by users of PlatformAutoGen. It's
886 # only used by factory method __new__() to do real initialization work for an
887 # object of PlatformAutoGen
889 # @param Workspace WorkspaceAutoGen object
890 # @param PlatformFile Platform file (DSC file)
891 # @param Target Build target (DEBUG, RELEASE)
892 # @param Toolchain Name of tool chain
893 # @param Arch arch of the platform supports
895 def _Init(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
896 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
897 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
899 self
.MetaFile
= PlatformFile
900 self
.Workspace
= Workspace
901 self
.WorkspaceDir
= Workspace
.WorkspaceDir
902 self
.ToolChain
= Toolchain
903 self
.BuildTarget
= Target
905 self
.SourceDir
= PlatformFile
.SubDir
906 self
.SourceOverrideDir
= None
907 self
.FdTargetList
= self
.Workspace
.FdTargetList
908 self
.FvTargetList
= self
.Workspace
.FvTargetList
910 # get the original module/package/platform objects
911 self
.BuildDatabase
= Workspace
.BuildDatabase
913 # flag indicating if the makefile/C-code file has been created or not
914 self
.IsMakeFileCreated
= False
915 self
.IsCodeFileCreated
= False
917 self
._Platform
= None
922 self
._BuildRule
= None
923 self
._SourceDir
= None
924 self
._BuildDir
= None
925 self
._OutputDir
= None
927 self
._MakeFileDir
= None
930 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
931 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
932 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
933 self
._NonDynamicPcdDict
= {}
935 self
._ToolDefinitions
= None
936 self
._ToolDefFile
= None # toolcode : tool path
937 self
._ToolChainFamily
= None
938 self
._BuildRuleFamily
= None
939 self
._BuildOption
= None # toolcode : option
940 self
._EdkBuildOption
= None # edktoolcode : option
941 self
._EdkIIBuildOption
= None # edkiitoolcode : option
942 self
._PackageList
= None
943 self
._ModuleAutoGenList
= None
944 self
._LibraryAutoGenList
= None
945 self
._BuildCommand
= None
946 self
._AsBuildInfList
= []
947 self
._AsBuildModuleList
= []
948 if GlobalData
.gFdfParser
!= None:
949 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
950 for Inf
in self
._AsBuildInfList
:
951 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
952 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
953 if not M
.IsSupportedArch
:
955 self
._AsBuildModuleList
.append(InfClass
)
956 # get library/modules for build
957 self
.LibraryBuildDirectoryList
= []
958 self
.ModuleBuildDirectoryList
= []
962 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
964 ## Create autogen code for platform and modules
966 # Since there's no autogen code for platform, this method will do nothing
967 # if CreateModuleCodeFile is set to False.
969 # @param CreateModuleCodeFile Flag indicating if creating module's
970 # autogen code file or not
972 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
973 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
974 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
977 for Ma
in self
.ModuleAutoGenList
:
978 Ma
.CreateCodeFile(True)
980 # don't do this twice
981 self
.IsCodeFileCreated
= True
983 ## Generate Fds Command
984 def _GenFdsCommand(self
):
985 return self
.Workspace
.GenFdsCommand
987 ## Create makefile for the platform and mdoules in it
989 # @param CreateModuleMakeFile Flag indicating if the makefile for
990 # modules will be created as well
992 def CreateMakeFile(self
, CreateModuleMakeFile
=False):
993 if CreateModuleMakeFile
:
994 for ModuleFile
in self
.Platform
.Modules
:
995 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
996 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
997 Ma
.CreateMakeFile(True)
998 #Ma.CreateAsBuiltInf()
1000 # no need to create makefile for the platform more than once
1001 if self
.IsMakeFileCreated
:
1004 # create library/module build dirs for platform
1005 Makefile
= GenMake
.PlatformMakefile(self
)
1006 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
1007 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
1009 self
.IsMakeFileCreated
= True
1011 ## Deal with Shared FixedAtBuild Pcds
1013 def CollectFixedAtBuildPcds(self
):
1014 for LibAuto
in self
.LibraryAutoGenList
:
1015 FixedAtBuildPcds
= {}
1016 ShareFixedAtBuildPcdsSameValue
= {}
1017 for Module
in LibAuto
._ReferenceModules
:
1018 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
1019 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1020 if key
not in FixedAtBuildPcds
:
1021 ShareFixedAtBuildPcdsSameValue
[key
] = True
1022 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
1024 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
1025 ShareFixedAtBuildPcdsSameValue
[key
] = False
1026 for Pcd
in LibAuto
.FixedAtBuildPcds
:
1027 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1028 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
1031 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
1032 if DscPcd
.Type
!= "FixedAtBuild":
1034 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
1035 LibAuto
.ConstPcd
[key
] = Pcd
.DefaultValue
1037 ## Collect dynamic PCDs
1039 # Gather dynamic PCDs list from each module and their settings from platform
1040 # This interface should be invoked explicitly when platform action is created.
1042 def CollectPlatformDynamicPcds(self
):
1043 # Override the platform Pcd's value by build option
1044 if GlobalData
.BuildOptionPcd
:
1045 for key
in self
.Platform
.Pcds
:
1046 PlatformPcd
= self
.Platform
.Pcds
[key
]
1047 for PcdItem
in GlobalData
.BuildOptionPcd
:
1048 if (PlatformPcd
.TokenSpaceGuidCName
, PlatformPcd
.TokenCName
) == (PcdItem
[0], PcdItem
[1]):
1049 PlatformPcd
.DefaultValue
= PcdItem
[2]
1050 if PlatformPcd
.SkuInfoList
:
1051 Sku
= PlatformPcd
.SkuInfoList
[PlatformPcd
.SkuInfoList
.keys()[0]]
1052 Sku
.DefaultValue
= PcdItem
[2]
1055 # for gathering error information
1056 NoDatumTypePcdList
= set()
1058 self
._GuidValue
= {}
1060 for InfName
in self
._AsBuildInfList
:
1061 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
1062 FdfModuleList
.append(os
.path
.normpath(InfName
))
1063 for F
in self
.Platform
.Modules
.keys():
1064 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
1065 #GuidValue.update(M.Guids)
1067 self
.Platform
.Modules
[F
].M
= M
1069 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
1070 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1071 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1072 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
1074 # Check the PCD from Binary INF or Source INF
1075 if M
.IsBinaryModule
== True:
1076 PcdFromModule
.IsFromBinaryInf
= True
1078 # Check the PCD from DSC or not
1079 if (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
.keys():
1080 PcdFromModule
.IsFromDsc
= True
1082 PcdFromModule
.IsFromDsc
= False
1083 if PcdFromModule
.Type
in GenC
.gDynamicPcd
or PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1084 if F
.Path
not in FdfModuleList
:
1085 # If one of the Source built modules listed in the DSC is not listed
1086 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1087 # access method (it is only listed in the DEC file that declares the
1088 # PCD as PcdsDynamic), then build tool will report warning message
1089 # notify the PI that they are attempting to build a module that must
1090 # be included in a flash image in order to be functional. These Dynamic
1091 # PCD will not be added into the Database unless it is used by other
1092 # modules that are included in the FDF file.
1093 if PcdFromModule
.Type
in GenC
.gDynamicPcd
and \
1094 PcdFromModule
.IsFromBinaryInf
== False:
1095 # Print warning message to let the developer make a determine.
1096 if PcdFromModule
not in PcdNotInDb
:
1097 PcdNotInDb
.append(PcdFromModule
)
1099 # If one of the Source built modules listed in the DSC is not listed in
1100 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1101 # access method (it is only listed in the DEC file that declares the
1102 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1103 # PCD to the Platform's PCD Database.
1104 if PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1105 if PcdFromModule
not in PcdNotInDb
:
1106 PcdNotInDb
.append(PcdFromModule
)
1109 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1110 # it should be stored in Pcd PEI database, If a dynamic only
1111 # used by DXE module, it should be stored in DXE PCD database.
1112 # The default Phase is DXE
1114 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1115 PcdFromModule
.Phase
= "PEI"
1116 if PcdFromModule
not in self
._DynaPcdList
_:
1117 self
._DynaPcdList
_.append(PcdFromModule
)
1118 elif PcdFromModule
.Phase
== 'PEI':
1119 # overwrite any the same PCD existing, if Phase is PEI
1120 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1121 self
._DynaPcdList
_[Index
] = PcdFromModule
1122 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1123 self
._NonDynaPcdList
_.append(PcdFromModule
)
1124 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1125 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1126 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1127 #The PCD from Binary INF will override the same one from source INF
1128 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1129 PcdFromModule
.Pending
= False
1130 self
._NonDynaPcdList
_.append (PcdFromModule
)
1131 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1133 for ModuleInf
in self
.Platform
.Modules
.keys():
1134 DscModuleList
.append (os
.path
.normpath(ModuleInf
.Path
))
1135 # add the PCD from modules that listed in FDF but not in DSC to Database
1136 for InfName
in FdfModuleList
:
1137 if InfName
not in DscModuleList
:
1138 InfClass
= PathClass(InfName
)
1139 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1140 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1141 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1142 # For binary module, if in current arch, we need to list the PCDs into database.
1143 if not M
.IsSupportedArch
:
1145 # Override the module PCD setting by platform setting
1146 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1147 for PcdFromModule
in ModulePcdList
:
1148 PcdFromModule
.IsFromBinaryInf
= True
1149 PcdFromModule
.IsFromDsc
= False
1150 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1151 if PcdFromModule
.Type
not in GenC
.gDynamicExPcd
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1152 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1154 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1155 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1156 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1157 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1158 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1159 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1160 PcdFromModule
.Phase
= "PEI"
1161 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1162 self
._DynaPcdList
_.append(PcdFromModule
)
1163 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1164 self
._NonDynaPcdList
_.append(PcdFromModule
)
1165 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1166 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1167 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1168 # module & DXE module at a same time.
1169 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1170 # INF file as DynamicEx.
1171 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1172 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1173 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1174 for PcdFromModule
in self
._NonDynaPcdList
_:
1175 # If a PCD is not listed in the DSC file, but binary INF files used by
1176 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1177 # section, AND all source INF files used by this platform the build
1178 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1179 # section, then the tools must NOT add the PCD to the Platform's PCD
1180 # Database; the build must assign the access method for this PCD as
1181 # PcdsPatchableInModule.
1182 if PcdFromModule
not in self
._DynaPcdList
_:
1184 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1185 if PcdFromModule
.IsFromDsc
== False and \
1186 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1187 PcdFromModule
.IsFromBinaryInf
== True and \
1188 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1189 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1190 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1192 # print out error information and break the build, if error found
1193 if len(NoDatumTypePcdList
) > 0:
1194 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1195 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1197 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1198 % NoDatumTypePcdListString
)
1199 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1200 self
._DynamicPcdList
= self
._DynaPcdList
_
1202 # Sort dynamic PCD list to:
1203 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1204 # try to be put header of dynamicd List
1205 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1207 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1209 UnicodePcdArray
= []
1213 VpdFile
= VpdInfoFile
.VpdInfoFile()
1214 NeedProcessVpdMapFile
= False
1216 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1217 for Pcd
in self
._DynamicPcdList
:
1218 # just pick the a value to determine whether is unicode string type
1219 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1220 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1222 PcdValue
= Sku
.DefaultValue
1223 if Pcd
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1224 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1225 UnicodePcdArray
.append(Pcd
)
1226 elif len(Sku
.VariableName
) > 0:
1227 # if found HII type PCD then insert to right of UnicodeIndex
1228 HiiPcdArray
.append(Pcd
)
1230 OtherPcdArray
.append(Pcd
)
1231 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1232 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1234 PlatformPcds
= self
.Platform
.Pcds
.keys()
1237 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1239 for PcdKey
in PlatformPcds
:
1240 Pcd
= self
.Platform
.Pcds
[PcdKey
]
1241 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1242 PcdKey
in VpdPcdDict
:
1243 Pcd
= VpdPcdDict
[PcdKey
]
1244 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1245 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1246 PcdValue
= Sku
.DefaultValue
1248 PcdValue
= Pcd
.DefaultValue
1249 if Sku
.VpdOffset
!= '*':
1250 if PcdValue
.startswith("{"):
1252 elif PcdValue
.startswith("L"):
1257 VpdOffset
= int(Sku
.VpdOffset
)
1260 VpdOffset
= int(Sku
.VpdOffset
, 16)
1262 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
1263 if VpdOffset
% Alignment
!= 0:
1264 if PcdValue
.startswith("{"):
1265 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
1267 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1268 VpdFile
.Add(Pcd
, Sku
.VpdOffset
)
1269 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1270 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1271 NeedProcessVpdMapFile
= True
1272 if self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== '':
1273 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1274 "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.")
1278 # Fix the PCDs define in VPD PCD section that never referenced by module.
1279 # An example is PCD for signature usage.
1281 for DscPcd
in PlatformPcds
:
1282 DscPcdEntry
= self
.Platform
.Pcds
[DscPcd
]
1283 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1284 if not (self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== ''):
1286 for VpdPcd
in VpdFile
._VpdArray
.keys():
1287 # This PCD has been referenced by module
1288 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1289 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1292 # Not found, it should be signature
1294 # just pick the a value to determine whether is unicode string type
1295 for (SkuName
,Sku
) in DscPcdEntry
.SkuInfoList
.items():
1296 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1298 # Need to iterate DEC pcd information to get the value & datumtype
1299 for eachDec
in self
.PackageList
:
1300 for DecPcd
in eachDec
.Pcds
:
1301 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1302 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1303 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1304 # Print warning message to let the developer make a determine.
1305 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1306 File
=self
.MetaFile
, \
1307 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1308 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1310 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1311 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1312 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1313 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1314 # Only fix the value while no value provided in DSC file.
1315 if (Sku
.DefaultValue
== "" or Sku
.DefaultValue
==None):
1316 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1318 if DscPcdEntry
not in self
._DynamicPcdList
:
1319 self
._DynamicPcdList
.append(DscPcdEntry
)
1320 # Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]
1321 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1322 PcdValue
= Sku
.DefaultValue
1324 PcdValue
= DscPcdEntry
.DefaultValue
1325 if Sku
.VpdOffset
!= '*':
1326 if PcdValue
.startswith("{"):
1328 elif PcdValue
.startswith("L"):
1333 VpdOffset
= int(Sku
.VpdOffset
)
1336 VpdOffset
= int(Sku
.VpdOffset
, 16)
1338 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
1339 if VpdOffset
% Alignment
!= 0:
1340 if PcdValue
.startswith("{"):
1341 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
1343 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1344 VpdFile
.Add(DscPcdEntry
, Sku
.VpdOffset
)
1345 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1346 NeedProcessVpdMapFile
= True
1347 if DscPcdEntry
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1348 UnicodePcdArray
.append(DscPcdEntry
)
1349 elif len(Sku
.VariableName
) > 0:
1350 HiiPcdArray
.append(DscPcdEntry
)
1352 OtherPcdArray
.append(DscPcdEntry
)
1354 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1358 if (self
.Platform
.FlashDefinition
== None or self
.Platform
.FlashDefinition
== '') and \
1359 VpdFile
.GetCount() != 0:
1360 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1361 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1363 if VpdFile
.GetCount() != 0:
1364 FvPath
= os
.path
.join(self
.BuildDir
, "FV")
1365 if not os
.path
.exists(FvPath
):
1369 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1371 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1373 if VpdFile
.Write(VpdFilePath
):
1374 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1376 for ToolDef
in self
.ToolDefinition
.values():
1377 if ToolDef
.has_key("GUID") and ToolDef
["GUID"] == self
.Platform
.VpdToolGuid
:
1378 if not ToolDef
.has_key("PATH"):
1379 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1380 BPDGToolName
= ToolDef
["PATH"]
1382 # Call third party GUID BPDG tool.
1383 if BPDGToolName
!= None:
1384 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1386 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.")
1388 # Process VPD map file generated by third party BPDG tool
1389 if NeedProcessVpdMapFile
:
1390 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1391 if os
.path
.exists(VpdMapFilePath
):
1392 VpdFile
.Read(VpdMapFilePath
)
1395 for Pcd
in self
._DynamicPcdList
:
1396 # just pick the a value to determine whether is unicode string type
1398 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1399 if Sku
.VpdOffset
== "*":
1400 Sku
.VpdOffset
= VpdFile
.GetOffset(Pcd
)[i
].strip()
1403 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1405 # Delete the DynamicPcdList At the last time enter into this function
1406 del self
._DynamicPcdList
[:]
1407 self
._DynamicPcdList
.extend(UnicodePcdArray
)
1408 self
._DynamicPcdList
.extend(HiiPcdArray
)
1409 self
._DynamicPcdList
.extend(OtherPcdArray
)
1410 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1412 ## Return the platform build data object
1413 def _GetPlatform(self
):
1414 if self
._Platform
== None:
1415 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1416 return self
._Platform
1418 ## Return platform name
1420 return self
.Platform
.PlatformName
1422 ## Return the meta file GUID
1424 return self
.Platform
.Guid
1426 ## Return the platform version
1427 def _GetVersion(self
):
1428 return self
.Platform
.Version
1430 ## Return the FDF file name
1431 def _GetFdfFile(self
):
1432 if self
._FdfFile
== None:
1433 if self
.Workspace
.FdfFile
!= "":
1434 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1437 return self
._FdfFile
1439 ## Return the build output directory platform specifies
1440 def _GetOutputDir(self
):
1441 return self
.Platform
.OutputDirectory
1443 ## Return the directory to store all intermediate and final files built
1444 def _GetBuildDir(self
):
1445 if self
._BuildDir
== None:
1446 if os
.path
.isabs(self
.OutputDir
):
1447 self
._BuildDir
= path
.join(
1448 path
.abspath(self
.OutputDir
),
1449 self
.BuildTarget
+ "_" + self
.ToolChain
,
1452 self
._BuildDir
= path
.join(
1455 self
.BuildTarget
+ "_" + self
.ToolChain
,
1457 return self
._BuildDir
1459 ## Return directory of platform makefile
1461 # @retval string Makefile directory
1463 def _GetMakeFileDir(self
):
1464 if self
._MakeFileDir
== None:
1465 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1466 return self
._MakeFileDir
1468 ## Return build command string
1470 # @retval string Build command string
1472 def _GetBuildCommand(self
):
1473 if self
._BuildCommand
== None:
1474 self
._BuildCommand
= []
1475 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1476 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1477 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1478 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1480 self
._BuildCommand
+= SplitOption(NewOption
)
1481 return self
._BuildCommand
1483 ## Get tool chain definition
1485 # Get each tool defition for given tool chain from tools_def.txt and platform
1487 def _GetToolDefinition(self
):
1488 if self
._ToolDefinitions
== None:
1489 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1490 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1491 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1492 ExtraData
="[%s]" % self
.MetaFile
)
1493 self
._ToolDefinitions
= {}
1495 for Def
in ToolDefinition
:
1496 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1497 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1500 Value
= ToolDefinition
[Def
]
1501 # don't record the DLL
1503 DllPathList
.add(Value
)
1506 if Tool
not in self
._ToolDefinitions
:
1507 self
._ToolDefinitions
[Tool
] = {}
1508 self
._ToolDefinitions
[Tool
][Attr
] = Value
1512 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1513 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1514 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1515 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1517 for Tool
in self
._ToolDefinitions
:
1518 for Attr
in self
._ToolDefinitions
[Tool
]:
1519 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1520 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1521 # check if override is indicated
1522 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1523 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1525 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1528 # Don't put MAKE definition in the file
1532 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1534 # Don't put MAKE definition in the file
1539 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1542 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1543 for DllPath
in DllPathList
:
1544 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1545 os
.environ
["MAKE_FLAGS"] = MakeFlags
1547 return self
._ToolDefinitions
1549 ## Return the paths of tools
1550 def _GetToolDefFile(self
):
1551 if self
._ToolDefFile
== None:
1552 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1553 return self
._ToolDefFile
1555 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1556 def _GetToolChainFamily(self
):
1557 if self
._ToolChainFamily
== None:
1558 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1559 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1560 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1561 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1562 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1564 self
._ToolChainFamily
= "MSFT"
1566 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1567 return self
._ToolChainFamily
1569 def _GetBuildRuleFamily(self
):
1570 if self
._BuildRuleFamily
== None:
1571 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1572 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1573 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1574 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1575 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1577 self
._BuildRuleFamily
= "MSFT"
1579 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1580 return self
._BuildRuleFamily
1582 ## Return the build options specific for all modules in this platform
1583 def _GetBuildOptions(self
):
1584 if self
._BuildOption
== None:
1585 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1586 return self
._BuildOption
1588 ## Return the build options specific for EDK modules in this platform
1589 def _GetEdkBuildOptions(self
):
1590 if self
._EdkBuildOption
== None:
1591 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1592 return self
._EdkBuildOption
1594 ## Return the build options specific for EDKII modules in this platform
1595 def _GetEdkIIBuildOptions(self
):
1596 if self
._EdkIIBuildOption
== None:
1597 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1598 return self
._EdkIIBuildOption
1600 ## Parse build_rule.txt in Conf Directory.
1602 # @retval BuildRule object
1604 def _GetBuildRule(self
):
1605 if self
._BuildRule
== None:
1606 BuildRuleFile
= None
1607 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1608 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1609 if BuildRuleFile
in [None, '']:
1610 BuildRuleFile
= gDefaultBuildRuleFile
1611 self
._BuildRule
= BuildRule(BuildRuleFile
)
1612 if self
._BuildRule
._FileVersion
== "":
1613 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
1615 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1616 # If Build Rule's version is less than the version number required by the tools, halting the build.
1617 EdkLogger
.error("build", AUTOGEN_ERROR
,
1618 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])"\
1619 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1621 return self
._BuildRule
1623 ## Summarize the packages used by modules in this platform
1624 def _GetPackageList(self
):
1625 if self
._PackageList
== None:
1626 self
._PackageList
= set()
1627 for La
in self
.LibraryAutoGenList
:
1628 self
._PackageList
.update(La
.DependentPackageList
)
1629 for Ma
in self
.ModuleAutoGenList
:
1630 self
._PackageList
.update(Ma
.DependentPackageList
)
1631 #Collect package set information from INF of FDF
1633 for ModuleFile
in self
._AsBuildModuleList
:
1634 if ModuleFile
in self
.Platform
.Modules
:
1636 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1637 PkgSet
.update(ModuleData
.Packages
)
1638 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
1639 return self
._PackageList
1641 def _GetNonDynamicPcdDict(self
):
1642 if self
._NonDynamicPcdDict
:
1643 return self
._NonDynamicPcdDict
1644 for Pcd
in self
.NonDynamicPcdList
:
1645 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
1646 return self
._NonDynamicPcdDict
1648 ## Get list of non-dynamic PCDs
1649 def _GetNonDynamicPcdList(self
):
1650 if self
._NonDynamicPcdList
== None:
1651 self
.CollectPlatformDynamicPcds()
1652 return self
._NonDynamicPcdList
1654 ## Get list of dynamic PCDs
1655 def _GetDynamicPcdList(self
):
1656 if self
._DynamicPcdList
== None:
1657 self
.CollectPlatformDynamicPcds()
1658 return self
._DynamicPcdList
1660 ## Generate Token Number for all PCD
1661 def _GetPcdTokenNumbers(self
):
1662 if self
._PcdTokenNumber
== None:
1663 self
._PcdTokenNumber
= sdict()
1666 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1670 # TokenNumber 0 ~ 10
1672 # TokeNumber 11 ~ 20
1674 for Pcd
in self
.DynamicPcdList
:
1675 if Pcd
.Phase
== "PEI":
1676 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1677 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1678 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1681 for Pcd
in self
.DynamicPcdList
:
1682 if Pcd
.Phase
== "PEI":
1683 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
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
== "DXE":
1690 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
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 ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
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
.NonDynamicPcdList
:
1703 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1705 return self
._PcdTokenNumber
1707 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
1708 def _GetAutoGenObjectList(self
):
1709 self
._ModuleAutoGenList
= []
1710 self
._LibraryAutoGenList
= []
1711 for ModuleFile
in self
.Platform
.Modules
:
1720 if Ma
not in self
._ModuleAutoGenList
:
1721 self
._ModuleAutoGenList
.append(Ma
)
1722 for La
in Ma
.LibraryAutoGenList
:
1723 if La
not in self
._LibraryAutoGenList
:
1724 self
._LibraryAutoGenList
.append(La
)
1725 if Ma
not in La
._ReferenceModules
:
1726 La
._ReferenceModules
.append(Ma
)
1728 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
1729 def _GetModuleAutoGenList(self
):
1730 if self
._ModuleAutoGenList
== None:
1731 self
._GetAutoGenObjectList
()
1732 return self
._ModuleAutoGenList
1734 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
1735 def _GetLibraryAutoGenList(self
):
1736 if self
._LibraryAutoGenList
== None:
1737 self
._GetAutoGenObjectList
()
1738 return self
._LibraryAutoGenList
1740 ## Test if a module is supported by the platform
1742 # An error will be raised directly if the module or its arch is not supported
1743 # by the platform or current configuration
1745 def ValidModule(self
, Module
):
1746 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
1747 or Module
in self
._AsBuildModuleList
1749 ## Resolve the library classes in a module to library instances
1751 # This method will not only resolve library classes but also sort the library
1752 # instances according to the dependency-ship.
1754 # @param Module The module from which the library classes will be resolved
1756 # @retval library_list List of library instances sorted
1758 def ApplyLibraryInstance(self
, Module
):
1759 ModuleType
= Module
.ModuleType
1761 # for overridding library instances with module specific setting
1762 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
1764 # add forced library instances (specified under LibraryClasses sections)
1766 # If a module has a MODULE_TYPE of USER_DEFINED,
1767 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
1769 if Module
.ModuleType
!= SUP_MODULE_USER_DEFINED
:
1770 for LibraryClass
in self
.Platform
.LibraryClasses
.GetKeys():
1771 if LibraryClass
.startswith("NULL") and self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]:
1772 Module
.LibraryClasses
[LibraryClass
] = self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]
1774 # add forced library instances (specified in module overrides)
1775 for LibraryClass
in PlatformModule
.LibraryClasses
:
1776 if LibraryClass
.startswith("NULL"):
1777 Module
.LibraryClasses
[LibraryClass
] = PlatformModule
.LibraryClasses
[LibraryClass
]
1780 LibraryConsumerList
= [Module
]
1782 ConsumedByList
= sdict()
1783 LibraryInstance
= sdict()
1785 EdkLogger
.verbose("")
1786 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
1787 while len(LibraryConsumerList
) > 0:
1788 M
= LibraryConsumerList
.pop()
1789 for LibraryClassName
in M
.LibraryClasses
:
1790 if LibraryClassName
not in LibraryInstance
:
1791 # override library instance for this module
1792 if LibraryClassName
in PlatformModule
.LibraryClasses
:
1793 LibraryPath
= PlatformModule
.LibraryClasses
[LibraryClassName
]
1795 LibraryPath
= self
.Platform
.LibraryClasses
[LibraryClassName
, ModuleType
]
1796 if LibraryPath
== None or LibraryPath
== "":
1797 LibraryPath
= M
.LibraryClasses
[LibraryClassName
]
1798 if LibraryPath
== None or LibraryPath
== "":
1799 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
1800 "Instance of library class [%s] is not found" % LibraryClassName
,
1802 ExtraData
="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M
), self
.Arch
, str(Module
)))
1804 LibraryModule
= self
.BuildDatabase
[LibraryPath
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1805 # for those forced library instance (NULL library), add a fake library class
1806 if LibraryClassName
.startswith("NULL"):
1807 LibraryModule
.LibraryClass
.append(LibraryClassObject(LibraryClassName
, [ModuleType
]))
1808 elif LibraryModule
.LibraryClass
== None \
1809 or len(LibraryModule
.LibraryClass
) == 0 \
1810 or (ModuleType
!= 'USER_DEFINED'
1811 and ModuleType
not in LibraryModule
.LibraryClass
[0].SupModList
):
1812 # only USER_DEFINED can link against any library instance despite of its SupModList
1813 EdkLogger
.error("build", OPTION_MISSING
,
1814 "Module type [%s] is not supported by library instance [%s]" \
1815 % (ModuleType
, LibraryPath
), File
=self
.MetaFile
,
1816 ExtraData
="consumed by [%s]" % str(Module
))
1818 LibraryInstance
[LibraryClassName
] = LibraryModule
1819 LibraryConsumerList
.append(LibraryModule
)
1820 EdkLogger
.verbose("\t" + str(LibraryClassName
) + " : " + str(LibraryModule
))
1822 LibraryModule
= LibraryInstance
[LibraryClassName
]
1824 if LibraryModule
== None:
1827 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
1828 Constructor
.append(LibraryModule
)
1830 if LibraryModule
not in ConsumedByList
:
1831 ConsumedByList
[LibraryModule
] = []
1832 # don't add current module itself to consumer list
1834 if M
in ConsumedByList
[LibraryModule
]:
1836 ConsumedByList
[LibraryModule
].append(M
)
1838 # Initialize the sorted output list to the empty set
1840 SortedLibraryList
= []
1842 # Q <- Set of all nodes with no incoming edges
1844 LibraryList
= [] #LibraryInstance.values()
1846 for LibraryClassName
in LibraryInstance
:
1847 M
= LibraryInstance
[LibraryClassName
]
1848 LibraryList
.append(M
)
1849 if ConsumedByList
[M
] == []:
1853 # start the DAG algorithm
1857 while Q
== [] and EdgeRemoved
:
1859 # for each node Item with a Constructor
1860 for Item
in LibraryList
:
1861 if Item
not in Constructor
:
1863 # for each Node without a constructor with an edge e from Item to Node
1864 for Node
in ConsumedByList
[Item
]:
1865 if Node
in Constructor
:
1867 # remove edge e from the graph if Node has no constructor
1868 ConsumedByList
[Item
].remove(Node
)
1870 if ConsumedByList
[Item
] == []:
1871 # insert Item into Q
1876 # DAG is done if there's no more incoming edge for all nodes
1880 # remove node from Q
1883 SortedLibraryList
.append(Node
)
1885 # for each node Item with an edge e from Node to Item do
1886 for Item
in LibraryList
:
1887 if Node
not in ConsumedByList
[Item
]:
1889 # remove edge e from the graph
1890 ConsumedByList
[Item
].remove(Node
)
1892 if ConsumedByList
[Item
] != []:
1894 # insert Item into Q, if Item has no other incoming edges
1898 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
1900 for Item
in LibraryList
:
1901 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
1902 ErrorMessage
= "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]])
1903 EdkLogger
.error("build", BUILD_ERROR
, 'Library [%s] with constructors has a cycle' % str(Item
),
1904 ExtraData
=ErrorMessage
, File
=self
.MetaFile
)
1905 if Item
not in SortedLibraryList
:
1906 SortedLibraryList
.append(Item
)
1909 # Build the list of constructor and destructir names
1910 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
1912 SortedLibraryList
.reverse()
1913 return SortedLibraryList
1916 ## Override PCD setting (type, value, ...)
1918 # @param ToPcd The PCD to be overrided
1919 # @param FromPcd The PCD overrideing from
1921 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
=""):
1923 # in case there's PCDs coming from FDF file, which have no type given.
1924 # at this point, ToPcd.Type has the type found from dependent
1928 if ToPcd
.Pending
and FromPcd
.Type
not in [None, '']:
1929 ToPcd
.Type
= FromPcd
.Type
1930 elif (ToPcd
.Type
not in [None, '']) and (FromPcd
.Type
not in [None, ''])\
1931 and (ToPcd
.Type
!= FromPcd
.Type
) and (ToPcd
.Type
in FromPcd
.Type
):
1932 if ToPcd
.Type
.strip() == "DynamicEx":
1933 ToPcd
.Type
= FromPcd
.Type
1934 elif ToPcd
.Type
not in [None, ''] and FromPcd
.Type
not in [None, ''] \
1935 and ToPcd
.Type
!= FromPcd
.Type
:
1936 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
1937 ExtraData
="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
1938 % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
,
1939 ToPcd
.Type
, Module
, FromPcd
.Type
),
1942 if FromPcd
.MaxDatumSize
not in [None, '']:
1943 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
1944 if FromPcd
.DefaultValue
not in [None, '']:
1945 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
1946 if FromPcd
.TokenValue
not in [None, '']:
1947 ToPcd
.TokenValue
= FromPcd
.TokenValue
1948 if FromPcd
.MaxDatumSize
not in [None, '']:
1949 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
1950 if FromPcd
.DatumType
not in [None, '']:
1951 ToPcd
.DatumType
= FromPcd
.DatumType
1952 if FromPcd
.SkuInfoList
not in [None, '', []]:
1953 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
1955 # check the validation of datum
1956 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
1958 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
1959 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
))
1960 ToPcd
.validateranges
= FromPcd
.validateranges
1961 ToPcd
.validlists
= FromPcd
.validlists
1962 ToPcd
.expressions
= FromPcd
.expressions
1964 if ToPcd
.DatumType
== "VOID*" and ToPcd
.MaxDatumSize
in ['', None]:
1965 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
1966 % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
))
1967 Value
= ToPcd
.DefaultValue
1968 if Value
in [None, '']:
1969 ToPcd
.MaxDatumSize
= '1'
1970 elif Value
[0] == 'L':
1971 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
1972 elif Value
[0] == '{':
1973 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
1975 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
1977 # apply default SKU for dynamic PCDS if specified one is not available
1978 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_LIST
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_LIST
) \
1979 and ToPcd
.SkuInfoList
in [None, {}, '']:
1980 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
1981 SkuName
= self
.Platform
.SkuName
1984 ToPcd
.SkuInfoList
= {
1985 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
], '', '', '', '', '', ToPcd
.DefaultValue
)
1988 ## Apply PCD setting defined platform to a module
1990 # @param Module The module from which the PCD setting will be overrided
1992 # @retval PCD_list The list PCDs with settings from platform
1994 def ApplyPcdSetting(self
, Module
, Pcds
):
1995 # for each PCD in module
1996 for Name
, Guid
in Pcds
:
1997 PcdInModule
= Pcds
[Name
, Guid
]
1998 # find out the PCD setting in platform
1999 if (Name
, Guid
) in self
.Platform
.Pcds
:
2000 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
2002 PcdInPlatform
= None
2003 # then override the settings if any
2004 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
)
2005 # resolve the VariableGuid value
2006 for SkuId
in PcdInModule
.SkuInfoList
:
2007 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
2008 if Sku
.VariableGuid
== '': continue
2009 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
)
2010 if Sku
.VariableGuidValue
== None:
2011 PackageList
= "\n\t".join([str(P
) for P
in self
.PackageList
])
2014 RESOURCE_NOT_AVAILABLE
,
2015 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
2016 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
2017 % (Guid
, Name
, str(Module
)),
2021 # override PCD settings with module specific setting
2022 if Module
in self
.Platform
.Modules
:
2023 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2024 for Key
in PlatformModule
.Pcds
:
2026 self
._OverridePcd
(Pcds
[Key
], PlatformModule
.Pcds
[Key
], Module
)
2027 return Pcds
.values()
2029 ## Resolve library names to library modules
2031 # (for Edk.x modules)
2033 # @param Module The module from which the library names will be resolved
2035 # @retval library_list The list of library modules
2037 def ResolveLibraryReference(self
, Module
):
2038 EdkLogger
.verbose("")
2039 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
2040 LibraryConsumerList
= [Module
]
2042 # "CompilerStub" is a must for Edk modules
2043 if Module
.Libraries
:
2044 Module
.Libraries
.append("CompilerStub")
2046 while len(LibraryConsumerList
) > 0:
2047 M
= LibraryConsumerList
.pop()
2048 for LibraryName
in M
.Libraries
:
2049 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
2051 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
2052 if LibraryName
.upper() == Key
.upper():
2053 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
2056 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
2057 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
2060 if Library
not in LibraryList
:
2061 LibraryList
.append(Library
)
2062 LibraryConsumerList
.append(Library
)
2063 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
2066 ## Calculate the priority value of the build option
2068 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2070 # @retval Value Priority value based on the priority list.
2072 def CalculatePriorityValue(self
, Key
):
2073 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
2074 PriorityValue
= 0x11111
2076 PriorityValue
&= 0x01111
2077 if ToolChain
== "*":
2078 PriorityValue
&= 0x10111
2080 PriorityValue
&= 0x11011
2081 if CommandType
== "*":
2082 PriorityValue
&= 0x11101
2084 PriorityValue
&= 0x11110
2086 return self
.PrioList
["0x%0.5x" % PriorityValue
]
2089 ## Expand * in build option key
2091 # @param Options Options to be expanded
2093 # @retval options Options expanded
2095 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
2102 # Construct a list contain the build options which need override.
2106 # Key[0] -- tool family
2107 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2109 if (Key
[0] == self
.BuildRuleFamily
and
2110 (ModuleStyle
== None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
2111 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
2112 if Target
== self
.BuildTarget
or Target
== "*":
2113 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
2114 if Arch
== self
.Arch
or Arch
== "*":
2115 if Options
[Key
].startswith("="):
2116 if OverrideList
.get(Key
[1]) != None:
2117 OverrideList
.pop(Key
[1])
2118 OverrideList
[Key
[1]] = Options
[Key
]
2121 # Use the highest priority value.
2123 if (len(OverrideList
) >= 2):
2124 KeyList
= OverrideList
.keys()
2125 for Index
in range(len(KeyList
)):
2126 NowKey
= KeyList
[Index
]
2127 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2128 for Index1
in range(len(KeyList
) - Index
- 1):
2129 NextKey
= KeyList
[Index1
+ Index
+ 1]
2131 # Compare two Key, if one is included by another, choose the higher priority one
2133 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2134 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2135 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2136 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2137 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2138 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2139 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2140 if Options
.get((self
.BuildRuleFamily
, NextKey
)) != None:
2141 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2143 if Options
.get((self
.BuildRuleFamily
, NowKey
)) != None:
2144 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2147 if ModuleStyle
!= None and len (Key
) > 2:
2148 # Check Module style is EDK or EDKII.
2149 # Only append build option for the matched style module.
2150 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2152 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2155 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2156 # if tool chain family doesn't match, skip it
2157 if Tool
in self
.ToolDefinition
and Family
!= "":
2158 FamilyIsNull
= False
2159 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2160 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2162 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2165 # expand any wildcard
2166 if Target
== "*" or Target
== self
.BuildTarget
:
2167 if Tag
== "*" or Tag
== self
.ToolChain
:
2168 if Arch
== "*" or Arch
== self
.Arch
:
2169 if Tool
not in BuildOptions
:
2170 BuildOptions
[Tool
] = {}
2171 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2172 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2174 # append options for the same tool
2175 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2176 # Build Option Family has been checked, which need't to be checked again for family.
2177 if FamilyMatch
or FamilyIsNull
:
2181 if ModuleStyle
!= None and len (Key
) > 2:
2182 # Check Module style is EDK or EDKII.
2183 # Only append build option for the matched style module.
2184 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2186 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2189 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2190 # if tool chain family doesn't match, skip it
2191 if Tool
not in self
.ToolDefinition
or Family
== "":
2193 # option has been added before
2194 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2197 # expand any wildcard
2198 if Target
== "*" or Target
== self
.BuildTarget
:
2199 if Tag
== "*" or Tag
== self
.ToolChain
:
2200 if Arch
== "*" or Arch
== self
.Arch
:
2201 if Tool
not in BuildOptions
:
2202 BuildOptions
[Tool
] = {}
2203 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2204 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2206 # append options for the same tool
2207 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2210 ## Append build options in platform to a module
2212 # @param Module The module to which the build options will be appened
2214 # @retval options The options appended with build options in platform
2216 def ApplyBuildOption(self
, Module
):
2217 # Get the different options for the different style module
2218 if Module
.AutoGenVersion
< 0x00010005:
2219 PlatformOptions
= self
.EdkBuildOption
2220 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2222 PlatformOptions
= self
.EdkIIBuildOption
2223 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2224 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2225 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2226 if Module
in self
.Platform
.Modules
:
2227 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2228 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2230 PlatformModuleOptions
= {}
2232 BuildRuleOrder
= None
2233 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2234 for Tool
in Options
:
2235 for Attr
in Options
[Tool
]:
2236 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2237 BuildRuleOrder
= Options
[Tool
][Attr
]
2239 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2240 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2241 self
.ToolDefinition
.keys())
2243 for Tool
in AllTools
:
2244 if Tool
not in BuildOptions
:
2245 BuildOptions
[Tool
] = {}
2247 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2248 if Tool
not in Options
:
2250 for Attr
in Options
[Tool
]:
2251 Value
= Options
[Tool
][Attr
]
2253 # Do not generate it in Makefile
2255 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2257 if Attr
not in BuildOptions
[Tool
]:
2258 BuildOptions
[Tool
][Attr
] = ""
2259 # check if override is indicated
2260 if Value
.startswith('='):
2261 ToolPath
= Value
[1:]
2262 ToolPath
= mws
.handleWsMacro(ToolPath
)
2263 BuildOptions
[Tool
][Attr
] = ToolPath
2265 Value
= mws
.handleWsMacro(Value
)
2266 BuildOptions
[Tool
][Attr
] += " " + Value
2267 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
!= None:
2269 # Override UNI flag only for EDK module.
2271 if 'BUILD' not in BuildOptions
:
2272 BuildOptions
['BUILD'] = {}
2273 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2274 return BuildOptions
, BuildRuleOrder
2276 Platform
= property(_GetPlatform
)
2277 Name
= property(_GetName
)
2278 Guid
= property(_GetGuid
)
2279 Version
= property(_GetVersion
)
2281 OutputDir
= property(_GetOutputDir
)
2282 BuildDir
= property(_GetBuildDir
)
2283 MakeFileDir
= property(_GetMakeFileDir
)
2284 FdfFile
= property(_GetFdfFile
)
2286 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2287 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2288 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2289 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2290 PackageList
= property(_GetPackageList
)
2292 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2293 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2294 ToolChainFamily
= property(_GetToolChainFamily
)
2295 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2296 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2297 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2298 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2300 BuildCommand
= property(_GetBuildCommand
)
2301 BuildRule
= property(_GetBuildRule
)
2302 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2303 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2304 GenFdsCommand
= property(_GenFdsCommand
)
2306 ## ModuleAutoGen class
2308 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2309 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2310 # to the [depex] section in module's inf file.
2312 class ModuleAutoGen(AutoGen
):
2313 ## The real constructor of ModuleAutoGen
2315 # This method is not supposed to be called by users of ModuleAutoGen. It's
2316 # only used by factory method __new__() to do real initialization work for an
2317 # object of ModuleAutoGen
2319 # @param Workspace EdkIIWorkspaceBuild object
2320 # @param ModuleFile The path of module file
2321 # @param Target Build target (DEBUG, RELEASE)
2322 # @param Toolchain Name of tool chain
2323 # @param Arch The arch the module supports
2324 # @param PlatformFile Platform meta-file
2326 def _Init(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2327 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2328 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2330 self
.Workspace
= Workspace
2331 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2333 self
.MetaFile
= ModuleFile
2334 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2335 # check if this module is employed by active platform
2336 if not self
.PlatformInfo
.ValidModule(self
.MetaFile
):
2337 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2338 % (self
.MetaFile
, Arch
))
2341 self
.SourceDir
= self
.MetaFile
.SubDir
2342 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2344 self
.SourceOverrideDir
= None
2345 # use overrided path defined in DSC file
2346 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2347 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2349 self
.ToolChain
= Toolchain
2350 self
.BuildTarget
= Target
2352 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2353 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2355 self
.IsMakeFileCreated
= False
2356 self
.IsCodeFileCreated
= False
2357 self
.IsAsBuiltInfCreated
= False
2358 self
.DepexGenerated
= False
2360 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2361 self
.BuildRuleOrder
= None
2366 self
._Version
= None
2367 self
._ModuleType
= None
2368 self
._ComponentType
= None
2369 self
._PcdIsDriver
= None
2370 self
._AutoGenVersion
= None
2371 self
._LibraryFlag
= None
2372 self
._CustomMakefile
= None
2375 self
._BuildDir
= None
2376 self
._OutputDir
= None
2377 self
._DebugDir
= None
2378 self
._MakeFileDir
= None
2380 self
._IncludePathList
= None
2381 self
._IncludePathLength
= 0
2382 self
._AutoGenFileList
= None
2383 self
._UnicodeFileList
= None
2384 self
._SourceFileList
= None
2385 self
._ObjectFileList
= None
2386 self
._BinaryFileList
= None
2388 self
._DependentPackageList
= None
2389 self
._DependentLibraryList
= None
2390 self
._LibraryAutoGenList
= None
2391 self
._DerivedPackageList
= None
2392 self
._ModulePcdList
= None
2393 self
._LibraryPcdList
= None
2394 self
._PcdComments
= sdict()
2395 self
._GuidList
= None
2396 self
._GuidsUsedByPcd
= None
2397 self
._GuidComments
= sdict()
2398 self
._ProtocolList
= None
2399 self
._ProtocolComments
= sdict()
2400 self
._PpiList
= None
2401 self
._PpiComments
= sdict()
2402 self
._DepexList
= None
2403 self
._DepexExpressionList
= None
2404 self
._BuildOption
= None
2405 self
._BuildOptionIncPathList
= None
2406 self
._BuildTargets
= None
2407 self
._IntroBuildTargetList
= None
2408 self
._FinalBuildTargetList
= None
2409 self
._FileTypes
= None
2410 self
._BuildRules
= None
2412 ## The Modules referenced to this Library
2413 # Only Library has this attribute
2414 self
._ReferenceModules
= []
2416 ## Store the FixedAtBuild Pcds
2418 self
._FixedAtBuildPcds
= []
2423 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2425 # Get FixedAtBuild Pcds of this Module
2426 def _GetFixedAtBuildPcds(self
):
2427 if self
._FixedAtBuildPcds
:
2428 return self
._FixedAtBuildPcds
2429 for Pcd
in self
.ModulePcdList
:
2431 if not (Pcd
.Pending
== False and Pcd
.Type
== "FixedAtBuild"):
2433 elif Pcd
.Type
!= "FixedAtBuild":
2435 if Pcd
not in self
._FixedAtBuildPcds
:
2436 self
._FixedAtBuildPcds
.append(Pcd
)
2438 return self
._FixedAtBuildPcds
2440 def _GetUniqueBaseName(self
):
2441 BaseName
= self
.Name
2442 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2443 if Module
.MetaFile
== self
.MetaFile
:
2445 if Module
.Name
== self
.Name
:
2446 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2447 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2448 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2449 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2452 # Macros could be used in build_rule.txt (also Makefile)
2453 def _GetMacros(self
):
2454 if self
._Macro
== None:
2455 self
._Macro
= sdict()
2456 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2457 self
._Macro
["MODULE_NAME" ] = self
.Name
2458 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2459 self
._Macro
["MODULE_GUID" ] = self
.Guid
2460 self
._Macro
["MODULE_VERSION" ] = self
.Version
2461 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2462 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2463 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2464 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2465 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2467 self
._Macro
["BASE_NAME" ] = self
.Name
2469 self
._Macro
["ARCH" ] = self
.Arch
2470 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2471 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2472 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2473 self
._Macro
["TARGET" ] = self
.BuildTarget
2475 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2476 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2477 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2478 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2479 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2480 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2481 self
._Macro
["DEST_DIR_OUTPUT" ] = self
.OutputDir
2482 self
._Macro
["DEST_DIR_DEBUG" ] = self
.DebugDir
2485 ## Return the module build data object
2486 def _GetModule(self
):
2487 if self
._Module
== None:
2488 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2491 ## Return the module name
2492 def _GetBaseName(self
):
2493 return self
.Module
.BaseName
2495 ## Return the module DxsFile if exist
2496 def _GetDxsFile(self
):
2497 return self
.Module
.DxsFile
2499 ## Return the module SourceOverridePath
2500 def _GetSourceOverridePath(self
):
2501 return self
.Module
.SourceOverridePath
2503 ## Return the module meta-file GUID
2506 # To build same module more than once, the module path with FILE_GUID overridden has
2507 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2508 # in DSC. The overridden GUID can be retrieved from file name
2510 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2512 # Length of GUID is 36
2514 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2515 return self
.Module
.Guid
2517 ## Return the module version
2518 def _GetVersion(self
):
2519 return self
.Module
.Version
2521 ## Return the module type
2522 def _GetModuleType(self
):
2523 return self
.Module
.ModuleType
2525 ## Return the component type (for Edk.x style of module)
2526 def _GetComponentType(self
):
2527 return self
.Module
.ComponentType
2529 ## Return the build type
2530 def _GetBuildType(self
):
2531 return self
.Module
.BuildType
2533 ## Return the PCD_IS_DRIVER setting
2534 def _GetPcdIsDriver(self
):
2535 return self
.Module
.PcdIsDriver
2537 ## Return the autogen version, i.e. module meta-file version
2538 def _GetAutoGenVersion(self
):
2539 return self
.Module
.AutoGenVersion
2541 ## Check if the module is library or not
2542 def _IsLibrary(self
):
2543 if self
._LibraryFlag
== None:
2544 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2545 self
._LibraryFlag
= True
2547 self
._LibraryFlag
= False
2548 return self
._LibraryFlag
2550 ## Check if the module is binary module or not
2551 def _IsBinaryModule(self
):
2552 return self
.Module
.IsBinaryModule
2554 ## Return the directory to store intermediate files of the module
2555 def _GetBuildDir(self
):
2556 if self
._BuildDir
== None:
2557 self
._BuildDir
= path
.join(
2558 self
.PlatformInfo
.BuildDir
,
2561 self
.MetaFile
.BaseName
2563 CreateDirectory(self
._BuildDir
)
2564 return self
._BuildDir
2566 ## Return the directory to store the intermediate object files of the mdoule
2567 def _GetOutputDir(self
):
2568 if self
._OutputDir
== None:
2569 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2570 CreateDirectory(self
._OutputDir
)
2571 return self
._OutputDir
2573 ## Return the directory to store auto-gened source files of the mdoule
2574 def _GetDebugDir(self
):
2575 if self
._DebugDir
== None:
2576 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2577 CreateDirectory(self
._DebugDir
)
2578 return self
._DebugDir
2580 ## Return the path of custom file
2581 def _GetCustomMakefile(self
):
2582 if self
._CustomMakefile
== None:
2583 self
._CustomMakefile
= {}
2584 for Type
in self
.Module
.CustomMakefile
:
2585 if Type
in gMakeTypeMap
:
2586 MakeType
= gMakeTypeMap
[Type
]
2589 if self
.SourceOverrideDir
!= None:
2590 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2591 if not os
.path
.exists(File
):
2592 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2594 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2595 self
._CustomMakefile
[MakeType
] = File
2596 return self
._CustomMakefile
2598 ## Return the directory of the makefile
2600 # @retval string The directory string of module's makefile
2602 def _GetMakeFileDir(self
):
2603 return self
.BuildDir
2605 ## Return build command string
2607 # @retval string Build command string
2609 def _GetBuildCommand(self
):
2610 return self
.PlatformInfo
.BuildCommand
2612 ## Get object list of all packages the module and its dependent libraries belong to
2614 # @retval list The list of package object
2616 def _GetDerivedPackageList(self
):
2618 for M
in [self
.Module
] + self
.DependentLibraryList
:
2619 for Package
in M
.Packages
:
2620 if Package
in PackageList
:
2622 PackageList
.append(Package
)
2625 ## Get the depex string
2627 # @return : a string contain all depex expresion.
2628 def _GetDepexExpresionString(self
):
2631 ## DPX_SOURCE IN Define section.
2632 if self
.Module
.DxsFile
:
2634 for M
in [self
.Module
] + self
.DependentLibraryList
:
2635 Filename
= M
.MetaFile
.Path
2636 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2637 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2638 for DepexExpresion
in DepexExpresionList
:
2639 for key
in DepexExpresion
.keys():
2640 Arch
, ModuleType
= key
2641 # the type of build module is USER_DEFINED.
2642 # All different DEPEX section tags would be copied into the As Built INF file
2643 # and there would be separate DEPEX section tags
2644 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2645 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2646 DepexList
.append({(Arch
, ModuleType
): DepexExpresion
[key
][:]})
2648 if Arch
.upper() == TAB_ARCH_COMMON
or \
2649 (Arch
.upper() == self
.Arch
.upper() and \
2650 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2651 DepexList
.append({(Arch
, ModuleType
): DepexExpresion
[key
][:]})
2653 #the type of build module is USER_DEFINED.
2654 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2655 for Depex
in DepexList
:
2656 for key
in Depex
.keys():
2657 DepexStr
+= '[Depex.%s.%s]\n' % key
2658 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
2661 return '[Depex.%s]\n' % self
.Arch
2664 #the type of build module not is USER_DEFINED.
2666 for Depex
in DepexList
:
2671 for D
in Depex
.values():
2672 DepexStr
+= ' '.join([val
for val
in D
])
2673 Index
= DepexStr
.find('END')
2674 if Index
> -1 and Index
== len(DepexStr
) - 3:
2675 DepexStr
= DepexStr
[:-3]
2676 DepexStr
= DepexStr
.strip()
2679 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
2681 return '[Depex.%s]\n' % self
.Arch
2682 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
2684 ## Merge dependency expression
2686 # @retval list The token list of the dependency expression after parsed
2688 def _GetDepexTokenList(self
):
2689 if self
._DepexList
== None:
2690 self
._DepexList
= {}
2691 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2692 return self
._DepexList
2694 self
._DepexList
[self
.ModuleType
] = []
2696 for ModuleType
in self
._DepexList
:
2697 DepexList
= self
._DepexList
[ModuleType
]
2699 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2701 for M
in [self
.Module
] + self
.DependentLibraryList
:
2703 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
2705 DepexList
.append('AND')
2706 DepexList
.append('(')
2708 if DepexList
[-1] == 'END': # no need of a END at this time
2710 DepexList
.append(')')
2713 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
2714 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
2716 if len(DepexList
) > 0:
2717 EdkLogger
.verbose('')
2718 return self
._DepexList
2720 ## Merge dependency expression
2722 # @retval list The token list of the dependency expression after parsed
2724 def _GetDepexExpressionTokenList(self
):
2725 if self
._DepexExpressionList
== None:
2726 self
._DepexExpressionList
= {}
2727 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2728 return self
._DepexExpressionList
2730 self
._DepexExpressionList
[self
.ModuleType
] = ''
2732 for ModuleType
in self
._DepexExpressionList
:
2733 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
2735 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2737 for M
in [self
.Module
] + self
.DependentLibraryList
:
2739 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
2740 if DepexExpressionList
!= '':
2741 DepexExpressionList
+= ' AND '
2742 DepexExpressionList
+= '('
2743 DepexExpressionList
+= D
2744 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
2745 DepexExpressionList
+= ')'
2748 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
2749 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
2751 if len(DepexExpressionList
) > 0:
2752 EdkLogger
.verbose('')
2753 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
2754 return self
._DepexExpressionList
2756 ## Return the list of specification version required for the module
2758 # @retval list The list of specification defined in module file
2760 def _GetSpecification(self
):
2761 return self
.Module
.Specification
2763 ## Tool option for the module build
2765 # @param PlatformInfo The object of PlatformBuildInfo
2766 # @retval dict The dict containing valid options
2768 def _GetModuleBuildOption(self
):
2769 if self
._BuildOption
== None:
2770 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
2771 if self
.BuildRuleOrder
:
2772 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
2773 return self
._BuildOption
2775 ## Get include path list from tool option for the module build
2777 # @retval list The include path list
2779 def _GetBuildOptionIncPathList(self
):
2780 if self
._BuildOptionIncPathList
== None:
2782 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
2783 # is the former use /I , the Latter used -I to specify include directories
2785 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
2786 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
2787 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
2788 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
2791 # New ToolChainFamily, don't known whether there is option to specify include directories
2793 self
._BuildOptionIncPathList
= []
2794 return self
._BuildOptionIncPathList
2796 BuildOptionIncPathList
= []
2797 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
2800 FlagOption
= self
.BuildOption
[Tool
][Attr
]
2804 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
2805 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
2808 # RVCT may specify a list of directory seperated by commas
2811 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
2812 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
2813 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
2816 # EDK II modules must not reference header files outside of the packages they depend on or
2817 # within the module's directory tree. Report error if violation.
2819 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
2820 for Path
in IncPathList
:
2821 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
2822 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
2823 EdkLogger
.error("build",
2826 File
=str(self
.MetaFile
))
2829 BuildOptionIncPathList
+= IncPathList
2831 self
._BuildOptionIncPathList
= BuildOptionIncPathList
2833 return self
._BuildOptionIncPathList
2835 ## Return a list of files which can be built from source
2837 # What kind of files can be built is determined by build rules in
2838 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
2840 def _GetSourceFileList(self
):
2841 if self
._SourceFileList
== None:
2842 self
._SourceFileList
= []
2843 for F
in self
.Module
.Sources
:
2845 if F
.TagName
not in ("", "*", self
.ToolChain
):
2846 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
2847 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
2849 # match tool chain family
2850 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
2853 "The file [%s] must be built by tools of [%s], " \
2854 "but current toolchain family is [%s]" \
2855 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
2858 # add the file path into search path list for file including
2859 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
2860 self
.IncludePathList
.insert(0, F
.Dir
)
2861 self
._SourceFileList
.append(F
)
2863 self
._MatchBuildRuleOrder
(self
._SourceFileList
)
2865 for F
in self
._SourceFileList
:
2866 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
2867 return self
._SourceFileList
2869 def _MatchBuildRuleOrder(self
, FileList
):
2871 self
._GetModuleBuildOption
()
2872 for SingleFile
in FileList
:
2873 if self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRuleOrder
and SingleFile
.Ext
in self
.BuildRules
:
2874 key
= SingleFile
.Path
.split(SingleFile
.Ext
)[0]
2875 if key
in Order_Dict
:
2876 Order_Dict
[key
].append(SingleFile
.Ext
)
2878 Order_Dict
[key
] = [SingleFile
.Ext
]
2881 for F
in Order_Dict
:
2882 if len(Order_Dict
[F
]) > 1:
2883 Order_Dict
[F
].sort(key
=lambda i
: self
.BuildRuleOrder
.index(i
))
2884 for Ext
in Order_Dict
[F
][1:]:
2885 RemoveList
.append(F
+ Ext
)
2887 for item
in RemoveList
:
2888 FileList
.remove(item
)
2892 ## Return the list of unicode files
2893 def _GetUnicodeFileList(self
):
2894 if self
._UnicodeFileList
== None:
2895 if TAB_UNICODE_FILE
in self
.FileTypes
:
2896 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
2898 self
._UnicodeFileList
= []
2899 return self
._UnicodeFileList
2901 ## Return a list of files which can be built from binary
2903 # "Build" binary files are just to copy them to build directory.
2905 # @retval list The list of files which can be built later
2907 def _GetBinaryFiles(self
):
2908 if self
._BinaryFileList
== None:
2909 self
._BinaryFileList
= []
2910 for F
in self
.Module
.Binaries
:
2911 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
2913 self
._BinaryFileList
.append(F
)
2914 self
._ApplyBuildRule
(F
, F
.Type
)
2915 return self
._BinaryFileList
2917 def _GetBuildRules(self
):
2918 if self
._BuildRules
== None:
2920 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
2921 for Type
in BuildRuleDatabase
.FileTypeList
:
2922 #first try getting build rule by BuildRuleFamily
2923 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
2925 # build type is always module type, but ...
2926 if self
.ModuleType
!= self
.BuildType
:
2927 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
2928 #second try getting build rule by ToolChainFamily
2930 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
2932 # build type is always module type, but ...
2933 if self
.ModuleType
!= self
.BuildType
:
2934 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
2937 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
2938 BuildRules
[Type
] = RuleObject
2939 for Ext
in RuleObject
.SourceFileExtList
:
2940 BuildRules
[Ext
] = RuleObject
2941 self
._BuildRules
= BuildRules
2942 return self
._BuildRules
2944 def _ApplyBuildRule(self
, File
, FileType
):
2945 if self
._BuildTargets
== None:
2946 self
._IntroBuildTargetList
= set()
2947 self
._FinalBuildTargetList
= set()
2948 self
._BuildTargets
= {}
2949 self
._FileTypes
= {}
2951 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
2952 if not os
.path
.exists(SubDirectory
):
2953 CreateDirectory(SubDirectory
)
2959 # Make sure to get build rule order value
2961 self
._GetModuleBuildOption
()
2963 while Index
< len(SourceList
):
2964 Source
= SourceList
[Index
]
2968 CreateDirectory(Source
.Dir
)
2970 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
2971 # Skip all files that are not binary libraries
2972 if not self
.IsLibrary
:
2974 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
2975 elif FileType
in self
.BuildRules
:
2976 RuleObject
= self
.BuildRules
[FileType
]
2977 elif Source
.Ext
in self
.BuildRules
:
2978 RuleObject
= self
.BuildRules
[Source
.Ext
]
2980 # stop at no more rules
2982 self
._FinalBuildTargetList
.add(LastTarget
)
2985 FileType
= RuleObject
.SourceFileType
2986 if FileType
not in self
._FileTypes
:
2987 self
._FileTypes
[FileType
] = set()
2988 self
._FileTypes
[FileType
].add(Source
)
2990 # stop at STATIC_LIBRARY for library
2991 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
2993 self
._FinalBuildTargetList
.add(LastTarget
)
2996 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
2999 self
._FinalBuildTargetList
.add(LastTarget
)
3001 elif not Target
.Outputs
:
3002 # Only do build for target with outputs
3003 self
._FinalBuildTargetList
.add(Target
)
3005 if FileType
not in self
._BuildTargets
:
3006 self
._BuildTargets
[FileType
] = set()
3007 self
._BuildTargets
[FileType
].add(Target
)
3009 if not Source
.IsBinary
and Source
== File
:
3010 self
._IntroBuildTargetList
.add(Target
)
3012 # to avoid cyclic rule
3013 if FileType
in RuleChain
:
3016 RuleChain
.append(FileType
)
3017 SourceList
.extend(Target
.Outputs
)
3019 FileType
= TAB_UNKNOWN_FILE
3021 def _GetTargets(self
):
3022 if self
._BuildTargets
== None:
3023 self
._IntroBuildTargetList
= set()
3024 self
._FinalBuildTargetList
= set()
3025 self
._BuildTargets
= {}
3026 self
._FileTypes
= {}
3028 #TRICK: call _GetSourceFileList to apply build rule for source files
3029 if self
.SourceFileList
:
3032 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3033 if self
.BinaryFileList
:
3036 return self
._BuildTargets
3038 def _GetIntroTargetList(self
):
3040 return self
._IntroBuildTargetList
3042 def _GetFinalTargetList(self
):
3044 return self
._FinalBuildTargetList
3046 def _GetFileTypes(self
):
3048 return self
._FileTypes
3050 ## Get the list of package object the module depends on
3052 # @retval list The package object list
3054 def _GetDependentPackageList(self
):
3055 return self
.Module
.Packages
3057 ## Return the list of auto-generated code file
3059 # @retval list The list of auto-generated file
3061 def _GetAutoGenFileList(self
):
3062 UniStringAutoGenC
= True
3063 UniStringBinBuffer
= StringIO()
3064 if self
.BuildType
== 'UEFI_HII':
3065 UniStringAutoGenC
= False
3066 if self
._AutoGenFileList
== None:
3067 self
._AutoGenFileList
= {}
3068 AutoGenC
= TemplateString()
3069 AutoGenH
= TemplateString()
3070 StringH
= TemplateString()
3071 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
)
3073 # AutoGen.c is generated if there are library classes in inf, or there are object files
3075 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
3076 or TAB_OBJECT_FILE
in self
.FileTypes
):
3077 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
3078 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
3079 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3080 if str(AutoGenH
) != "":
3081 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
3082 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
3083 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3084 if str(StringH
) != "":
3085 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
3086 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
3087 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3088 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
3089 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
3090 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
3091 AutoFile
.IsBinary
= True
3092 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
3093 if UniStringBinBuffer
!= None:
3094 UniStringBinBuffer
.close()
3095 return self
._AutoGenFileList
3097 ## Return the list of library modules explicitly or implicityly used by this module
3098 def _GetLibraryList(self
):
3099 if self
._DependentLibraryList
== None:
3100 # only merge library classes and PCD for non-library module
3102 self
._DependentLibraryList
= []
3104 if self
.AutoGenVersion
< 0x00010005:
3105 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
3107 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
3108 return self
._DependentLibraryList
3111 def UpdateComments(Recver
, Src
):
3113 if Key
not in Recver
:
3115 Recver
[Key
].extend(Src
[Key
])
3116 ## Get the list of PCDs from current module
3118 # @retval list The list of PCD
3120 def _GetModulePcdList(self
):
3121 if self
._ModulePcdList
== None:
3122 # apply PCD settings from platform
3123 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
3124 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
3125 return self
._ModulePcdList
3127 ## Get the list of PCDs from dependent libraries
3129 # @retval list The list of PCD
3131 def _GetLibraryPcdList(self
):
3132 if self
._LibraryPcdList
== None:
3134 if not self
.IsLibrary
:
3135 # get PCDs from dependent libraries
3136 for Library
in self
.DependentLibraryList
:
3137 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
3138 for Key
in Library
.Pcds
:
3139 # skip duplicated PCDs
3140 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
3142 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
3143 # apply PCD settings from platform
3144 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3146 self
._LibraryPcdList
= []
3147 return self
._LibraryPcdList
3149 ## Get the GUID value mapping
3151 # @retval dict The mapping between GUID cname and its value
3153 def _GetGuidList(self
):
3154 if self
._GuidList
== None:
3155 self
._GuidList
= sdict()
3156 self
._GuidList
.update(self
.Module
.Guids
)
3157 for Library
in self
.DependentLibraryList
:
3158 self
._GuidList
.update(Library
.Guids
)
3159 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3160 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3161 return self
._GuidList
3163 def GetGuidsUsedByPcd(self
):
3164 if self
._GuidsUsedByPcd
== None:
3165 self
._GuidsUsedByPcd
= sdict()
3166 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3167 for Library
in self
.DependentLibraryList
:
3168 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3169 return self
._GuidsUsedByPcd
3170 ## Get the protocol value mapping
3172 # @retval dict The mapping between protocol cname and its value
3174 def _GetProtocolList(self
):
3175 if self
._ProtocolList
== None:
3176 self
._ProtocolList
= sdict()
3177 self
._ProtocolList
.update(self
.Module
.Protocols
)
3178 for Library
in self
.DependentLibraryList
:
3179 self
._ProtocolList
.update(Library
.Protocols
)
3180 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3181 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3182 return self
._ProtocolList
3184 ## Get the PPI value mapping
3186 # @retval dict The mapping between PPI cname and its value
3188 def _GetPpiList(self
):
3189 if self
._PpiList
== None:
3190 self
._PpiList
= sdict()
3191 self
._PpiList
.update(self
.Module
.Ppis
)
3192 for Library
in self
.DependentLibraryList
:
3193 self
._PpiList
.update(Library
.Ppis
)
3194 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3195 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3196 return self
._PpiList
3198 ## Get the list of include search path
3200 # @retval list The list path
3202 def _GetIncludePathList(self
):
3203 if self
._IncludePathList
== None:
3204 self
._IncludePathList
= []
3205 if self
.AutoGenVersion
< 0x00010005:
3206 for Inc
in self
.Module
.Includes
:
3207 if Inc
not in self
._IncludePathList
:
3208 self
._IncludePathList
.append(Inc
)
3210 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3211 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3212 self
._IncludePathList
.append(Inc
)
3213 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3214 self
._IncludePathList
.append(self
.DebugDir
)
3216 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3217 self
._IncludePathList
.append(self
.DebugDir
)
3219 for Package
in self
.Module
.Packages
:
3220 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3221 if PackageDir
not in self
._IncludePathList
:
3222 self
._IncludePathList
.append(PackageDir
)
3223 for Inc
in Package
.Includes
:
3224 if Inc
not in self
._IncludePathList
:
3225 self
._IncludePathList
.append(str(Inc
))
3226 return self
._IncludePathList
3228 def _GetIncludePathLength(self
):
3229 self
._IncludePathLength
= 0
3230 if self
._IncludePathList
:
3231 for inc
in self
._IncludePathList
:
3232 self
._IncludePathLength
+= len(' ' + inc
)
3233 return self
._IncludePathLength
3235 ## Get HII EX PCDs which maybe used by VFR
3237 # efivarstore used by VFR may relate with HII EX PCDs
3238 # Get the variable name and GUID from efivarstore and HII EX PCD
3239 # List the HII EX PCDs in As Built INF if both name and GUID match.
3241 # @retval list HII EX PCDs
3243 def _GetPcdsMaybeUsedByVfr(self
):
3244 if not self
.SourceFileList
:
3248 for SrcFile
in self
.SourceFileList
:
3249 if SrcFile
.Ext
.lower() != '.vfr':
3251 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3252 if not os
.path
.exists(Vfri
):
3254 VfriFile
= open(Vfri
, 'r')
3255 Content
= VfriFile
.read()
3257 Pos
= Content
.find('efivarstore')
3260 # Make sure 'efivarstore' is the start of efivarstore statement
3261 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3264 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3266 if Index
>= 0 and Content
[Index
] != ';':
3267 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3270 # 'efivarstore' must be followed by name and guid
3272 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3275 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3278 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3279 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3280 Pos
= Content
.find('efivarstore', Name
.end())
3284 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3285 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3287 for SkuName
in Pcd
.SkuInfoList
:
3288 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3289 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3290 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
)
3293 Guid
= GuidStructureStringToGuidString(Value
)
3294 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3295 HiiExPcds
.append(Pcd
)
3300 def _GenOffsetBin(self
):
3302 for SourceFile
in self
.Module
.Sources
:
3303 if SourceFile
.Type
.upper() == ".VFR" :
3305 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3307 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3308 if SourceFile
.Type
.upper() == ".UNI" :
3310 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3312 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3314 if len(VfrUniBaseName
) == 0:
3316 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3317 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3318 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3319 if not VfrUniOffsetList
:
3322 OutputName
= '%sOffset.bin' % self
.Name
3323 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3326 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3328 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3330 # Use a instance of StringIO to cache data
3331 fStringIO
= StringIO('')
3333 for Item
in VfrUniOffsetList
:
3334 if (Item
[0].find("Strings") != -1):
3336 # UNI offset in image.
3338 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3340 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3341 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3342 fStringIO
.write(''.join(UniGuid
))
3343 UniValue
= pack ('Q', int (Item
[1], 16))
3344 fStringIO
.write (UniValue
)
3347 # VFR binary offset in image.
3349 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3351 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3352 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3353 fStringIO
.write(''.join(VfrGuid
))
3355 VfrValue
= pack ('Q', int (Item
[1], 16))
3356 fStringIO
.write (VfrValue
)
3358 # write data into file.
3361 fInputfile
.write (fStringIO
.getvalue())
3363 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3364 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3370 ## Create AsBuilt INF file the module
3372 def CreateAsBuiltInf(self
):
3373 if self
.IsAsBuiltInfCreated
:
3376 # Skip the following code for EDK I inf
3377 if self
.AutoGenVersion
< 0x00010005:
3380 # Skip the following code for libraries
3384 # Skip the following code for modules with no source files
3385 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3388 # Skip the following code for modules without any binary files
3389 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3392 ### TODO: How to handles mixed source and binary modules
3394 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3395 # Also find all packages that the DynamicEx PCDs depend on
3400 PcdTokenSpaceList
= []
3401 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3402 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3403 PatchablePcds
[Pcd
.TokenCName
] = Pcd
3404 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3405 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3408 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3409 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3410 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3412 GuidList
.update(self
.GuidList
)
3413 for TokenSpace
in self
.GetGuidsUsedByPcd():
3414 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3415 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3416 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3417 GuidList
.pop(TokenSpace
)
3418 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3419 for Package
in self
.DerivedPackageList
:
3420 if Package
in Packages
:
3422 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3424 for Index
in range(len(BeChecked
)):
3425 for Item
in CheckList
[Index
]:
3426 if Item
in BeChecked
[Index
]:
3427 Packages
+= [Package
]
3432 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3433 for Pkg
in self
.PlatformInfo
.PackageList
:
3436 for VfrPcd
in VfrPcds
:
3437 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3438 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3442 ModuleType
= self
.ModuleType
3443 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3444 ModuleType
= 'DXE_DRIVER'
3447 if self
.PcdIsDriver
!= '':
3448 DriverType
= self
.PcdIsDriver
3451 MDefs
= self
.Module
.Defines
3454 'module_name' : self
.Name
,
3455 'module_guid' : Guid
,
3456 'module_module_type' : ModuleType
,
3457 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3458 'pcd_is_driver_string' : [],
3459 'module_uefi_specification_version' : [],
3460 'module_pi_specification_version' : [],
3461 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3462 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3463 'module_constructor' : self
.Module
.ConstructorList
,
3464 'module_destructor' : self
.Module
.DestructorList
,
3465 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3466 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3467 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3468 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3469 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3470 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3471 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3472 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3473 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3474 'module_arch' : self
.Arch
,
3475 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3477 'patchablepcd_item' : [],
3479 'protocol_item' : [],
3483 'libraryclasses_item' : []
3486 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3487 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3489 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3492 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3494 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3495 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3496 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3497 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3499 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3500 if self
.ModuleType
in ['BASE', 'USER_DEFINED']:
3501 for Item
in self
.CodaTargetList
:
3502 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3503 if Item
.Target
.Ext
.lower() == '.aml':
3504 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3505 elif Item
.Target
.Ext
.lower() == '.acpi':
3506 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3508 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3510 for Item
in self
.CodaTargetList
:
3511 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3512 if Item
.Target
.Ext
.lower() == '.efi':
3513 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3515 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3516 if self
.DepexGenerated
:
3517 if self
.ModuleType
in ['PEIM']:
3518 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3519 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3520 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3521 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3522 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3524 Bin
= self
._GenOffsetBin
()
3526 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3528 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3530 if File
.lower().endswith('.pdb'):
3531 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3532 HeaderComments
= self
.Module
.HeaderComments
3534 for Index
in range(len(HeaderComments
)):
3535 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3536 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3539 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3540 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3543 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3544 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3545 (GuidList
, self
._GuidComments
, 'guid_item')
3547 for Item
in GenList
:
3548 for CName
in Item
[0]:
3550 if CName
in Item
[1]:
3551 Comments
= '\n '.join(Item
[1][CName
])
3554 Entry
= Comments
+ '\n ' + CName
3555 AsBuiltInfDict
[Item
[2]].append(Entry
)
3556 PatchList
= parsePcdInfoFromMapFile(
3557 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3558 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3561 for PatchPcd
in PatchList
:
3562 if PatchPcd
[0] not in PatchablePcds
:
3564 Pcd
= PatchablePcds
[PatchPcd
[0]]
3566 if Pcd
.DatumType
!= 'VOID*':
3567 HexFormat
= '0x%02x'
3568 if Pcd
.DatumType
== 'UINT16':
3569 HexFormat
= '0x%04x'
3570 elif Pcd
.DatumType
== 'UINT32':
3571 HexFormat
= '0x%08x'
3572 elif Pcd
.DatumType
== 'UINT64':
3573 HexFormat
= '0x%016x'
3574 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3576 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
3577 EdkLogger
.error("build", AUTOGEN_ERROR
,
3578 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3580 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3581 PcdValue
= Pcd
.DefaultValue
3582 if PcdValue
[0] != '{':
3584 if PcdValue
[0] == 'L':
3586 PcdValue
= PcdValue
.lstrip('L')
3587 PcdValue
= eval(PcdValue
)
3589 for Index
in range(0, len(PcdValue
)):
3591 CharVal
= ord(PcdValue
[Index
])
3592 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3593 + '0x%02x' % (CharVal
>> 8) + ', '
3595 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3598 Padding
= Padding
* 2
3599 ArraySize
= ArraySize
/ 2
3600 if ArraySize
< (len(PcdValue
) + 1):
3601 EdkLogger
.error("build", AUTOGEN_ERROR
,
3602 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3604 if ArraySize
> len(PcdValue
) + 1:
3605 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3606 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3607 elif len(PcdValue
.split(',')) <= ArraySize
:
3608 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3611 EdkLogger
.error("build", AUTOGEN_ERROR
,
3612 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3614 PcdItem
= '%s.%s|%s|0x%X' % \
3615 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, PcdValue
, PatchPcd
[1])
3617 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3618 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
3620 PcdItem
= PcdComments
+ '\n ' + PcdItem
3621 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
3624 for Pcd
in Pcds
+ VfrPcds
:
3629 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
3630 for SkuName
in Pcd
.SkuInfoList
:
3631 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3632 SkuId
= SkuInfo
.SkuId
3633 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
3637 # Don't generate duplicated HII PCD
3639 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
3642 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
3643 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3644 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
3648 for Index
, Comment
in enumerate(PcdCommentList
):
3649 for Usage
in UsageList
:
3650 if Comment
.find(Usage
) != -1:
3654 if UsageIndex
!= -1:
3655 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
3657 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
3658 PcdComments
= '\n '.join(PcdCommentList
)
3659 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + Pcd
.TokenCName
3661 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
3662 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
3663 for Item
in self
.BuildOption
:
3664 if 'FLAGS' in self
.BuildOption
[Item
]:
3665 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
3667 # Generated LibraryClasses section in comments.
3668 for Library
in self
.LibraryAutoGenList
:
3669 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
3671 # Generated depex expression section in comments.
3672 AsBuiltInfDict
['depexsection_item'] = ''
3673 DepexExpresion
= self
._GetDepexExpresionString
()
3675 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
3677 AsBuiltInf
= TemplateString()
3678 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
3680 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
3682 self
.IsAsBuiltInfCreated
= True
3684 ## Create makefile for the module and its dependent libraries
3686 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
3687 # dependent libraries will be created
3689 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
3690 # Ignore generating makefile when it is a binary module
3691 if self
.IsBinaryModule
:
3694 if self
.IsMakeFileCreated
:
3697 if not self
.IsLibrary
and CreateLibraryMakeFile
:
3698 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3699 LibraryAutoGen
.CreateMakeFile()
3701 if len(self
.CustomMakefile
) == 0:
3702 Makefile
= GenMake
.ModuleMakefile(self
)
3704 Makefile
= GenMake
.CustomMakefile(self
)
3705 if Makefile
.Generate():
3706 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
3707 (self
.Name
, self
.Arch
))
3709 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
3710 (self
.Name
, self
.Arch
))
3712 self
.IsMakeFileCreated
= True
3714 def CopyBinaryFiles(self
):
3715 for File
in self
.Module
.Binaries
:
3717 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
3718 CopyLongFilePath(SrcPath
, DstPath
)
3719 ## Create autogen code for the module and its dependent libraries
3721 # @param CreateLibraryCodeFile Flag indicating if or not the code of
3722 # dependent libraries will be created
3724 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
3725 if self
.IsCodeFileCreated
:
3728 # Need to generate PcdDatabase even PcdDriver is binarymodule
3729 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
3730 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
3732 if self
.IsBinaryModule
:
3734 self
.CopyBinaryFiles()
3737 if not self
.IsLibrary
and CreateLibraryCodeFile
:
3738 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3739 LibraryAutoGen
.CreateCodeFile()
3742 IgoredAutoGenList
= []
3744 for File
in self
.AutoGenFileList
:
3745 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
3746 #Ignore Edk AutoGen.c
3747 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
3750 AutoGenList
.append(str(File
))
3752 IgoredAutoGenList
.append(str(File
))
3754 # Skip the following code for EDK I inf
3755 if self
.AutoGenVersion
< 0x00010005:
3758 for ModuleType
in self
.DepexList
:
3759 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
3760 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
3763 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
3764 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
3766 if len(Dpx
.PostfixNotation
) <> 0:
3767 self
.DepexGenerated
= True
3769 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
3770 AutoGenList
.append(str(DpxFile
))
3772 IgoredAutoGenList
.append(str(DpxFile
))
3774 if IgoredAutoGenList
== []:
3775 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
3776 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
3777 elif AutoGenList
== []:
3778 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
3779 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3781 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
3782 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3784 self
.IsCodeFileCreated
= True
3787 ## Summarize the ModuleAutoGen objects of all libraries used by this module
3788 def _GetLibraryAutoGenList(self
):
3789 if self
._LibraryAutoGenList
== None:
3790 self
._LibraryAutoGenList
= []
3791 for Library
in self
.DependentLibraryList
:
3798 self
.PlatformInfo
.MetaFile
3800 if La
not in self
._LibraryAutoGenList
:
3801 self
._LibraryAutoGenList
.append(La
)
3802 for Lib
in La
.CodaTargetList
:
3803 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
3804 return self
._LibraryAutoGenList
3806 Module
= property(_GetModule
)
3807 Name
= property(_GetBaseName
)
3808 Guid
= property(_GetGuid
)
3809 Version
= property(_GetVersion
)
3810 ModuleType
= property(_GetModuleType
)
3811 ComponentType
= property(_GetComponentType
)
3812 BuildType
= property(_GetBuildType
)
3813 PcdIsDriver
= property(_GetPcdIsDriver
)
3814 AutoGenVersion
= property(_GetAutoGenVersion
)
3815 Macros
= property(_GetMacros
)
3816 Specification
= property(_GetSpecification
)
3818 IsLibrary
= property(_IsLibrary
)
3819 IsBinaryModule
= property(_IsBinaryModule
)
3820 BuildDir
= property(_GetBuildDir
)
3821 OutputDir
= property(_GetOutputDir
)
3822 DebugDir
= property(_GetDebugDir
)
3823 MakeFileDir
= property(_GetMakeFileDir
)
3824 CustomMakefile
= property(_GetCustomMakefile
)
3826 IncludePathList
= property(_GetIncludePathList
)
3827 IncludePathLength
= property(_GetIncludePathLength
)
3828 AutoGenFileList
= property(_GetAutoGenFileList
)
3829 UnicodeFileList
= property(_GetUnicodeFileList
)
3830 SourceFileList
= property(_GetSourceFileList
)
3831 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
3832 Targets
= property(_GetTargets
)
3833 IntroTargetList
= property(_GetIntroTargetList
)
3834 CodaTargetList
= property(_GetFinalTargetList
)
3835 FileTypes
= property(_GetFileTypes
)
3836 BuildRules
= property(_GetBuildRules
)
3838 DependentPackageList
= property(_GetDependentPackageList
)
3839 DependentLibraryList
= property(_GetLibraryList
)
3840 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
3841 DerivedPackageList
= property(_GetDerivedPackageList
)
3843 ModulePcdList
= property(_GetModulePcdList
)
3844 LibraryPcdList
= property(_GetLibraryPcdList
)
3845 GuidList
= property(_GetGuidList
)
3846 ProtocolList
= property(_GetProtocolList
)
3847 PpiList
= property(_GetPpiList
)
3848 DepexList
= property(_GetDepexTokenList
)
3849 DxsFile
= property(_GetDxsFile
)
3850 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
3851 BuildOption
= property(_GetModuleBuildOption
)
3852 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
3853 BuildCommand
= property(_GetBuildCommand
)
3855 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
3857 # This acts like the main() function for the script, unless it is 'import'ed into another script.
3858 if __name__
== '__main__':