2 # Create makefile for MS nmake and GNU make
4 # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
10 from __future__
import print_function
11 from __future__
import absolute_import
12 import os
.path
as path
14 from collections
import defaultdict
16 from .BuildEngine
import BuildRule
,gDefaultBuildRuleFile
,AutoGenReqBuildRuleVerNum
17 from .GenVar
import VariableMgr
, var_info
19 from AutoGen
.DataPipe
import MemoryDataPipe
20 from AutoGen
.ModuleAutoGen
import ModuleAutoGen
21 from AutoGen
.AutoGen
import AutoGen
22 from AutoGen
.AutoGen
import CalculatePriorityValue
23 from Workspace
.WorkspaceCommon
import GetModuleLibInstances
24 from CommonDataClass
.CommonClass
import SkuInfoClass
25 from Common
.caching
import cached_class_function
26 from Common
.Expression
import ValueExpressionEx
27 from Common
.StringUtils
import StringToArray
,NormPath
28 from Common
.BuildToolError
import *
29 from Common
.DataType
import *
30 from Common
.Misc
import *
31 import Common
.VpdInfoFile
as VpdInfoFile
33 ## Split command line option string to list
35 # subprocess.Popen needs the args to be a sequence. Otherwise there's problem
36 # in non-windows platform to launch command
38 def _SplitOption(OptionString
):
43 for Index
in range(0, len(OptionString
)):
44 CurrentChar
= OptionString
[Index
]
45 if CurrentChar
in ['"', "'"]:
46 if QuotationMark
== CurrentChar
:
48 elif QuotationMark
== "":
49 QuotationMark
= CurrentChar
54 if CurrentChar
in ["/", "-"] and LastChar
in [" ", "\t", "\r", "\n"]:
55 if Index
> OptionStart
:
56 OptionList
.append(OptionString
[OptionStart
:Index
- 1])
58 LastChar
= CurrentChar
59 OptionList
.append(OptionString
[OptionStart
:])
62 ## AutoGen class for platform
64 # PlatformAutoGen class will process the original information in platform
65 # file in order to generate makefile for platform.
67 class PlatformAutoGen(AutoGen
):
68 # call super().__init__ then call the worker function with different parameter count
69 def __init__(self
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
70 if not hasattr(self
, "_Init"):
71 self
._InitWorker
(Workspace
, MetaFile
, Target
, Toolchain
, Arch
)
74 # Used to store all PCDs for both PEI and DXE phase, in order to generate
75 # correct PCD database
83 ## Initialize PlatformAutoGen
86 # @param Workspace WorkspaceAutoGen object
87 # @param PlatformFile Platform file (DSC file)
88 # @param Target Build target (DEBUG, RELEASE)
89 # @param Toolchain Name of tool chain
90 # @param Arch arch of the platform supports
92 def _InitWorker(self
, Workspace
, PlatformFile
, Target
, Toolchain
, Arch
):
93 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "AutoGen platform [%s] [%s]" % (PlatformFile
, Arch
))
94 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (PlatformFile
, Arch
, Toolchain
, Target
)
96 self
.MetaFile
= PlatformFile
97 self
.Workspace
= Workspace
98 self
.WorkspaceDir
= Workspace
.WorkspaceDir
99 self
.ToolChain
= Toolchain
100 self
.BuildTarget
= Target
102 self
.SourceDir
= PlatformFile
.SubDir
103 self
.FdTargetList
= self
.Workspace
.FdTargetList
104 self
.FvTargetList
= self
.Workspace
.FvTargetList
105 # get the original module/package/platform objects
106 self
.BuildDatabase
= Workspace
.BuildDatabase
107 self
.DscBuildDataObj
= Workspace
.Platform
109 # flag indicating if the makefile/C-code file has been created or not
110 self
.IsMakeFileCreated
= False
112 self
._DynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
113 self
._NonDynamicPcdList
= None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
115 self
._AsBuildInfList
= []
116 self
._AsBuildModuleList
= []
118 self
.VariableInfo
= None
120 if GlobalData
.gFdfParser
is not None:
121 self
._AsBuildInfList
= GlobalData
.gFdfParser
.Profile
.InfList
122 for Inf
in self
._AsBuildInfList
:
123 InfClass
= PathClass(NormPath(Inf
), GlobalData
.gWorkspace
, self
.Arch
)
124 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
125 if not M
.IsBinaryModule
:
127 self
._AsBuildModuleList
.append(InfClass
)
128 # get library/modules for build
129 self
.LibraryBuildDirectoryList
= []
130 self
.ModuleBuildDirectoryList
= []
132 self
.DataPipe
= MemoryDataPipe(self
.BuildDir
)
133 self
.DataPipe
.FillData(self
)
136 def FillData_LibConstPcd(self
):
138 for LibAuto
in self
.LibraryAutoGenList
:
140 libConstPcd
[(LibAuto
.MetaFile
.File
,LibAuto
.MetaFile
.Root
,LibAuto
.Arch
,LibAuto
.MetaFile
.Path
)] = LibAuto
.ConstPcd
141 self
.DataPipe
.DataContainer
= {"LibConstPcd":libConstPcd
}
142 ## hash() operator of PlatformAutoGen
144 # The platform file path and arch string will be used to represent
145 # hash value of this object
147 # @retval int Hash value of the platform file path and arch
149 @cached_class_function
151 return hash((self
.MetaFile
, self
.Arch
))
152 @cached_class_function
154 return "%s [%s]" % (self
.MetaFile
, self
.Arch
)
156 ## Create autogen code for platform and modules
158 # Since there's no autogen code for platform, this method will do nothing
159 # if CreateModuleCodeFile is set to False.
161 # @param CreateModuleCodeFile Flag indicating if creating module's
162 # autogen code file or not
164 @cached_class_function
165 def CreateCodeFile(self
, CreateModuleCodeFile
=False):
166 # only module has code to be created, so do nothing if CreateModuleCodeFile is False
167 if not CreateModuleCodeFile
:
170 for Ma
in self
.ModuleAutoGenList
:
171 Ma
.CreateCodeFile(CreateModuleCodeFile
)
173 ## Generate Fds Command
175 def GenFdsCommand(self
):
176 return self
.Workspace
.GenFdsCommand
178 ## Create makefile for the platform and modules in it
180 # @param CreateModuleMakeFile Flag indicating if the makefile for
181 # modules will be created as well
183 def CreateMakeFile(self
, CreateModuleMakeFile
=False, FfsCommand
= {}):
184 if CreateModuleMakeFile
:
185 for Ma
in self
._MaList
:
186 key
= (Ma
.MetaFile
.File
, self
.Arch
)
187 if key
in FfsCommand
:
188 Ma
.CreateMakeFile(CreateModuleMakeFile
, FfsCommand
[key
])
190 Ma
.CreateMakeFile(CreateModuleMakeFile
)
191 self
.CreateLibModuelDirs()
193 def CreateLibModuelDirs(self
):
194 # no need to create makefile for the platform more than once
195 if self
.IsMakeFileCreated
:
198 # create library/module build dirs for platform
199 Makefile
= GenMake
.PlatformMakefile(self
)
200 self
.LibraryBuildDirectoryList
= Makefile
.GetLibraryBuildDirectoryList()
201 self
.ModuleBuildDirectoryList
= Makefile
.GetModuleBuildDirectoryList()
203 self
.IsMakeFileCreated
= True
206 def AllPcdList(self
):
207 return self
.DynamicPcdList
+ self
.NonDynamicPcdList
208 ## Deal with Shared FixedAtBuild Pcds
210 def CollectFixedAtBuildPcds(self
):
211 for LibAuto
in self
.LibraryAutoGenList
:
212 FixedAtBuildPcds
= {}
213 ShareFixedAtBuildPcdsSameValue
= {}
214 for Module
in LibAuto
.ReferenceModules
:
215 for Pcd
in set(Module
.FixedAtBuildPcds
+ LibAuto
.FixedAtBuildPcds
):
216 DefaultValue
= Pcd
.DefaultValue
217 # Cover the case: DSC component override the Pcd value and the Pcd only used in one Lib
218 if Pcd
in Module
.LibraryPcdList
:
219 Index
= Module
.LibraryPcdList
.index(Pcd
)
220 DefaultValue
= Module
.LibraryPcdList
[Index
].DefaultValue
221 key
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
222 if key
not in FixedAtBuildPcds
:
223 ShareFixedAtBuildPcdsSameValue
[key
] = True
224 FixedAtBuildPcds
[key
] = DefaultValue
226 if FixedAtBuildPcds
[key
] != DefaultValue
:
227 ShareFixedAtBuildPcdsSameValue
[key
] = False
228 for Pcd
in LibAuto
.FixedAtBuildPcds
:
229 key
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
230 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in self
.NonDynamicPcdDict
:
233 DscPcd
= self
.NonDynamicPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)]
234 if DscPcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
:
236 if key
in ShareFixedAtBuildPcdsSameValue
and ShareFixedAtBuildPcdsSameValue
[key
]:
237 LibAuto
.ConstPcd
[key
] = FixedAtBuildPcds
[key
]
239 def CollectVariables(self
, DynamicPcdSet
):
242 if self
.Workspace
.FdfFile
:
243 FdDict
= self
.Workspace
.FdfProfile
.FdDict
[GlobalData
.gFdfParser
.CurrentFdName
]
244 for FdRegion
in FdDict
.RegionList
:
245 for item
in FdRegion
.RegionDataList
:
246 if self
.Platform
.VpdToolGuid
.strip() and self
.Platform
.VpdToolGuid
in item
:
247 VpdRegionSize
= FdRegion
.Size
248 VpdRegionBase
= FdRegion
.Offset
251 VariableInfo
= VariableMgr(self
.DscBuildDataObj
._GetDefaultStores
(), self
.DscBuildDataObj
.SkuIds
)
252 VariableInfo
.SetVpdRegionMaxSize(VpdRegionSize
)
253 VariableInfo
.SetVpdRegionOffset(VpdRegionBase
)
255 for Pcd
in DynamicPcdSet
:
256 pcdname
= ".".join((Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
257 for SkuName
in Pcd
.SkuInfoList
:
258 Sku
= Pcd
.SkuInfoList
[SkuName
]
260 if SkuId
is None or SkuId
== '':
262 if len(Sku
.VariableName
) > 0:
263 if Sku
.VariableAttribute
and 'NV' not in Sku
.VariableAttribute
:
265 VariableGuidStructure
= Sku
.VariableGuidValue
266 VariableGuid
= GuidStructureStringToGuidString(VariableGuidStructure
)
267 for StorageName
in Sku
.DefaultStoreDict
:
268 VariableInfo
.append_variable(var_info(Index
, pcdname
, StorageName
, SkuName
, StringToArray(Sku
.VariableName
), VariableGuid
, Sku
.VariableOffset
, Sku
.VariableAttribute
, Sku
.HiiDefaultValue
, Sku
.DefaultStoreDict
[StorageName
] if Pcd
.DatumType
in TAB_PCD_NUMERIC_TYPES
else StringToArray(Sku
.DefaultStoreDict
[StorageName
]), Pcd
.DatumType
, Pcd
.CustomAttribute
['DscPosition'], Pcd
.CustomAttribute
.get('IsStru',False)))
272 def UpdateNVStoreMaxSize(self
, OrgVpdFile
):
273 if self
.VariableInfo
:
274 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
275 PcdNvStoreDfBuffer
= [item
for item
in self
._DynamicPcdList
if item
.TokenCName
== "PcdNvStoreDefaultValueBuffer" and item
.TokenSpaceGuidCName
== "gEfiMdeModulePkgTokenSpaceGuid"]
277 if PcdNvStoreDfBuffer
:
279 OrgVpdFile
.Read(VpdMapFilePath
)
280 PcdItems
= OrgVpdFile
.GetOffset(PcdNvStoreDfBuffer
[0])
281 NvStoreOffset
= list(PcdItems
.values())[0].strip() if PcdItems
else '0'
283 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
285 NvStoreOffset
= int(NvStoreOffset
, 16) if NvStoreOffset
.upper().startswith("0X") else int(NvStoreOffset
)
286 default_skuobj
= PcdNvStoreDfBuffer
[0].SkuInfoList
.get(TAB_DEFAULT
)
287 maxsize
= self
.VariableInfo
.VpdRegionSize
- NvStoreOffset
if self
.VariableInfo
.VpdRegionSize
else len(default_skuobj
.DefaultValue
.split(","))
288 var_data
= self
.VariableInfo
.PatchNVStoreDefaultMaxSize(maxsize
)
290 if var_data
and default_skuobj
:
291 default_skuobj
.DefaultValue
= var_data
292 PcdNvStoreDfBuffer
[0].DefaultValue
= var_data
293 PcdNvStoreDfBuffer
[0].SkuInfoList
.clear()
294 PcdNvStoreDfBuffer
[0].SkuInfoList
[TAB_DEFAULT
] = default_skuobj
295 PcdNvStoreDfBuffer
[0].MaxDatumSize
= str(len(default_skuobj
.DefaultValue
.split(",")))
299 ## Collect dynamic PCDs
301 # Gather dynamic PCDs list from each module and their settings from platform
302 # This interface should be invoked explicitly when platform action is created.
304 def CollectPlatformDynamicPcds(self
):
306 self
.SortDynamicPcd()
308 def CategoryPcds(self
):
309 # Category Pcds into DynamicPcds and NonDynamicPcds
310 # for gathering error information
311 NoDatumTypePcdList
= set()
313 for InfName
in self
._AsBuildInfList
:
314 InfName
= mws
.join(self
.WorkspaceDir
, InfName
)
315 FdfModuleList
.append(os
.path
.normpath(InfName
))
316 for M
in self
._MbList
:
317 # F is the Module for which M is the module autogen
318 ModPcdList
= self
.ApplyPcdSetting(M
, M
.ModulePcdList
)
320 for lib
in M
.LibraryPcdList
:
321 LibPcdList
.extend(self
.ApplyPcdSetting(M
, M
.LibraryPcdList
[lib
], lib
))
322 for PcdFromModule
in ModPcdList
+ LibPcdList
:
324 # make sure that the "VOID*" kind of datum has MaxDatumSize set
325 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
326 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, M
.MetaFile
))
328 # Check the PCD from Binary INF or Source INF
329 if M
.IsBinaryModule
== True:
330 PcdFromModule
.IsFromBinaryInf
= True
332 # Check the PCD from DSC or not
333 PcdFromModule
.IsFromDsc
= (PcdFromModule
.TokenCName
, PcdFromModule
.TokenSpaceGuidCName
) in self
.Platform
.Pcds
335 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
or PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
336 if M
.MetaFile
.Path
not in FdfModuleList
:
337 # If one of the Source built modules listed in the DSC is not listed
338 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
339 # access method (it is only listed in the DEC file that declares the
340 # PCD as PcdsDynamic), then build tool will report warning message
341 # notify the PI that they are attempting to build a module that must
342 # be included in a flash image in order to be functional. These Dynamic
343 # PCD will not be added into the Database unless it is used by other
344 # modules that are included in the FDF file.
345 if PcdFromModule
.Type
in PCD_DYNAMIC_TYPE_SET
and \
346 PcdFromModule
.IsFromBinaryInf
== False:
347 # Print warning message to let the developer make a determine.
349 # If one of the Source built modules listed in the DSC is not listed in
350 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
351 # access method (it is only listed in the DEC file that declares the
352 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
353 # PCD to the Platform's PCD Database.
354 if PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
357 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
358 # it should be stored in Pcd PEI database, If a dynamic only
359 # used by DXE module, it should be stored in DXE PCD database.
360 # The default Phase is DXE
362 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
363 PcdFromModule
.Phase
= "PEI"
364 if PcdFromModule
not in self
._DynaPcdList
_:
365 self
._DynaPcdList
_.append(PcdFromModule
)
366 elif PcdFromModule
.Phase
== 'PEI':
367 # overwrite any the same PCD existing, if Phase is PEI
368 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
369 self
._DynaPcdList
_[Index
] = PcdFromModule
370 elif PcdFromModule
not in self
._NonDynaPcdList
_:
371 self
._NonDynaPcdList
_.append(PcdFromModule
)
372 elif PcdFromModule
in self
._NonDynaPcdList
_ and PcdFromModule
.IsFromBinaryInf
== True:
373 Index
= self
._NonDynaPcdList
_.index(PcdFromModule
)
374 if self
._NonDynaPcdList
_[Index
].IsFromBinaryInf
== False:
375 #The PCD from Binary INF will override the same one from source INF
376 self
._NonDynaPcdList
_.remove (self
._NonDynaPcdList
_[Index
])
377 PcdFromModule
.Pending
= False
378 self
._NonDynaPcdList
_.append (PcdFromModule
)
379 DscModuleSet
= {os
.path
.normpath(ModuleInf
.Path
) for ModuleInf
in self
.Platform
.Modules
}
380 # add the PCD from modules that listed in FDF but not in DSC to Database
381 for InfName
in FdfModuleList
:
382 if InfName
not in DscModuleSet
:
383 InfClass
= PathClass(InfName
)
384 M
= self
.BuildDatabase
[InfClass
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
385 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
386 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
387 # For binary module, if in current arch, we need to list the PCDs into database.
388 if not M
.IsBinaryModule
:
390 # Override the module PCD setting by platform setting
391 ModulePcdList
= self
.ApplyPcdSetting(M
, M
.Pcds
)
392 for PcdFromModule
in ModulePcdList
:
393 PcdFromModule
.IsFromBinaryInf
= True
394 PcdFromModule
.IsFromDsc
= False
395 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
396 if PcdFromModule
.Type
not in PCD_DYNAMIC_EX_TYPE_SET
and PcdFromModule
.Type
not in TAB_PCDS_PATCHABLE_IN_MODULE
:
397 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
399 ExtraData
="\n\tExisted %s PCD %s in:\n\t\t%s\n"
400 % (PcdFromModule
.Type
, PcdFromModule
.TokenCName
, InfName
))
401 # make sure that the "VOID*" kind of datum has MaxDatumSize set
402 if PcdFromModule
.DatumType
== TAB_VOID
and not PcdFromModule
.MaxDatumSize
:
403 NoDatumTypePcdList
.add("%s.%s [%s]" % (PcdFromModule
.TokenSpaceGuidCName
, PcdFromModule
.TokenCName
, InfName
))
404 if M
.ModuleType
in SUP_MODULE_SET_PEI
:
405 PcdFromModule
.Phase
= "PEI"
406 if PcdFromModule
not in self
._DynaPcdList
_ and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
407 self
._DynaPcdList
_.append(PcdFromModule
)
408 elif PcdFromModule
not in self
._NonDynaPcdList
_ and PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
:
409 self
._NonDynaPcdList
_.append(PcdFromModule
)
410 if PcdFromModule
in self
._DynaPcdList
_ and PcdFromModule
.Phase
== 'PEI' and PcdFromModule
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
411 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
412 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
413 # module & DXE module at a same time.
414 # Overwrite the type of the PCDs in source INF by the type of AsBuild
415 # INF file as DynamicEx.
416 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
417 self
._DynaPcdList
_[Index
].Phase
= PcdFromModule
.Phase
418 self
._DynaPcdList
_[Index
].Type
= PcdFromModule
.Type
419 for PcdFromModule
in self
._NonDynaPcdList
_:
420 # If a PCD is not listed in the DSC file, but binary INF files used by
421 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
422 # section, AND all source INF files used by this platform the build
423 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
424 # section, then the tools must NOT add the PCD to the Platform's PCD
425 # Database; the build must assign the access method for this PCD as
426 # PcdsPatchableInModule.
427 if PcdFromModule
not in self
._DynaPcdList
_:
429 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
430 if PcdFromModule
.IsFromDsc
== False and \
431 PcdFromModule
.Type
in TAB_PCDS_PATCHABLE_IN_MODULE
and \
432 PcdFromModule
.IsFromBinaryInf
== True and \
433 self
._DynaPcdList
_[Index
].IsFromBinaryInf
== False:
434 Index
= self
._DynaPcdList
_.index(PcdFromModule
)
435 self
._DynaPcdList
_.remove (self
._DynaPcdList
_[Index
])
437 # print out error information and break the build, if error found
438 if len(NoDatumTypePcdList
) > 0:
439 NoDatumTypePcdListString
= "\n\t\t".join(NoDatumTypePcdList
)
440 EdkLogger
.error("build", AUTOGEN_ERROR
, "PCD setting error",
442 ExtraData
="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
443 % NoDatumTypePcdListString
)
444 self
._NonDynamicPcdList
= sorted(self
._NonDynaPcdList
_)
445 self
._DynamicPcdList
= self
._DynaPcdList
_
447 def SortDynamicPcd(self
):
449 # Sort dynamic PCD list to:
450 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
451 # try to be put header of dynamicd List
452 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
454 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
456 UnicodePcdArray
= set()
458 OtherPcdArray
= set()
460 VpdFile
= VpdInfoFile
.VpdInfoFile()
461 NeedProcessVpdMapFile
= False
463 for pcd
in self
.Platform
.Pcds
:
464 if pcd
not in self
._PlatformPcds
:
465 self
._PlatformPcds
[pcd
] = self
.Platform
.Pcds
[pcd
]
467 for item
in self
._PlatformPcds
:
468 if self
._PlatformPcds
[item
].DatumType
and self
._PlatformPcds
[item
].DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
469 self
._PlatformPcds
[item
].DatumType
= TAB_VOID
471 if (self
.Workspace
.ArchList
[-1] == self
.Arch
):
472 for Pcd
in self
._DynamicPcdList
:
473 # just pick the a value to determine whether is unicode string type
474 Sku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
475 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
477 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
478 Pcd
.DatumType
= TAB_VOID
480 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
481 # if found HII type PCD then insert to right of UnicodeIndex
482 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
483 VpdPcdDict
[(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
)] = Pcd
485 #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer
486 PcdNvStoreDfBuffer
= VpdPcdDict
.get(("PcdNvStoreDefaultValueBuffer", "gEfiMdeModulePkgTokenSpaceGuid"))
487 if PcdNvStoreDfBuffer
:
488 self
.VariableInfo
= self
.CollectVariables(self
._DynamicPcdList
)
489 vardump
= self
.VariableInfo
.dump()
492 #According to PCD_DATABASE_INIT in edk2\MdeModulePkg\Include\Guid\PcdDataBaseSignatureGuid.h,
493 #the max size for string PCD should not exceed USHRT_MAX 65535(0xffff).
494 #typedef UINT16 SIZE_INFO;
495 #//SIZE_INFO SizeTable[];
496 if len(vardump
.split(",")) > 0xffff:
497 EdkLogger
.error("build", RESOURCE_OVERFLOW
, 'The current length of PCD %s value is %d, it exceeds to the max size of String PCD.' %(".".join([PcdNvStoreDfBuffer
.TokenSpaceGuidCName
,PcdNvStoreDfBuffer
.TokenCName
]) ,len(vardump
.split(","))))
498 PcdNvStoreDfBuffer
.DefaultValue
= vardump
499 for skuname
in PcdNvStoreDfBuffer
.SkuInfoList
:
500 PcdNvStoreDfBuffer
.SkuInfoList
[skuname
].DefaultValue
= vardump
501 PcdNvStoreDfBuffer
.MaxDatumSize
= str(len(vardump
.split(",")))
503 #If the end user define [DefaultStores] and [XXX.Menufacturing] in DSC, but forget to configure PcdNvStoreDefaultValueBuffer to PcdsDynamicVpd
504 if [Pcd
for Pcd
in self
._DynamicPcdList
if Pcd
.UserDefinedDefaultStoresFlag
]:
505 EdkLogger
.warn("build", "PcdNvStoreDefaultValueBuffer should be defined as PcdsDynamicExVpd in dsc file since the DefaultStores is enabled for this platform.\n%s" %self
.Platform
.MetaFile
.Path
)
506 PlatformPcds
= sorted(self
._PlatformPcds
.keys())
508 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
511 for PcdKey
in PlatformPcds
:
512 Pcd
= self
._PlatformPcds
[PcdKey
]
513 if Pcd
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
] and \
514 PcdKey
in VpdPcdDict
:
515 Pcd
= VpdPcdDict
[PcdKey
]
517 DefaultSku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
519 PcdValue
= DefaultSku
.DefaultValue
520 if PcdValue
not in SkuValueMap
:
521 SkuValueMap
[PcdValue
] = []
522 VpdFile
.Add(Pcd
, TAB_DEFAULT
, DefaultSku
.VpdOffset
)
523 SkuValueMap
[PcdValue
].append(DefaultSku
)
525 for (SkuName
, Sku
) in Pcd
.SkuInfoList
.items():
526 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
527 PcdValue
= Sku
.DefaultValue
529 PcdValue
= Pcd
.DefaultValue
530 if Sku
.VpdOffset
!= TAB_STAR
:
531 if PcdValue
.startswith("{"):
533 elif PcdValue
.startswith("L"):
538 VpdOffset
= int(Sku
.VpdOffset
)
541 VpdOffset
= int(Sku
.VpdOffset
, 16)
543 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
))
544 if VpdOffset
% Alignment
!= 0:
545 if PcdValue
.startswith("{"):
546 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
), File
=self
.MetaFile
)
548 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenCName
, Alignment
))
549 if PcdValue
not in SkuValueMap
:
550 SkuValueMap
[PcdValue
] = []
551 VpdFile
.Add(Pcd
, SkuName
, Sku
.VpdOffset
)
552 SkuValueMap
[PcdValue
].append(Sku
)
553 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
554 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== TAB_STAR
:
555 NeedProcessVpdMapFile
= True
556 if self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== '':
557 EdkLogger
.error("Build", FILE_NOT_FOUND
, \
558 "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.")
560 VpdSkuMap
[PcdKey
] = SkuValueMap
562 # Fix the PCDs define in VPD PCD section that never referenced by module.
563 # An example is PCD for signature usage.
565 for DscPcd
in PlatformPcds
:
566 DscPcdEntry
= self
._PlatformPcds
[DscPcd
]
567 if DscPcdEntry
.Type
in [TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_EX_VPD
]:
568 if not (self
.Platform
.VpdToolGuid
is None or self
.Platform
.VpdToolGuid
== ''):
570 for VpdPcd
in VpdFile
._VpdArray
:
571 # This PCD has been referenced by module
572 if (VpdPcd
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
573 (VpdPcd
.TokenCName
== DscPcdEntry
.TokenCName
):
576 # Not found, it should be signature
578 # just pick the a value to determine whether is unicode string type
580 SkuObjList
= list(DscPcdEntry
.SkuInfoList
.items())
581 DefaultSku
= DscPcdEntry
.SkuInfoList
.get(TAB_DEFAULT
)
583 defaultindex
= SkuObjList
.index((TAB_DEFAULT
, DefaultSku
))
584 SkuObjList
[0], SkuObjList
[defaultindex
] = SkuObjList
[defaultindex
], SkuObjList
[0]
585 for (SkuName
, Sku
) in SkuObjList
:
586 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
588 # Need to iterate DEC pcd information to get the value & datumtype
589 for eachDec
in self
.PackageList
:
590 for DecPcd
in eachDec
.Pcds
:
591 DecPcdEntry
= eachDec
.Pcds
[DecPcd
]
592 if (DecPcdEntry
.TokenSpaceGuidCName
== DscPcdEntry
.TokenSpaceGuidCName
) and \
593 (DecPcdEntry
.TokenCName
== DscPcdEntry
.TokenCName
):
594 # Print warning message to let the developer make a determine.
595 EdkLogger
.warn("build", "Unreferenced vpd pcd used!",
596 File
=self
.MetaFile
, \
597 ExtraData
= "PCD: %s.%s used in the DSC file %s is unreferenced." \
598 %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, self
.Platform
.MetaFile
.Path
))
600 DscPcdEntry
.DatumType
= DecPcdEntry
.DatumType
601 DscPcdEntry
.DefaultValue
= DecPcdEntry
.DefaultValue
602 DscPcdEntry
.TokenValue
= DecPcdEntry
.TokenValue
603 DscPcdEntry
.TokenSpaceGuidValue
= eachDec
.Guids
[DecPcdEntry
.TokenSpaceGuidCName
]
604 # Only fix the value while no value provided in DSC file.
605 if not Sku
.DefaultValue
:
606 DscPcdEntry
.SkuInfoList
[list(DscPcdEntry
.SkuInfoList
.keys())[0]].DefaultValue
= DecPcdEntry
.DefaultValue
608 if DscPcdEntry
not in self
._DynamicPcdList
:
609 self
._DynamicPcdList
.append(DscPcdEntry
)
610 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
611 PcdValue
= Sku
.DefaultValue
613 PcdValue
= DscPcdEntry
.DefaultValue
614 if Sku
.VpdOffset
!= TAB_STAR
:
615 if PcdValue
.startswith("{"):
617 elif PcdValue
.startswith("L"):
622 VpdOffset
= int(Sku
.VpdOffset
)
625 VpdOffset
= int(Sku
.VpdOffset
, 16)
627 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid offset value %s for PCD %s.%s." % (Sku
.VpdOffset
, DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
))
628 if VpdOffset
% Alignment
!= 0:
629 if PcdValue
.startswith("{"):
630 EdkLogger
.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
), File
=self
.MetaFile
)
632 EdkLogger
.error("build", FORMAT_INVALID
, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry
.TokenSpaceGuidCName
, DscPcdEntry
.TokenCName
, Alignment
))
633 if PcdValue
not in SkuValueMap
:
634 SkuValueMap
[PcdValue
] = []
635 VpdFile
.Add(DscPcdEntry
, SkuName
, Sku
.VpdOffset
)
636 SkuValueMap
[PcdValue
].append(Sku
)
637 if not NeedProcessVpdMapFile
and Sku
.VpdOffset
== TAB_STAR
:
638 NeedProcessVpdMapFile
= True
639 if DscPcdEntry
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
640 UnicodePcdArray
.add(DscPcdEntry
)
641 elif len(Sku
.VariableName
) > 0:
642 HiiPcdArray
.add(DscPcdEntry
)
644 OtherPcdArray
.add(DscPcdEntry
)
646 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
647 VpdSkuMap
[DscPcd
] = SkuValueMap
648 if (self
.Platform
.FlashDefinition
is None or self
.Platform
.FlashDefinition
== '') and \
649 VpdFile
.GetCount() != 0:
650 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
651 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self
.Platform
.MetaFile
))
653 if VpdFile
.GetCount() != 0:
655 self
.FixVpdOffset(VpdFile
)
657 self
.FixVpdOffset(self
.UpdateNVStoreMaxSize(VpdFile
))
658 PcdNvStoreDfBuffer
= [item
for item
in self
._DynamicPcdList
if item
.TokenCName
== "PcdNvStoreDefaultValueBuffer" and item
.TokenSpaceGuidCName
== "gEfiMdeModulePkgTokenSpaceGuid"]
659 if PcdNvStoreDfBuffer
:
660 PcdName
,PcdGuid
= PcdNvStoreDfBuffer
[0].TokenCName
, PcdNvStoreDfBuffer
[0].TokenSpaceGuidCName
661 if (PcdName
,PcdGuid
) in VpdSkuMap
:
662 DefaultSku
= PcdNvStoreDfBuffer
[0].SkuInfoList
.get(TAB_DEFAULT
)
663 VpdSkuMap
[(PcdName
,PcdGuid
)] = {DefaultSku
.DefaultValue
:[SkuObj
for SkuObj
in PcdNvStoreDfBuffer
[0].SkuInfoList
.values() ]}
665 # Process VPD map file generated by third party BPDG tool
666 if NeedProcessVpdMapFile
:
667 VpdMapFilePath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
, "%s.map" % self
.Platform
.VpdToolGuid
)
669 VpdFile
.Read(VpdMapFilePath
)
671 # Fixup TAB_STAR offset
672 for pcd
in VpdSkuMap
:
673 vpdinfo
= VpdFile
.GetVpdInfo(pcd
)
675 # just pick the a value to determine whether is unicode string type
677 for pcdvalue
in VpdSkuMap
[pcd
]:
678 for sku
in VpdSkuMap
[pcd
][pcdvalue
]:
680 if item
[2] == pcdvalue
:
681 sku
.VpdOffset
= item
[1]
683 EdkLogger
.error("build", FILE_READ_FAILURE
, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath
)
685 # Delete the DynamicPcdList At the last time enter into this function
686 for Pcd
in self
._DynamicPcdList
:
687 # just pick the a value to determine whether is unicode string type
688 Sku
= Pcd
.SkuInfoList
.get(TAB_DEFAULT
)
689 Sku
.VpdOffset
= Sku
.VpdOffset
.strip()
691 if Pcd
.DatumType
not in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
, TAB_VOID
, "BOOLEAN"]:
692 Pcd
.DatumType
= TAB_VOID
694 PcdValue
= Sku
.DefaultValue
695 if Pcd
.DatumType
== TAB_VOID
and PcdValue
.startswith("L"):
696 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
697 UnicodePcdArray
.add(Pcd
)
698 elif len(Sku
.VariableName
) > 0:
699 # if found HII type PCD then insert to right of UnicodeIndex
702 OtherPcdArray
.add(Pcd
)
703 del self
._DynamicPcdList
[:]
704 self
._DynamicPcdList
.extend(list(UnicodePcdArray
))
705 self
._DynamicPcdList
.extend(list(HiiPcdArray
))
706 self
._DynamicPcdList
.extend(list(OtherPcdArray
))
707 self
._DynamicPcdList
.sort()
708 allskuset
= [(SkuName
, Sku
.SkuId
) for pcd
in self
._DynamicPcdList
for (SkuName
, Sku
) in pcd
.SkuInfoList
.items()]
709 for pcd
in self
._DynamicPcdList
:
710 if len(pcd
.SkuInfoList
) == 1:
711 for (SkuName
, SkuId
) in allskuset
:
712 if isinstance(SkuId
, str) and eval(SkuId
) == 0 or SkuId
== 0:
714 pcd
.SkuInfoList
[SkuName
] = copy
.deepcopy(pcd
.SkuInfoList
[TAB_DEFAULT
])
715 pcd
.SkuInfoList
[SkuName
].SkuId
= SkuId
716 pcd
.SkuInfoList
[SkuName
].SkuIdName
= SkuName
718 def FixVpdOffset(self
, VpdFile
):
719 FvPath
= os
.path
.join(self
.BuildDir
, TAB_FV_DIRECTORY
)
720 if not os
.path
.exists(FvPath
):
724 EdkLogger
.error("build", FILE_WRITE_FAILURE
, "Fail to create FV folder under %s" % self
.BuildDir
)
726 VpdFilePath
= os
.path
.join(FvPath
, "%s.txt" % self
.Platform
.VpdToolGuid
)
728 if VpdFile
.Write(VpdFilePath
):
729 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
731 for ToolDef
in self
.ToolDefinition
.values():
732 if TAB_GUID
in ToolDef
and ToolDef
[TAB_GUID
] == self
.Platform
.VpdToolGuid
:
733 if "PATH" not in ToolDef
:
734 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self
.Platform
.VpdToolGuid
)
735 BPDGToolName
= ToolDef
["PATH"]
737 # Call third party GUID BPDG tool.
738 if BPDGToolName
is not None:
739 VpdInfoFile
.CallExtenalBPDGTool(BPDGToolName
, VpdFilePath
)
741 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.")
743 ## Return the platform build data object
746 return self
.BuildDatabase
[self
.MetaFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
748 ## Return platform name
751 return self
.Platform
.PlatformName
753 ## Return the meta file GUID
756 return self
.Platform
.Guid
758 ## Return the platform version
761 return self
.Platform
.Version
763 ## Return the FDF file name
766 if self
.Workspace
.FdfFile
:
767 RetVal
= mws
.join(self
.WorkspaceDir
, self
.Workspace
.FdfFile
)
772 ## Return the build output directory platform specifies
775 return self
.Platform
.OutputDirectory
777 ## Return the directory to store all intermediate and final files built
780 if os
.path
.isabs(self
.OutputDir
):
781 GlobalData
.gBuildDirectory
= RetVal
= path
.join(
782 path
.abspath(self
.OutputDir
),
783 self
.BuildTarget
+ "_" + self
.ToolChain
,
786 GlobalData
.gBuildDirectory
= RetVal
= path
.join(
789 self
.BuildTarget
+ "_" + self
.ToolChain
,
793 ## Return directory of platform makefile
795 # @retval string Makefile directory
798 def MakeFileDir(self
):
799 return path
.join(self
.BuildDir
, self
.Arch
)
801 ## Return build command string
803 # @retval string Build command string
806 def BuildCommand(self
):
808 if "MAKE" in self
.ToolDefinition
and "PATH" in self
.ToolDefinition
["MAKE"]:
809 RetVal
+= _SplitOption(self
.ToolDefinition
["MAKE"]["PATH"])
810 if "FLAGS" in self
.ToolDefinition
["MAKE"]:
811 NewOption
= self
.ToolDefinition
["MAKE"]["FLAGS"].strip()
813 RetVal
+= _SplitOption(NewOption
)
814 if "MAKE" in self
.EdkIIBuildOption
:
815 if "FLAGS" in self
.EdkIIBuildOption
["MAKE"]:
816 Flags
= self
.EdkIIBuildOption
["MAKE"]["FLAGS"]
817 if Flags
.startswith('='):
818 RetVal
= [RetVal
[0]] + [Flags
[1:]]
823 ## Get tool chain definition
825 # Get each tool definition for given tool chain from tools_def.txt and platform
828 def ToolDefinition(self
):
829 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDictionary
830 if TAB_TOD_DEFINES_COMMAND_TYPE
not in self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
:
831 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No tools found in configuration",
832 ExtraData
="[%s]" % self
.MetaFile
)
833 RetVal
= OrderedDict()
835 for Def
in ToolDefinition
:
836 Target
, Tag
, Arch
, Tool
, Attr
= Def
.split("_")
837 if Target
!= self
.BuildTarget
or Tag
!= self
.ToolChain
or Arch
!= self
.Arch
:
840 Value
= ToolDefinition
[Def
]
841 # don't record the DLL
843 DllPathList
.add(Value
)
846 if Tool
not in RetVal
:
847 RetVal
[Tool
] = OrderedDict()
848 RetVal
[Tool
][Attr
] = Value
851 if GlobalData
.gOptions
.SilentMode
and "MAKE" in RetVal
:
852 if "FLAGS" not in RetVal
["MAKE"]:
853 RetVal
["MAKE"]["FLAGS"] = ""
854 RetVal
["MAKE"]["FLAGS"] += " -s"
857 for Attr
in RetVal
[Tool
]:
858 Value
= RetVal
[Tool
][Attr
]
859 if Tool
in self
._BuildOptionWithToolDef
(RetVal
) and Attr
in self
._BuildOptionWithToolDef
(RetVal
)[Tool
]:
860 # check if override is indicated
861 if self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
].startswith('='):
862 Value
= self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
][1:]
865 Value
+= " " + self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
]
867 Value
= self
._BuildOptionWithToolDef
(RetVal
)[Tool
][Attr
]
870 # Don't put MAKE definition in the file
872 ToolsDef
+= "%s = %s\n" % (Tool
, Value
)
874 # Don't put MAKE definition in the file
879 ToolsDef
+= "%s_%s = %s\n" % (Tool
, Attr
, Value
)
882 tool_def_file
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
883 SaveFileOnChange(tool_def_file
, ToolsDef
, False)
884 for DllPath
in DllPathList
:
885 os
.environ
["PATH"] = DllPath
+ os
.pathsep
+ os
.environ
["PATH"]
886 os
.environ
["MAKE_FLAGS"] = MakeFlags
890 ## Return the paths of tools
892 def ToolDefinitionFile(self
):
893 tool_def_file
= os
.path
.join(self
.MakeFileDir
, "TOOLS_DEF." + self
.Arch
)
894 if not os
.path
.exists(tool_def_file
):
898 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
900 def ToolChainFamily(self
):
901 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
902 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition \
903 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
904 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]:
905 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
907 RetVal
= TAB_COMPILER_MSFT
909 RetVal
= ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][self
.ToolChain
]
913 def BuildRuleFamily(self
):
914 ToolDefinition
= self
.Workspace
.ToolDef
.ToolsDefTxtDatabase
915 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in ToolDefinition \
916 or self
.ToolChain
not in ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] \
917 or not ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]:
918 EdkLogger
.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
920 return TAB_COMPILER_MSFT
922 return ToolDefinition
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][self
.ToolChain
]
924 ## Return the build options specific for all modules in this platform
926 def BuildOption(self
):
927 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
)
929 def _BuildOptionWithToolDef(self
, ToolDef
):
930 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, ToolDef
=ToolDef
)
932 ## Return the build options specific for EDK modules in this platform
934 def EdkBuildOption(self
):
935 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDK_NAME
)
937 ## Return the build options specific for EDKII modules in this platform
939 def EdkIIBuildOption(self
):
940 return self
._ExpandBuildOption
(self
.Platform
.BuildOptions
, EDKII_NAME
)
942 ## Parse build_rule.txt in Conf Directory.
944 # @retval BuildRule object
949 if TAB_TAT_DEFINES_BUILD_RULE_CONF
in self
.Workspace
.TargetTxt
.TargetTxtDictionary
:
950 BuildRuleFile
= self
.Workspace
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_BUILD_RULE_CONF
]
951 if not BuildRuleFile
:
952 BuildRuleFile
= gDefaultBuildRuleFile
953 RetVal
= BuildRule(BuildRuleFile
)
954 if RetVal
._FileVersion
== "":
955 RetVal
._FileVersion
= AutoGenReqBuildRuleVerNum
957 if RetVal
._FileVersion
< AutoGenReqBuildRuleVerNum
:
958 # If Build Rule's version is less than the version number required by the tools, halting the build.
959 EdkLogger
.error("build", AUTOGEN_ERROR
,
960 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])"\
961 % (RetVal
._FileVersion
, AutoGenReqBuildRuleVerNum
))
964 ## Summarize the packages used by modules in this platform
966 def PackageList(self
):
968 for Mb
in self
._MbList
:
969 RetVal
.update(Mb
.Packages
)
970 for lb
in Mb
.LibInstances
:
971 RetVal
.update(lb
.Packages
)
972 #Collect package set information from INF of FDF
973 for ModuleFile
in self
._AsBuildModuleList
:
974 if ModuleFile
in self
.Platform
.Modules
:
976 ModuleData
= self
.BuildDatabase
[ModuleFile
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
]
977 RetVal
.update(ModuleData
.Packages
)
981 def NonDynamicPcdDict(self
):
982 return {(Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
):Pcd
for Pcd
in self
.NonDynamicPcdList
}
984 ## Get list of non-dynamic PCDs
986 def NonDynamicPcdList(self
):
987 if not self
._NonDynamicPcdList
:
988 self
.CollectPlatformDynamicPcds()
989 return self
._NonDynamicPcdList
991 ## Get list of dynamic PCDs
993 def DynamicPcdList(self
):
994 if not self
._DynamicPcdList
:
995 self
.CollectPlatformDynamicPcds()
996 return self
._DynamicPcdList
998 ## Generate Token Number for all PCD
1000 def PcdTokenNumber(self
):
1001 RetVal
= OrderedDict()
1004 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1008 # TokenNumber 0 ~ 10
1010 # TokeNumber 11 ~ 20
1012 for Pcd
in self
.DynamicPcdList
:
1013 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
1014 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1015 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1018 for Pcd
in self
.DynamicPcdList
:
1019 if Pcd
.Phase
== "PEI" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1020 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1021 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1024 for Pcd
in self
.DynamicPcdList
:
1025 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_TYPE_SET
:
1026 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1027 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1030 for Pcd
in self
.DynamicPcdList
:
1031 if Pcd
.Phase
== "DXE" and Pcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
:
1032 EdkLogger
.debug(EdkLogger
.DEBUG_5
, "%s %s (%s) -> %d" % (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
, Pcd
.Phase
, TokenNumber
))
1033 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1036 for Pcd
in self
.NonDynamicPcdList
:
1037 RetVal
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
] = TokenNumber
1043 return [self
.BuildDatabase
[m
, self
.Arch
, self
.BuildTarget
, self
.ToolChain
] for m
in self
.Platform
.Modules
]
1047 for ModuleFile
in self
.Platform
.Modules
:
1057 self
.Platform
.Modules
[ModuleFile
].M
= Ma
1058 return [x
.M
for x
in self
.Platform
.Modules
.values()]
1060 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
1062 def ModuleAutoGenList(self
):
1064 for Ma
in self
._MaList
:
1065 if Ma
not in RetVal
:
1069 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
1071 def LibraryAutoGenList(self
):
1073 for Ma
in self
._MaList
:
1074 for La
in Ma
.LibraryAutoGenList
:
1075 if La
not in RetVal
:
1077 if Ma
not in La
.ReferenceModules
:
1078 La
.ReferenceModules
.append(Ma
)
1081 ## Test if a module is supported by the platform
1083 # An error will be raised directly if the module or its arch is not supported
1084 # by the platform or current configuration
1086 def ValidModule(self
, Module
):
1087 return Module
in self
.Platform
.Modules
or Module
in self
.Platform
.LibraryInstances \
1088 or Module
in self
._AsBuildModuleList
1090 def GetAllModuleInfo(self
,WithoutPcd
=True):
1092 for m
in self
.Platform
.Modules
:
1093 module_obj
= self
.BuildDatabase
[m
,self
.Arch
,self
.BuildTarget
,self
.ToolChain
]
1094 if not bool(module_obj
.LibraryClass
):
1095 Libs
= GetModuleLibInstances(module_obj
, self
.Platform
, self
.BuildDatabase
, self
.Arch
,self
.BuildTarget
,self
.ToolChain
,self
.MetaFile
,EdkLogger
)
1098 ModuleLibs
.update( set([(l
.MetaFile
.File
,l
.MetaFile
.Root
,l
.MetaFile
.Path
,l
.MetaFile
.BaseName
,l
.MetaFile
.OriginalPath
,l
.Arch
,True) for l
in Libs
]))
1099 if WithoutPcd
and module_obj
.PcdIsDriver
:
1101 ModuleLibs
.add((m
.File
,m
.Root
,m
.Path
,m
.BaseName
,m
.OriginalPath
,module_obj
.Arch
,bool(module_obj
.LibraryClass
)))
1105 ## Resolve the library classes in a module to library instances
1107 # This method will not only resolve library classes but also sort the library
1108 # instances according to the dependency-ship.
1110 # @param Module The module from which the library classes will be resolved
1112 # @retval library_list List of library instances sorted
1114 def ApplyLibraryInstance(self
, Module
):
1115 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
1116 if str(Module
) not in self
.Platform
.Modules
:
1119 return GetModuleLibInstances(Module
,
1128 ## Override PCD setting (type, value, ...)
1130 # @param ToPcd The PCD to be overridden
1131 # @param FromPcd The PCD overriding from
1133 def _OverridePcd(self
, ToPcd
, FromPcd
, Module
="", Msg
="", Library
=""):
1135 # in case there's PCDs coming from FDF file, which have no type given.
1136 # at this point, ToPcd.Type has the type found from dependent
1139 TokenCName
= ToPcd
.TokenCName
1140 for PcdItem
in GlobalData
.MixedPcd
:
1141 if (ToPcd
.TokenCName
, ToPcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1142 TokenCName
= PcdItem
[0]
1144 if FromPcd
is not None:
1145 if ToPcd
.Pending
and FromPcd
.Type
:
1146 ToPcd
.Type
= FromPcd
.Type
1147 elif ToPcd
.Type
and FromPcd
.Type\
1148 and ToPcd
.Type
!= FromPcd
.Type
and ToPcd
.Type
in FromPcd
.Type
:
1149 if ToPcd
.Type
.strip() == TAB_PCDS_DYNAMIC_EX
:
1150 ToPcd
.Type
= FromPcd
.Type
1151 elif ToPcd
.Type
and FromPcd
.Type \
1152 and ToPcd
.Type
!= FromPcd
.Type
:
1154 Module
= str(Module
) + " 's library file (" + str(Library
) + ")"
1155 EdkLogger
.error("build", OPTION_CONFLICT
, "Mismatched PCD type",
1156 ExtraData
="%s.%s is used as [%s] in module %s, but as [%s] in %s."\
1157 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
,
1158 ToPcd
.Type
, Module
, FromPcd
.Type
, Msg
),
1161 if FromPcd
.MaxDatumSize
:
1162 ToPcd
.MaxDatumSize
= FromPcd
.MaxDatumSize
1163 ToPcd
.MaxSizeUserSet
= FromPcd
.MaxDatumSize
1164 if FromPcd
.DefaultValue
:
1165 ToPcd
.DefaultValue
= FromPcd
.DefaultValue
1166 if FromPcd
.TokenValue
:
1167 ToPcd
.TokenValue
= FromPcd
.TokenValue
1168 if FromPcd
.DatumType
:
1169 ToPcd
.DatumType
= FromPcd
.DatumType
1170 if FromPcd
.SkuInfoList
:
1171 ToPcd
.SkuInfoList
= FromPcd
.SkuInfoList
1172 if FromPcd
.UserDefinedDefaultStoresFlag
:
1173 ToPcd
.UserDefinedDefaultStoresFlag
= FromPcd
.UserDefinedDefaultStoresFlag
1174 # Add Flexible PCD format parse
1175 if ToPcd
.DefaultValue
:
1177 ToPcd
.DefaultValue
= ValueExpressionEx(ToPcd
.DefaultValue
, ToPcd
.DatumType
, self
.Platform
._GuidDict
)(True)
1178 except BadExpression
as Value
:
1179 EdkLogger
.error('Parser', FORMAT_INVALID
, 'PCD [%s.%s] Value "%s", %s' %(ToPcd
.TokenSpaceGuidCName
, ToPcd
.TokenCName
, ToPcd
.DefaultValue
, Value
),
1182 # check the validation of datum
1183 IsValid
, Cause
= CheckPcdDatum(ToPcd
.DatumType
, ToPcd
.DefaultValue
)
1185 EdkLogger
.error('build', FORMAT_INVALID
, Cause
, File
=self
.MetaFile
,
1186 ExtraData
="%s.%s" % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
1187 ToPcd
.validateranges
= FromPcd
.validateranges
1188 ToPcd
.validlists
= FromPcd
.validlists
1189 ToPcd
.expressions
= FromPcd
.expressions
1190 ToPcd
.CustomAttribute
= FromPcd
.CustomAttribute
1192 if FromPcd
is not None and ToPcd
.DatumType
== TAB_VOID
and not ToPcd
.MaxDatumSize
:
1193 EdkLogger
.debug(EdkLogger
.DEBUG_9
, "No MaxDatumSize specified for PCD %s.%s" \
1194 % (ToPcd
.TokenSpaceGuidCName
, TokenCName
))
1195 Value
= ToPcd
.DefaultValue
1197 ToPcd
.MaxDatumSize
= '1'
1198 elif Value
[0] == 'L':
1199 ToPcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
1200 elif Value
[0] == '{':
1201 ToPcd
.MaxDatumSize
= str(len(Value
.split(',')))
1203 ToPcd
.MaxDatumSize
= str(len(Value
) - 1)
1205 # apply default SKU for dynamic PCDS if specified one is not available
1206 if (ToPcd
.Type
in PCD_DYNAMIC_TYPE_SET
or ToPcd
.Type
in PCD_DYNAMIC_EX_TYPE_SET
) \
1207 and not ToPcd
.SkuInfoList
:
1208 if self
.Platform
.SkuName
in self
.Platform
.SkuIds
:
1209 SkuName
= self
.Platform
.SkuName
1211 SkuName
= TAB_DEFAULT
1212 ToPcd
.SkuInfoList
= {
1213 SkuName
: SkuInfoClass(SkuName
, self
.Platform
.SkuIds
[SkuName
][0], '', '', '', '', '', ToPcd
.DefaultValue
)
1216 ## Apply PCD setting defined platform to a module
1218 # @param Module The module from which the PCD setting will be overridden
1220 # @retval PCD_list The list PCDs with settings from platform
1222 def ApplyPcdSetting(self
, Module
, Pcds
, Library
=""):
1223 # for each PCD in module
1224 for Name
, Guid
in Pcds
:
1225 PcdInModule
= Pcds
[Name
, Guid
]
1226 # find out the PCD setting in platform
1227 if (Name
, Guid
) in self
.Platform
.Pcds
:
1228 PcdInPlatform
= self
.Platform
.Pcds
[Name
, Guid
]
1230 PcdInPlatform
= None
1231 # then override the settings if any
1232 self
._OverridePcd
(PcdInModule
, PcdInPlatform
, Module
, Msg
="DSC PCD sections", Library
=Library
)
1233 # resolve the VariableGuid value
1234 for SkuId
in PcdInModule
.SkuInfoList
:
1235 Sku
= PcdInModule
.SkuInfoList
[SkuId
]
1236 if Sku
.VariableGuid
== '': continue
1237 Sku
.VariableGuidValue
= GuidValue(Sku
.VariableGuid
, self
.PackageList
, self
.MetaFile
.Path
)
1238 if Sku
.VariableGuidValue
is None:
1239 PackageList
= "\n\t".join(str(P
) for P
in self
.PackageList
)
1242 RESOURCE_NOT_AVAILABLE
,
1243 "Value of GUID [%s] is not found in" % Sku
.VariableGuid
,
1244 ExtraData
=PackageList
+ "\n\t(used with %s.%s from module %s)" \
1245 % (Guid
, Name
, str(Module
)),
1249 # override PCD settings with module specific setting
1250 if Module
in self
.Platform
.Modules
:
1251 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
1252 for Key
in PlatformModule
.Pcds
:
1253 if GlobalData
.BuildOptionPcd
:
1254 for pcd
in GlobalData
.BuildOptionPcd
:
1255 (TokenSpaceGuidCName
, TokenCName
, FieldName
, pcdvalue
, _
) = pcd
1256 if (TokenCName
, TokenSpaceGuidCName
) == Key
and FieldName
=="":
1257 PlatformModule
.Pcds
[Key
].DefaultValue
= pcdvalue
1258 PlatformModule
.Pcds
[Key
].PcdValueFromComm
= pcdvalue
1264 elif Key
in GlobalData
.MixedPcd
:
1265 for PcdItem
in GlobalData
.MixedPcd
[Key
]:
1267 ToPcd
= Pcds
[PcdItem
]
1271 self
._OverridePcd
(ToPcd
, PlatformModule
.Pcds
[Key
], Module
, Msg
="DSC Components Module scoped PCD section", Library
=Library
)
1272 # use PCD value to calculate the MaxDatumSize when it is not specified
1273 for Name
, Guid
in Pcds
:
1274 Pcd
= Pcds
[Name
, Guid
]
1275 if Pcd
.DatumType
== TAB_VOID
and not Pcd
.MaxDatumSize
:
1276 Pcd
.MaxSizeUserSet
= None
1277 Value
= Pcd
.DefaultValue
1279 Pcd
.MaxDatumSize
= '1'
1280 elif Value
[0] == 'L':
1281 Pcd
.MaxDatumSize
= str((len(Value
) - 2) * 2)
1282 elif Value
[0] == '{':
1283 Pcd
.MaxDatumSize
= str(len(Value
.split(',')))
1285 Pcd
.MaxDatumSize
= str(len(Value
) - 1)
1286 return list(Pcds
.values())
1288 ## Append build options in platform to a module
1290 # @param Module The module to which the build options will be appended
1292 # @retval options The options appended with build options in platform
1294 def ApplyBuildOption(self
, Module
):
1295 # Get the different options for the different style module
1296 PlatformOptions
= self
.EdkIIBuildOption
1297 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
1298 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
1299 ModuleOptions
= self
._ExpandBuildOption
(Module
.BuildOptions
)
1300 if Module
in self
.Platform
.Modules
:
1301 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
1302 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
1304 PlatformModuleOptions
= {}
1306 BuildRuleOrder
= None
1307 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
1308 for Tool
in Options
:
1309 for Attr
in Options
[Tool
]:
1310 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
1311 BuildRuleOrder
= Options
[Tool
][Attr
]
1313 AllTools
= set(list(ModuleOptions
.keys()) + list(PlatformOptions
.keys()) +
1314 list(PlatformModuleOptions
.keys()) + list(ModuleTypeOptions
.keys()) +
1315 list(self
.ToolDefinition
.keys()))
1316 BuildOptions
= defaultdict(lambda: defaultdict(str))
1317 for Tool
in AllTools
:
1318 for Options
in [self
.ToolDefinition
, ModuleOptions
, PlatformOptions
, ModuleTypeOptions
, PlatformModuleOptions
]:
1319 if Tool
not in Options
:
1321 for Attr
in Options
[Tool
]:
1323 # Do not generate it in Makefile
1325 if Attr
== TAB_TOD_DEFINES_BUILDRULEORDER
:
1327 Value
= Options
[Tool
][Attr
]
1328 # check if override is indicated
1329 if Value
.startswith('='):
1330 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
[1:])
1333 BuildOptions
[Tool
][Attr
] += " " + mws
.handleWsMacro(Value
)
1335 BuildOptions
[Tool
][Attr
] = mws
.handleWsMacro(Value
)
1337 return BuildOptions
, BuildRuleOrder
1340 def GetGlobalBuildOptions(self
,Module
):
1341 ModuleTypeOptions
= self
.Platform
.GetBuildOptionsByModuleType(EDKII_NAME
, Module
.ModuleType
)
1342 ModuleTypeOptions
= self
._ExpandBuildOption
(ModuleTypeOptions
)
1344 if Module
in self
.Platform
.Modules
:
1345 PlatformModule
= self
.Platform
.Modules
[str(Module
)]
1346 PlatformModuleOptions
= self
._ExpandBuildOption
(PlatformModule
.BuildOptions
)
1348 PlatformModuleOptions
= {}
1350 return ModuleTypeOptions
,PlatformModuleOptions
1351 def ModuleGuid(self
,Module
):
1352 if os
.path
.basename(Module
.MetaFile
.File
) != os
.path
.basename(Module
.MetaFile
.Path
):
1354 # Length of GUID is 36
1356 return os
.path
.basename(Module
.MetaFile
.Path
)[:36]
1359 def UniqueBaseName(self
):
1363 for Module
in self
._MbList
:
1364 unique_base_name
= '%s_%s' % (Module
.BaseName
,self
.ModuleGuid(Module
))
1365 if unique_base_name
not in ModuleNameDict
:
1366 ModuleNameDict
[unique_base_name
] = []
1367 ModuleNameDict
[unique_base_name
].append(Module
.MetaFile
)
1368 if Module
.BaseName
not in UniqueName
:
1369 UniqueName
[Module
.BaseName
] = set()
1370 UniqueName
[Module
.BaseName
].add((self
.ModuleGuid(Module
),Module
.MetaFile
))
1371 for module_paths
in ModuleNameDict
.values():
1372 if len(set(module_paths
))>1:
1373 samemodules
= list(set(module_paths
))
1374 EdkLogger
.error("build", FILE_DUPLICATED
, 'Modules have same BaseName and FILE_GUID:\n'
1375 ' %s\n %s' % (samemodules
[0], samemodules
[1]))
1376 for name
in UniqueName
:
1377 Guid_Path
= UniqueName
[name
]
1378 if len(Guid_Path
) > 1:
1379 for guid
,mpath
in Guid_Path
:
1380 retVal
[(name
,mpath
)] = '%s_%s' % (name
,guid
)
1382 ## Expand * in build option key
1384 # @param Options Options to be expanded
1385 # @param ToolDef Use specified ToolDef instead of full version.
1386 # This is needed during initialization to prevent
1387 # infinite recursion betweeh BuildOptions,
1388 # ToolDefinition, and this function.
1390 # @retval options Options expanded
1392 def _ExpandBuildOption(self
, Options
, ModuleStyle
=None, ToolDef
=None):
1394 ToolDef
= self
.ToolDefinition
1401 # Construct a list contain the build options which need override.
1405 # Key[0] -- tool family
1406 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1408 if (Key
[0] == self
.BuildRuleFamily
and
1409 (ModuleStyle
is None or len(Key
) < 3 or (len(Key
) > 2 and Key
[2] == ModuleStyle
))):
1410 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
[1].split('_')
1411 if (Target
== self
.BuildTarget
or Target
== TAB_STAR
) and\
1412 (ToolChain
== self
.ToolChain
or ToolChain
== TAB_STAR
) and\
1413 (Arch
== self
.Arch
or Arch
== TAB_STAR
) and\
1414 Options
[Key
].startswith("="):
1416 if OverrideList
.get(Key
[1]) is not None:
1417 OverrideList
.pop(Key
[1])
1418 OverrideList
[Key
[1]] = Options
[Key
]
1421 # Use the highest priority value.
1423 if (len(OverrideList
) >= 2):
1424 KeyList
= list(OverrideList
.keys())
1425 for Index
in range(len(KeyList
)):
1426 NowKey
= KeyList
[Index
]
1427 Target1
, ToolChain1
, Arch1
, CommandType1
, Attr1
= NowKey
.split("_")
1428 for Index1
in range(len(KeyList
) - Index
- 1):
1429 NextKey
= KeyList
[Index1
+ Index
+ 1]
1431 # Compare two Key, if one is included by another, choose the higher priority one
1433 Target2
, ToolChain2
, Arch2
, CommandType2
, Attr2
= NextKey
.split("_")
1434 if (Target1
== Target2
or Target1
== TAB_STAR
or Target2
== TAB_STAR
) and\
1435 (ToolChain1
== ToolChain2
or ToolChain1
== TAB_STAR
or ToolChain2
== TAB_STAR
) and\
1436 (Arch1
== Arch2
or Arch1
== TAB_STAR
or Arch2
== TAB_STAR
) and\
1437 (CommandType1
== CommandType2
or CommandType1
== TAB_STAR
or CommandType2
== TAB_STAR
) and\
1438 (Attr1
== Attr2
or Attr1
== TAB_STAR
or Attr2
== TAB_STAR
):
1440 if CalculatePriorityValue(NowKey
) > CalculatePriorityValue(NextKey
):
1441 if Options
.get((self
.BuildRuleFamily
, NextKey
)) is not None:
1442 Options
.pop((self
.BuildRuleFamily
, NextKey
))
1444 if Options
.get((self
.BuildRuleFamily
, NowKey
)) is not None:
1445 Options
.pop((self
.BuildRuleFamily
, NowKey
))
1448 if ModuleStyle
is not None and len (Key
) > 2:
1449 # Check Module style is EDK or EDKII.
1450 # Only append build option for the matched style module.
1451 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
1453 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
1456 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
1457 # if tool chain family doesn't match, skip it
1458 if Tool
in ToolDef
and Family
!= "":
1459 FamilyIsNull
= False
1460 if ToolDef
[Tool
].get(TAB_TOD_DEFINES_BUILDRULEFAMILY
, "") != "":
1461 if Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
1463 elif Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
1466 # expand any wildcard
1467 if Target
== TAB_STAR
or Target
== self
.BuildTarget
:
1468 if Tag
== TAB_STAR
or Tag
== self
.ToolChain
:
1469 if Arch
== TAB_STAR
or Arch
== self
.Arch
:
1470 if Tool
not in BuildOptions
:
1471 BuildOptions
[Tool
] = {}
1472 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
1473 BuildOptions
[Tool
][Attr
] = Options
[Key
]
1475 # append options for the same tool except PATH
1477 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
1479 BuildOptions
[Tool
][Attr
] = Options
[Key
]
1480 # Build Option Family has been checked, which need't to be checked again for family.
1481 if FamilyMatch
or FamilyIsNull
:
1485 if ModuleStyle
is not None and len (Key
) > 2:
1486 # Check Module style is EDK or EDKII.
1487 # Only append build option for the matched style module.
1488 if ModuleStyle
== EDK_NAME
and Key
[2] != EDK_NAME
:
1490 elif ModuleStyle
== EDKII_NAME
and Key
[2] != EDKII_NAME
:
1493 Target
, Tag
, Arch
, Tool
, Attr
= Key
[1].split("_")
1494 # if tool chain family doesn't match, skip it
1495 if Tool
not in ToolDef
or Family
== "":
1497 # option has been added before
1498 if Family
!= ToolDef
[Tool
][TAB_TOD_DEFINES_FAMILY
]:
1501 # expand any wildcard
1502 if Target
== TAB_STAR
or Target
== self
.BuildTarget
:
1503 if Tag
== TAB_STAR
or Tag
== self
.ToolChain
:
1504 if Arch
== TAB_STAR
or Arch
== self
.Arch
:
1505 if Tool
not in BuildOptions
:
1506 BuildOptions
[Tool
] = {}
1507 if Attr
!= "FLAGS" or Attr
not in BuildOptions
[Tool
] or Options
[Key
].startswith('='):
1508 BuildOptions
[Tool
][Attr
] = Options
[Key
]
1510 # append options for the same tool except PATH
1512 BuildOptions
[Tool
][Attr
] += " " + Options
[Key
]
1514 BuildOptions
[Tool
][Attr
] = Options
[Key
]