BaseTools:change some incorrect parameter defaults

BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1858

for Dict={},There are pitfalls in the way this default parameter is set
and Dict is not used in functions, other functions have these two cases,
I will change some incorrect parameter defaults

This patch is going to fix this issue

Cc: Liming Gao <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
Fan, ZhijuX
2019-09-12 16:18:27 +08:00
committed by Feng, Bob C
parent b67735a7e8
commit e32f7bc96d
19 changed files with 60 additions and 23 deletions

View File

@ -176,7 +176,9 @@ class FileBuildRule:
CommandString = "\n\t".join(self.CommandList) CommandString = "\n\t".join(self.CommandList)
return "%s : %s\n\t%s" % (DestString, SourceString, CommandString) return "%s : %s\n\t%s" % (DestString, SourceString, CommandString)
def Instantiate(self, Macros={}): def Instantiate(self, Macros = None):
if Macros is None:
Macros = {}
NewRuleObject = copy.copy(self) NewRuleObject = copy.copy(self)
NewRuleObject.BuildTargets = {} NewRuleObject.BuildTargets = {}
NewRuleObject.DestFileList = [] NewRuleObject.DestFileList = []

View File

@ -205,10 +205,12 @@ class BuildFile(object):
def GetRemoveDirectoryCommand(self, DirList): def GetRemoveDirectoryCommand(self, DirList):
return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList] return [self._RD_TEMPLATE_[self._FileType] % {'dir':Dir} for Dir in DirList]
def PlaceMacro(self, Path, MacroDefinitions={}): def PlaceMacro(self, Path, MacroDefinitions=None):
if Path.startswith("$("): if Path.startswith("$("):
return Path return Path
else: else:
if MacroDefinitions is None:
MacroDefinitions = {}
PathLength = len(Path) PathLength = len(Path)
for MacroName in MacroDefinitions: for MacroName in MacroDefinitions:
MacroValue = MacroDefinitions[MacroName] MacroValue = MacroDefinitions[MacroName]
@ -1762,4 +1764,4 @@ def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList)
# This acts like the main() function for the script, unless it is 'import'ed into another script. # This acts like the main() function for the script, unless it is 'import'ed into another script.
if __name__ == '__main__': if __name__ == '__main__':
pass pass

View File

@ -342,7 +342,9 @@ class RangeExpression(BaseExpression):
raise BadExpression(ERR_STRING_EXPR % Operator) raise BadExpression(ERR_STRING_EXPR % Operator)
def __init__(self, Expression, PcdDataType, SymbolTable = {}): def __init__(self, Expression, PcdDataType, SymbolTable = None):
if SymbolTable is None:
SymbolTable = {}
super(RangeExpression, self).__init__(self, Expression, PcdDataType, SymbolTable) super(RangeExpression, self).__init__(self, Expression, PcdDataType, SymbolTable)
self._NoProcess = False self._NoProcess = False
if not isinstance(Expression, type('')): if not isinstance(Expression, type('')):

View File

@ -243,8 +243,10 @@ def SplitModuleType(Key):
# #
# @retval NewList A new string list whose macros are replaced # @retval NewList A new string list whose macros are replaced
# #
def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False): def ReplaceMacros(StringList, MacroDefinitions=None, SelfReplacement=False):
NewList = [] NewList = []
if MacroDefinitions is None:
MacroDefinitions = {}
for String in StringList: for String in StringList:
if isinstance(String, type('')): if isinstance(String, type('')):
NewList.append(ReplaceMacro(String, MacroDefinitions, SelfReplacement)) NewList.append(ReplaceMacro(String, MacroDefinitions, SelfReplacement))
@ -264,8 +266,10 @@ def ReplaceMacros(StringList, MacroDefinitions={}, SelfReplacement=False):
# #
# @retval string The string whose macros are replaced # @retval string The string whose macros are replaced
# #
def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement=False, RaiseError=False): def ReplaceMacro(String, MacroDefinitions=None, SelfReplacement=False, RaiseError=False):
LastString = String LastString = String
if MacroDefinitions is None:
MacroDefinitions = {}
while String and MacroDefinitions: while String and MacroDefinitions:
MacroUsed = GlobalData.gMacroRefPattern.findall(String) MacroUsed = GlobalData.gMacroRefPattern.findall(String)
# no macro found in String, stop replacing # no macro found in String, stop replacing
@ -298,7 +302,7 @@ def ReplaceMacro(String, MacroDefinitions={}, SelfReplacement=False, RaiseError=
# #
# @retval Path Formatted path # @retval Path Formatted path
# #
def NormPath(Path, Defines={}): def NormPath(Path, Defines=None):
IsRelativePath = False IsRelativePath = False
if Path: if Path:
if Path[0] == '.': if Path[0] == '.':

View File

@ -46,7 +46,9 @@ class AprioriSection (object):
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# @retval string Generated file name # @retval string Generated file name
# #
def GenFfs (self, FvName, Dict = {}, IsMakefile = False): def GenFfs (self, FvName, Dict = None, IsMakefile = False):
if Dict is None:
Dict = {}
Buffer = BytesIO() Buffer = BytesIO()
if self.AprioriType == "PEI": if self.AprioriType == "PEI":
AprioriFileGuid = PEI_APRIORI_GUID AprioriFileGuid = PEI_APRIORI_GUID

View File

@ -49,7 +49,7 @@ class CompressSection (CompressSectionClassObject) :
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# @retval tuple (Generated file name, section alignment) # @retval tuple (Generated file name, section alignment)
# #
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False): def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):
if FfsInf is not None: if FfsInf is not None:
self.CompType = FfsInf.__ExtendMacro__(self.CompType) self.CompType = FfsInf.__ExtendMacro__(self.CompType)
@ -59,6 +59,8 @@ class CompressSection (CompressSectionClassObject) :
SectAlign = [] SectAlign = []
Index = 0 Index = 0
MaxAlign = None MaxAlign = None
if Dict is None:
Dict = {}
for Sect in self.SectionList: for Sect in self.SectionList:
Index = Index + 1 Index = Index + 1
SecIndex = '%s.%d' %(SecNum, Index) SecIndex = '%s.%d' %(SecNum, Index)

