From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v1 09/11] BaseTools: refactor to stop re-allocating strings
Date: Mon, 14 May 2018 11:09:18 -0700 [thread overview]
Message-ID: <c0f6fa0f03dc85a12fd07544912ed8d04924932c.1526321053.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1526321052.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1526321052.git.jaben.carsey@intel.com>
strings are immutable. allocate minimal duplication.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
BaseTools/Source/Python/AutoGen/AutoGen.py | 94 +++++++++++---------
BaseTools/Source/Python/AutoGen/GenC.py | 2 +-
BaseTools/Source/Python/AutoGen/GenDepex.py | 15 ++--
BaseTools/Source/Python/AutoGen/GenMake.py | 6 +-
BaseTools/Source/Python/AutoGen/GenVar.py | 2 +-
BaseTools/Source/Python/AutoGen/IdfClassObject.py | 2 +-
BaseTools/Source/Python/AutoGen/StrGather.py | 4 +-
BaseTools/Source/Python/AutoGen/UniClassObject.py | 3 +-
BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py | 17 ++--
BaseTools/Source/Python/Common/Expression.py | 42 +++++----
BaseTools/Source/Python/Common/Misc.py | 8 +-
BaseTools/Source/Python/Common/String.py | 2 +-
BaseTools/Source/Python/CommonDataClass/CommonClass.py | 29 +++---
BaseTools/Source/Python/GenFds/Capsule.py | 19 ++--
BaseTools/Source/Python/GenFds/FdfParser.py | 8 +-
BaseTools/Source/Python/GenFds/FfsInfStatement.py | 8 +-
BaseTools/Source/Python/GenFds/Fv.py | 72 +++++----------
BaseTools/Source/Python/GenFds/GenFds.py | 4 +-
BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 24 ++---
BaseTools/Source/Python/GenFds/OptionRom.py | 2 -
BaseTools/Source/Python/GenFds/Vtf.py | 76 +++++-----------
BaseTools/Source/Python/Table/TableDataModel.py | 11 +--
BaseTools/Source/Python/Workspace/DscBuildData.py | 14 +--
BaseTools/Source/Python/Workspace/InfBuildData.py | 4 +-
BaseTools/Source/Python/Workspace/MetaDataTable.py | 10 +--
BaseTools/Source/Python/Workspace/MetaFileParser.py | 4 +-
26 files changed, 196 insertions(+), 286 deletions(-)
diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 599331060187..4ccb50a0a0af 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -815,42 +815,46 @@ class WorkspaceAutoGen(AutoGen):
_PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")")
PcdFoundFlag = False
for Pa in self.AutoGenObjectList:
- if not PcdFoundFlag:
- for PcdItem in Pa.AllPcdList:
- if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName:
+ #
+ # once found, get out of the loop
+ #
+ if PcdFoundFlag:
+ break
+ for PcdItem in Pa.AllPcdList:
+ if "{TSG}.{CN}".format(TSG=PcdItem.TokenSpaceGuidCName, CN=PcdItem.TokenCName) == _PcdName:
+ #
+ # First convert from CFormatGuid to GUID string
+ #
+ _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)
+
+ if not _PcdGuidString:
#
- # First convert from CFormatGuid to GUID string
+ # Then try Byte array.
#
- _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)
-
- if not _PcdGuidString:
- #
- # Then try Byte array.
- #
- _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)
+ _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)
- if not _PcdGuidString:
- #
- # Not Byte array or CFormat GUID, raise error.
- #
- EdkLogger.error("build",
- FORMAT_INVALID,
- "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue),
- ExtraData=self.FdfFile)
+ if not _PcdGuidString:
+ #
+ # Not Byte array or CFormat GUID, raise error.
+ #
+ EdkLogger.error("build",
+ FORMAT_INVALID,
+ "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue),
+ ExtraData=self.FdfFile)
- if _PcdGuidString.upper() not in _GuidDict:
- _GuidDict[_PcdGuidString.upper()] = FfsFile
- PcdFoundFlag = True
- break
- else:
- EdkLogger.error("build",
- FORMAT_INVALID,
- "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,
- FfsFile.CurrentLineContent,
- _GuidDict[_PcdGuidString.upper()].CurrentLineNum,
- _GuidDict[_PcdGuidString.upper()].CurrentLineContent,
- FfsFile.NameGuid.upper()),
- ExtraData=self.FdfFile)
+ if _PcdGuidString.upper() not in _GuidDict:
+ _GuidDict[_PcdGuidString.upper()] = FfsFile
+ PcdFoundFlag = True
+ break
+ else:
+ EdkLogger.error("build",
+ FORMAT_INVALID,
+ "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,
+ FfsFile.CurrentLineContent,
+ _GuidDict[_PcdGuidString.upper()].CurrentLineNum,
+ _GuidDict[_PcdGuidString.upper()].CurrentLineContent,
+ FfsFile.NameGuid.upper()),
+ ExtraData=self.FdfFile)
if FfsFile.NameGuid.upper() not in _GuidDict:
_GuidDict[FfsFile.NameGuid.upper()] = FfsFile
@@ -1832,13 +1836,13 @@ class PlatformAutoGen(AutoGen):
if os.path.isabs(self.OutputDir):
self._BuildDir = path.join(
path.abspath(self.OutputDir),
- self.BuildTarget + "_" + self.ToolChain,
+ "{BT}_{TC}".format(BT=self.BuildTarget, TC=self.ToolChain),
)
else:
self._BuildDir = path.join(
self.WorkspaceDir,
self.OutputDir,
- self.BuildTarget + "_" + self.ToolChain,
+ "{BT}_{TC}".format(BT=self.BuildTarget, TC=self.ToolChain),
)
GlobalData.gBuildDirectory = self._BuildDir
return self._BuildDir
@@ -1916,7 +1920,7 @@ class PlatformAutoGen(AutoGen):
Value = self.BuildOption[Tool][Attr][1:]
else:
if Attr != 'PATH':
- Value += " " + self.BuildOption[Tool][Attr]
+ Value = "{Val} {At}".format(Val=Value,At=self.BuildOption[Tool][Attr])
else:
Value = self.BuildOption[Tool][Attr]
@@ -1934,8 +1938,10 @@ class PlatformAutoGen(AutoGen):
ToolsDef += "\n"
SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)
- for DllPath in DllPathList:
- os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]
+ os.environ["PATH"]='{new}{sep}{start}'.format(
+ new=os.pathsep.join(DllPathList),
+ sep=os.pathsep,
+ start=os.environ["PATH"])
os.environ["MAKE_FLAGS"] = MakeFlags
return self._ToolDefinitions
@@ -1943,7 +1949,7 @@ class PlatformAutoGen(AutoGen):
## Return the paths of tools
def _GetToolDefFile(self):
if self._ToolDefFile is None:
- self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)
+ self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF.{ARCH}".format(ARCH=self.Arch))
return self._ToolDefFile
## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
@@ -2215,7 +2221,7 @@ class PlatformAutoGen(AutoGen):
LibraryInstance[LibraryClassName] = LibraryModule
LibraryConsumerList.append(LibraryModule)
- EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))
+ EdkLogger.verbose("\t{LCN}:{LM}".format(LCN=str(LibraryClassName), LM=str(LibraryModule)))
else:
LibraryModule = LibraryInstance[LibraryClassName]
@@ -2295,7 +2301,7 @@ class PlatformAutoGen(AutoGen):
#
for Item in LibraryList:
if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:
- ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join(str(L) for L in ConsumedByList[Item])
+ ErrorMessage = "\tconsumed by {LIST}".format(LIST="\n\tconsumed by ".join(str(L) for L in ConsumedByList[Item]))
EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),
ExtraData=ErrorMessage, File=self.MetaFile)
if Item not in SortedLibraryList:
@@ -2491,7 +2497,7 @@ class PlatformAutoGen(AutoGen):
if Library not in LibraryList:
LibraryList.append(Library)
LibraryConsumerList.append(Library)
- EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))
+ EdkLogger.verbose("\t{LN}:{LIB} {TYPE}".format(LN=LibraryName, LIB=str(Library), TYPE=str(type(Library))))
return LibraryList
## Calculate the priority value of the build option
@@ -2604,7 +2610,7 @@ class PlatformAutoGen(AutoGen):
else:
# append options for the same tool except PATH
if Attr != 'PATH':
- BuildOptions[Tool][Attr] += " " + Options[Key]
+ BuildOptions[Tool][Attr] = "{ORIG} {NEW}".format(ORIG=BuildOptions[Tool][Attr], NEW=Options[Key])
else:
BuildOptions[Tool][Attr] = Options[Key]
# Build Option Family has been checked, which need't to be checked again for family.
@@ -2639,7 +2645,7 @@ class PlatformAutoGen(AutoGen):
else:
# append options for the same tool except PATH
if Attr != 'PATH':
- BuildOptions[Tool][Attr] += " " + Options[Key]
+ BuildOptions[Tool][Attr] = "{ORIG} {NEW}".format(ORIG=BuildOptions[Tool][Attr], NEW=Options[Key])
else:
BuildOptions[Tool][Attr] = Options[Key]
return BuildOptions
@@ -2693,7 +2699,7 @@ class PlatformAutoGen(AutoGen):
BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:])
else:
if Attr != 'PATH':
- BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value)
+ BuildOptions[Tool][Attr] = "{ORIG} {NEW}".format(ORIG=BuildOptions[Tool][Attr], NEW=mws.handleWsMacro(Value))
else:
BuildOptions[Tool][Attr] = mws.handleWsMacro(Value)
diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py
index 46c7c1c1390b..e73d83395255 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -917,7 +917,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
TokenNumber = PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName]
AutoGenH.Append('\n#define %s %dU\n' % (PcdTokenName, TokenNumber))
- EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for " + TokenCName + "." + Pcd.TokenSpaceGuidCName)
+ EdkLogger.debug(EdkLogger.DEBUG_3, "Creating code for {TCN}.{CN}".format(TCN=TokenCName, CN=Pcd.TokenSpaceGuidCName))
if Pcd.Type not in gItemTypeStringDatabase:
EdkLogger.error("build", AUTOGEN_ERROR,
"Unknown PCD type [%s] of PCD %s.%s" % (Pcd.Type, Pcd.TokenSpaceGuidCName, TokenCName),
diff --git a/BaseTools/Source/Python/AutoGen/GenDepex.py b/BaseTools/Source/Python/AutoGen/GenDepex.py
index ed5df2b75440..873ed6e59300 100644
--- a/BaseTools/Source/Python/AutoGen/GenDepex.py
+++ b/BaseTools/Source/Python/AutoGen/GenDepex.py
@@ -156,19 +156,16 @@ class DependencyExpression:
EdkLogger.debug(EdkLogger.DEBUG_8, repr(self))
if Optimize:
self.Optimize()
- EdkLogger.debug(EdkLogger.DEBUG_8, "\n Optimized: " + repr(self))
+ EdkLogger.debug(EdkLogger.DEBUG_8, "\n Optimized: {ME}".format(ME=repr(self)))
def __str__(self):
return " ".join(self.TokenList)
def __repr__(self):
- WellForm = ''
- for Token in self.PostfixNotation:
- if Token in self.SupportedOpcode:
- WellForm += "\n " + Token
- else:
- WellForm += ' ' + Token
- return WellForm
+ return ''.join("{sep}{tok}".format(
+ tok=Token,
+ sep="\n " if Token in DependencyExpression.SupportedOpcode else ' ')
+ for Token in self.PostfixNotation)
## Split the expression string into token list
def GetExpressionTokenList(self):
@@ -359,11 +356,9 @@ class DependencyExpression:
else:
Buffer.write(self.GetGuidValue(Item))
- FilePath = ""
FileChangeFlag = True
if File is None:
sys.stdout.write(Buffer.getvalue())
- FilePath = "STDOUT"
else:
FileChangeFlag = SaveFileOnChange(File, Buffer.getvalue(), True)
diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index 30280d449f62..4ae977ccd400 100644
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -1029,7 +1029,7 @@ cleanlib:
with open(F.Path, 'r') as f:
FileContent = f.read()
except BaseException, X:
- EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))
+ EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData="{PATH}\n\t{VAL}".format(PATH=F.Path, VAL=str(X)))
if len(FileContent) == 0:
continue
@@ -1552,9 +1552,9 @@ class TopLevelMakefile(BuildFile):
else:
pcdname = '.'.join(pcd[0:2])
if pcd[3].startswith('{'):
- ExtraOption += " --pcd " + pcdname + '=' + 'H' + '"' + pcd[3] + '"'
+ ExtraOption = '{ORIG} --pcd {NAME}=H"{VAL}"'.format(NAME=pcdname, VAL=pcd[3], ORIG=ExtraOption)
else:
- ExtraOption += " --pcd " + pcdname + '=' + pcd[3]
+ ExtraOption = "{ORIG} --pcd {NAME}={VAL}".format(NAME=pcdname, VAL=pcd[3], ORIG=ExtraOption)
MakefileName = self._FILE_NAME_[self._FileType]
SubBuildCommandList = []
diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/Python/AutoGen/GenVar.py
index 2eab278d6876..35f022ac2e19 100644
--- a/BaseTools/Source/Python/AutoGen/GenVar.py
+++ b/BaseTools/Source/Python/AutoGen/GenVar.py
@@ -78,7 +78,7 @@ class VariableMgr(object):
value_list += [hex(unpack("B",data_byte)[0])]
newvalue[int(item.var_offset,16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = value_list
try:
- newvaluestr = "{" + ",".join(VariableMgr.assemble_variable(newvalue)) +"}"
+ newvaluestr = '{{{mid}}}'.format(mid=",".join(VariableMgr.assemble_variable(newvalue)))
except:
EdkLogger.error("build", AUTOGEN_ERROR, "Variable offset conflict in PCDs: %s \n" % (" and ".join(item.pcdname for item in sku_var_info_offset_list)))
n = sku_var_info_offset_list[0]
diff --git a/BaseTools/Source/Python/AutoGen/IdfClassObject.py b/BaseTools/Source/Python/AutoGen/IdfClassObject.py
index 8b84806f9f36..8a1f51daf435 100644
--- a/BaseTools/Source/Python/AutoGen/IdfClassObject.py
+++ b/BaseTools/Source/Python/AutoGen/IdfClassObject.py
@@ -121,7 +121,7 @@ def SearchImageID(ImageFileObject, FileList):
for Line in f:
ImageIdList = IMAGE_TOKEN.findall(Line)
for ID in ImageIdList:
- EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: " + ID)
+ EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: {id}".format(id=ID))
ImageFileObject.SetImageIDReferenced(ID)
class ImageFileObject(object):
diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py
index c0a39e4a12f1..bc5a23e9d920 100644
--- a/BaseTools/Source/Python/AutoGen/StrGather.py
+++ b/BaseTools/Source/Python/AutoGen/StrGather.py
@@ -110,7 +110,7 @@ def DecToHexStr(Dec, Digit = 8):
#
def DecToHexList(Dec, Digit = 8):
Hex = '{0:0{1}X}'.format(Dec,Digit)
- return ["0x" + Hex[Bit:Bit + 2] for Bit in range(Digit - 2, -1, -2)]
+ return ["0x{HEX}".format(HEX=Hex[Bit:Bit + 2]) for Bit in range(Digit - 2, -1, -2)]
## Convert a acsii string to a hex list
#
@@ -532,7 +532,7 @@ def SearchString(UniObjectClass, FileList, IsCompatibleMode):
with open(File, 'r') as f:
for Line in f:
for StrName in STRING_TOKEN.findall(Line):
- EdkLogger.debug(EdkLogger.DEBUG_5, "Found string identifier: " + StrName)
+ EdkLogger.debug(EdkLogger.DEBUG_5, "Found string identifier: {NAME}".format(NAME=StrName))
UniObjectClass.SetStringReferenced(StrName)
UniObjectClass.ReToken()
diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py
index bb37fbfd6a0c..73ca5b54778f 100644
--- a/BaseTools/Source/Python/AutoGen/UniClassObject.py
+++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py
@@ -161,8 +161,7 @@ class Ucs2Codec(codecs.Codec):
for Char in input:
CodePoint = ord(Char)
if CodePoint >= 0xd800 and CodePoint <= 0xdfff:
- raise ValueError("Code Point is in range reserved for " +
- "UTF-16 surrogate pairs")
+ raise ValueError("Code Point is in range reserved for UTF-16 surrogate pairs")
elif CodePoint > 0xffff:
raise ValueError("Code Point too large to encode in UCS-2")
return self.__utf16.encode(input)
diff --git a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
index 2c6bb8e396a9..b2a9bb1134ed 100644
--- a/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
+++ b/BaseTools/Source/Python/AutoGen/ValidCheckingInfoObject.py
@@ -186,7 +186,7 @@ class VAR_CHECK_PCD_VARIABLE_TAB(object):
self.Type = 0
self.Reserved = 0
self.Attributes = 0x00000000
- self.Guid = eval("[" + TokenSpaceGuid.replace("{", "").replace("}", "") + "]")
+ self.Guid = eval("[{GUID}]".format(GUID=TokenSpaceGuid.replace("{", "").replace("}", "")))
self.Name = PcdCName
self.validtab = []
@@ -258,7 +258,6 @@ class VAR_CHECK_PCD_VALID_LIST(VAR_CHECK_PCD_VALID_OBJ):
else:
self.data.add(int(valid_num))
-
self.Length = 5 + len(self.data) * self.StorageWidth
@@ -266,13 +265,10 @@ class VAR_CHECK_PCD_VALID_RANGE(VAR_CHECK_PCD_VALID_OBJ):
def __init__(self, VarOffset, validrange, PcdDataType):
super(VAR_CHECK_PCD_VALID_RANGE, self).__init__(VarOffset, validrange, PcdDataType)
self.Type = 2
- RangeExpr = ""
- i = 0
- for item in self.rawdata:
- if i == 0:
- RangeExpr = "( " + item + " )"
- else:
- RangeExpr = RangeExpr + "OR ( " + item + " )"
+ if self.rawdata:
+ RangeExpr = "( {ITEM} )".format(ITEM=self.rawdata[-1])
+ else:
+ RangeExpr = ""
range_result = RangeExpression(RangeExpr, self.PcdDataType)(True)
for rangelist in range_result:
for obj in rangelist.pop():
@@ -285,5 +281,4 @@ def GetValidationObject(PcdClass, VarOffset):
return VAR_CHECK_PCD_VALID_RANGE(VarOffset, PcdClass.validateranges, PcdClass.DatumType)
if PcdClass.validlists:
return VAR_CHECK_PCD_VALID_LIST(VarOffset, PcdClass.validlists, PcdClass.DatumType)
- else:
- return None
+ return None
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index e5d17e6b4de0..36f2654fc9cf 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -133,7 +133,7 @@ def BuildOptionValue(PcdValue, GuidDict):
elif PcdValue.startswith(("L'", "'")):
InputValue = PcdValue
elif PcdValue.startswith('L'):
- InputValue = 'L"' + PcdValue[1:] + '"'
+ InputValue = 'L"{VAL}"'.format(VAL=PcdValue[1:])
else:
InputValue = PcdValue
if IsFieldValueAnArray(InputValue):
@@ -178,7 +178,7 @@ def ReplaceExprMacro(String, Macros, ExceptionList = None):
# For example: DEFINE ARCH = IA32 X64
# $(ARCH) is replaced with "IA32 X64"
if ExceptionList and Macro in ExceptionList:
- RetStr += '"' + Macros[Macro] + '"'
+ RetStr = '{ORIG}"{MACRO}"'.format(MACRO=Macros[Macro], ORIG=RetStr)
elif Macros[Macro].strip():
RetStr += Macros[Macro]
else:
@@ -197,7 +197,7 @@ def IntToStr(Value):
while Value > 0:
StrList.append(chr(Value & 0xff))
Value = Value >> 8
- Value = '"' + ''.join(StrList) + '"'
+ Value = '"{VAL}"'.format(VAL=''.join(StrList))
return Value
SupportedInMacroList = ['TARGET', 'TOOL_CHAIN_TAG', 'ARCH', 'FAMILY']
@@ -223,17 +223,24 @@ class BaseExpression(object):
class ValueExpression(BaseExpression):
# Logical operator mapping
LogicalOperators = {
- '&&' : 'and', '||' : 'or',
- '!' : 'not', 'AND': 'and',
- 'OR' : 'or' , 'NOT': 'not',
- 'XOR': '^' , 'xor': '^',
- 'EQ' : '==' , 'NE' : '!=',
- 'GT' : '>' , 'LT' : '<',
- 'GE' : '>=' , 'LE' : '<=',
+ '&&' : 'and',
+ '||' : 'or',
+ '!' : 'not',
+ 'AND': 'and',
+ 'OR' : 'or',
+ 'NOT': 'not',
+ 'XOR': '^',
+ 'xor': '^',
+ 'EQ' : '==',
+ 'NE' : '!=',
+ 'GT' : '>',
+ 'LT' : '<',
+ 'GE' : '>=',
+ 'LE' : '<=',
'IN' : 'in'
}
- NonLetterOpLst = ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']
+ NonLetterOpLst = {'+', '-', '*', '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':'}
SymbolPattern = re.compile("("
@@ -710,18 +717,15 @@ class ValueExpression(BaseExpression):
if Expr.startswith('L"'):
# Skip L
self._Idx += 1
- UStr = self.__GetString()
- self._Token = 'L"' + UStr + '"'
+ self._Token = 'L"{STR}"'.format(STR=self.__GetString())
return self._Token
elif Expr.startswith("L'"):
# Skip L
self._Idx += 1
- UStr = self.__GetString()
- self._Token = "L'" + UStr + "'"
+ self._Token = "L'{STR}'".format(STR=self.__GetString())
return self._Token
elif Expr.startswith("'"):
- UStr = self.__GetString()
- self._Token = "'" + UStr + "'"
+ self._Token = "'{STR}'".format(STR=self.__GetString())
return self._Token
elif Expr.startswith('UINT'):
Re = re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)')
@@ -758,7 +762,7 @@ class ValueExpression(BaseExpression):
return self.__GetString()
elif Ch == '{':
return self.__GetArray()
- elif Ch == '(' or Ch == ')':
+ elif Ch in {'(', ')'}:
self._Idx += 1
self._Token = Ch
return self._Token
@@ -768,7 +772,7 @@ class ValueExpression(BaseExpression):
# Parse operator
def _GetOperator(self):
self.__SkipWS()
- LegalOpLst = ['&&', '||', '!=', '==', '>=', '<='] + self.NonLetterOpLst + ['?',':']
+ LegalOpLst = {'&&', '||', '!=', '==', '>=', '<=', '?', ':'}.union(self.NonLetterOpLst)
self._Token = ''
Expr = self._Expr[self._Idx:]
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index 0bfb26548d9b..bfb6e56a923f 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -713,7 +713,7 @@ class TemplateString(object):
self._SubSectionList = [TemplateSection]
def __str__(self):
- return self._Template + " : " + str(self._PlaceHolderList)
+ return "{TEM} : {LIST}".format(TEM=self._Template, LIST=str(self._PlaceHolderList))
def Instantiate(self, PlaceHolderValues):
RepeatTime = -1
@@ -894,7 +894,7 @@ class Progressor:
TimeUp = self.Interval
time.sleep(self._CheckInterval)
TimeUp -= self._CheckInterval
- sys.stdout.write(" " + self.CodaMessage + "\n")
+ sys.stdout.write(" {MSG}\n".format(MSG=self.CodaMessage))
sys.stdout.flush()
## Abort the progress display
@@ -1313,7 +1313,7 @@ def ParseFieldValue (Value):
if Value[0] == '"' and Value[-1] == '"':
Value = Value[1:-1]
try:
- Value = "'" + uuid.UUID(Value).get_bytes_le() + "'"
+ Value = "'{GUID}'".format(GUID=uuid.UUID(Value).get_bytes_le())
except ValueError, Message:
raise BadExpression('%s' % Message)
Value, Size = ParseFieldValue(Value)
@@ -2050,7 +2050,7 @@ class SkuClass():
ArrayStrList.append(hex(int(self.AvailableSkuIds[skuname])))
skuname = self.GetNextSkuId(skuname)
ArrayStrList.append("0x0")
- ArrayStr = "{" + ",".join(ArrayStrList) + "}"
+ ArrayStr = "{{{ARRAY}}}".format(ARRAY=",".join(ArrayStrList))
return ArrayStr
def __GetAvailableSkuIds(self):
return self.AvailableSkuIds
diff --git a/BaseTools/Source/Python/Common/String.py b/BaseTools/Source/Python/Common/String.py
index 34361ecdd58c..1516e6c2ae9c 100644
--- a/BaseTools/Source/Python/Common/String.py
+++ b/BaseTools/Source/Python/Common/String.py
@@ -712,7 +712,7 @@ def RaiseParserError(Line, Section, File, Format='', LineNo= -1):
LineNo = GetLineNo(open(os.path.normpath(File), 'r').read(), Line)
ErrorMsg = "Invalid statement '%s' is found in section '%s'" % (Line, Section)
if Format != '':
- Format = "Correct format is " + Format
+ Format = "Correct format is {FMT}".format(FMT=Format)
EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=File, Line=LineNo, ExtraData=Format, RaiseError=EdkLogger.IsRaiseError)
## WorkspaceFile
diff --git a/BaseTools/Source/Python/CommonDataClass/CommonClass.py b/BaseTools/Source/Python/CommonDataClass/CommonClass.py
index e29f5211d5c7..d7123fe91ee1 100644
--- a/BaseTools/Source/Python/CommonDataClass/CommonClass.py
+++ b/BaseTools/Source/Python/CommonDataClass/CommonClass.py
@@ -35,16 +35,14 @@
# @var DefaultValue: To store value for DefaultValue
#
class SkuInfoClass(object):
- def __init__(self, SkuIdName = '', SkuId = '', VariableName = '', VariableGuid = '', VariableOffset = '',
- HiiDefaultValue = '', VpdOffset = '', DefaultValue = '', VariableGuidValue = '', VariableAttribute = '', DefaultStore = None):
+ def __init__(self, SkuIdName = '', SkuId = '', VariableName = '', VariableGuid = '', VariableOffset = '',
+ HiiDefaultValue = '', VpdOffset = '', DefaultValue = '', VariableGuidValue = '', VariableAttribute = '', DefaultStore = {}):
self.SkuIdName = SkuIdName
self.SkuId = SkuId
#
# Used by Hii
#
- if DefaultStore is None:
- DefaultStore = {}
self.VariableName = VariableName
self.VariableGuid = VariableGuid
self.VariableGuidValue = VariableGuidValue
@@ -68,15 +66,18 @@ class SkuInfoClass(object):
# Convert each member of the class to string
# Organize to a signle line format string
#
- # @retval Rtn Formatted String
+ # @retval Formatted String
#
def __str__(self):
- Rtn = 'SkuId = ' + str(self.SkuId) + "," + \
- 'SkuIdName = ' + str(self.SkuIdName) + "," + \
- 'VariableName = ' + str(self.VariableName) + "," + \
- 'VariableGuid = ' + str(self.VariableGuid) + "," + \
- 'VariableOffset = ' + str(self.VariableOffset) + "," + \
- 'HiiDefaultValue = ' + str(self.HiiDefaultValue) + "," + \
- 'VpdOffset = ' + str(self.VpdOffset) + "," + \
- 'DefaultValue = ' + str(self.DefaultValue) + ","
- return Rtn
+ return 'SkuId = {SKUID},SkuIdName = {SKUNAME},'\
+ 'VariableName = {VARNAME},VariableGuid = {VARGUID},'\
+ 'VariableOffset = {VAROFFSET},HiiDefaultValue = {DEF},'\
+ 'VpdOffset = {OFFSET},DefaultValue = {DEF2},'.format(
+ SKUID=self.SkuId,
+ SKUNAME=self.SkuIdName,
+ VARNAME=self.VariableName,
+ VARGUID=self.VariableGuid,
+ VAROFFSET=self.VariableOffset,
+ DEF=self.HiiDefaultValue,
+ OFFSET=self.VpdOffset,
+ DEF2=self.DefaultValue)
diff --git a/BaseTools/Source/Python/GenFds/Capsule.py b/BaseTools/Source/Python/GenFds/Capsule.py
index 6aae2fcb7d97..ab5ea9fc0dd0 100644
--- a/BaseTools/Source/Python/GenFds/Capsule.py
+++ b/BaseTools/Source/Python/GenFds/Capsule.py
@@ -28,9 +28,8 @@ from struct import pack
from GenFds import FindExtendTool
from Common import EdkLogger
from Common.BuildToolError import *
+from Common.DataType import TAB_LINE_BREAK
-
-T_CHAR_LF = '\n'
WIN_CERT_REVISION = 0x0200
WIN_CERT_TYPE_EFI_GUID = 0x0EF1
EFI_CERT_TYPE_PKCS7_GUID = uuid.UUID('{4aafd29d-68df-49ee-8aa9-347d375665a7}')
@@ -209,16 +208,14 @@ class Capsule (CapsuleClassObject) :
return self.GenFmpCapsule()
CapInfFile = self.GenCapInf()
- CapInfFile.writelines("[files]" + T_CHAR_LF)
+ CapInfFile.writelines("[files]{END}".format(END=TAB_LINE_BREAK))
CapFileList = []
for CapsuleDataObj in self.CapsuleDataList :
CapsuleDataObj.CapsuleName = self.CapsuleName
FileName = CapsuleDataObj.GenCapsuleSubItem()
CapsuleDataObj.CapsuleName = None
CapFileList.append(FileName)
- CapInfFile.writelines("EFI_FILE_NAME = " + \
- FileName + \
- T_CHAR_LF)
+ CapInfFile.writelines("EFI_FILE_NAME = {NAME}{END}".format(NAME=FileName, END=TAB_LINE_BREAK))
SaveFileOnChange(self.CapInfFileName, CapInfFile.getvalue(), False)
CapInfFile.close()
#
@@ -245,16 +242,12 @@ class Capsule (CapsuleClassObject) :
#
def GenCapInf(self):
self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
- self.UiCapsuleName + "_Cap" + '.inf')
+ "{NAME}_Cap.inf".format(NAME=self.UiCapsuleName))
CapInfFile = StringIO.StringIO()
- CapInfFile.writelines("[options]" + T_CHAR_LF)
+ CapInfFile.writelines("[options]{END}".format(END=TAB_LINE_BREAK))
for Item in self.TokensDict:
- CapInfFile.writelines("EFI_" + \
- Item + \
- ' = ' + \
- self.TokensDict[Item] + \
- T_CHAR_LF)
+ CapInfFile.writelines("EFI_{ITEM} = {ENTRY}{END}".format(ITEM=Item, ENTRY=self.TokensDict[Item], END=TAB_LINE_BREAK))
return CapInfFile
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index d511cf4f9d5a..55348083b954 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -2019,9 +2019,9 @@ class FdfParser:
AllStrLen = len (AllString)
DataString = ""
while AllStrLen > 4:
- DataString = DataString + "0x" + AllString[AllStrLen - 2: AllStrLen] + ","
+ DataString = "{ORIG}0x{VAL},".format(ORIG=DataString, VAL=AllString[AllStrLen - 2: AllStrLen])
AllStrLen = AllStrLen - 2
- DataString = DataString + AllString[:AllStrLen] + ","
+ DataString = "{ORIG}{VAL},".format(ORIG=DataString, VAL=AllString[:AllStrLen])
# byte value array
if len (self.__Token) <= 4:
@@ -2059,9 +2059,9 @@ class FdfParser:
AllStrLen = len (AllString)
DataString = ""
while AllStrLen > 4:
- DataString = DataString + "0x" + AllString[AllStrLen - 2: AllStrLen] + ","
+ DataString = "{ORIG}0x{VAL},".format(ORIG=DataString, VAL=AllString[AllStrLen - 2: AllStrLen])
AllStrLen = AllStrLen - 2
- DataString = DataString + AllString[:AllStrLen] + ","
+ DataString = "{ORIG}{VAL},".format(ORIG=DataString, VAL=AllString[:AllStrLen])
# byte value array
if len (self.__Token) <= 4:
diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index 39426b939b4a..e4276c3a8c07 100644
--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
@@ -361,7 +361,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
os.makedirs(self.OutputPath)
self.EfiOutputPath, self.EfiDebugPath = self.__GetEFIOutPutPath__()
- GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: " + self.EfiOutputPath)
+ GenFdsGlobalVariable.VerboseLogger( "ModuelEFIPath: {PATH}".format(PATH=self.EfiOutputPath))
## PatchEfiFile
#
@@ -564,7 +564,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
Rule = GenFdsGlobalVariable.FdfParser.Profile.RuleDict.get(RuleName)
if Rule is not None:
- GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : " + RuleName)
+ GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : {NAME}".format(NAME=RuleName))
return Rule
RuleName = 'RULE' + \
@@ -582,7 +582,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
Rule = GenFdsGlobalVariable.FdfParser.Profile.RuleDict.get(RuleName)
if Rule is not None:
- GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : " + RuleName)
+ GenFdsGlobalVariable.VerboseLogger ("Want To Find Rule Name is : {NAME}".format(NAME=RuleName))
return Rule
if Rule is None :
@@ -634,7 +634,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
CurArchList = TargetArchList
if PlatformArchList != []:
CurArchList = list(set (TargetArchList) & set (PlatformArchList))
- GenFdsGlobalVariable.VerboseLogger ("Valid target architecture(s) is : " + " ".join(CurArchList))
+ GenFdsGlobalVariable.VerboseLogger ("Valid target architecture(s) is : {ARCH}".format(ARCH=" ".join(CurArchList)))
ArchList = []
if self.KeyStringList != []:
diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py
index d4b0611fc55a..c672f1d7d8fa 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -108,9 +108,7 @@ class FV (FvClassObject):
FfsFileList.append(FileName)
# Add Apriori file name to Inf file
if not Flag:
- self.FvInfFile.writelines("EFI_FILE_NAME = " + \
- FileName + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_FILE_NAME = {FN}{END}".format(FN=FileName, END=TAB_LINE_BREAK))
# Process Modules in FfsList
for FfsFile in self.FfsList :
@@ -122,9 +120,7 @@ class FV (FvClassObject):
FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress, IsMakefile=Flag, FvName=self.UiFvName)
FfsFileList.append(FileName)
if not Flag:
- self.FvInfFile.writelines("EFI_FILE_NAME = " + \
- FileName + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_FILE_NAME = {FN}{END}".format(FN=FileName, END=TAB_LINE_BREAK))
if not Flag:
SaveFileOnChange(self.InfFileName, self.FvInfFile.getvalue(), False)
self.FvInfFile.close()
@@ -267,67 +263,46 @@ class FV (FvClassObject):
#
# Add [Options]
#
- self.FvInfFile.writelines("[options]" + TAB_LINE_BREAK)
+ self.FvInfFile.writelines("[options]{END}".format(END=TAB_LINE_BREAK))
if BaseAddress is not None :
- self.FvInfFile.writelines("EFI_BASE_ADDRESS = " + \
- BaseAddress + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_BASE_ADDRESS = {BA}{END}".format(BA=BaseAddress,END=TAB_LINE_BREAK))
if BlockSize is not None:
- self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \
- '0x%X' %BlockSize + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x{BS:x}{END}".format(BS=BlockSize,END=TAB_LINE_BREAK))
if BlockNum is not None:
- self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \
- ' 0x%X' %BlockNum + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_NUM_BLOCKS = 0x{BN:x}{END}".format(BN=BlockNum, END=TAB_LINE_BREAK))
else:
if self.BlockSizeList == []:
if not self._GetBlockSize():
#set default block size is 1
- self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x1" + TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x1{END}".format(END=TAB_LINE_BREAK))
for BlockSize in self.BlockSizeList :
if BlockSize[0] is not None:
- self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \
- '0x%X' %BlockSize[0] + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_BLOCK_SIZE = 0x{BS:x}{END}".format(BS=BlockSize[0], END=TAB_LINE_BREAK))
if BlockSize[1] is not None:
- self.FvInfFile.writelines("EFI_NUM_BLOCKS = " + \
- ' 0x%X' %BlockSize[1] + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_NUM_BLOCKS = 0x{BN:x}{END}".format(BN=BlockSize[1], END=TAB_LINE_BREAK))
if self.BsBaseAddress is not None:
- self.FvInfFile.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = ' + \
- '0x%X' %self.BsBaseAddress)
+ self.FvInfFile.writelines('EFI_BOOT_DRIVER_BASE_ADDRESS = 0x{BA:x}'.format(BA=self.BsBaseAddress))
if self.RtBaseAddress is not None:
- self.FvInfFile.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = ' + \
- '0x%X' %self.RtBaseAddress)
+ self.FvInfFile.writelines('EFI_RUNTIME_DRIVER_BASE_ADDRESS = 0x{BA:x}'.format(BA=self.RtBaseAddress))
#
# Add attribute
#
- self.FvInfFile.writelines("[attributes]" + TAB_LINE_BREAK)
+ self.FvInfFile.writelines("[attributes]{END}".format(END=TAB_LINE_BREAK))
- self.FvInfFile.writelines("EFI_ERASE_POLARITY = " + \
- ' %s' %ErasePloarity + \
- TAB_LINE_BREAK)
- if not (self.FvAttributeDict is None):
+ self.FvInfFile.writelines("EFI_ERASE_POLARITY = {EP}{END}".format(EP=ErasePloarity, END=TAB_LINE_BREAK))
+ if self.FvAttributeDict:
for FvAttribute in self.FvAttributeDict.keys() :
if FvAttribute == "FvUsedSizeEnable":
- if self.FvAttributeDict[FvAttribute].upper() in ('TRUE', '1') :
+ if self.FvAttributeDict[FvAttribute].upper() in {'TRUE', '1'}:
self.UsedSizeEnable = True
continue
- self.FvInfFile.writelines("EFI_" + \
- FvAttribute + \
- ' = ' + \
- self.FvAttributeDict[FvAttribute] + \
- TAB_LINE_BREAK )
- if self.FvAlignment is not None:
- self.FvInfFile.writelines("EFI_FVB2_ALIGNMENT_" + \
- self.FvAlignment.strip() + \
- " = TRUE" + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_{FA} = {VAL}{END}".format(FA=FvAttribute, VAL=self.FvAttributeDict[FvAttribute], END=TAB_LINE_BREAK))
+ if self.FvAlignment:
+ self.FvInfFile.writelines("EFI_FVB2_ALIGNMENT_{FA} = TRUE{END}".format(FA=self.FvAlignment.strip(), END=TAB_LINE_BREAK))
#
# Generate FV extension header file
@@ -410,16 +385,11 @@ class FV (FvClassObject):
if Changed:
if os.path.exists (self.InfFileName):
os.remove (self.InfFileName)
- self.FvInfFile.writelines("EFI_FV_EXT_HEADER_FILE_NAME = " + \
- FvExtHeaderFileName + \
- TAB_LINE_BREAK)
-
+ self.FvInfFile.writelines("EFI_FV_EXT_HEADER_FILE_NAME = {NAME}{END}".format(NAME=FvExtHeaderFileName, END=TAB_LINE_BREAK))
#
# Add [Files]
#
- self.FvInfFile.writelines("[files]" + TAB_LINE_BREAK)
+ self.FvInfFile.writelines("[files]{END}".format(END=TAB_LINE_BREAK))
if VtfDict and self.UiFvName in VtfDict:
- self.FvInfFile.writelines("EFI_FILE_NAME = " + \
- VtfDict[self.UiFvName] + \
- TAB_LINE_BREAK)
+ self.FvInfFile.writelines("EFI_FILE_NAME = {NAME}{END}".format(NAME=VtfDict[self.UiFvName], END=TAB_LINE_BREAK))
diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py
index f0b51e25dfa2..998bd5345c3c 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -95,7 +95,7 @@ def main():
if 'EDK_SOURCE' in os.environ:
GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE'])
if (Options.debug):
- GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace)
+ GenFdsGlobalVariable.VerboseLogger("Using Workspace: {WKSP}".format(WKSP=Workspace))
if Options.GenfdsMultiThread:
GenFdsGlobalVariable.EnableGenfdsMultiThread = True
os.chdir(GenFdsGlobalVariable.WorkSpaceDir)
@@ -207,7 +207,7 @@ def main():
GlobalData.gEdkSource = List[1].strip()
GlobalData.gGlobalDefines["EDK_SOURCE"] = GlobalData.gEdkSource
continue
- elif List[0].strip() in ["WORKSPACE", "TARGET", "TOOLCHAIN"]:
+ elif List[0].strip() in {"WORKSPACE", "TARGET", "TOOLCHAIN"}:
GlobalData.gGlobalDefines[List[0].strip()] = List[1].strip()
else:
GlobalData.gCommandLineDefines[List[0].strip()] = List[1].strip()
diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
index 8537800bc2b2..b840079e7ad4 100644
--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
@@ -295,7 +295,6 @@ class GenFdsGlobalVariable:
if not os.path.exists(GenFdsGlobalVariable.FfsDir) :
os.makedirs(GenFdsGlobalVariable.FfsDir)
- T_CHAR_LF = '\n'
#
# Create FV Address inf file
#
@@ -313,13 +312,9 @@ class GenFdsGlobalVariable:
#
# Add [Options]
#
- FvAddressFile.writelines("[options]" + T_CHAR_LF)
- FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
- BsAddress + \
- T_CHAR_LF)
- FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
- RtAddress + \
- T_CHAR_LF)
+ FvAddressFile.writelines("[options]{END}".format(END=DataType.TAB_LINE_BREAK))
+ FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = {BS}{END}".format(BS=BsAddress, END=DataType.TAB_LINE_BREAK))
+ FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = {RT}{END}".format(RT=RtAddress, END=DataType.TAB_LINE_BREAK))
def SetEnv(FdfParser, WorkSpace, ArchList, GlobalData):
@@ -352,7 +347,6 @@ class GenFdsGlobalVariable:
if not os.path.exists(GenFdsGlobalVariable.FfsDir):
os.makedirs(GenFdsGlobalVariable.FfsDir)
- T_CHAR_LF = '\n'
#
# Create FV Address inf file
#
@@ -376,13 +370,9 @@ class GenFdsGlobalVariable:
#
# Add [Options]
#
- FvAddressFile.writelines("[options]" + T_CHAR_LF)
- FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \
- BsAddress + \
- T_CHAR_LF)
- FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \
- RtAddress + \
- T_CHAR_LF)
+ FvAddressFile.writelines("[options]{END}".format(END=DataType.TAB_LINE_BREAK))
+ FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = {BS}{END}".format(BS=BsAddress, END=DataType.TAB_LINE_BREAK))
+ FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = {RT}{END}".format(RT=RtAddress, END=DataType.TAB_LINE_BREAK))
## ReplaceWorkspaceMacro()
#
@@ -692,7 +682,7 @@ class GenFdsGlobalVariable:
if " ".join(Cmd).strip() not in GenFdsGlobalVariable.SecCmdList:
GenFdsGlobalVariable.SecCmdList.append(" ".join(Cmd).strip())
else:
- GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call " + ToolPath, returnValue)
+ GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to call {PATH}".format(PATH=ToolPath), returnValue)
def CallExternalTool (cmd, errorMess, returnValue=[]):
diff --git a/BaseTools/Source/Python/GenFds/OptionRom.py b/BaseTools/Source/Python/GenFds/OptionRom.py
index b05841529940..0b8e79588ff1 100644
--- a/BaseTools/Source/Python/GenFds/OptionRom.py
+++ b/BaseTools/Source/Python/GenFds/OptionRom.py
@@ -27,8 +27,6 @@ from Common.Misc import SaveFileOnChange
from Common import EdkLogger
from Common.BuildToolError import *
-T_CHAR_LF = '\n'
-
##
#
#
diff --git a/BaseTools/Source/Python/GenFds/Vtf.py b/BaseTools/Source/Python/GenFds/Vtf.py
index 291070827b78..6016b6d94e94 100644
--- a/BaseTools/Source/Python/GenFds/Vtf.py
+++ b/BaseTools/Source/Python/GenFds/Vtf.py
@@ -19,7 +19,7 @@ from GenFdsGlobalVariable import GenFdsGlobalVariable
import Common.LongFilePathOs as os
from CommonDataClass.FdfClass import VtfClassObject
from Common.LongFilePathSupport import OpenLongFilePath as open
-T_CHAR_LF = '\n'
+from Common.DataType import TAB_LINE_BREAK
## generate VTF
#
@@ -43,7 +43,7 @@ class Vtf (VtfClassObject):
#
def GenVtf(self, FdAddressDict) :
self.GenBsfInf()
- OutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiName + '.Vtf')
+ OutputFile = os.path.join(GenFdsGlobalVariable.FvDir, '{NAME}.Vtf'.format(self.UiName))
BaseAddArg = self.GetBaseAddressArg(FdAddressDict)
OutputArg, VtfRawDict = self.GenOutputArg()
@@ -69,77 +69,43 @@ class Vtf (VtfClassObject):
self.BsfInfName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiName + '.inf')
with open(self.BsfInfName, 'w') as BsfInf:
if self.ResetBin is not None:
- BsfInf.writelines ("[OPTIONS]" + T_CHAR_LF)
- BsfInf.writelines ("IA32_RST_BIN" + \
- " = " + \
- GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.ResetBin)) + \
- T_CHAR_LF)
- BsfInf.writelines (T_CHAR_LF)
+ BsfInf.writelines ("[OPTIONS]{END}".format(END=TAB_LINE_BREAK))
+ BsfInf.writelines ("IA32_RST_BIN = {DATA}{END}".format(
+ DATA=GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.ResetBin)),
+ END=TAB_LINE_BREAK))
+ BsfInf.writelines (TAB_LINE_BREAK)
- BsfInf.writelines ("[COMPONENTS]" + T_CHAR_LF)
+ BsfInf.writelines ("[COMPONENTS]{END}".format(END=TAB_LINE_BREAK))
for ComponentObj in self.ComponentStatementList :
- BsfInf.writelines ("COMP_NAME" + \
- " = " + \
- ComponentObj.CompName + \
- T_CHAR_LF)
+ BsfInf.writelines ("COMP_NAME = {DATA}{END}".format(DATA=ComponentObj.CompName,END=TAB_LINE_BREAK))
+
if ComponentObj.CompLoc.upper() == 'NONE':
- BsfInf.writelines ("COMP_LOC" + \
- " = " + \
- 'N' + \
- T_CHAR_LF)
-
+ BsfInf.writelines ("COMP_LOC = N{END}".format(END=TAB_LINE_BREAK))
elif ComponentObj.FilePos is not None:
- BsfInf.writelines ("COMP_LOC" + \
- " = " + \
- ComponentObj.FilePos + \
- T_CHAR_LF)
+ BsfInf.writelines ("COMP_LOC = {POS}{END}".format(POS=ComponentObj.FilePos, END=TAB_LINE_BREAK))
else:
Index = FvList.index(ComponentObj.CompLoc.upper())
if Index == 0:
- BsfInf.writelines ("COMP_LOC" + \
- " = " + \
- 'F' + \
- T_CHAR_LF)
+ BsfInf.writelines ("COMP_LOC = F{END}".format(END=TAB_LINE_BREAK))
elif Index == 1:
- BsfInf.writelines ("COMP_LOC" + \
- " = " + \
- 'S' + \
- T_CHAR_LF)
+ BsfInf.writelines ("COMP_LOC = S{END}".format(END=TAB_LINE_BREAK))
- BsfInf.writelines ("COMP_TYPE" + \
- " = " + \
- ComponentObj.CompType + \
- T_CHAR_LF)
- BsfInf.writelines ("COMP_VER" + \
- " = " + \
- ComponentObj.CompVer + \
- T_CHAR_LF)
- BsfInf.writelines ("COMP_CS" + \
- " = " + \
- ComponentObj.CompCs + \
- T_CHAR_LF)
+ BsfInf.writelines ("COMP_TYPE = {DATA}{END}".format(DATA=ComponentObj.CompType,END=TAB_LINE_BREAK))
+ BsfInf.writelines ("COMP_VER = {DATA}{END}".format(DATA=ComponentObj.CompVer,END=TAB_LINE_BREAK))
+ BsfInf.writelines ("COMP_CS = {DATA}{END}".format(DATA=ComponentObj.CompCs,END=TAB_LINE_BREAK))
BinPath = ComponentObj.CompBin
if BinPath != '-':
BinPath = GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(BinPath))
- BsfInf.writelines ("COMP_BIN" + \
- " = " + \
- BinPath + \
- T_CHAR_LF)
+ BsfInf.writelines ("COMP_BIN = {DATA}{END}".format(DATA=BinPath, END=TAB_LINE_BREAK))
SymPath = ComponentObj.CompSym
if SymPath != '-':
SymPath = GenFdsGlobalVariable.MacroExtend(GenFdsGlobalVariable.ReplaceWorkspaceMacro(SymPath))
- BsfInf.writelines ("COMP_SYM" + \
- " = " + \
- SymPath + \
- T_CHAR_LF)
- BsfInf.writelines ("COMP_SIZE" + \
- " = " + \
- ComponentObj.CompSize + \
- T_CHAR_LF)
- BsfInf.writelines (T_CHAR_LF)
+ BsfInf.writelines ("COMP_SYM = {DATA}{END}".format(DATA=SymPath, END=TAB_LINE_BREAK))
+ BsfInf.writelines ("COMP_SIZE = {DATA}{END}".format(DATA=ComponentObj.CompSiz, END=TAB_LINE_BREAK))
+ BsfInf.writelines (TAB_LINE_BREAK)
## GenFvList() method
#
diff --git a/BaseTools/Source/Python/Table/TableDataModel.py b/BaseTools/Source/Python/Table/TableDataModel.py
index 9c3d7bd9345f..ec47b9f37097 100644
--- a/BaseTools/Source/Python/Table/TableDataModel.py
+++ b/BaseTools/Source/Python/Table/TableDataModel.py
@@ -1,7 +1,7 @@
## @file
# This file is used to create/update/query/erase table for data models
#
-# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -60,7 +60,7 @@ class TableDataModel(Table):
def Insert(self, CrossIndex, Name, Description):
self.ID = self.ID + 1
(Name, Description) = ConvertToSqlString((Name, Description))
- SqlCommand = """insert into %s values(%s, %s, '%s', '%s')""" % (self.Table, self.ID, CrossIndex, Name, Description)
+ SqlCommand = "insert into %s values(%s, %s, '%s', '%s')" % (self.Table, self.ID, CrossIndex, Name, Description)
Table.Insert(self, SqlCommand)
return self.ID
@@ -87,9 +87,6 @@ class TableDataModel(Table):
#
def GetCrossIndex(self, ModelName):
CrossIndex = -1
- SqlCommand = """select CrossIndex from DataModel where name = '""" + ModelName + """'"""
+ SqlCommand = "select CrossIndex from DataModel where name = '{NAME}'".format(NAME=ModelName)
self.Cur.execute(SqlCommand)
- for Item in self.Cur:
- CrossIndex = Item[0]
-
- return CrossIndex
+ return self.Cur[-1][0]
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index d714c781e970..7b062b564da5 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -220,7 +220,7 @@ class DscBuildData(PlatformBuildClassObject):
@property
def OutputPath(self):
if os.getenv("WORKSPACE"):
- return os.path.join(os.getenv("WORKSPACE"), self.OutputDirectory, self._Target + "_" + self._Toolchain,PcdValueInitName)
+ return os.path.join(os.getenv("WORKSPACE"), self.OutputDirectory, "{TGT}_{TC}".format(TGT=self._Target, TC=self._Toolchain),PcdValueInitName)
else:
return os.path.dirname(self.DscFile)
@@ -762,7 +762,7 @@ class DscBuildData(PlatformBuildClassObject):
Module.BuildOptions[ToolChainFamily, ToolChain] = Option
else:
OptionString = Module.BuildOptions[ToolChainFamily, ToolChain]
- Module.BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
+ Module.BuildOptions[ToolChainFamily, ToolChain] = "{OPT1} {OPT2}".format(OPT1=OptionString, OPT2=Option)
RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, None, ModuleId]
if DuplicatedFile and not RecordList:
@@ -1539,7 +1539,7 @@ class DscBuildData(PlatformBuildClassObject):
if not FieldList:
continue
for FieldName in FieldList:
- FieldName = "." + FieldName
+ FieldName = ".{ORIG}".format(ORIG=FieldName)
IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])
if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):
try:
@@ -1569,7 +1569,7 @@ class DscBuildData(PlatformBuildClassObject):
if not FieldList:
continue
for FieldName in FieldList:
- FieldName = "." + FieldName
+ FieldName = ".{ORIG}".format(ORIG=FieldName)
IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])
if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')):
try:
@@ -1593,7 +1593,7 @@ class DscBuildData(PlatformBuildClassObject):
if Pcd.PcdFieldValueFromComm:
CApp = CApp + "// From Command Line \n"
for FieldName in Pcd.PcdFieldValueFromComm:
- FieldName = "." + FieldName
+ FieldName = ".{ORIG}".format(ORIG=FieldName)
IsArray = IsFieldValueAnArray(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0])
if IsArray and not (Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].startswith('{GUID') and Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].endswith('}')):
try:
@@ -2043,7 +2043,7 @@ class DscBuildData(PlatformBuildClassObject):
else:
# append options for the same tool except PATH
if Attr != 'PATH':
- BuildOptions[Tool][Attr] += " " + self.BuildOptions[Options]
+ BuildOptions[Tool][Attr] = "{ORIG} {NEW}".format(ORIG=BuildOptions[Tool][Attr], NEW=self.BuildOptions[Options])
else:
BuildOptions[Tool][Attr] = self.BuildOptions[Options]
if BuildOptions:
@@ -2054,7 +2054,7 @@ class DscBuildData(PlatformBuildClassObject):
ValueList = Value.split()
if ValueList:
for Id, Item in enumerate(ValueList):
- if Item in ['-D', '/D', '-U', '/U']:
+ if Item in {'-D', '/D', '-U', '/U'}:
CC_FLAGS += ' ' + Item
if Id + 1 < len(ValueList):
CC_FLAGS += ' ' + ValueList[Id + 1]
diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py b/BaseTools/Source/Python/Workspace/InfBuildData.py
index 12d848b5fc41..3d9391039f4f 100644
--- a/BaseTools/Source/Python/Workspace/InfBuildData.py
+++ b/BaseTools/Source/Python/Workspace/InfBuildData.py
@@ -395,7 +395,7 @@ class InfBuildData(ModuleBuildClassObject):
self._BuildOptions[ToolChainFamily, ToolChain] = Value
else:
OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
- self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Value
+ self._BuildOptions[ToolChainFamily, ToolChain] = "{OPTION} {VAL}".format(OPTION=OptionString, VAL=Value)
# set _Header to non-None in order to avoid database re-querying
self._Header_ = 'DUMMY'
@@ -863,7 +863,7 @@ class InfBuildData(ModuleBuildClassObject):
else:
# concatenate the option string if they're for the same tool
OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
- self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
+ self._BuildOptions[ToolChainFamily, ToolChain] = "{OPTION} {OPT}".format(OPTION=OptionString, OPT=Option)
return self._BuildOptions
## Retrieve dependency expression
diff --git a/BaseTools/Source/Python/Workspace/MetaDataTable.py b/BaseTools/Source/Python/Workspace/MetaDataTable.py
index e37a10c82f8f..83963008ef4c 100644
--- a/BaseTools/Source/Python/Workspace/MetaDataTable.py
+++ b/BaseTools/Source/Python/Workspace/MetaDataTable.py
@@ -22,7 +22,7 @@ from CommonDataClass.DataClass import FileClass
## Convert to SQL required string format
def ConvertToSqlString(StringList):
- return map(lambda s: "'" + s.replace("'", "''") + "'", StringList)
+ return map(lambda s: "'{mid}'".format(mid=s.replace("'", "''")), StringList)
## TableFile
#
@@ -329,10 +329,6 @@ class TableDataModel(Table):
#
def GetCrossIndex(self, ModelName):
CrossIndex = -1
- SqlCommand = """select CrossIndex from DataModel where name = '""" + ModelName + """'"""
+ SqlCommand = "select CrossIndex from DataModel where name = '{NAME}'".format(NAME=ModelName)
self.Cur.execute(SqlCommand)
- for Item in self.Cur:
- CrossIndex = Item[0]
-
- return CrossIndex
-
+ return self.Cur[-1][0]
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index 21b20bce4018..2c116ddbcb71 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -1924,10 +1924,10 @@ class DecParser(MetaFileParser):
return
if self._include_flag:
- self._ValueList[1] = "<HeaderFiles>_" + md5.new(self._CurrentLine).hexdigest()
+ self._ValueList[1] = "<HeaderFiles>_{MD5}".format(MD5=md5.new(self._CurrentLine).hexdigest())
self._ValueList[2] = self._CurrentLine
if self._package_flag and "}" != self._CurrentLine:
- self._ValueList[1] = "<Packages>_" + md5.new(self._CurrentLine).hexdigest()
+ self._ValueList[1] = "<Packages>_{MD5}".format(MD5=md5.new(self._CurrentLine).hexdigest())
self._ValueList[2] = self._CurrentLine
if self._CurrentLine == "}":
self._package_flag = False
--
2.16.2.windows.1
next prev parent reply other threads:[~2018-05-14 18:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-14 18:09 [PATCH v1 00/11] BaseTools refactoring Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 01/11] BaseTools: decorate base classes to prevent instantiation Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 02/11] BaseTools: Workspace - create a base class Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 03/11] BaseTools: remove unused code Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 04/11] BaseTools: remove repeated calls to startswith/endswith Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 05/11] BaseTools: use set presence instead of series of equality Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 06/11] BaseTools: refactor section generation Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 07/11] BaseTools: refactor file opening/writing Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 08/11] BaseTools: refactor to change object types Jaben Carsey
2018-05-14 18:09 ` Jaben Carsey [this message]
2018-05-14 18:09 ` [PATCH v1 10/11] BaseTools: change to set for membership testing Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 11/11] BaseTools: remove extra assignment Jaben Carsey
-- strict thread matches above, loose matches on Subject: below --
2018-06-20 21:08 [PATCH v2 00/11] BaseTools Refactoring Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 09/11] BaseTools: refactor to stop re-allocating strings Jaben Carsey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c0f6fa0f03dc85a12fd07544912ed8d04924932c.1526321053.git.jaben.carsey@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox