2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2015, 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 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
321 for FdRegion
in FdDict
.RegionList
:
322 if str(FdRegion
.RegionType
) is 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
323 if int(FdRegion
.Offset
) % 8 != 0:
324 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
325 ModuleList
= Fdf
.Profile
.InfList
326 self
.FdfProfile
= Fdf
.Profile
327 for fvname
in self
.FvTargetList
:
328 if fvname
.upper() not in self
.FdfProfile
.FvDict
:
329 EdkLogger
.error("build", OPTION_VALUE_INVALID
,
330 "No such an FV in FDF file: %s" % fvname
)
334 self
.FdfProfile
= None
335 if self
.FdTargetList
:
336 EdkLogger
.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self
.FdTargetList
))
337 self
.FdTargetList
= []
338 if self
.FvTargetList
:
339 EdkLogger
.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self
.FvTargetList
))
340 self
.FvTargetList
= []
341 if self
.CapTargetList
:
342 EdkLogger
.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self
.CapTargetList
))
343 self
.CapTargetList
= []
345 # apply SKU and inject PCDs from Flash Definition file
346 for Arch
in self
.ArchList
:
347 Platform
= self
.BuildDatabase
[self
.MetaFile
, Arch
, Target
, Toolchain
]
351 PGen
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
352 #Collect package set information from INF of FDF
354 for Inf
in ModuleList
:
355 ModuleFile
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, Arch
)
356 if ModuleFile
in Platform
.Modules
:
358 ModuleData
= self
.BuildDatabase
[ModuleFile
, Arch
, Target
, Toolchain
]
359 PkgSet
.update(ModuleData
.Packages
)
360 Pkgs
= list(PkgSet
) + list(PGen
.PackageList
)
363 DecPcds
[Pcd
[0], Pcd
[1]] = Pkg
.Pcds
[Pcd
]
364 DecPcdsKey
.add((Pcd
[0], Pcd
[1], Pcd
[2]))
366 Platform
.SkuName
= self
.SkuId
367 for Name
, Guid
in PcdSet
:
368 if (Name
, Guid
) not in DecPcds
:
372 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid
, Name
),
373 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
374 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
377 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
378 if (Name
, Guid
, TAB_PCDS_FIXED_AT_BUILD
) in DecPcdsKey \
379 or (Name
, Guid
, TAB_PCDS_PATCHABLE_IN_MODULE
) in DecPcdsKey \
380 or (Name
, Guid
, TAB_PCDS_FEATURE_FLAG
) in DecPcdsKey
:
381 Platform
.AddPcd(Name
, Guid
, PcdSet
[Name
, Guid
])
383 elif (Name
, Guid
, TAB_PCDS_DYNAMIC
) in DecPcdsKey
or (Name
, Guid
, TAB_PCDS_DYNAMIC_EX
) in DecPcdsKey
:
387 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid
, Name
),
388 File
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][0],
389 Line
= self
.FdfProfile
.PcdFileLineDict
[Name
, Guid
][1]
392 Pa
= PlatformAutoGen(self
, self
.MetaFile
, Target
, Toolchain
, Arch
)
394 # Explicitly collect platform's dynamic PCDs
396 Pa
.CollectPlatformDynamicPcds()
397 Pa
.CollectFixedAtBuildPcds()
398 self
.AutoGenObjectList
.append(Pa
)
401 # Check PCDs token value conflict in each DEC file.
403 self
._CheckAllPcdsTokenValueConflict
()
406 # Check PCD type and definition between DSC and DEC
408 self
._CheckPcdDefineAndType
()
411 # self._CheckDuplicateInFV(Fdf)
413 self
._BuildDir
= None
415 self
._MakeFileDir
= None
416 self
._BuildCommand
= None
420 ## _CheckDuplicateInFV() method
422 # Check whether there is duplicate modules/files exist in FV section.
423 # The check base on the file GUID;
425 def _CheckDuplicateInFV(self
, Fdf
):
426 for Fv
in Fdf
.Profile
.FvDict
:
428 for FfsFile
in Fdf
.Profile
.FvDict
[Fv
].FfsList
:
429 if FfsFile
.InfFileName
and FfsFile
.NameGuid
== None:
434 for Pa
in self
.AutoGenObjectList
:
437 for Module
in Pa
.ModuleAutoGenList
:
438 if path
.normpath(Module
.MetaFile
.File
) == path
.normpath(FfsFile
.InfFileName
):
440 if not Module
.Guid
.upper() in _GuidDict
.keys():
441 _GuidDict
[Module
.Guid
.upper()] = FfsFile
444 EdkLogger
.error("build",
446 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
447 FfsFile
.CurrentLineContent
,
448 _GuidDict
[Module
.Guid
.upper()].CurrentLineNum
,
449 _GuidDict
[Module
.Guid
.upper()].CurrentLineContent
,
450 Module
.Guid
.upper()),
451 ExtraData
=self
.FdfFile
)
453 # Some INF files not have entity in DSC file.
456 if FfsFile
.InfFileName
.find('$') == -1:
457 InfPath
= NormPath(FfsFile
.InfFileName
)
458 if not os
.path
.exists(InfPath
):
459 EdkLogger
.error('build', GENFDS_ERROR
, "Non-existant Module %s !" % (FfsFile
.InfFileName
))
461 PathClassObj
= PathClass(FfsFile
.InfFileName
, self
.WorkspaceDir
)
463 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
464 # BuildObject from one of AutoGenObjectList is enough.
466 InfObj
= self
.AutoGenObjectList
[0].BuildDatabase
.WorkspaceDb
.BuildObject
[PathClassObj
, 'COMMON', self
.BuildTarget
, self
.ToolChain
]
467 if not InfObj
.Guid
.upper() in _GuidDict
.keys():
468 _GuidDict
[InfObj
.Guid
.upper()] = FfsFile
470 EdkLogger
.error("build",
472 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
473 FfsFile
.CurrentLineContent
,
474 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineNum
,
475 _GuidDict
[InfObj
.Guid
.upper()].CurrentLineContent
,
476 InfObj
.Guid
.upper()),
477 ExtraData
=self
.FdfFile
)
480 if FfsFile
.NameGuid
!= None:
481 _CheckPCDAsGuidPattern
= re
.compile("^PCD\(.+\..+\)$")
484 # If the NameGuid reference a PCD name.
485 # The style must match: PCD(xxxx.yyy)
487 if _CheckPCDAsGuidPattern
.match(FfsFile
.NameGuid
):
489 # Replace the PCD value.
491 _PcdName
= FfsFile
.NameGuid
.lstrip("PCD(").rstrip(")")
493 for Pa
in self
.AutoGenObjectList
:
495 for PcdItem
in Pa
.AllPcdList
:
496 if (PcdItem
.TokenSpaceGuidCName
+ "." + PcdItem
.TokenCName
) == _PcdName
:
498 # First convert from CFormatGuid to GUID string
500 _PcdGuidString
= GuidStructureStringToGuidString(PcdItem
.DefaultValue
)
502 if not _PcdGuidString
:
504 # Then try Byte array.
506 _PcdGuidString
= GuidStructureByteArrayToGuidString(PcdItem
.DefaultValue
)
508 if not _PcdGuidString
:
510 # Not Byte array or CFormat GUID, raise error.
512 EdkLogger
.error("build",
514 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName
, PcdItem
.DefaultValue
),
515 ExtraData
=self
.FdfFile
)
517 if not _PcdGuidString
.upper() in _GuidDict
.keys():
518 _GuidDict
[_PcdGuidString
.upper()] = FfsFile
522 EdkLogger
.error("build",
524 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
525 FfsFile
.CurrentLineContent
,
526 _GuidDict
[_PcdGuidString
.upper()].CurrentLineNum
,
527 _GuidDict
[_PcdGuidString
.upper()].CurrentLineContent
,
528 FfsFile
.NameGuid
.upper()),
529 ExtraData
=self
.FdfFile
)
531 if not FfsFile
.NameGuid
.upper() in _GuidDict
.keys():
532 _GuidDict
[FfsFile
.NameGuid
.upper()] = FfsFile
535 # Two raw file GUID conflict.
537 EdkLogger
.error("build",
539 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile
.CurrentLineNum
,
540 FfsFile
.CurrentLineContent
,
541 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineNum
,
542 _GuidDict
[FfsFile
.NameGuid
.upper()].CurrentLineContent
,
543 FfsFile
.NameGuid
.upper()),
544 ExtraData
=self
.FdfFile
)
547 def _CheckPcdDefineAndType(self
):
549 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
550 "Dynamic", #"DynamicHii", "DynamicVpd",
551 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
554 # This dict store PCDs which are not used by any modules with specified arches
556 for Pa
in self
.AutoGenObjectList
:
557 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
558 for Pcd
in Pa
.Platform
.Pcds
:
559 PcdType
= Pa
.Platform
.Pcds
[Pcd
].Type
561 # If no PCD type, this PCD comes from FDF
565 # Try to remove Hii and Vpd suffix
566 if PcdType
.startswith("DynamicEx"):
567 PcdType
= "DynamicEx"
568 elif PcdType
.startswith("Dynamic"):
571 for Package
in Pa
.PackageList
:
572 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
573 if (Pcd
[0], Pcd
[1], PcdType
) in Package
.Pcds
:
575 for Type
in PcdTypeList
:
576 if (Pcd
[0], Pcd
[1], Type
) in Package
.Pcds
:
580 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
581 % (Pa
.Platform
.Pcds
[Pcd
].Type
, Pcd
[1], Pcd
[0], Type
),
586 UnusedPcd
.setdefault(Pcd
, []).append(Pa
.Arch
)
588 for Pcd
in UnusedPcd
:
591 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
592 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
593 % (Pcd
[1], Pcd
[0], os
.path
.basename(str(self
.MetaFile
)), str(UnusedPcd
[Pcd
])),
598 return "%s [%s]" % (self
.MetaFile
, ", ".join(self
.ArchList
))
600 ## Return the directory to store FV files
602 if self
._FvDir
== None:
603 self
._FvDir
= path
.join(self
.BuildDir
, 'FV')
606 ## Return the directory to store all intermediate and final files built
607 def _GetBuildDir(self
):
608 return self
.AutoGenObjectList
[0].BuildDir
610 ## Return the build output directory platform specifies
611 def _GetOutputDir(self
):
612 return self
.Platform
.OutputDirectory
614 ## Return platform name
616 return self
.Platform
.PlatformName
618 ## Return meta-file GUID
620 return self
.Platform
.Guid
622 ## Return platform version
623 def _GetVersion(self
):
624 return self
.Platform
.Version
626 ## Return paths of tools
627 def _GetToolDefinition(self
):
628 return self
.AutoGenObjectList
[0].ToolDefinition
630 ## Return directory of platform makefile
632 # @retval string Makefile directory
634 def _GetMakeFileDir(self
):
635 if self
._MakeFileDir
== None:
636 self
._MakeFileDir
= self
.BuildDir
637 return self
._MakeFileDir
639 ## Return build command string
641 # @retval string Build command string
643 def _GetBuildCommand(self
):
644 if self
._BuildCommand
== None:
645 # BuildCommand should be all the same. So just get one from platform AutoGen
646 self
._BuildCommand
= self
.AutoGenObjectList
[0].BuildCommand
647 return self
._BuildCommand
649 ## Check the PCDs token value conflict in each DEC file.
651 # Will cause build break and raise error message while two PCDs conflict.
655 def _CheckAllPcdsTokenValueConflict(self
):
656 for Pa
in self
.AutoGenObjectList
:
657 for Package
in Pa
.PackageList
:
658 PcdList
= Package
.Pcds
.values()
659 PcdList
.sort(lambda x
, y
: cmp(int(x
.TokenValue
, 0), int(y
.TokenValue
, 0)))
661 while (Count
< len(PcdList
) - 1) :
662 Item
= PcdList
[Count
]
663 ItemNext
= PcdList
[Count
+ 1]
665 # Make sure in the same token space the TokenValue should be unique
667 if (int(Item
.TokenValue
, 0) == int(ItemNext
.TokenValue
, 0)):
668 SameTokenValuePcdList
= []
669 SameTokenValuePcdList
.append(Item
)
670 SameTokenValuePcdList
.append(ItemNext
)
671 RemainPcdListLength
= len(PcdList
) - Count
- 2
672 for ValueSameCount
in range(RemainPcdListLength
):
673 if int(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
].TokenValue
, 0) == int(Item
.TokenValue
, 0):
674 SameTokenValuePcdList
.append(PcdList
[len(PcdList
) - RemainPcdListLength
+ ValueSameCount
])
678 # Sort same token value PCD list with TokenGuid and TokenCName
680 SameTokenValuePcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
681 SameTokenValuePcdListCount
= 0
682 while (SameTokenValuePcdListCount
< len(SameTokenValuePcdList
) - 1):
683 TemListItem
= SameTokenValuePcdList
[SameTokenValuePcdListCount
]
684 TemListItemNext
= SameTokenValuePcdList
[SameTokenValuePcdListCount
+ 1]
686 if (TemListItem
.TokenSpaceGuidCName
== TemListItemNext
.TokenSpaceGuidCName
) and (TemListItem
.TokenCName
!= TemListItemNext
.TokenCName
):
690 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
691 % (TemListItem
.TokenValue
, TemListItem
.TokenSpaceGuidCName
, TemListItem
.TokenCName
, TemListItemNext
.TokenSpaceGuidCName
, TemListItemNext
.TokenCName
, Package
),
694 SameTokenValuePcdListCount
+= 1
695 Count
+= SameTokenValuePcdListCount
698 PcdList
= Package
.Pcds
.values()
699 PcdList
.sort(lambda x
, y
: cmp("%s.%s" % (x
.TokenSpaceGuidCName
, x
.TokenCName
), "%s.%s" % (y
.TokenSpaceGuidCName
, y
.TokenCName
)))
701 while (Count
< len(PcdList
) - 1) :
702 Item
= PcdList
[Count
]
703 ItemNext
= PcdList
[Count
+ 1]
705 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
707 if (Item
.TokenSpaceGuidCName
== ItemNext
.TokenSpaceGuidCName
) and (Item
.TokenCName
== ItemNext
.TokenCName
) and (int(Item
.TokenValue
, 0) != int(ItemNext
.TokenValue
, 0)):
711 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
712 % (Item
.TokenValue
, Item
.TokenSpaceGuidCName
, Item
.TokenCName
, Package
),
716 ## Generate fds command
717 def _GenFdsCommand(self
):
718 return (GenMake
.TopLevelMakefile(self
)._TEMPLATE
_.Replace(GenMake
.TopLevelMakefile(self
)._TemplateDict
)).strip()
720 ## Create makefile for the platform and modules in it
722 # @param CreateDepsMakeFile Flag indicating if the makefile for
723 # modules will be created as well
725 def CreateMakeFile(self
, CreateDepsMakeFile
=False):
726 if CreateDepsMakeFile
:
727 for Pa
in self
.AutoGenObjectList
:
728 Pa
.CreateMakeFile(CreateDepsMakeFile
)
730 ## Create autogen code for platform and modules
732 # Since there's no autogen code for platform, this method will do nothing
733 # if CreateModuleCodeFile is set to False.
735 # @param CreateDepsCodeFile Flag indicating if creating module's
736 # autogen code file or not
738 def CreateCodeFile(self
, CreateDepsCodeFile
=False):
739 if not CreateDepsCodeFile
:
741 for Pa
in self
.AutoGenObjectList
:
742 Pa
.CreateCodeFile(CreateDepsCodeFile
)
744 ## Create AsBuilt INF file the platform
746 def CreateAsBuiltInf(self
):
749 Name
= property(_GetName
)
750 Guid
= property(_GetGuid
)
751 Version
= property(_GetVersion
)
752 OutputDir
= property(_GetOutputDir
)
754 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
756 BuildDir
= property(_GetBuildDir
)
757 FvDir
= property(_GetFvDir
)
758 MakeFileDir
= property(_GetMakeFileDir
)
759 BuildCommand
= property(_GetBuildCommand
)
760 GenFdsCommand
= property(_GenFdsCommand
)
762 ## AutoGen class for platform
764 # PlatformAutoGen class will process the original information in platform
765 # file in order to generate makefile for platform.
767 class PlatformAutoGen(AutoGen
):
769 # Used to store all PCDs for both PEI and DXE phase, in order to generate
770 # correct PCD database
773 _NonDynaPcdList_
= []
776 # The priority list while override build option
778 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
779 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
780 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
781 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
782 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
783 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
784 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
785 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
786 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
787 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
788 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
789 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
790 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
791 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
792 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
793 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
795 ## The real constructor of PlatformAutoGen
797 # This method is not supposed to be called by users of PlatformAutoGen. It's
798 # only used by factory method __new__() to do real initialization work for an
799 # object of PlatformAutoGen
801 # @param Workspace WorkspaceAutoGen object
802 # @param PlatformFile Platform file (DSC file)
803 # @param Target Build target (DEBUG, RELEASE)
804 # @param Toolchain Name of tool chain
805 # @param Arch arch of the platform supports
807 def _Init(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
808 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
809 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
811 self
.MetaFile
= PlatformFile
812 self
.Workspace
= Workspace
813 self
.WorkspaceDir
= Workspace
.WorkspaceDir
814 self
.ToolChain
= Toolchain
815 self
.BuildTarget
= Target
817 self
.SourceDir
= PlatformFile
.SubDir
818 self
.SourceOverrideDir
= None
819 self
.FdTargetList
= self
.Workspace
.FdTargetList
820 self
.FvTargetList
= self
.Workspace
.FvTargetList
822 # get the original module/package/platform objects
823 self
.BuildDatabase
= Workspace
.BuildDatabase
825 # flag indicating if the makefile/C-code file has been created or not
826 self
.IsMakeFileCreated
= False
827 self
.IsCodeFileCreated
= False
829 self
._Platform
= None
834 self
._BuildRule
= None
835 self
._SourceDir
= None
836 self
._BuildDir
= None
837 self
._OutputDir
= None
839 self
._MakeFileDir
= None
842 self
._PcdTokenNumber
= None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
843 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
844 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
845 self
._NonDynamicPcdDict
= {}
847 self
._ToolDefinitions
= None
848 self
._ToolDefFile
= None # toolcode : tool path
849 self
._ToolChainFamily
= None
850 self
._BuildRuleFamily
= None
851 self
._BuildOption
= None # toolcode : option
852 self
._EdkBuildOption
= None # edktoolcode : option
853 self
._EdkIIBuildOption
= None # edkiitoolcode : option
854 self
._PackageList
= None
855 self
._ModuleAutoGenList
= None
856 self
._LibraryAutoGenList
= None
857 self
._BuildCommand
= None
858 self
._AsBuildInfList
= []
859 self
._AsBuildModuleList
= []
860 if GlobalData
.gFdfParser
!= None:
861 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
862 for Inf
in self
._AsBuildInfList
:
863 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
864 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
865 if not M
.IsSupportedArch
:
867 self
._AsBuildModuleList
.append(InfClass
)
868 # get library/modules for build
869 self
.LibraryBuildDirectoryList
= []
870 self
.ModuleBuildDirectoryList
= []
874 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
876 ## Create autogen code for platform and modules
878 # Since there's no autogen code for platform, this method will do nothing
879 # if CreateModuleCodeFile is set to False.
881 # @param CreateModuleCodeFile Flag indicating if creating module's
882 # autogen code file or not
884 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
885 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
886 if self
.IsCodeFileCreated
or not CreateModuleCodeFile
:
889 for Ma
in self
.ModuleAutoGenList
:
890 Ma
.CreateCodeFile(True)
892 # don't do this twice
893 self
.IsCodeFileCreated
= True
895 ## Generate Fds Command
896 def _GenFdsCommand(self
):
897 return self
.Workspace
.GenFdsCommand
899 ## Create makefile for the platform and mdoules in it
901 # @param CreateModuleMakeFile Flag indicating if the makefile for
902 # modules will be created as well
904 def CreateMakeFile(self
, CreateModuleMakeFile
=False):
905 if CreateModuleMakeFile
:
906 for ModuleFile
in self
.Platform
.Modules
:
907 Ma
= ModuleAutoGen(self
.Workspace
, ModuleFile
, self
.BuildTarget
,
908 self
.ToolChain
, self
.Arch
, self
.MetaFile
)
909 Ma
.CreateMakeFile(True)
910 #Ma.CreateAsBuiltInf()
912 # no need to create makefile for the platform more than once
913 if self
.IsMakeFileCreated
:
916 # create library/module build dirs for platform
917 Makefile
= GenMake
.PlatformMakefile(self
)
918 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
919 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
921 self
.IsMakeFileCreated
= True
923 ## Deal with Shared FixedAtBuild Pcds
925 def CollectFixedAtBuildPcds(self
):
926 for LibAuto
in self
.LibraryAutoGenList
:
927 FixedAtBuildPcds
= {}
928 ShareFixedAtBuildPcdsSameValue
= {}
929 for Module
in LibAuto
._ReferenceModules
:
930 for Pcd
in Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
:
931 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
932 if key
not in FixedAtBuildPcds
:
933 ShareFixedAtBuildPcdsSameValue
[key
] = True
934 FixedAtBuildPcds
[key
] = Pcd
.DefaultValue
936 if FixedAtBuildPcds
[key
] != Pcd
.DefaultValue
:
937 ShareFixedAtBuildPcdsSameValue
[key
] = False
938 for Pcd
in LibAuto
.FixedAtBuildPcds
:
939 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
940 if (Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
943 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)]
944 if DscPcd
.Type
!= "FixedAtBuild":
946 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
947 LibAuto
.ConstPcd
[key
] = Pcd
.DefaultValue
949 ## Collect dynamic PCDs
951 # Gather dynamic PCDs list from each module and their settings from platform
952 # This interface should be invoked explicitly when platform action is created.
954 def CollectPlatformDynamicPcds(self
):
955 # for gathering error information
956 NoDatumTypePcdList
= set()
960 for InfName
in self
._AsBuildInfList
:
961 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
962 FdfModuleList
.append(os
.path
.normpath(InfName
))
963 for F
in self
.Platform
.Modules
.keys():
964 M
= ModuleAutoGen(self
.Workspace
, F
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, self
.MetaFile
)
965 #GuidValue.update(M.Guids)
967 self
.Platform
.Modules
[F
].M
= M
969 for PcdFromModule
in M
.ModulePcdList
+ M
.LibraryPcdList
:
970 # make sure that the "VOID*" kind of datum has MaxDatumSize set
971 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
972 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, F
))
974 # Check the PCD from Binary INF or Source INF
975 if M
.IsBinaryModule
== True:
976 PcdFromModule
.IsFromBinaryInf
= True
978 # Check the PCD from DSC or not
979 if (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
.keys():
980 PcdFromModule
.IsFromDsc
= True
982 PcdFromModule
.IsFromDsc
= False
983 if PcdFromModule
.Type
in GenC
.gDynamicPcd
or PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
984 if F
.Path
not in FdfModuleList
:
985 # If one of the Source built modules listed in the DSC is not listed
986 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
987 # access method (it is only listed in the DEC file that declares the
988 # PCD as PcdsDynamic), then build tool will report warning message
989 # notify the PI that they are attempting to build a module that must
990 # be included in a flash image in order to be functional. These Dynamic
991 # PCD will not be added into the Database unless it is used by other
992 # modules that are included in the FDF file.
993 if PcdFromModule
.Type
in GenC
.gDynamicPcd
and \
994 PcdFromModule
.IsFromBinaryInf
== False:
995 # Print warning message to let the developer make a determine.
996 if PcdFromModule
not in PcdNotInDb
:
997 PcdNotInDb
.append(PcdFromModule
)
999 # If one of the Source built modules listed in the DSC is not listed in
1000 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1001 # access method (it is only listed in the DEC file that declares the
1002 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1003 # PCD to the Platform's PCD Database.
1004 if PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1005 if PcdFromModule
not in PcdNotInDb
:
1006 PcdNotInDb
.append(PcdFromModule
)
1009 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1010 # it should be stored in Pcd PEI database, If a dynamic only
1011 # used by DXE module, it should be stored in DXE PCD database.
1012 # The default Phase is DXE
1014 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1015 PcdFromModule
.Phase
= "PEI"
1016 if PcdFromModule
not in self
._DynaPcdList
_:
1017 self
._DynaPcdList
_.append(PcdFromModule
)
1018 elif PcdFromModule
.Phase
== 'PEI':
1019 # overwrite any the same PCD existing, if Phase is PEI
1020 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1021 self
._DynaPcdList
_[Index
] = PcdFromModule
1022 elif PcdFromModule
not in self
._NonDynaPcdList
_:
1023 self
._NonDynaPcdList
_.append(PcdFromModule
)
1024 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
1025 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
1026 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
1027 #The PCD from Binary INF will override the same one from source INF
1028 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
1029 PcdFromModule
.Pending
= False
1030 self
._NonDynaPcdList
_.append (PcdFromModule
)
1031 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1033 for ModuleInf
in self
.Platform
.Modules
.keys():
1034 DscModuleList
.append (os
.path
.normpath(ModuleInf
.Path
))
1035 # add the PCD from modules that listed in FDF but not in DSC to Database
1036 for InfName
in FdfModuleList
:
1037 if InfName
not in DscModuleList
:
1038 InfClass
= PathClass(InfName
)
1039 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1040 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1041 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1042 # For binary module, if in current arch, we need to list the PCDs into database.
1043 if not M
.IsSupportedArch
:
1045 # Override the module PCD setting by platform setting
1046 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
1047 for PcdFromModule
in ModulePcdList
:
1048 PcdFromModule
.IsFromBinaryInf
= True
1049 PcdFromModule
.IsFromDsc
= False
1050 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1051 if PcdFromModule
.Type
not in GenC
.gDynamicExPcd
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
1052 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1054 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1055 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
1056 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1057 if PcdFromModule
.DatumType
== "VOID*" and PcdFromModule
.MaxDatumSize
in [None, '']:
1058 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
1059 if M
.ModuleType
in ["PEIM", "PEI_CORE"]:
1060 PcdFromModule
.Phase
= "PEI"
1061 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1062 self
._DynaPcdList
_.append(PcdFromModule
)
1063 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
1064 self
._NonDynaPcdList
_.append(PcdFromModule
)
1065 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in GenC
.gDynamicExPcd
:
1066 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1067 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1068 # module & DXE module at a same time.
1069 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1070 # INF file as DynamicEx.
1071 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1072 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
1073 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
1074 for PcdFromModule
in self
._NonDynaPcdList
_:
1075 # If a PCD is not listed in the DSC file, but binary INF files used by
1076 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1077 # section, AND all source INF files used by this platform the build
1078 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1079 # section, then the tools must NOT add the PCD to the Platform's PCD
1080 # Database; the build must assign the access method for this PCD as
1081 # PcdsPatchableInModule.
1082 if PcdFromModule
not in self
._DynaPcdList
_:
1084 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1085 if PcdFromModule
.IsFromDsc
== False and \
1086 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
1087 PcdFromModule
.IsFromBinaryInf
== True and \
1088 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
1089 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
1090 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
1092 # print out error information and break the build, if error found
1093 if len(NoDatumTypePcdList
) > 0:
1094 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
1095 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
1097 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1098 % NoDatumTypePcdListString
)
1099 self
._NonDynamicPcdList
= self
._NonDynaPcdList
_
1100 self
._DynamicPcdList
= self
._DynaPcdList
_
1102 # Sort dynamic PCD list to:
1103 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1104 # try to be put header of dynamicd List
1105 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1107 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1109 UnicodePcdArray
= []
1113 VpdFile
= VpdInfoFile
.VpdInfoFile()
1114 NeedProcessVpdMapFile
= False
1116 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
1117 for Pcd
in self
._DynamicPcdList
:
1118 # just pick the a value to determine whether is unicode string type
1119 Sku
= Pcd
.SkuInfoList
[Pcd
.SkuInfoList
.keys()[0]]
1120 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1122 PcdValue
= Sku
.DefaultValue
1123 if Pcd
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1124 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1125 UnicodePcdArray
.append(Pcd
)
1126 elif len(Sku
.VariableName
) > 0:
1127 # if found HII type PCD then insert to right of UnicodeIndex
1128 HiiPcdArray
.append(Pcd
)
1130 OtherPcdArray
.append(Pcd
)
1131 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1132 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
1134 PlatformPcds
= self
.Platform
.Pcds
.keys()
1137 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1139 for PcdKey
in PlatformPcds
:
1140 Pcd
= self
.Platform
.Pcds
[PcdKey
]
1141 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
1142 PcdKey
in VpdPcdDict
:
1143 Pcd
= VpdPcdDict
[PcdKey
]
1144 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1145 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1146 PcdValue
= Sku
.DefaultValue
1148 PcdValue
= Pcd
.DefaultValue
1149 if Sku
.VpdOffset
!= '*':
1150 if PcdValue
.startswith("{"):
1152 elif PcdValue
.startswith("L"):
1156 if int(Sku
.VpdOffset
) % Alignment
!= 0:
1157 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
1158 VpdFile
.Add(Pcd
, Sku
.VpdOffset
)
1159 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1160 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1161 NeedProcessVpdMapFile
= True
1162 if self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== '':
1163 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
1164 "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.")
1168 # Fix the PCDs define in VPD PCD section that never referenced by module.
1169 # An example is PCD for signature usage.
1171 for DscPcd
in PlatformPcds
:
1172 DscPcdEntry
= self
.Platform
.Pcds
[DscPcd
]
1173 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
1174 if not (self
.Platform
.VpdToolGuid
== None or self
.Platform
.VpdToolGuid
== ''):
1176 for VpdPcd
in VpdFile
._VpdArray
.keys():
1177 # This PCD has been referenced by module
1178 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1179 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
1182 # Not found, it should be signature
1184 # just pick the a value to determine whether is unicode string type
1185 for (SkuName
,Sku
) in DscPcdEntry
.SkuInfoList
.items():
1186 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1188 # Need to iterate DEC pcd information to get the value & datumtype
1189 for eachDec
in self
.PackageList
:
1190 for DecPcd
in eachDec
.Pcds
:
1191 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
1192 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
1193 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
1194 # Print warning message to let the developer make a determine.
1195 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
1196 File
=self
.MetaFile
, \
1197 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
1198 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
1200 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
1201 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
1202 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
1203 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
1204 # Only fix the value while no value provided in DSC file.
1205 if (Sku
.DefaultValue
== "" or Sku
.DefaultValue
==None):
1206 DscPcdEntry
.SkuInfoList
[DscPcdEntry
.SkuInfoList
.keys()[0]].DefaultValue
= DecPcdEntry
.DefaultValue
1208 if DscPcdEntry
not in self
._DynamicPcdList
:
1209 self
._DynamicPcdList
.append(DscPcdEntry
)
1210 # Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]
1211 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
1212 PcdValue
= Sku
.DefaultValue
1214 PcdValue
= DscPcdEntry
.DefaultValue
1215 if Sku
.VpdOffset
!= '*':
1216 if PcdValue
.startswith("{"):
1218 elif PcdValue
.startswith("L"):
1222 if int(Sku
.VpdOffset
) % Alignment
!= 0:
1223 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
1224 VpdFile
.Add(DscPcdEntry
, Sku
.VpdOffset
)
1225 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== "*":
1226 NeedProcessVpdMapFile
= True
1227 if DscPcdEntry
.DatumType
== 'VOID*' and PcdValue
.startswith("L"):
1228 UnicodePcdArray
.append(DscPcdEntry
)
1229 elif len(Sku
.VariableName
) > 0:
1230 HiiPcdArray
.append(DscPcdEntry
)
1232 OtherPcdArray
.append(DscPcdEntry
)
1234 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1238 if (self
.Platform
.FlashDefinition
== None or self
.Platform
.FlashDefinition
== '') and \
1239 VpdFile
.GetCount() != 0:
1240 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1241 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
1243 if VpdFile
.GetCount() != 0:
1244 DscTimeStamp
= self
.Platform
.MetaFile
.TimeStamp
1245 FvPath
= os
.path
.join(self
.BuildDir
, "FV")
1246 if not os
.path
.exists(FvPath
):
1250 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
1253 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
1256 if not os
.path
.exists(VpdFilePath
) or os
.path
.getmtime(VpdFilePath
) < DscTimeStamp
:
1257 VpdFile
.Write(VpdFilePath
)
1259 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1261 for ToolDef
in self
.ToolDefinition
.values():
1262 if ToolDef
.has_key("GUID") and ToolDef
["GUID"] == self
.Platform
.VpdToolGuid
:
1263 if not ToolDef
.has_key("PATH"):
1264 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
1265 BPDGToolName
= ToolDef
["PATH"]
1267 # Call third party GUID BPDG tool.
1268 if BPDGToolName
!= None:
1269 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
1271 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.")
1273 # Process VPD map file generated by third party BPDG tool
1274 if NeedProcessVpdMapFile
:
1275 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, "FV", "%s.map" % self
.Platform
.VpdToolGuid
)
1276 if os
.path
.exists(VpdMapFilePath
):
1277 VpdFile
.Read(VpdMapFilePath
)
1280 for Pcd
in self
._DynamicPcdList
:
1281 # just pick the a value to determine whether is unicode string type
1283 for (SkuName
,Sku
) in Pcd
.SkuInfoList
.items():
1284 if Sku
.VpdOffset
== "*":
1285 Sku
.VpdOffset
= VpdFile
.GetOffset(Pcd
)[i
].strip()
1288 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
1290 # Delete the DynamicPcdList At the last time enter into this function
1291 del self
._DynamicPcdList
[:]
1292 self
._DynamicPcdList
.extend(UnicodePcdArray
)
1293 self
._DynamicPcdList
.extend(HiiPcdArray
)
1294 self
._DynamicPcdList
.extend(OtherPcdArray
)
1295 self
.AllPcdList
= self
._NonDynamicPcdList
+ self
._DynamicPcdList
1297 ## Return the platform build data object
1298 def _GetPlatform(self
):
1299 if self
._Platform
== None:
1300 self
._Platform
= self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1301 return self
._Platform
1303 ## Return platform name
1305 return self
.Platform
.PlatformName
1307 ## Return the meta file GUID
1309 return self
.Platform
.Guid
1311 ## Return the platform version
1312 def _GetVersion(self
):
1313 return self
.Platform
.Version
1315 ## Return the FDF file name
1316 def _GetFdfFile(self
):
1317 if self
._FdfFile
== None:
1318 if self
.Workspace
.FdfFile
!= "":
1319 self
._FdfFile
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
1322 return self
._FdfFile
1324 ## Return the build output directory platform specifies
1325 def _GetOutputDir(self
):
1326 return self
.Platform
.OutputDirectory
1328 ## Return the directory to store all intermediate and final files built
1329 def _GetBuildDir(self
):
1330 if self
._BuildDir
== None:
1331 if os
.path
.isabs(self
.OutputDir
):
1332 self
._BuildDir
= path
.join(
1333 path
.abspath(self
.OutputDir
),
1334 self
.BuildTarget
+ "_" + self
.ToolChain
,
1337 self
._BuildDir
= path
.join(
1340 self
.BuildTarget
+ "_" + self
.ToolChain
,
1342 return self
._BuildDir
1344 ## Return directory of platform makefile
1346 # @retval string Makefile directory
1348 def _GetMakeFileDir(self
):
1349 if self
._MakeFileDir
== None:
1350 self
._MakeFileDir
= path
.join(self
.BuildDir
, self
.Arch
)
1351 return self
._MakeFileDir
1353 ## Return build command string
1355 # @retval string Build command string
1357 def _GetBuildCommand(self
):
1358 if self
._BuildCommand
== None:
1359 self
._BuildCommand
= []
1360 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
1361 self
._BuildCommand
+= SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
1362 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
1363 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
1365 self
._BuildCommand
+= SplitOption(NewOption
)
1366 return self
._BuildCommand
1368 ## Get tool chain definition
1370 # Get each tool defition for given tool chain from tools_def.txt and platform
1372 def _GetToolDefinition(self
):
1373 if self
._ToolDefinitions
== None:
1374 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
1375 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
1376 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
1377 ExtraData
="[%s]" % self
.MetaFile
)
1378 self
._ToolDefinitions
= {}
1380 for Def
in ToolDefinition
:
1381 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
1382 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
1385 Value
= ToolDefinition
[Def
]
1386 # don't record the DLL
1388 DllPathList
.add(Value
)
1391 if Tool
not in self
._ToolDefinitions
:
1392 self
._ToolDefinitions
[Tool
] = {}
1393 self
._ToolDefinitions
[Tool
][Attr
] = Value
1397 if GlobalData
.gOptions
.SilentMode
and "MAKE" in self
._ToolDefinitions
:
1398 if "FLAGS" not in self
._ToolDefinitions
["MAKE"]:
1399 self
._ToolDefinitions
["MAKE"]["FLAGS"] = ""
1400 self
._ToolDefinitions
["MAKE"]["FLAGS"] += " -s"
1402 for Tool
in self
._ToolDefinitions
:
1403 for Attr
in self
._ToolDefinitions
[Tool
]:
1404 Value
= self
._ToolDefinitions
[Tool
][Attr
]
1405 if Tool
in self
.BuildOption
and Attr
in self
.BuildOption
[Tool
]:
1406 # check if override is indicated
1407 if self
.BuildOption
[Tool
][Attr
].startswith('='):
1408 Value
= self
.BuildOption
[Tool
][Attr
][1:]
1410 Value
+= " " + self
.BuildOption
[Tool
][Attr
]
1413 # Don't put MAKE definition in the file
1417 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
1419 # Don't put MAKE definition in the file
1424 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
1427 SaveFileOnChange(self
.ToolDefinitionFile
, ToolsDef
)
1428 for DllPath
in DllPathList
:
1429 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
1430 os
.environ
["MAKE_FLAGS"] = MakeFlags
1432 return self
._ToolDefinitions
1434 ## Return the paths of tools
1435 def _GetToolDefFile(self
):
1436 if self
._ToolDefFile
== None:
1437 self
._ToolDefFile
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
1438 return self
._ToolDefFile
1440 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1441 def _GetToolChainFamily(self
):
1442 if self
._ToolChainFamily
== None:
1443 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1444 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
1445 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
1446 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
1447 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1449 self
._ToolChainFamily
= "MSFT"
1451 self
._ToolChainFamily
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
1452 return self
._ToolChainFamily
1454 def _GetBuildRuleFamily(self
):
1455 if self
._BuildRuleFamily
== None:
1456 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
1457 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
1458 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
1459 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
1460 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1462 self
._BuildRuleFamily
= "MSFT"
1464 self
._BuildRuleFamily
= ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
1465 return self
._BuildRuleFamily
1467 ## Return the build options specific for all modules in this platform
1468 def _GetBuildOptions(self
):
1469 if self
._BuildOption
== None:
1470 self
._BuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
1471 return self
._BuildOption
1473 ## Return the build options specific for EDK modules in this platform
1474 def _GetEdkBuildOptions(self
):
1475 if self
._EdkBuildOption
== None:
1476 self
._EdkBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
1477 return self
._EdkBuildOption
1479 ## Return the build options specific for EDKII modules in this platform
1480 def _GetEdkIIBuildOptions(self
):
1481 if self
._EdkIIBuildOption
== None:
1482 self
._EdkIIBuildOption
= self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
1483 return self
._EdkIIBuildOption
1485 ## Parse build_rule.txt in Conf Directory.
1487 # @retval BuildRule object
1489 def _GetBuildRule(self
):
1490 if self
._BuildRule
== None:
1491 BuildRuleFile
= None
1492 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
1493 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
1494 if BuildRuleFile
in [None, '']:
1495 BuildRuleFile
= gDefaultBuildRuleFile
1496 self
._BuildRule
= BuildRule(BuildRuleFile
)
1497 if self
._BuildRule
._FileVersion
== "":
1498 self
._BuildRule
._FileVersion
= AutoGenReqBuildRuleVerNum
1500 if self
._BuildRule
._FileVersion
< AutoGenReqBuildRuleVerNum
:
1501 # If Build Rule's version is less than the version number required by the tools, halting the build.
1502 EdkLogger
.error("build", AUTOGEN_ERROR
,
1503 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])"\
1504 % (self
._BuildRule
._FileVersion
, AutoGenReqBuildRuleVerNum
))
1506 return self
._BuildRule
1508 ## Summarize the packages used by modules in this platform
1509 def _GetPackageList(self
):
1510 if self
._PackageList
== None:
1511 self
._PackageList
= set()
1512 for La
in self
.LibraryAutoGenList
:
1513 self
._PackageList
.update(La
.DependentPackageList
)
1514 for Ma
in self
.ModuleAutoGenList
:
1515 self
._PackageList
.update(Ma
.DependentPackageList
)
1516 #Collect package set information from INF of FDF
1518 for ModuleFile
in self
._AsBuildModuleList
:
1519 if ModuleFile
in self
.Platform
.Modules
:
1521 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1522 PkgSet
.update(ModuleData
.Packages
)
1523 self
._PackageList
= list(self
._PackageList
) + list (PkgSet
)
1524 return self
._PackageList
1526 def _GetNonDynamicPcdDict(self
):
1527 if self
._NonDynamicPcdDict
:
1528 return self
._NonDynamicPcdDict
1529 for Pcd
in self
.NonDynamicPcdList
:
1530 self
._NonDynamicPcdDict
[(Pcd
.TokenCName
,Pcd
.TokenSpaceGuidCName
)] = Pcd
1531 return self
._NonDynamicPcdDict
1533 ## Get list of non-dynamic PCDs
1534 def _GetNonDynamicPcdList(self
):
1535 if self
._NonDynamicPcdList
== None:
1536 self
.CollectPlatformDynamicPcds()
1537 return self
._NonDynamicPcdList
1539 ## Get list of dynamic PCDs
1540 def _GetDynamicPcdList(self
):
1541 if self
._DynamicPcdList
== None:
1542 self
.CollectPlatformDynamicPcds()
1543 return self
._DynamicPcdList
1545 ## Generate Token Number for all PCD
1546 def _GetPcdTokenNumbers(self
):
1547 if self
._PcdTokenNumber
== None:
1548 self
._PcdTokenNumber
= sdict()
1551 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1555 # TokenNumber 0 ~ 10
1557 # TokeNumber 11 ~ 20
1559 for Pcd
in self
.DynamicPcdList
:
1560 if Pcd
.Phase
== "PEI":
1561 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1562 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1563 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1566 for Pcd
in self
.DynamicPcdList
:
1567 if Pcd
.Phase
== "PEI":
1568 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1569 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1570 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1573 for Pcd
in self
.DynamicPcdList
:
1574 if Pcd
.Phase
== "DXE":
1575 if Pcd
.Type
in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1576 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1577 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1580 for Pcd
in self
.DynamicPcdList
:
1581 if Pcd
.Phase
== "DXE":
1582 if Pcd
.Type
in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1583 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1584 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1587 for Pcd
in self
.NonDynamicPcdList
:
1588 self
._PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1590 return self
._PcdTokenNumber
1592 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
1593 def _GetAutoGenObjectList(self
):
1594 self
._ModuleAutoGenList
= []
1595 self
._LibraryAutoGenList
= []
1596 for ModuleFile
in self
.Platform
.Modules
:
1605 if Ma
not in self
._ModuleAutoGenList
:
1606 self
._ModuleAutoGenList
.append(Ma
)
1607 for La
in Ma
.LibraryAutoGenList
:
1608 if La
not in self
._LibraryAutoGenList
:
1609 self
._LibraryAutoGenList
.append(La
)
1610 if Ma
not in La
._ReferenceModules
:
1611 La
._ReferenceModules
.append(Ma
)
1613 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
1614 def _GetModuleAutoGenList(self
):
1615 if self
._ModuleAutoGenList
== None:
1616 self
._GetAutoGenObjectList
()
1617 return self
._ModuleAutoGenList
1619 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
1620 def _GetLibraryAutoGenList(self
):
1621 if self
._LibraryAutoGenList
== None:
1622 self
._GetAutoGenObjectList
()
1623 return self
._LibraryAutoGenList
1625 ## Test if a module is supported by the platform
1627 # An error will be raised directly if the module or its arch is not supported
1628 # by the platform or current configuration
1630 def ValidModule(self
, Module
):
1631 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
1632 or Module
in self
._AsBuildModuleList
1634 ## Resolve the library classes in a module to library instances
1636 # This method will not only resolve library classes but also sort the library
1637 # instances according to the dependency-ship.
1639 # @param Module The module from which the library classes will be resolved
1641 # @retval library_list List of library instances sorted
1643 def ApplyLibraryInstance(self
, Module
):
1644 ModuleType
= Module
.ModuleType
1646 # for overridding library instances with module specific setting
1647 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
1649 # add forced library instances (specified under LibraryClasses sections)
1651 # If a module has a MODULE_TYPE of USER_DEFINED,
1652 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
1654 if Module
.ModuleType
!= SUP_MODULE_USER_DEFINED
:
1655 for LibraryClass
in self
.Platform
.LibraryClasses
.GetKeys():
1656 if LibraryClass
.startswith("NULL") and self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]:
1657 Module
.LibraryClasses
[LibraryClass
] = self
.Platform
.LibraryClasses
[LibraryClass
, Module
.ModuleType
]
1659 # add forced library instances (specified in module overrides)
1660 for LibraryClass
in PlatformModule
.LibraryClasses
:
1661 if LibraryClass
.startswith("NULL"):
1662 Module
.LibraryClasses
[LibraryClass
] = PlatformModule
.LibraryClasses
[LibraryClass
]
1665 LibraryConsumerList
= [Module
]
1667 ConsumedByList
= sdict()
1668 LibraryInstance
= sdict()
1670 EdkLogger
.verbose("")
1671 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
1672 while len(LibraryConsumerList
) > 0:
1673 M
= LibraryConsumerList
.pop()
1674 for LibraryClassName
in M
.LibraryClasses
:
1675 if LibraryClassName
not in LibraryInstance
:
1676 # override library instance for this module
1677 if LibraryClassName
in PlatformModule
.LibraryClasses
:
1678 LibraryPath
= PlatformModule
.LibraryClasses
[LibraryClassName
]
1680 LibraryPath
= self
.Platform
.LibraryClasses
[LibraryClassName
, ModuleType
]
1681 if LibraryPath
== None or LibraryPath
== "":
1682 LibraryPath
= M
.LibraryClasses
[LibraryClassName
]
1683 if LibraryPath
== None or LibraryPath
== "":
1684 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
1685 "Instance of library class [%s] is not found" % LibraryClassName
,
1687 ExtraData
="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M
), self
.Arch
, str(Module
)))
1689 LibraryModule
= self
.BuildDatabase
[LibraryPath
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
1690 # for those forced library instance (NULL library), add a fake library class
1691 if LibraryClassName
.startswith("NULL"):
1692 LibraryModule
.LibraryClass
.append(LibraryClassObject(LibraryClassName
, [ModuleType
]))
1693 elif LibraryModule
.LibraryClass
== None \
1694 or len(LibraryModule
.LibraryClass
) == 0 \
1695 or (ModuleType
!= 'USER_DEFINED'
1696 and ModuleType
not in LibraryModule
.LibraryClass
[0].SupModList
):
1697 # only USER_DEFINED can link against any library instance despite of its SupModList
1698 EdkLogger
.error("build", OPTION_MISSING
,
1699 "Module type [%s] is not supported by library instance [%s]" \
1700 % (ModuleType
, LibraryPath
), File
=self
.MetaFile
,
1701 ExtraData
="consumed by [%s]" % str(Module
))
1703 LibraryInstance
[LibraryClassName
] = LibraryModule
1704 LibraryConsumerList
.append(LibraryModule
)
1705 EdkLogger
.verbose("\t" + str(LibraryClassName
) + " : " + str(LibraryModule
))
1707 LibraryModule
= LibraryInstance
[LibraryClassName
]
1709 if LibraryModule
== None:
1712 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
1713 Constructor
.append(LibraryModule
)
1715 if LibraryModule
not in ConsumedByList
:
1716 ConsumedByList
[LibraryModule
] = []
1717 # don't add current module itself to consumer list
1719 if M
in ConsumedByList
[LibraryModule
]:
1721 ConsumedByList
[LibraryModule
].append(M
)
1723 # Initialize the sorted output list to the empty set
1725 SortedLibraryList
= []
1727 # Q <- Set of all nodes with no incoming edges
1729 LibraryList
= [] #LibraryInstance.values()
1731 for LibraryClassName
in LibraryInstance
:
1732 M
= LibraryInstance
[LibraryClassName
]
1733 LibraryList
.append(M
)
1734 if ConsumedByList
[M
] == []:
1738 # start the DAG algorithm
1742 while Q
== [] and EdgeRemoved
:
1744 # for each node Item with a Constructor
1745 for Item
in LibraryList
:
1746 if Item
not in Constructor
:
1748 # for each Node without a constructor with an edge e from Item to Node
1749 for Node
in ConsumedByList
[Item
]:
1750 if Node
in Constructor
:
1752 # remove edge e from the graph if Node has no constructor
1753 ConsumedByList
[Item
].remove(Node
)
1755 if ConsumedByList
[Item
] == []:
1756 # insert Item into Q
1761 # DAG is done if there's no more incoming edge for all nodes
1765 # remove node from Q
1768 SortedLibraryList
.append(Node
)
1770 # for each node Item with an edge e from Node to Item do
1771 for Item
in LibraryList
:
1772 if Node
not in ConsumedByList
[Item
]:
1774 # remove edge e from the graph
1775 ConsumedByList
[Item
].remove(Node
)
1777 if ConsumedByList
[Item
] != []:
1779 # insert Item into Q, if Item has no other incoming edges
1783 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
1785 for Item
in LibraryList
:
1786 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
1787 ErrorMessage
= "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]])
1788 EdkLogger
.error("build", BUILD_ERROR
, 'Library [%s] with constructors has a cycle' % str(Item
),
1789 ExtraData
=ErrorMessage
, File
=self
.MetaFile
)
1790 if Item
not in SortedLibraryList
:
1791 SortedLibraryList
.append(Item
)
1794 # Build the list of constructor and destructir names
1795 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
1797 SortedLibraryList
.reverse()
1798 return SortedLibraryList
1801 ## Override PCD setting (type, value, ...)
1803 # @param ToPcd The PCD to be overrided
1804 # @param FromPcd The PCD overrideing from
1806 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
=""):
1808 # in case there's PCDs coming from FDF file, which have no type given.
1809 # at this point, ToPcd.Type has the type found from dependent
1813 if ToPcd
.Pending
and FromPcd
.Type
not in [None, '']:
1814 ToPcd
.Type
= FromPcd
.Type
1815 elif (ToPcd
.Type
not in [None, '']) and (FromPcd
.Type
not in [None, ''])\
1816 and (ToPcd
.Type
!= FromPcd
.Type
) and (ToPcd
.Type
in FromPcd
.Type
):
1817 if ToPcd
.Type
.strip() == "DynamicEx":
1818 ToPcd
.Type
= FromPcd
.Type
1819 elif ToPcd
.Type
not in [None, ''] and FromPcd
.Type
not in [None, ''] \
1820 and ToPcd
.Type
!= FromPcd
.Type
:
1821 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
1822 ExtraData
="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
1823 % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
,
1824 ToPcd
.Type
, Module
, FromPcd
.Type
),
1827 if FromPcd
.MaxDatumSize
not in [None, '']:
1828 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
1829 if FromPcd
.DefaultValue
not in [None, '']:
1830 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
1831 if FromPcd
.TokenValue
not in [None, '']:
1832 ToPcd
.TokenValue
= FromPcd
.TokenValue
1833 if FromPcd
.MaxDatumSize
not in [None, '']:
1834 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
1835 if FromPcd
.DatumType
not in [None, '']:
1836 ToPcd
.DatumType
= FromPcd
.DatumType
1837 if FromPcd
.SkuInfoList
not in [None, '', []]:
1838 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
1840 # check the validation of datum
1841 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
1843 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
1844 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
))
1845 ToPcd
.validateranges
= FromPcd
.validateranges
1846 ToPcd
.validlists
= FromPcd
.validlists
1847 ToPcd
.expressions
= FromPcd
.expressions
1849 if ToPcd
.DatumType
== "VOID*" and ToPcd
.MaxDatumSize
in ['', None]:
1850 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
1851 % (ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
))
1852 Value
= ToPcd
.DefaultValue
1853 if Value
in [None, '']:
1854 ToPcd
.MaxDatumSize
= '1'
1855 elif Value
[0] == 'L':
1856 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
1857 elif Value
[0] == '{':
1858 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
1860 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
1862 # apply default SKU for dynamic PCDS if specified one is not available
1863 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_LIST
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_LIST
) \
1864 and ToPcd
.SkuInfoList
in [None, {}, '']:
1865 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
1866 SkuName
= self
.Platform
.SkuName
1869 ToPcd
.SkuInfoList
= {
1870 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
], '', '', '', '', '', ToPcd
.DefaultValue
)
1873 ## Apply PCD setting defined platform to a module
1875 # @param Module The module from which the PCD setting will be overrided
1877 # @retval PCD_list The list PCDs with settings from platform
1879 def ApplyPcdSetting(self
, Module
, Pcds
):
1880 # for each PCD in module
1881 for Name
, Guid
in Pcds
:
1882 PcdInModule
= Pcds
[Name
, Guid
]
1883 # find out the PCD setting in platform
1884 if (Name
, Guid
) in self
.Platform
.Pcds
:
1885 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
1887 PcdInPlatform
= None
1888 # then override the settings if any
1889 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
)
1890 # resolve the VariableGuid value
1891 for SkuId
in PcdInModule
.SkuInfoList
:
1892 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
1893 if Sku
.VariableGuid
== '': continue
1894 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
)
1895 if Sku
.VariableGuidValue
== None:
1896 PackageList
= "\n\t".join([str(P
) for P
in self
.PackageList
])
1899 RESOURCE_NOT_AVAILABLE
,
1900 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
1901 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
1902 % (Guid
, Name
, str(Module
)),
1906 # override PCD settings with module specific setting
1907 if Module
in self
.Platform
.Modules
:
1908 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
1909 for Key
in PlatformModule
.Pcds
:
1911 self
._OverridePcd
(Pcds
[Key
], PlatformModule
.Pcds
[Key
], Module
)
1912 return Pcds
.values()
1914 ## Resolve library names to library modules
1916 # (for Edk.x modules)
1918 # @param Module The module from which the library names will be resolved
1920 # @retval library_list The list of library modules
1922 def ResolveLibraryReference(self
, Module
):
1923 EdkLogger
.verbose("")
1924 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), self
.Arch
))
1925 LibraryConsumerList
= [Module
]
1927 # "CompilerStub" is a must for Edk modules
1928 if Module
.Libraries
:
1929 Module
.Libraries
.append("CompilerStub")
1931 while len(LibraryConsumerList
) > 0:
1932 M
= LibraryConsumerList
.pop()
1933 for LibraryName
in M
.Libraries
:
1934 Library
= self
.Platform
.LibraryClasses
[LibraryName
, ':dummy:']
1936 for Key
in self
.Platform
.LibraryClasses
.data
.keys():
1937 if LibraryName
.upper() == Key
.upper():
1938 Library
= self
.Platform
.LibraryClasses
[Key
, ':dummy:']
1941 EdkLogger
.warn("build", "Library [%s] is not found" % LibraryName
, File
=str(M
),
1942 ExtraData
="\t%s [%s]" % (str(Module
), self
.Arch
))
1945 if Library
not in LibraryList
:
1946 LibraryList
.append(Library
)
1947 LibraryConsumerList
.append(Library
)
1948 EdkLogger
.verbose("\t" + LibraryName
+ " : " + str(Library
) + ' ' + str(type(Library
)))
1951 ## Calculate the priority value of the build option
1953 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1955 # @retval Value Priority value based on the priority list.
1957 def CalculatePriorityValue(self
, Key
):
1958 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
1959 PriorityValue
= 0x11111
1961 PriorityValue
&= 0x01111
1962 if ToolChain
== "*":
1963 PriorityValue
&= 0x10111
1965 PriorityValue
&= 0x11011
1966 if CommandType
== "*":
1967 PriorityValue
&= 0x11101
1969 PriorityValue
&= 0x11110
1971 return self
.PrioList
["0x%0.5x" % PriorityValue
]
1974 ## Expand * in build option key
1976 # @param Options Options to be expanded
1978 # @retval options Options expanded
1980 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None):
1987 # Construct a list contain the build options which need override.
1991 # Key[0] -- tool family
1992 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1994 if (Key
[0] == self
.BuildRuleFamily
and
1995 (ModuleStyle
== None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
1996 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
1997 if Target
== self
.BuildTarget
or Target
== "*":
1998 if ToolChain
== self
.ToolChain
or ToolChain
== "*":
1999 if Arch
== self
.Arch
or Arch
== "*":
2000 if Options
[Key
].startswith("="):
2001 if OverrideList
.get(Key
[1]) != None:
2002 OverrideList
.pop(Key
[1])
2003 OverrideList
[Key
[1]] = Options
[Key
]
2006 # Use the highest priority value.
2008 if (len(OverrideList
) >= 2):
2009 KeyList
= OverrideList
.keys()
2010 for Index
in range(len(KeyList
)):
2011 NowKey
= KeyList
[Index
]
2012 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
2013 for Index1
in range(len(KeyList
) - Index
- 1):
2014 NextKey
= KeyList
[Index1
+ Index
+ 1]
2016 # Compare two Key, if one is included by another, choose the higher priority one
2018 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
2019 if Target1
== Target2
or Target1
== "*" or Target2
== "*":
2020 if ToolChain1
== ToolChain2
or ToolChain1
== "*" or ToolChain2
== "*":
2021 if Arch1
== Arch2
or Arch1
== "*" or Arch2
== "*":
2022 if CommandType1
== CommandType2
or CommandType1
== "*" or CommandType2
== "*":
2023 if Attr1
== Attr2
or Attr1
== "*" or Attr2
== "*":
2024 if self
.CalculatePriorityValue(NowKey
) > self
.CalculatePriorityValue(NextKey
):
2025 if Options
.get((self
.BuildRuleFamily
, NextKey
)) != None:
2026 Options
.pop((self
.BuildRuleFamily
, NextKey
))
2028 if Options
.get((self
.BuildRuleFamily
, NowKey
)) != None:
2029 Options
.pop((self
.BuildRuleFamily
, NowKey
))
2032 if ModuleStyle
!= None and len (Key
) > 2:
2033 # Check Module style is EDK or EDKII.
2034 # Only append build option for the matched style module.
2035 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2037 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2040 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2041 # if tool chain family doesn't match, skip it
2042 if Tool
in self
.ToolDefinition
and Family
!= "":
2043 FamilyIsNull
= False
2044 if self
.ToolDefinition
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
2045 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
2047 elif Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2050 # expand any wildcard
2051 if Target
== "*" or Target
== self
.BuildTarget
:
2052 if Tag
== "*" or Tag
== self
.ToolChain
:
2053 if Arch
== "*" or Arch
== self
.Arch
:
2054 if Tool
not in BuildOptions
:
2055 BuildOptions
[Tool
] = {}
2056 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2057 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2059 # append options for the same tool
2060 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2061 # Build Option Family has been checked, which need't to be checked again for family.
2062 if FamilyMatch
or FamilyIsNull
:
2066 if ModuleStyle
!= None and len (Key
) > 2:
2067 # Check Module style is EDK or EDKII.
2068 # Only append build option for the matched style module.
2069 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
2071 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
2074 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
2075 # if tool chain family doesn't match, skip it
2076 if Tool
not in self
.ToolDefinition
or Family
== "":
2078 # option has been added before
2079 if Family
!= self
.ToolDefinition
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
2082 # expand any wildcard
2083 if Target
== "*" or Target
== self
.BuildTarget
:
2084 if Tag
== "*" or Tag
== self
.ToolChain
:
2085 if Arch
== "*" or Arch
== self
.Arch
:
2086 if Tool
not in BuildOptions
:
2087 BuildOptions
[Tool
] = {}
2088 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
2089 BuildOptions
[Tool
][Attr
] = Options
[Key
]
2091 # append options for the same tool
2092 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
2095 ## Append build options in platform to a module
2097 # @param Module The module to which the build options will be appened
2099 # @retval options The options appended with build options in platform
2101 def ApplyBuildOption(self
, Module
):
2102 # Get the different options for the different style module
2103 if Module
.AutoGenVersion
< 0x00010005:
2104 PlatformOptions
= self
.EdkBuildOption
2105 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDK_NAME
, Module
.ModuleType
)
2107 PlatformOptions
= self
.EdkIIBuildOption
2108 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
2109 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
2110 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
2111 if Module
in self
.Platform
.Modules
:
2112 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
2113 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
2115 PlatformModuleOptions
= {}
2117 BuildRuleOrder
= None
2118 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2119 for Tool
in Options
:
2120 for Attr
in Options
[Tool
]:
2121 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2122 BuildRuleOrder
= Options
[Tool
][Attr
]
2124 AllTools
= set(ModuleOptions
.keys() + PlatformOptions
.keys() +
2125 PlatformModuleOptions
.keys() + ModuleTypeOptions
.keys() +
2126 self
.ToolDefinition
.keys())
2128 for Tool
in AllTools
:
2129 if Tool
not in BuildOptions
:
2130 BuildOptions
[Tool
] = {}
2132 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
2133 if Tool
not in Options
:
2135 for Attr
in Options
[Tool
]:
2136 Value
= Options
[Tool
][Attr
]
2138 # Do not generate it in Makefile
2140 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
2142 if Attr
not in BuildOptions
[Tool
]:
2143 BuildOptions
[Tool
][Attr
] = ""
2144 # check if override is indicated
2145 if Value
.startswith('='):
2146 ToolPath
= Value
[1:]
2147 ToolPath
= mws
.handleWsMacro(ToolPath
)
2148 BuildOptions
[Tool
][Attr
] = ToolPath
2150 Value
= mws
.handleWsMacro(Value
)
2151 BuildOptions
[Tool
][Attr
] += " " + Value
2152 if Module
.AutoGenVersion
< 0x00010005 and self
.Workspace
.UniFlag
!= None:
2154 # Override UNI flag only for EDK module.
2156 if 'BUILD' not in BuildOptions
:
2157 BuildOptions
['BUILD'] = {}
2158 BuildOptions
['BUILD']['FLAGS'] = self
.Workspace
.UniFlag
2159 return BuildOptions
, BuildRuleOrder
2161 Platform
= property(_GetPlatform
)
2162 Name
= property(_GetName
)
2163 Guid
= property(_GetGuid
)
2164 Version
= property(_GetVersion
)
2166 OutputDir
= property(_GetOutputDir
)
2167 BuildDir
= property(_GetBuildDir
)
2168 MakeFileDir
= property(_GetMakeFileDir
)
2169 FdfFile
= property(_GetFdfFile
)
2171 PcdTokenNumber
= property(_GetPcdTokenNumbers
) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2172 DynamicPcdList
= property(_GetDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2173 NonDynamicPcdList
= property(_GetNonDynamicPcdList
) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2174 NonDynamicPcdDict
= property(_GetNonDynamicPcdDict
)
2175 PackageList
= property(_GetPackageList
)
2177 ToolDefinition
= property(_GetToolDefinition
) # toolcode : tool path
2178 ToolDefinitionFile
= property(_GetToolDefFile
) # toolcode : lib path
2179 ToolChainFamily
= property(_GetToolChainFamily
)
2180 BuildRuleFamily
= property(_GetBuildRuleFamily
)
2181 BuildOption
= property(_GetBuildOptions
) # toolcode : option
2182 EdkBuildOption
= property(_GetEdkBuildOptions
) # edktoolcode : option
2183 EdkIIBuildOption
= property(_GetEdkIIBuildOptions
) # edkiitoolcode : option
2185 BuildCommand
= property(_GetBuildCommand
)
2186 BuildRule
= property(_GetBuildRule
)
2187 ModuleAutoGenList
= property(_GetModuleAutoGenList
)
2188 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
2189 GenFdsCommand
= property(_GenFdsCommand
)
2191 ## ModuleAutoGen class
2193 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2194 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2195 # to the [depex] section in module's inf file.
2197 class ModuleAutoGen(AutoGen
):
2198 ## The real constructor of ModuleAutoGen
2200 # This method is not supposed to be called by users of ModuleAutoGen. It's
2201 # only used by factory method __new__() to do real initialization work for an
2202 # object of ModuleAutoGen
2204 # @param Workspace EdkIIWorkspaceBuild object
2205 # @param ModuleFile The path of module file
2206 # @param Target Build target (DEBUG, RELEASE)
2207 # @param Toolchain Name of tool chain
2208 # @param Arch The arch the module supports
2209 # @param PlatformFile Platform meta-file
2211 def _Init(self
, Workspace
, ModuleFile
, Target
, Toolchain
, Arch
, PlatformFile
):
2212 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen module [%s] [%s]" % (ModuleFile
, Arch
))
2213 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (ModuleFile
, Arch
, Toolchain
, Target
)
2215 self
.Workspace
= Workspace
2216 self
.WorkspaceDir
= Workspace
.WorkspaceDir
2218 self
.MetaFile
= ModuleFile
2219 self
.PlatformInfo
= PlatformAutoGen(Workspace
, PlatformFile
, Target
, Toolchain
, Arch
)
2220 # check if this module is employed by active platform
2221 if not self
.PlatformInfo
.ValidModule(self
.MetaFile
):
2222 EdkLogger
.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2223 % (self
.MetaFile
, Arch
))
2226 self
.SourceDir
= self
.MetaFile
.SubDir
2227 self
.SourceDir
= mws
.relpath(self
.SourceDir
, self
.WorkspaceDir
)
2229 self
.SourceOverrideDir
= None
2230 # use overrided path defined in DSC file
2231 if self
.MetaFile
.Key
in GlobalData
.gOverrideDir
:
2232 self
.SourceOverrideDir
= GlobalData
.gOverrideDir
[self
.MetaFile
.Key
]
2234 self
.ToolChain
= Toolchain
2235 self
.BuildTarget
= Target
2237 self
.ToolChainFamily
= self
.PlatformInfo
.ToolChainFamily
2238 self
.BuildRuleFamily
= self
.PlatformInfo
.BuildRuleFamily
2240 self
.IsMakeFileCreated
= False
2241 self
.IsCodeFileCreated
= False
2242 self
.IsAsBuiltInfCreated
= False
2243 self
.DepexGenerated
= False
2245 self
.BuildDatabase
= self
.Workspace
.BuildDatabase
2246 self
.BuildRuleOrder
= None
2251 self
._Version
= None
2252 self
._ModuleType
= None
2253 self
._ComponentType
= None
2254 self
._PcdIsDriver
= None
2255 self
._AutoGenVersion
= None
2256 self
._LibraryFlag
= None
2257 self
._CustomMakefile
= None
2260 self
._BuildDir
= None
2261 self
._OutputDir
= None
2262 self
._DebugDir
= None
2263 self
._MakeFileDir
= None
2265 self
._IncludePathList
= None
2266 self
._AutoGenFileList
= None
2267 self
._UnicodeFileList
= None
2268 self
._SourceFileList
= None
2269 self
._ObjectFileList
= None
2270 self
._BinaryFileList
= None
2272 self
._DependentPackageList
= None
2273 self
._DependentLibraryList
= None
2274 self
._LibraryAutoGenList
= None
2275 self
._DerivedPackageList
= None
2276 self
._ModulePcdList
= None
2277 self
._LibraryPcdList
= None
2278 self
._PcdComments
= sdict()
2279 self
._GuidList
= None
2280 self
._GuidsUsedByPcd
= None
2281 self
._GuidComments
= sdict()
2282 self
._ProtocolList
= None
2283 self
._ProtocolComments
= sdict()
2284 self
._PpiList
= None
2285 self
._PpiComments
= sdict()
2286 self
._DepexList
= None
2287 self
._DepexExpressionList
= None
2288 self
._BuildOption
= None
2289 self
._BuildOptionIncPathList
= None
2290 self
._BuildTargets
= None
2291 self
._IntroBuildTargetList
= None
2292 self
._FinalBuildTargetList
= None
2293 self
._FileTypes
= None
2294 self
._BuildRules
= None
2296 ## The Modules referenced to this Library
2297 # Only Library has this attribute
2298 self
._ReferenceModules
= []
2300 ## Store the FixedAtBuild Pcds
2302 self
._FixedAtBuildPcds
= []
2307 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
2309 # Get FixedAtBuild Pcds of this Module
2310 def _GetFixedAtBuildPcds(self
):
2311 if self
._FixedAtBuildPcds
:
2312 return self
._FixedAtBuildPcds
2313 for Pcd
in self
.ModulePcdList
:
2315 if not (Pcd
.Pending
== False and Pcd
.Type
== "FixedAtBuild"):
2317 elif Pcd
.Type
!= "FixedAtBuild":
2319 if Pcd
not in self
._FixedAtBuildPcds
:
2320 self
._FixedAtBuildPcds
.append(Pcd
)
2322 return self
._FixedAtBuildPcds
2324 def _GetUniqueBaseName(self
):
2325 BaseName
= self
.Name
2326 for Module
in self
.PlatformInfo
.ModuleAutoGenList
:
2327 if Module
.MetaFile
== self
.MetaFile
:
2329 if Module
.Name
== self
.Name
:
2330 if uuid
.UUID(Module
.Guid
) == uuid
.UUID(self
.Guid
):
2331 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
2332 ' %s\n %s' % (Module
.MetaFile
, self
.MetaFile
))
2333 BaseName
= '%s_%s' % (self
.Name
, self
.Guid
)
2336 # Macros could be used in build_rule.txt (also Makefile)
2337 def _GetMacros(self
):
2338 if self
._Macro
== None:
2339 self
._Macro
= sdict()
2340 self
._Macro
["WORKSPACE" ] = self
.WorkspaceDir
2341 self
._Macro
["MODULE_NAME" ] = self
.Name
2342 self
._Macro
["MODULE_NAME_GUID" ] = self
._GetUniqueBaseName
()
2343 self
._Macro
["MODULE_GUID" ] = self
.Guid
2344 self
._Macro
["MODULE_VERSION" ] = self
.Version
2345 self
._Macro
["MODULE_TYPE" ] = self
.ModuleType
2346 self
._Macro
["MODULE_FILE" ] = str(self
.MetaFile
)
2347 self
._Macro
["MODULE_FILE_BASE_NAME" ] = self
.MetaFile
.BaseName
2348 self
._Macro
["MODULE_RELATIVE_DIR" ] = self
.SourceDir
2349 self
._Macro
["MODULE_DIR" ] = self
.SourceDir
2351 self
._Macro
["BASE_NAME" ] = self
.Name
2353 self
._Macro
["ARCH" ] = self
.Arch
2354 self
._Macro
["TOOLCHAIN" ] = self
.ToolChain
2355 self
._Macro
["TOOLCHAIN_TAG" ] = self
.ToolChain
2356 self
._Macro
["TOOL_CHAIN_TAG" ] = self
.ToolChain
2357 self
._Macro
["TARGET" ] = self
.BuildTarget
2359 self
._Macro
["BUILD_DIR" ] = self
.PlatformInfo
.BuildDir
2360 self
._Macro
["BIN_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2361 self
._Macro
["LIB_DIR" ] = os
.path
.join(self
.PlatformInfo
.BuildDir
, self
.Arch
)
2362 self
._Macro
["MODULE_BUILD_DIR" ] = self
.BuildDir
2363 self
._Macro
["OUTPUT_DIR" ] = self
.OutputDir
2364 self
._Macro
["DEBUG_DIR" ] = self
.DebugDir
2367 ## Return the module build data object
2368 def _GetModule(self
):
2369 if self
._Module
== None:
2370 self
._Module
= self
.Workspace
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
2373 ## Return the module name
2374 def _GetBaseName(self
):
2375 return self
.Module
.BaseName
2377 ## Return the module DxsFile if exist
2378 def _GetDxsFile(self
):
2379 return self
.Module
.DxsFile
2381 ## Return the module SourceOverridePath
2382 def _GetSourceOverridePath(self
):
2383 return self
.Module
.SourceOverridePath
2385 ## Return the module meta-file GUID
2388 # To build same module more than once, the module path with FILE_GUID overridden has
2389 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2390 # in DSC. The overridden GUID can be retrieved from file name
2392 if os
.path
.basename(self
.MetaFile
.File
) != os
.path
.basename(self
.MetaFile
.Path
):
2394 # Length of GUID is 36
2396 return os
.path
.basename(self
.MetaFile
.Path
)[:36]
2397 return self
.Module
.Guid
2399 ## Return the module version
2400 def _GetVersion(self
):
2401 return self
.Module
.Version
2403 ## Return the module type
2404 def _GetModuleType(self
):
2405 return self
.Module
.ModuleType
2407 ## Return the component type (for Edk.x style of module)
2408 def _GetComponentType(self
):
2409 return self
.Module
.ComponentType
2411 ## Return the build type
2412 def _GetBuildType(self
):
2413 return self
.Module
.BuildType
2415 ## Return the PCD_IS_DRIVER setting
2416 def _GetPcdIsDriver(self
):
2417 return self
.Module
.PcdIsDriver
2419 ## Return the autogen version, i.e. module meta-file version
2420 def _GetAutoGenVersion(self
):
2421 return self
.Module
.AutoGenVersion
2423 ## Check if the module is library or not
2424 def _IsLibrary(self
):
2425 if self
._LibraryFlag
== None:
2426 if self
.Module
.LibraryClass
!= None and self
.Module
.LibraryClass
!= []:
2427 self
._LibraryFlag
= True
2429 self
._LibraryFlag
= False
2430 return self
._LibraryFlag
2432 ## Check if the module is binary module or not
2433 def _IsBinaryModule(self
):
2434 return self
.Module
.IsBinaryModule
2436 ## Return the directory to store intermediate files of the module
2437 def _GetBuildDir(self
):
2438 if self
._BuildDir
== None:
2439 self
._BuildDir
= path
.join(
2440 self
.PlatformInfo
.BuildDir
,
2443 self
.MetaFile
.BaseName
2445 CreateDirectory(self
._BuildDir
)
2446 return self
._BuildDir
2448 ## Return the directory to store the intermediate object files of the mdoule
2449 def _GetOutputDir(self
):
2450 if self
._OutputDir
== None:
2451 self
._OutputDir
= path
.join(self
.BuildDir
, "OUTPUT")
2452 CreateDirectory(self
._OutputDir
)
2453 return self
._OutputDir
2455 ## Return the directory to store auto-gened source files of the mdoule
2456 def _GetDebugDir(self
):
2457 if self
._DebugDir
== None:
2458 self
._DebugDir
= path
.join(self
.BuildDir
, "DEBUG")
2459 CreateDirectory(self
._DebugDir
)
2460 return self
._DebugDir
2462 ## Return the path of custom file
2463 def _GetCustomMakefile(self
):
2464 if self
._CustomMakefile
== None:
2465 self
._CustomMakefile
= {}
2466 for Type
in self
.Module
.CustomMakefile
:
2467 if Type
in gMakeTypeMap
:
2468 MakeType
= gMakeTypeMap
[Type
]
2471 if self
.SourceOverrideDir
!= None:
2472 File
= os
.path
.join(self
.SourceOverrideDir
, self
.Module
.CustomMakefile
[Type
])
2473 if not os
.path
.exists(File
):
2474 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2476 File
= os
.path
.join(self
.SourceDir
, self
.Module
.CustomMakefile
[Type
])
2477 self
._CustomMakefile
[MakeType
] = File
2478 return self
._CustomMakefile
2480 ## Return the directory of the makefile
2482 # @retval string The directory string of module's makefile
2484 def _GetMakeFileDir(self
):
2485 return self
.BuildDir
2487 ## Return build command string
2489 # @retval string Build command string
2491 def _GetBuildCommand(self
):
2492 return self
.PlatformInfo
.BuildCommand
2494 ## Get object list of all packages the module and its dependent libraries belong to
2496 # @retval list The list of package object
2498 def _GetDerivedPackageList(self
):
2500 for M
in [self
.Module
] + self
.DependentLibraryList
:
2501 for Package
in M
.Packages
:
2502 if Package
in PackageList
:
2504 PackageList
.append(Package
)
2507 ## Get the depex string
2509 # @return : a string contain all depex expresion.
2510 def _GetDepexExpresionString(self
):
2513 ## DPX_SOURCE IN Define section.
2514 if self
.Module
.DxsFile
:
2516 for M
in [self
.Module
] + self
.DependentLibraryList
:
2517 Filename
= M
.MetaFile
.Path
2518 InfObj
= InfSectionParser
.InfSectionParser(Filename
)
2519 DepexExpresionList
= InfObj
.GetDepexExpresionList()
2520 for DepexExpresion
in DepexExpresionList
:
2521 for key
in DepexExpresion
.keys():
2522 Arch
, ModuleType
= key
2523 # the type of build module is USER_DEFINED.
2524 # All different DEPEX section tags would be copied into the As Built INF file
2525 # and there would be separate DEPEX section tags
2526 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2527 if (Arch
.upper() == self
.Arch
.upper()) and (ModuleType
.upper() != TAB_ARCH_COMMON
):
2528 DepexList
.append({(Arch
, ModuleType
): DepexExpresion
[key
][:]})
2530 if Arch
.upper() == TAB_ARCH_COMMON
or \
2531 (Arch
.upper() == self
.Arch
.upper() and \
2532 ModuleType
.upper() in [TAB_ARCH_COMMON
, self
.ModuleType
.upper()]):
2533 DepexList
.append({(Arch
, ModuleType
): DepexExpresion
[key
][:]})
2535 #the type of build module is USER_DEFINED.
2536 if self
.ModuleType
.upper() == SUP_MODULE_USER_DEFINED
:
2537 for Depex
in DepexList
:
2538 for key
in Depex
.keys():
2539 DepexStr
+= '[Depex.%s.%s]\n' % key
2540 DepexStr
+= '\n'.join(['# '+ val
for val
in Depex
[key
]])
2543 return '[Depex.%s]\n' % self
.Arch
2546 #the type of build module not is USER_DEFINED.
2548 for Depex
in DepexList
:
2553 for D
in Depex
.values():
2554 DepexStr
+= ' '.join([val
for val
in D
])
2555 Index
= DepexStr
.find('END')
2556 if Index
> -1 and Index
== len(DepexStr
) - 3:
2557 DepexStr
= DepexStr
[:-3]
2558 DepexStr
= DepexStr
.strip()
2561 DepexStr
= DepexStr
.lstrip('(').rstrip(')').strip()
2563 return '[Depex.%s]\n' % self
.Arch
2564 return '[Depex.%s]\n# ' % self
.Arch
+ DepexStr
2566 ## Merge dependency expression
2568 # @retval list The token list of the dependency expression after parsed
2570 def _GetDepexTokenList(self
):
2571 if self
._DepexList
== None:
2572 self
._DepexList
= {}
2573 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2574 return self
._DepexList
2576 self
._DepexList
[self
.ModuleType
] = []
2578 for ModuleType
in self
._DepexList
:
2579 DepexList
= self
._DepexList
[ModuleType
]
2581 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2583 for M
in [self
.Module
] + self
.DependentLibraryList
:
2585 for D
in M
.Depex
[self
.Arch
, ModuleType
]:
2587 DepexList
.append('AND')
2588 DepexList
.append('(')
2590 if DepexList
[-1] == 'END': # no need of a END at this time
2592 DepexList
.append(')')
2595 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexList
))
2596 if 'BEFORE' in DepexList
or 'AFTER' in DepexList
:
2598 if len(DepexList
) > 0:
2599 EdkLogger
.verbose('')
2600 return self
._DepexList
2602 ## Merge dependency expression
2604 # @retval list The token list of the dependency expression after parsed
2606 def _GetDepexExpressionTokenList(self
):
2607 if self
._DepexExpressionList
== None:
2608 self
._DepexExpressionList
= {}
2609 if self
.DxsFile
or self
.IsLibrary
or TAB_DEPENDENCY_EXPRESSION_FILE
in self
.FileTypes
:
2610 return self
._DepexExpressionList
2612 self
._DepexExpressionList
[self
.ModuleType
] = ''
2614 for ModuleType
in self
._DepexExpressionList
:
2615 DepexExpressionList
= self
._DepexExpressionList
[ModuleType
]
2617 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2619 for M
in [self
.Module
] + self
.DependentLibraryList
:
2621 for D
in M
.DepexExpression
[self
.Arch
, ModuleType
]:
2622 if DepexExpressionList
!= '':
2623 DepexExpressionList
+= ' AND '
2624 DepexExpressionList
+= '('
2625 DepexExpressionList
+= D
2626 DepexExpressionList
= DepexExpressionList
.rstrip('END').strip()
2627 DepexExpressionList
+= ')'
2630 EdkLogger
.verbose("DEPEX[%s] (+%s) = %s" % (self
.Name
, M
.BaseName
, DepexExpressionList
))
2631 if 'BEFORE' in DepexExpressionList
or 'AFTER' in DepexExpressionList
:
2633 if len(DepexExpressionList
) > 0:
2634 EdkLogger
.verbose('')
2635 self
._DepexExpressionList
[ModuleType
] = DepexExpressionList
2636 return self
._DepexExpressionList
2638 ## Return the list of specification version required for the module
2640 # @retval list The list of specification defined in module file
2642 def _GetSpecification(self
):
2643 return self
.Module
.Specification
2645 ## Tool option for the module build
2647 # @param PlatformInfo The object of PlatformBuildInfo
2648 # @retval dict The dict containing valid options
2650 def _GetModuleBuildOption(self
):
2651 if self
._BuildOption
== None:
2652 self
._BuildOption
, self
.BuildRuleOrder
= self
.PlatformInfo
.ApplyBuildOption(self
.Module
)
2653 if self
.BuildRuleOrder
:
2654 self
.BuildRuleOrder
= ['.%s' % Ext
for Ext
in self
.BuildRuleOrder
.split()]
2655 return self
._BuildOption
2657 ## Get include path list from tool option for the module build
2659 # @retval list The include path list
2661 def _GetBuildOptionIncPathList(self
):
2662 if self
._BuildOptionIncPathList
== None:
2664 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
2665 # is the former use /I , the Latter used -I to specify include directories
2667 if self
.PlatformInfo
.ToolChainFamily
in ('MSFT'):
2668 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)/I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
2669 elif self
.PlatformInfo
.ToolChainFamily
in ('INTEL', 'GCC', 'RVCT'):
2670 gBuildOptIncludePattern
= re
.compile(r
"(?:.*?)-I[ \t]*([^ ]*)", re
.MULTILINE | re
.DOTALL
)
2673 # New ToolChainFamily, don't known whether there is option to specify include directories
2675 self
._BuildOptionIncPathList
= []
2676 return self
._BuildOptionIncPathList
2678 BuildOptionIncPathList
= []
2679 for Tool
in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
2682 FlagOption
= self
.BuildOption
[Tool
][Attr
]
2686 if self
.PlatformInfo
.ToolChainFamily
!= 'RVCT':
2687 IncPathList
= [NormPath(Path
, self
.Macros
) for Path
in gBuildOptIncludePattern
.findall(FlagOption
)]
2690 # RVCT may specify a list of directory seperated by commas
2693 for Path
in gBuildOptIncludePattern
.findall(FlagOption
):
2694 PathList
= GetSplitList(Path
, TAB_COMMA_SPLIT
)
2695 IncPathList
+= [NormPath(PathEntry
, self
.Macros
) for PathEntry
in PathList
]
2698 # EDK II modules must not reference header files outside of the packages they depend on or
2699 # within the module's directory tree. Report error if violation.
2701 if self
.AutoGenVersion
>= 0x00010005 and len(IncPathList
) > 0:
2702 for Path
in IncPathList
:
2703 if (Path
not in self
.IncludePathList
) and (CommonPath([Path
, self
.MetaFile
.Dir
]) != self
.MetaFile
.Dir
):
2704 ErrMsg
= "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path
, Tool
, FlagOption
)
2705 EdkLogger
.error("build",
2708 File
=str(self
.MetaFile
))
2711 BuildOptionIncPathList
+= IncPathList
2713 self
._BuildOptionIncPathList
= BuildOptionIncPathList
2715 return self
._BuildOptionIncPathList
2717 ## Return a list of files which can be built from source
2719 # What kind of files can be built is determined by build rules in
2720 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
2722 def _GetSourceFileList(self
):
2723 if self
._SourceFileList
== None:
2724 self
._SourceFileList
= []
2725 for F
in self
.Module
.Sources
:
2727 if F
.TagName
not in ("", "*", self
.ToolChain
):
2728 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "The toolchain [%s] for processing file [%s] is found, "
2729 "but [%s] is needed" % (F
.TagName
, str(F
), self
.ToolChain
))
2731 # match tool chain family
2732 if F
.ToolChainFamily
not in ("", "*", self
.ToolChainFamily
):
2735 "The file [%s] must be built by tools of [%s], " \
2736 "but current toolchain family is [%s]" \
2737 % (str(F
), F
.ToolChainFamily
, self
.ToolChainFamily
))
2740 # add the file path into search path list for file including
2741 if F
.Dir
not in self
.IncludePathList
and self
.AutoGenVersion
>= 0x00010005:
2742 self
.IncludePathList
.insert(0, F
.Dir
)
2743 self
._SourceFileList
.append(F
)
2744 self
._ApplyBuildRule
(F
, TAB_UNKNOWN_FILE
)
2745 return self
._SourceFileList
2747 ## Return the list of unicode files
2748 def _GetUnicodeFileList(self
):
2749 if self
._UnicodeFileList
== None:
2750 if TAB_UNICODE_FILE
in self
.FileTypes
:
2751 self
._UnicodeFileList
= self
.FileTypes
[TAB_UNICODE_FILE
]
2753 self
._UnicodeFileList
= []
2754 return self
._UnicodeFileList
2756 ## Return a list of files which can be built from binary
2758 # "Build" binary files are just to copy them to build directory.
2760 # @retval list The list of files which can be built later
2762 def _GetBinaryFiles(self
):
2763 if self
._BinaryFileList
== None:
2764 self
._BinaryFileList
= []
2765 for F
in self
.Module
.Binaries
:
2766 if F
.Target
not in ['COMMON', '*'] and F
.Target
!= self
.BuildTarget
:
2768 self
._BinaryFileList
.append(F
)
2769 self
._ApplyBuildRule
(F
, F
.Type
)
2770 return self
._BinaryFileList
2772 def _GetBuildRules(self
):
2773 if self
._BuildRules
== None:
2775 BuildRuleDatabase
= self
.PlatformInfo
.BuildRule
2776 for Type
in BuildRuleDatabase
.FileTypeList
:
2777 #first try getting build rule by BuildRuleFamily
2778 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.BuildRuleFamily
]
2780 # build type is always module type, but ...
2781 if self
.ModuleType
!= self
.BuildType
:
2782 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.BuildRuleFamily
]
2783 #second try getting build rule by ToolChainFamily
2785 RuleObject
= BuildRuleDatabase
[Type
, self
.BuildType
, self
.Arch
, self
.ToolChainFamily
]
2787 # build type is always module type, but ...
2788 if self
.ModuleType
!= self
.BuildType
:
2789 RuleObject
= BuildRuleDatabase
[Type
, self
.ModuleType
, self
.Arch
, self
.ToolChainFamily
]
2792 RuleObject
= RuleObject
.Instantiate(self
.Macros
)
2793 BuildRules
[Type
] = RuleObject
2794 for Ext
in RuleObject
.SourceFileExtList
:
2795 BuildRules
[Ext
] = RuleObject
2796 self
._BuildRules
= BuildRules
2797 return self
._BuildRules
2799 def _ApplyBuildRule(self
, File
, FileType
):
2800 if self
._BuildTargets
== None:
2801 self
._IntroBuildTargetList
= set()
2802 self
._FinalBuildTargetList
= set()
2803 self
._BuildTargets
= {}
2804 self
._FileTypes
= {}
2806 SubDirectory
= os
.path
.join(self
.OutputDir
, File
.SubDir
)
2807 if not os
.path
.exists(SubDirectory
):
2808 CreateDirectory(SubDirectory
)
2814 # Make sure to get build rule order value
2816 self
._GetModuleBuildOption
()
2818 while Index
< len(SourceList
):
2819 Source
= SourceList
[Index
]
2823 CreateDirectory(Source
.Dir
)
2825 if File
.IsBinary
and File
== Source
and self
._BinaryFileList
!= None and File
in self
._BinaryFileList
:
2826 # Skip all files that are not binary libraries
2827 if not self
.IsLibrary
:
2829 RuleObject
= self
.BuildRules
[TAB_DEFAULT_BINARY_FILE
]
2830 elif FileType
in self
.BuildRules
:
2831 RuleObject
= self
.BuildRules
[FileType
]
2832 elif Source
.Ext
in self
.BuildRules
:
2833 RuleObject
= self
.BuildRules
[Source
.Ext
]
2835 # stop at no more rules
2837 self
._FinalBuildTargetList
.add(LastTarget
)
2840 FileType
= RuleObject
.SourceFileType
2841 if FileType
not in self
._FileTypes
:
2842 self
._FileTypes
[FileType
] = set()
2843 self
._FileTypes
[FileType
].add(Source
)
2845 # stop at STATIC_LIBRARY for library
2846 if self
.IsLibrary
and FileType
== TAB_STATIC_LIBRARY
:
2848 self
._FinalBuildTargetList
.add(LastTarget
)
2851 Target
= RuleObject
.Apply(Source
, self
.BuildRuleOrder
)
2854 self
._FinalBuildTargetList
.add(LastTarget
)
2856 elif not Target
.Outputs
:
2857 # Only do build for target with outputs
2858 self
._FinalBuildTargetList
.add(Target
)
2860 if FileType
not in self
._BuildTargets
:
2861 self
._BuildTargets
[FileType
] = set()
2862 self
._BuildTargets
[FileType
].add(Target
)
2864 if not Source
.IsBinary
and Source
== File
:
2865 self
._IntroBuildTargetList
.add(Target
)
2867 # to avoid cyclic rule
2868 if FileType
in RuleChain
:
2871 RuleChain
.append(FileType
)
2872 SourceList
.extend(Target
.Outputs
)
2874 FileType
= TAB_UNKNOWN_FILE
2876 def _GetTargets(self
):
2877 if self
._BuildTargets
== None:
2878 self
._IntroBuildTargetList
= set()
2879 self
._FinalBuildTargetList
= set()
2880 self
._BuildTargets
= {}
2881 self
._FileTypes
= {}
2883 #TRICK: call _GetSourceFileList to apply build rule for source files
2884 if self
.SourceFileList
:
2887 #TRICK: call _GetBinaryFileList to apply build rule for binary files
2888 if self
.BinaryFileList
:
2891 return self
._BuildTargets
2893 def _GetIntroTargetList(self
):
2895 return self
._IntroBuildTargetList
2897 def _GetFinalTargetList(self
):
2899 return self
._FinalBuildTargetList
2901 def _GetFileTypes(self
):
2903 return self
._FileTypes
2905 ## Get the list of package object the module depends on
2907 # @retval list The package object list
2909 def _GetDependentPackageList(self
):
2910 return self
.Module
.Packages
2912 ## Return the list of auto-generated code file
2914 # @retval list The list of auto-generated file
2916 def _GetAutoGenFileList(self
):
2917 UniStringAutoGenC
= True
2918 UniStringBinBuffer
= StringIO()
2919 if self
.BuildType
== 'UEFI_HII':
2920 UniStringAutoGenC
= False
2921 if self
._AutoGenFileList
== None:
2922 self
._AutoGenFileList
= {}
2923 AutoGenC
= TemplateString()
2924 AutoGenH
= TemplateString()
2925 StringH
= TemplateString()
2926 GenC
.CreateCode(self
, AutoGenC
, AutoGenH
, StringH
, UniStringAutoGenC
, UniStringBinBuffer
)
2928 # AutoGen.c is generated if there are library classes in inf, or there are object files
2930 if str(AutoGenC
) != "" and (len(self
.Module
.LibraryClasses
) > 0
2931 or TAB_OBJECT_FILE
in self
.FileTypes
):
2932 AutoFile
= PathClass(gAutoGenCodeFileName
, self
.DebugDir
)
2933 self
._AutoGenFileList
[AutoFile
] = str(AutoGenC
)
2934 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
2935 if str(AutoGenH
) != "":
2936 AutoFile
= PathClass(gAutoGenHeaderFileName
, self
.DebugDir
)
2937 self
._AutoGenFileList
[AutoFile
] = str(AutoGenH
)
2938 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
2939 if str(StringH
) != "":
2940 AutoFile
= PathClass(gAutoGenStringFileName
% {"module_name":self
.Name
}, self
.DebugDir
)
2941 self
._AutoGenFileList
[AutoFile
] = str(StringH
)
2942 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
2943 if UniStringBinBuffer
!= None and UniStringBinBuffer
.getvalue() != "":
2944 AutoFile
= PathClass(gAutoGenStringFormFileName
% {"module_name":self
.Name
}, self
.OutputDir
)
2945 self
._AutoGenFileList
[AutoFile
] = UniStringBinBuffer
.getvalue()
2946 AutoFile
.IsBinary
= True
2947 self
._ApplyBuildRule
(AutoFile
, TAB_UNKNOWN_FILE
)
2948 if UniStringBinBuffer
!= None:
2949 UniStringBinBuffer
.close()
2950 return self
._AutoGenFileList
2952 ## Return the list of library modules explicitly or implicityly used by this module
2953 def _GetLibraryList(self
):
2954 if self
._DependentLibraryList
== None:
2955 # only merge library classes and PCD for non-library module
2957 self
._DependentLibraryList
= []
2959 if self
.AutoGenVersion
< 0x00010005:
2960 self
._DependentLibraryList
= self
.PlatformInfo
.ResolveLibraryReference(self
.Module
)
2962 self
._DependentLibraryList
= self
.PlatformInfo
.ApplyLibraryInstance(self
.Module
)
2963 return self
._DependentLibraryList
2966 def UpdateComments(Recver
, Src
):
2968 if Key
not in Recver
:
2970 Recver
[Key
].extend(Src
[Key
])
2971 ## Get the list of PCDs from current module
2973 # @retval list The list of PCD
2975 def _GetModulePcdList(self
):
2976 if self
._ModulePcdList
== None:
2977 # apply PCD settings from platform
2978 self
._ModulePcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, self
.Module
.Pcds
)
2979 self
.UpdateComments(self
._PcdComments
, self
.Module
.PcdComments
)
2980 return self
._ModulePcdList
2982 ## Get the list of PCDs from dependent libraries
2984 # @retval list The list of PCD
2986 def _GetLibraryPcdList(self
):
2987 if self
._LibraryPcdList
== None:
2989 if not self
.IsLibrary
:
2990 # get PCDs from dependent libraries
2991 for Library
in self
.DependentLibraryList
:
2992 self
.UpdateComments(self
._PcdComments
, Library
.PcdComments
)
2993 for Key
in Library
.Pcds
:
2994 # skip duplicated PCDs
2995 if Key
in self
.Module
.Pcds
or Key
in Pcds
:
2997 Pcds
[Key
] = copy
.copy(Library
.Pcds
[Key
])
2998 # apply PCD settings from platform
2999 self
._LibraryPcdList
= self
.PlatformInfo
.ApplyPcdSetting(self
.Module
, Pcds
)
3001 self
._LibraryPcdList
= []
3002 return self
._LibraryPcdList
3004 ## Get the GUID value mapping
3006 # @retval dict The mapping between GUID cname and its value
3008 def _GetGuidList(self
):
3009 if self
._GuidList
== None:
3010 self
._GuidList
= sdict()
3011 self
._GuidList
.update(self
.Module
.Guids
)
3012 for Library
in self
.DependentLibraryList
:
3013 self
._GuidList
.update(Library
.Guids
)
3014 self
.UpdateComments(self
._GuidComments
, Library
.GuidComments
)
3015 self
.UpdateComments(self
._GuidComments
, self
.Module
.GuidComments
)
3016 return self
._GuidList
3018 def GetGuidsUsedByPcd(self
):
3019 if self
._GuidsUsedByPcd
== None:
3020 self
._GuidsUsedByPcd
= sdict()
3021 self
._GuidsUsedByPcd
.update(self
.Module
.GetGuidsUsedByPcd())
3022 for Library
in self
.DependentLibraryList
:
3023 self
._GuidsUsedByPcd
.update(Library
.GetGuidsUsedByPcd())
3024 return self
._GuidsUsedByPcd
3025 ## Get the protocol value mapping
3027 # @retval dict The mapping between protocol cname and its value
3029 def _GetProtocolList(self
):
3030 if self
._ProtocolList
== None:
3031 self
._ProtocolList
= sdict()
3032 self
._ProtocolList
.update(self
.Module
.Protocols
)
3033 for Library
in self
.DependentLibraryList
:
3034 self
._ProtocolList
.update(Library
.Protocols
)
3035 self
.UpdateComments(self
._ProtocolComments
, Library
.ProtocolComments
)
3036 self
.UpdateComments(self
._ProtocolComments
, self
.Module
.ProtocolComments
)
3037 return self
._ProtocolList
3039 ## Get the PPI value mapping
3041 # @retval dict The mapping between PPI cname and its value
3043 def _GetPpiList(self
):
3044 if self
._PpiList
== None:
3045 self
._PpiList
= sdict()
3046 self
._PpiList
.update(self
.Module
.Ppis
)
3047 for Library
in self
.DependentLibraryList
:
3048 self
._PpiList
.update(Library
.Ppis
)
3049 self
.UpdateComments(self
._PpiComments
, Library
.PpiComments
)
3050 self
.UpdateComments(self
._PpiComments
, self
.Module
.PpiComments
)
3051 return self
._PpiList
3053 ## Get the list of include search path
3055 # @retval list The list path
3057 def _GetIncludePathList(self
):
3058 if self
._IncludePathList
== None:
3059 self
._IncludePathList
= []
3060 if self
.AutoGenVersion
< 0x00010005:
3061 for Inc
in self
.Module
.Includes
:
3062 if Inc
not in self
._IncludePathList
:
3063 self
._IncludePathList
.append(Inc
)
3065 Inc
= path
.join(Inc
, self
.Arch
.capitalize())
3066 if os
.path
.exists(Inc
) and Inc
not in self
._IncludePathList
:
3067 self
._IncludePathList
.append(Inc
)
3068 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3069 self
._IncludePathList
.append(self
.DebugDir
)
3071 self
._IncludePathList
.append(self
.MetaFile
.Dir
)
3072 self
._IncludePathList
.append(self
.DebugDir
)
3074 for Package
in self
.Module
.Packages
:
3075 PackageDir
= mws
.join(self
.WorkspaceDir
, Package
.MetaFile
.Dir
)
3076 if PackageDir
not in self
._IncludePathList
:
3077 self
._IncludePathList
.append(PackageDir
)
3078 for Inc
in Package
.Includes
:
3079 if Inc
not in self
._IncludePathList
:
3080 self
._IncludePathList
.append(str(Inc
))
3081 return self
._IncludePathList
3083 ## Get HII EX PCDs which maybe used by VFR
3085 # efivarstore used by VFR may relate with HII EX PCDs
3086 # Get the variable name and GUID from efivarstore and HII EX PCD
3087 # List the HII EX PCDs in As Built INF if both name and GUID match.
3089 # @retval list HII EX PCDs
3091 def _GetPcdsMaybeUsedByVfr(self
):
3092 if not self
.SourceFileList
:
3096 for SrcFile
in self
.SourceFileList
:
3097 if SrcFile
.Ext
.lower() != '.vfr':
3099 Vfri
= os
.path
.join(self
.OutputDir
, SrcFile
.BaseName
+ '.i')
3100 if not os
.path
.exists(Vfri
):
3102 VfriFile
= open(Vfri
, 'r')
3103 Content
= VfriFile
.read()
3105 Pos
= Content
.find('efivarstore')
3108 # Make sure 'efivarstore' is the start of efivarstore statement
3109 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3112 while Index
>= 0 and Content
[Index
] in ' \t\r\n':
3114 if Index
>= 0 and Content
[Index
] != ';':
3115 Pos
= Content
.find('efivarstore', Pos
+ len('efivarstore'))
3118 # 'efivarstore' must be followed by name and guid
3120 Name
= gEfiVarStoreNamePattern
.search(Content
, Pos
)
3123 Guid
= gEfiVarStoreGuidPattern
.search(Content
, Pos
)
3126 NameArray
= ConvertStringToByteArray('L"' + Name
.group(1) + '"')
3127 NameGuids
.append((NameArray
, GuidStructureStringToGuidString(Guid
.group(1))))
3128 Pos
= Content
.find('efivarstore', Name
.end())
3132 for Pcd
in self
.PlatformInfo
.Platform
.Pcds
.values():
3133 if Pcd
.Type
!= TAB_PCDS_DYNAMIC_EX_HII
:
3135 for SkuName
in Pcd
.SkuInfoList
:
3136 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3137 Name
= ConvertStringToByteArray(SkuInfo
.VariableName
)
3138 Value
= GuidValue(SkuInfo
.VariableGuid
, self
.PlatformInfo
.PackageList
)
3141 Guid
= GuidStructureStringToGuidString(Value
)
3142 if (Name
, Guid
) in NameGuids
and Pcd
not in HiiExPcds
:
3143 HiiExPcds
.append(Pcd
)
3148 def _GenOffsetBin(self
):
3150 for SourceFile
in self
.Module
.Sources
:
3151 if SourceFile
.Type
.upper() == ".VFR" :
3153 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3155 VfrUniBaseName
[SourceFile
.BaseName
] = (SourceFile
.BaseName
+ "Bin")
3156 if SourceFile
.Type
.upper() == ".UNI" :
3158 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3160 VfrUniBaseName
["UniOffsetName"] = (self
.Name
+ "Strings")
3162 if len(VfrUniBaseName
) == 0:
3164 MapFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".map")
3165 EfiFileName
= os
.path
.join(self
.OutputDir
, self
.Name
+ ".efi")
3166 VfrUniOffsetList
= GetVariableOffset(MapFileName
, EfiFileName
, VfrUniBaseName
.values())
3167 if not VfrUniOffsetList
:
3170 OutputName
= '%sOffset.bin' % self
.Name
3171 UniVfrOffsetFileName
= os
.path
.join( self
.OutputDir
, OutputName
)
3174 fInputfile
= open(UniVfrOffsetFileName
, "wb+", 0)
3176 EdkLogger
.error("build", FILE_OPEN_FAILURE
, "File open failed for %s" % UniVfrOffsetFileName
,None)
3178 # Use a instance of StringIO to cache data
3179 fStringIO
= StringIO('')
3181 for Item
in VfrUniOffsetList
:
3182 if (Item
[0].find("Strings") != -1):
3184 # UNI offset in image.
3186 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3188 UniGuid
= [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3189 UniGuid
= [chr(ItemGuid
) for ItemGuid
in UniGuid
]
3190 fStringIO
.write(''.join(UniGuid
))
3191 UniValue
= pack ('Q', int (Item
[1], 16))
3192 fStringIO
.write (UniValue
)
3195 # VFR binary offset in image.
3197 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3199 VfrGuid
= [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3200 VfrGuid
= [chr(ItemGuid
) for ItemGuid
in VfrGuid
]
3201 fStringIO
.write(''.join(VfrGuid
))
3203 VfrValue
= pack ('Q', int (Item
[1], 16))
3204 fStringIO
.write (VfrValue
)
3206 # write data into file.
3209 fInputfile
.write (fStringIO
.getvalue())
3211 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Write data to file %s failed, please check whether the "
3212 "file been locked or using by other applications." %UniVfrOffsetFileName
,None)
3218 ## Create AsBuilt INF file the module
3220 def CreateAsBuiltInf(self
):
3221 if self
.IsAsBuiltInfCreated
:
3224 # Skip the following code for EDK I inf
3225 if self
.AutoGenVersion
< 0x00010005:
3228 # Skip the following code for libraries
3232 # Skip the following code for modules with no source files
3233 if self
.SourceFileList
== None or self
.SourceFileList
== []:
3236 # Skip the following code for modules without any binary files
3237 if self
.BinaryFileList
<> None and self
.BinaryFileList
<> []:
3240 ### TODO: How to handles mixed source and binary modules
3242 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3243 # Also find all packages that the DynamicEx PCDs depend on
3248 PcdTokenSpaceList
= []
3249 for Pcd
in self
.ModulePcdList
+ self
.LibraryPcdList
:
3250 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
3251 PatchablePcds
[Pcd
.TokenCName
] = Pcd
3252 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'PatchableInModule'))
3253 elif Pcd
.Type
in GenC
.gDynamicExPcd
:
3256 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'DynamicEx'))
3257 PcdCheckList
.append((Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, 'Dynamic'))
3258 PcdTokenSpaceList
.append(Pcd
.TokenSpaceGuidCName
)
3260 GuidList
.update(self
.GuidList
)
3261 for TokenSpace
in self
.GetGuidsUsedByPcd():
3262 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3263 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3264 if TokenSpace
not in PcdTokenSpaceList
and TokenSpace
in GuidList
:
3265 GuidList
.pop(TokenSpace
)
3266 CheckList
= (GuidList
, self
.PpiList
, self
.ProtocolList
, PcdCheckList
)
3267 for Package
in self
.DerivedPackageList
:
3268 if Package
in Packages
:
3270 BeChecked
= (Package
.Guids
, Package
.Ppis
, Package
.Protocols
, Package
.Pcds
)
3272 for Index
in range(len(BeChecked
)):
3273 for Item
in CheckList
[Index
]:
3274 if Item
in BeChecked
[Index
]:
3275 Packages
+= [Package
]
3280 VfrPcds
= self
._GetPcdsMaybeUsedByVfr
()
3281 for Pkg
in self
.PlatformInfo
.PackageList
:
3284 for VfrPcd
in VfrPcds
:
3285 if ((VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'DynamicEx') in Pkg
.Pcds
or
3286 (VfrPcd
.TokenCName
, VfrPcd
.TokenSpaceGuidCName
, 'Dynamic') in Pkg
.Pcds
):
3290 ModuleType
= self
.ModuleType
3291 if ModuleType
== 'UEFI_DRIVER' and self
.DepexGenerated
:
3292 ModuleType
= 'DXE_DRIVER'
3295 if self
.PcdIsDriver
!= '':
3296 DriverType
= self
.PcdIsDriver
3299 MDefs
= self
.Module
.Defines
3302 'module_name' : self
.Name
,
3303 'module_guid' : Guid
,
3304 'module_module_type' : ModuleType
,
3305 'module_version_string' : [MDefs
['VERSION_STRING']] if 'VERSION_STRING' in MDefs
else [],
3306 'pcd_is_driver_string' : [],
3307 'module_uefi_specification_version' : [],
3308 'module_pi_specification_version' : [],
3309 'module_entry_point' : self
.Module
.ModuleEntryPointList
,
3310 'module_unload_image' : self
.Module
.ModuleUnloadImageList
,
3311 'module_constructor' : self
.Module
.ConstructorList
,
3312 'module_destructor' : self
.Module
.DestructorList
,
3313 'module_shadow' : [MDefs
['SHADOW']] if 'SHADOW' in MDefs
else [],
3314 'module_pci_vendor_id' : [MDefs
['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs
else [],
3315 'module_pci_device_id' : [MDefs
['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs
else [],
3316 'module_pci_class_code' : [MDefs
['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs
else [],
3317 'module_pci_revision' : [MDefs
['PCI_REVISION']] if 'PCI_REVISION' in MDefs
else [],
3318 'module_build_number' : [MDefs
['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs
else [],
3319 'module_spec' : [MDefs
['SPEC']] if 'SPEC' in MDefs
else [],
3320 'module_uefi_hii_resource_section' : [MDefs
['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs
else [],
3321 'module_uni_file' : [MDefs
['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs
else [],
3322 'module_arch' : self
.Arch
,
3323 'package_item' : ['%s' % (Package
.MetaFile
.File
.replace('\\', '/')) for Package
in Packages
],
3325 'patchablepcd_item' : [],
3327 'protocol_item' : [],
3331 'libraryclasses_item' : []
3334 if self
.AutoGenVersion
> int(gInfSpecVersion
, 0):
3335 AsBuiltInfDict
['module_inf_version'] = '0x%08x' % self
.AutoGenVersion
3337 AsBuiltInfDict
['module_inf_version'] = gInfSpecVersion
3340 AsBuiltInfDict
['pcd_is_driver_string'] += [DriverType
]
3342 if 'UEFI_SPECIFICATION_VERSION' in self
.Specification
:
3343 AsBuiltInfDict
['module_uefi_specification_version'] += [self
.Specification
['UEFI_SPECIFICATION_VERSION']]
3344 if 'PI_SPECIFICATION_VERSION' in self
.Specification
:
3345 AsBuiltInfDict
['module_pi_specification_version'] += [self
.Specification
['PI_SPECIFICATION_VERSION']]
3347 OutputDir
= self
.OutputDir
.replace('\\', '/').strip('/')
3348 if self
.ModuleType
in ['BASE', 'USER_DEFINED']:
3349 for Item
in self
.CodaTargetList
:
3350 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3351 if Item
.Target
.Ext
.lower() == '.aml':
3352 AsBuiltInfDict
['binary_item'] += ['ASL|' + File
]
3353 elif Item
.Target
.Ext
.lower() == '.acpi':
3354 AsBuiltInfDict
['binary_item'] += ['ACPI|' + File
]
3356 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3358 for Item
in self
.CodaTargetList
:
3359 File
= Item
.Target
.Path
.replace('\\', '/').strip('/').replace(OutputDir
, '').strip('/')
3360 if Item
.Target
.Ext
.lower() == '.efi':
3361 AsBuiltInfDict
['binary_item'] += ['PE32|' + self
.Name
+ '.efi']
3363 AsBuiltInfDict
['binary_item'] += ['BIN|' + File
]
3364 if self
.DepexGenerated
:
3365 if self
.ModuleType
in ['PEIM']:
3366 AsBuiltInfDict
['binary_item'] += ['PEI_DEPEX|' + self
.Name
+ '.depex']
3367 if self
.ModuleType
in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3368 AsBuiltInfDict
['binary_item'] += ['DXE_DEPEX|' + self
.Name
+ '.depex']
3369 if self
.ModuleType
in ['DXE_SMM_DRIVER']:
3370 AsBuiltInfDict
['binary_item'] += ['SMM_DEPEX|' + self
.Name
+ '.depex']
3372 Bin
= self
._GenOffsetBin
()
3374 AsBuiltInfDict
['binary_item'] += ['BIN|%s' % Bin
]
3376 for Root
, Dirs
, Files
in os
.walk(OutputDir
):
3378 if File
.lower().endswith('.pdb'):
3379 AsBuiltInfDict
['binary_item'] += ['DISPOSABLE|' + File
]
3380 HeaderComments
= self
.Module
.HeaderComments
3382 for Index
in range(len(HeaderComments
)):
3383 if HeaderComments
[Index
].find('@BinaryHeader') != -1:
3384 HeaderComments
[Index
] = HeaderComments
[Index
].replace('@BinaryHeader', '@file')
3387 AsBuiltInfDict
['header_comments'] = '\n'.join(HeaderComments
[StartPos
:]).replace(':#', '://')
3388 AsBuiltInfDict
['tail_comments'] = '\n'.join(self
.Module
.TailComments
)
3391 (self
.ProtocolList
, self
._ProtocolComments
, 'protocol_item'),
3392 (self
.PpiList
, self
._PpiComments
, 'ppi_item'),
3393 (GuidList
, self
._GuidComments
, 'guid_item')
3395 for Item
in GenList
:
3396 for CName
in Item
[0]:
3398 if CName
in Item
[1]:
3399 Comments
= '\n '.join(Item
[1][CName
])
3402 Entry
= Comments
+ '\n ' + CName
3403 AsBuiltInfDict
[Item
[2]].append(Entry
)
3404 PatchList
= parsePcdInfoFromMapFile(
3405 os
.path
.join(self
.OutputDir
, self
.Name
+ '.map'),
3406 os
.path
.join(self
.OutputDir
, self
.Name
+ '.efi')
3409 for PatchPcd
in PatchList
:
3410 if PatchPcd
[0] not in PatchablePcds
:
3412 Pcd
= PatchablePcds
[PatchPcd
[0]]
3414 if Pcd
.DatumType
!= 'VOID*':
3415 HexFormat
= '0x%02x'
3416 if Pcd
.DatumType
== 'UINT16':
3417 HexFormat
= '0x%04x'
3418 elif Pcd
.DatumType
== 'UINT32':
3419 HexFormat
= '0x%08x'
3420 elif Pcd
.DatumType
== 'UINT64':
3421 HexFormat
= '0x%016x'
3422 PcdValue
= HexFormat
% int(Pcd
.DefaultValue
, 0)
3424 if Pcd
.MaxDatumSize
== None or Pcd
.MaxDatumSize
== '':
3425 EdkLogger
.error("build", AUTOGEN_ERROR
,
3426 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3428 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
3429 PcdValue
= Pcd
.DefaultValue
3430 if PcdValue
[0] != '{':
3432 if PcdValue
[0] == 'L':
3434 PcdValue
= PcdValue
.lstrip('L')
3435 PcdValue
= eval(PcdValue
)
3437 for Index
in range(0, len(PcdValue
)):
3439 CharVal
= ord(PcdValue
[Index
])
3440 NewValue
= NewValue
+ '0x%02x' % (CharVal
& 0x00FF) + ', ' \
3441 + '0x%02x' % (CharVal
>> 8) + ', '
3443 NewValue
= NewValue
+ '0x%02x' % (ord(PcdValue
[Index
]) % 0x100) + ', '
3446 Padding
= Padding
* 2
3447 ArraySize
= ArraySize
/ 2
3448 if ArraySize
< (len(PcdValue
) + 1):
3449 EdkLogger
.error("build", AUTOGEN_ERROR
,
3450 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3452 if ArraySize
> len(PcdValue
) + 1:
3453 NewValue
= NewValue
+ Padding
* (ArraySize
- len(PcdValue
) - 1)
3454 PcdValue
= NewValue
+ Padding
.strip().rstrip(',') + '}'
3455 elif len(PcdValue
.split(',')) <= ArraySize
:
3456 PcdValue
= PcdValue
.rstrip('}') + ', 0x00' * (ArraySize
- len(PcdValue
.split(',')))
3459 EdkLogger
.error("build", AUTOGEN_ERROR
,
3460 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
)
3462 PcdItem
= '%s.%s|%s|0x%X' % \
3463 (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, PcdValue
, PatchPcd
[1])
3465 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3466 PcdComments
= '\n '.join(self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
])
3468 PcdItem
= PcdComments
+ '\n ' + PcdItem
3469 AsBuiltInfDict
['patchablepcd_item'].append(PcdItem
)
3472 for Pcd
in Pcds
+ VfrPcds
:
3477 if Pcd
.Type
== TAB_PCDS_DYNAMIC_EX_HII
:
3478 for SkuName
in Pcd
.SkuInfoList
:
3479 SkuInfo
= Pcd
.SkuInfoList
[SkuName
]
3480 SkuId
= SkuInfo
.SkuId
3481 HiiInfo
= '## %s|%s|%s' % (SkuInfo
.VariableName
, SkuInfo
.VariableGuid
, SkuInfo
.VariableOffset
)
3485 # Don't generate duplicated HII PCD
3487 if (SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in HiiPcds
:
3490 HiiPcds
.append((SkuId
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
3491 if (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
) in self
._PcdComments
:
3492 PcdCommentList
= self
._PcdComments
[Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
][:]
3496 for Index
, Comment
in enumerate(PcdCommentList
):
3497 for Usage
in UsageList
:
3498 if Comment
.find(Usage
) != -1:
3502 if UsageIndex
!= -1:
3503 PcdCommentList
[UsageIndex
] = '## %s %s %s' % (UsageStr
, HiiInfo
, PcdCommentList
[UsageIndex
].replace(UsageStr
, ''))
3505 PcdCommentList
.append('## UNDEFINED ' + HiiInfo
)
3506 PcdComments
= '\n '.join(PcdCommentList
)
3507 PcdEntry
= Pcd
.TokenSpaceGuidCName
+ '.' + Pcd
.TokenCName
3509 PcdEntry
= PcdComments
+ '\n ' + PcdEntry
3510 AsBuiltInfDict
['pcd_item'] += [PcdEntry
]
3511 for Item
in self
.BuildOption
:
3512 if 'FLAGS' in self
.BuildOption
[Item
]:
3513 AsBuiltInfDict
['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self
.ToolChainFamily
, self
.BuildTarget
, self
.ToolChain
, self
.Arch
, Item
, self
.BuildOption
[Item
]['FLAGS'].strip())]
3515 # Generated LibraryClasses section in comments.
3516 for Library
in self
.LibraryAutoGenList
:
3517 AsBuiltInfDict
['libraryclasses_item'] += [Library
.MetaFile
.File
.replace('\\', '/')]
3519 # Generated depex expression section in comments.
3520 AsBuiltInfDict
['depexsection_item'] = ''
3521 DepexExpresion
= self
._GetDepexExpresionString
()
3523 AsBuiltInfDict
['depexsection_item'] = DepexExpresion
3525 AsBuiltInf
= TemplateString()
3526 AsBuiltInf
.Append(gAsBuiltInfHeaderString
.Replace(AsBuiltInfDict
))
3528 SaveFileOnChange(os
.path
.join(self
.OutputDir
, self
.Name
+ '.inf'), str(AsBuiltInf
), False)
3530 self
.IsAsBuiltInfCreated
= True
3532 ## Create makefile for the module and its dependent libraries
3534 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
3535 # dependent libraries will be created
3537 def CreateMakeFile(self
, CreateLibraryMakeFile
=True):
3538 # Ignore generating makefile when it is a binary module
3539 if self
.IsBinaryModule
:
3542 if self
.IsMakeFileCreated
:
3545 if not self
.IsLibrary
and CreateLibraryMakeFile
:
3546 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3547 LibraryAutoGen
.CreateMakeFile()
3549 if len(self
.CustomMakefile
) == 0:
3550 Makefile
= GenMake
.ModuleMakefile(self
)
3552 Makefile
= GenMake
.CustomMakefile(self
)
3553 if Makefile
.Generate():
3554 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated makefile for module %s [%s]" %
3555 (self
.Name
, self
.Arch
))
3557 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of makefile for module %s [%s]" %
3558 (self
.Name
, self
.Arch
))
3560 self
.IsMakeFileCreated
= True
3562 def CopyBinaryFiles(self
):
3563 for File
in self
.Module
.Binaries
:
3565 DstPath
= os
.path
.join(self
.OutputDir
, os
.path
.basename(SrcPath
))
3566 CopyLongFilePath(SrcPath
, DstPath
)
3567 ## Create autogen code for the module and its dependent libraries
3569 # @param CreateLibraryCodeFile Flag indicating if or not the code of
3570 # dependent libraries will be created
3572 def CreateCodeFile(self
, CreateLibraryCodeFile
=True):
3573 if self
.IsCodeFileCreated
:
3576 # Need to generate PcdDatabase even PcdDriver is binarymodule
3577 if self
.IsBinaryModule
and self
.PcdIsDriver
!= '':
3578 CreatePcdDatabaseCode(self
, TemplateString(), TemplateString())
3580 if self
.IsBinaryModule
:
3582 self
.CopyBinaryFiles()
3585 if not self
.IsLibrary
and CreateLibraryCodeFile
:
3586 for LibraryAutoGen
in self
.LibraryAutoGenList
:
3587 LibraryAutoGen
.CreateCodeFile()
3590 IgoredAutoGenList
= []
3592 for File
in self
.AutoGenFileList
:
3593 if GenC
.Generate(File
.Path
, self
.AutoGenFileList
[File
], File
.IsBinary
):
3594 #Ignore Edk AutoGen.c
3595 if self
.AutoGenVersion
< 0x00010005 and File
.Name
== 'AutoGen.c':
3598 AutoGenList
.append(str(File
))
3600 IgoredAutoGenList
.append(str(File
))
3602 # Skip the following code for EDK I inf
3603 if self
.AutoGenVersion
< 0x00010005:
3606 for ModuleType
in self
.DepexList
:
3607 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
3608 if len(self
.DepexList
[ModuleType
]) == 0 or ModuleType
== "USER_DEFINED":
3611 Dpx
= GenDepex
.DependencyExpression(self
.DepexList
[ModuleType
], ModuleType
, True)
3612 DpxFile
= gAutoGenDepexFileName
% {"module_name" : self
.Name
}
3614 if len(Dpx
.PostfixNotation
) <> 0:
3615 self
.DepexGenerated
= True
3617 if Dpx
.Generate(path
.join(self
.OutputDir
, DpxFile
)):
3618 AutoGenList
.append(str(DpxFile
))
3620 IgoredAutoGenList
.append(str(DpxFile
))
3622 if IgoredAutoGenList
== []:
3623 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] files for module %s [%s]" %
3624 (" ".join(AutoGenList
), self
.Name
, self
.Arch
))
3625 elif AutoGenList
== []:
3626 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Skipped the generation of [%s] files for module %s [%s]" %
3627 (" ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3629 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "Generated [%s] (skipped %s) files for module %s [%s]" %
3630 (" ".join(AutoGenList
), " ".join(IgoredAutoGenList
), self
.Name
, self
.Arch
))
3632 self
.IsCodeFileCreated
= True
3635 ## Summarize the ModuleAutoGen objects of all libraries used by this module
3636 def _GetLibraryAutoGenList(self
):
3637 if self
._LibraryAutoGenList
== None:
3638 self
._LibraryAutoGenList
= []
3639 for Library
in self
.DependentLibraryList
:
3646 self
.PlatformInfo
.MetaFile
3648 if La
not in self
._LibraryAutoGenList
:
3649 self
._LibraryAutoGenList
.append(La
)
3650 for Lib
in La
.CodaTargetList
:
3651 self
._ApplyBuildRule
(Lib
.Target
, TAB_UNKNOWN_FILE
)
3652 return self
._LibraryAutoGenList
3654 Module
= property(_GetModule
)
3655 Name
= property(_GetBaseName
)
3656 Guid
= property(_GetGuid
)
3657 Version
= property(_GetVersion
)
3658 ModuleType
= property(_GetModuleType
)
3659 ComponentType
= property(_GetComponentType
)
3660 BuildType
= property(_GetBuildType
)
3661 PcdIsDriver
= property(_GetPcdIsDriver
)
3662 AutoGenVersion
= property(_GetAutoGenVersion
)
3663 Macros
= property(_GetMacros
)
3664 Specification
= property(_GetSpecification
)
3666 IsLibrary
= property(_IsLibrary
)
3667 IsBinaryModule
= property(_IsBinaryModule
)
3668 BuildDir
= property(_GetBuildDir
)
3669 OutputDir
= property(_GetOutputDir
)
3670 DebugDir
= property(_GetDebugDir
)
3671 MakeFileDir
= property(_GetMakeFileDir
)
3672 CustomMakefile
= property(_GetCustomMakefile
)
3674 IncludePathList
= property(_GetIncludePathList
)
3675 AutoGenFileList
= property(_GetAutoGenFileList
)
3676 UnicodeFileList
= property(_GetUnicodeFileList
)
3677 SourceFileList
= property(_GetSourceFileList
)
3678 BinaryFileList
= property(_GetBinaryFiles
) # FileType : [File List]
3679 Targets
= property(_GetTargets
)
3680 IntroTargetList
= property(_GetIntroTargetList
)
3681 CodaTargetList
= property(_GetFinalTargetList
)
3682 FileTypes
= property(_GetFileTypes
)
3683 BuildRules
= property(_GetBuildRules
)
3685 DependentPackageList
= property(_GetDependentPackageList
)
3686 DependentLibraryList
= property(_GetLibraryList
)
3687 LibraryAutoGenList
= property(_GetLibraryAutoGenList
)
3688 DerivedPackageList
= property(_GetDerivedPackageList
)
3690 ModulePcdList
= property(_GetModulePcdList
)
3691 LibraryPcdList
= property(_GetLibraryPcdList
)
3692 GuidList
= property(_GetGuidList
)
3693 ProtocolList
= property(_GetProtocolList
)
3694 PpiList
= property(_GetPpiList
)
3695 DepexList
= property(_GetDepexTokenList
)
3696 DxsFile
= property(_GetDxsFile
)
3697 DepexExpressionList
= property(_GetDepexExpressionTokenList
)
3698 BuildOption
= property(_GetModuleBuildOption
)
3699 BuildOptionIncPathList
= property(_GetBuildOptionIncPathList
)
3700 BuildCommand
= property(_GetBuildCommand
)
3702 FixedAtBuildPcds
= property(_GetFixedAtBuildPcds
)
3704 # This acts like the main() function for the script, unless it is 'import'ed into another script.
3705 if __name__
== '__main__':