View File

@ -44,10 +44,12 @@ class DataSection (DataSectionClassObject):
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# @retval tuple (Generated file name list, section alignment) # @retval tuple (Generated file name list, section alignment)
# #
def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False): def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):
# #
# Prepare the parameter of GenSection # Prepare the parameter of GenSection
# #
if Dict is None:
Dict = {}
if FfsFile is not None: if FfsFile is not None:
self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName) self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch) self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)

View File

@ -49,7 +49,7 @@ class EfiSection (EfiSectionClassObject):
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# @retval tuple (Generated file name list, section alignment) # @retval tuple (Generated file name list, section alignment)
# #
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False) : def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False) :
if self.FileName is not None and self.FileName.startswith('PCD('): if self.FileName is not None and self.FileName.startswith('PCD('):
self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName) self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)
@ -76,6 +76,8 @@ class EfiSection (EfiSectionClassObject):
"""If the file name was pointed out, add it in FileList""" """If the file name was pointed out, add it in FileList"""
FileList = [] FileList = []
if Dict is None:
Dict = {}
if Filename is not None: if Filename is not None:
Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict) Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)
# check if the path is absolute or relative # check if the path is absolute or relative

View File

@ -48,7 +48,7 @@ class FileStatement (FileStatementClassObject):
# @param FvParentAddr Parent Fv base address # @param FvParentAddr Parent Fv base address
# @retval string Generated FFS file name # @retval string Generated FFS file name
# #
def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None): def GenFfs(self, Dict = None, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):
if self.NameGuid and self.NameGuid.startswith('PCD('): if self.NameGuid and self.NameGuid.startswith('PCD('):
PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid) PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)
@ -70,6 +70,9 @@ class FileStatement (FileStatementClassObject):
if not os.path.exists(OutputDir): if not os.path.exists(OutputDir):
os.makedirs(OutputDir) os.makedirs(OutputDir)
if Dict is None:
Dict = {}
Dict.update(self.DefineVarDict) Dict.update(self.DefineVarDict)
SectionAlignments = None SectionAlignments = None
if self.FvName: if self.FvName:

View File

@ -437,11 +437,12 @@ class FfsInfStatement(FfsInfStatementClassObject):
# @param FvParentAddr Parent Fv base address # @param FvParentAddr Parent Fv base address
# @retval string Generated FFS file name # @retval string Generated FFS file name
# #
def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None, IsMakefile=False, FvName=None): def GenFfs(self, Dict = None, FvChildAddr = [], FvParentAddr=None, IsMakefile=False, FvName=None):
# #
# Parse Inf file get Module related information # Parse Inf file get Module related information
# #
if Dict is None:
Dict = {}
self.__InfParse__(Dict, IsGenFfs=True) self.__InfParse__(Dict, IsGenFfs=True)
Arch = self.GetCurrentArch() Arch = self.GetCurrentArch()
SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName); SrcFile = mws.join( GenFdsGlobalVariable.WorkSpaceDir, self.InfFileName);

View File

@ -71,9 +71,11 @@ class FV (object):
# @param MacroDict macro value pair # @param MacroDict macro value pair
# @retval string Generated FV file path # @retval string Generated FV file path
# #
def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', MacroDict = {}, Flag=False): def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', MacroDict = None, Flag=False):
if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict: if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict:
return GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] return GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv']
if MacroDict is None:
MacroDict = {}
# #
# Check whether FV in Capsule is in FD flash region. # Check whether FV in Capsule is in FD flash region.

View File

@ -47,9 +47,11 @@ class FvImageSection(FvImageSectionClassObject):
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# @retval tuple (Generated file name, section alignment) # @retval tuple (Generated file name, section alignment)
# #
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False): def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):
OutputFileList = [] OutputFileList = []
if Dict is None:
Dict = {}
if self.FvFileType is not None: if self.FvFileType is not None:
FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension) FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension)
if IsSect : if IsSect :

View File

@ -742,7 +742,7 @@ class GenFdsGlobalVariable:
# @param MacroDict Dictionary that contains macro value pair # @param MacroDict Dictionary that contains macro value pair
# #
@staticmethod @staticmethod
def MacroExtend (Str, MacroDict={}, Arch=DataType.TAB_COMMON): def MacroExtend (Str, MacroDict=None, Arch=DataType.TAB_COMMON):
if Str is None: if Str is None:
return None return None

View File

@ -50,7 +50,7 @@ class GuidSection(GuidSectionClassObject) :
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# @retval tuple (Generated file name, section alignment) # @retval tuple (Generated file name, section alignment)
# #
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile=False): def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile=False):
# #
# Generate all section # Generate all section
# #
@ -66,6 +66,8 @@ class GuidSection(GuidSectionClassObject) :
SectAlign = [] SectAlign = []
Index = 0 Index = 0
MaxAlign = None MaxAlign = None
if Dict is None:
Dict = {}
if self.FvAddr != []: if self.FvAddr != []:
FvAddrIsSet = True FvAddrIsSet = True
else: else:

View File

@ -34,7 +34,10 @@ class OptRomFileStatement:
# @param Dict dictionary contains macro and value pair # @param Dict dictionary contains macro and value pair
# @retval string Generated FFS file name # @retval string Generated FFS file name
# #
def GenFfs(self, Dict = {}, IsMakefile=False): def GenFfs(self, Dict = None, IsMakefile=False):
if Dict is None:
Dict = {}
if self.FileName is not None: if self.FileName is not None:
self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)

View File

@ -73,8 +73,10 @@ class Region(object):
# @retval string Generated FV file path # @retval string Generated FV file path
# #
def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, MacroDict={}, Flag=False): def AddToBuffer(self, Buffer, BaseAddress, BlockSizeList, ErasePolarity, ImageBinDict, MacroDict=None, Flag=False):
Size = self.Size Size = self.Size
if MacroDict is None:
MacroDict = {}
if not Flag: if not Flag:
GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset) GenFdsGlobalVariable.InfLogger('\nGenerate Region at Offset 0x%X' % self.Offset)
GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size) GenFdsGlobalVariable.InfLogger(" Region Size = 0x%X" % Size)

View File

@ -92,7 +92,7 @@ class Section (SectionClassObject):
# @param FfsInf FfsInfStatement object that contains this section data # @param FfsInf FfsInfStatement object that contains this section data
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# #
def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}): def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = None):
pass pass
## GetFileList() method ## GetFileList() method

View File

@ -44,7 +44,7 @@ class UiSection (UiSectionClassObject):
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# @retval tuple (Generated file name, section alignment) # @retval tuple (Generated file name, section alignment)
# #
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False): def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile = False):
# #
# Prepare the parameter of GenSection # Prepare the parameter of GenSection
# #
@ -58,6 +58,8 @@ class UiSection (UiSectionClassObject):
if self.StringData is not None : if self.StringData is not None :
NameString = self.StringData NameString = self.StringData
elif self.FileName is not None: elif self.FileName is not None:
if Dict is None:
Dict = {}
FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict) FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)
FileObj = open(FileNameStr, 'r') FileObj = open(FileNameStr, 'r')

View File

@ -42,7 +42,7 @@ class VerSection (VerSectionClassObject):
# @param Dict dictionary contains macro and its value # @param Dict dictionary contains macro and its value
# @retval tuple (Generated file name, section alignment) # @retval tuple (Generated file name, section alignment)
# #
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile = False): def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict=None, IsMakefile = False):
# #
# Prepare the parameter of GenSection # Prepare the parameter of GenSection
# #
@ -61,6 +61,8 @@ class VerSection (VerSectionClassObject):
if self.StringData: if self.StringData:
StringData = self.StringData StringData = self.StringData
elif self.FileName: elif self.FileName:
if Dict is None:
Dict = {}
FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict) FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict)
FileObj = open(FileNameStr, 'r') FileObj = open(FileNameStr, 'r')