BaseTools: remove redundant if comparison

inherently python will check string and list for None and having data

if <x> in [None, ''] and similar are superflous.

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>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Carsey, Jaben 2018-04-20 23:51:42 +08:00 committed by Yonghong Zhu
parent 1beb268a68
commit c93356ada9
6 changed files with 37 additions and 37 deletions

View File

@ -419,14 +419,14 @@ class WorkspaceAutoGen(AutoGen):
if BuildData.Pcds[key].Pending: if BuildData.Pcds[key].Pending:
if key in Platform.Pcds: if key in Platform.Pcds:
PcdInPlatform = Platform.Pcds[key] PcdInPlatform = Platform.Pcds[key]
if PcdInPlatform.Type not in [None, '']: if PcdInPlatform.Type:
BuildData.Pcds[key].Type = PcdInPlatform.Type BuildData.Pcds[key].Type = PcdInPlatform.Type
if BuildData.MetaFile in Platform.Modules: if BuildData.MetaFile in Platform.Modules:
PlatformModule = Platform.Modules[str(BuildData.MetaFile)] PlatformModule = Platform.Modules[str(BuildData.MetaFile)]
if key in PlatformModule.Pcds: if key in PlatformModule.Pcds:
PcdInPlatform = PlatformModule.Pcds[key] PcdInPlatform = PlatformModule.Pcds[key]
if PcdInPlatform.Type not in [None, '']: if PcdInPlatform.Type:
BuildData.Pcds[key].Type = PcdInPlatform.Type BuildData.Pcds[key].Type = PcdInPlatform.Type
if TAB_PCDS_DYNAMIC_EX in BuildData.Pcds[key].Type: if TAB_PCDS_DYNAMIC_EX in BuildData.Pcds[key].Type:
@ -1393,7 +1393,7 @@ class PlatformAutoGen(AutoGen):
for PcdFromModule in M.ModulePcdList + M.LibraryPcdList: for PcdFromModule in M.ModulePcdList + M.LibraryPcdList:
# make sure that the "VOID*" kind of datum has MaxDatumSize set # make sure that the "VOID*" kind of datum has MaxDatumSize set
if PcdFromModule.DatumType == TAB_VOID and PcdFromModule.MaxDatumSize in [None, '']: if PcdFromModule.DatumType == TAB_VOID and not PcdFromModule.MaxDatumSize:
NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F)) NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))
# Check the PCD from Binary INF or Source INF # Check the PCD from Binary INF or Source INF
@ -1470,7 +1470,7 @@ class PlatformAutoGen(AutoGen):
ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n" ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n"
% (PcdFromModule.Type, PcdFromModule.TokenCName, InfName)) % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName))
# make sure that the "VOID*" kind of datum has MaxDatumSize set # make sure that the "VOID*" kind of datum has MaxDatumSize set
if PcdFromModule.DatumType == TAB_VOID and PcdFromModule.MaxDatumSize in [None, '']: if PcdFromModule.DatumType == TAB_VOID and not PcdFromModule.MaxDatumSize:
NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName)) NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))
if M.ModuleType in SUP_MODULE_SET_PEI: if M.ModuleType in SUP_MODULE_SET_PEI:
PcdFromModule.Phase = "PEI" PcdFromModule.Phase = "PEI"
@ -1998,7 +1998,7 @@ class PlatformAutoGen(AutoGen):
BuildRuleFile = None BuildRuleFile = None
if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary: if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:
BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF] BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]
if BuildRuleFile in [None, '']: if not BuildRuleFile:
BuildRuleFile = gDefaultBuildRuleFile BuildRuleFile = gDefaultBuildRuleFile
self._BuildRule = BuildRule(BuildRuleFile) self._BuildRule = BuildRule(BuildRuleFile)
if self._BuildRule._FileVersion == "": if self._BuildRule._FileVersion == "":
@ -2326,13 +2326,13 @@ class PlatformAutoGen(AutoGen):
TokenCName = PcdItem[0] TokenCName = PcdItem[0]
break break
if FromPcd is not None: if FromPcd is not None:
if ToPcd.Pending and FromPcd.Type not in [None, '']: if ToPcd.Pending and FromPcd.Type:
ToPcd.Type = FromPcd.Type ToPcd.Type = FromPcd.Type
elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\ elif (ToPcd.Type) and (FromPcd.Type)\
and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type): and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):
if ToPcd.Type.strip() == TAB_PCDS_DYNAMIC_EX: if ToPcd.Type.strip() == TAB_PCDS_DYNAMIC_EX:
ToPcd.Type = FromPcd.Type ToPcd.Type = FromPcd.Type
elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \ elif ToPcd.Type and FromPcd.Type \
and ToPcd.Type != FromPcd.Type: and ToPcd.Type != FromPcd.Type:
EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type", EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",
ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\ ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
@ -2368,11 +2368,11 @@ class PlatformAutoGen(AutoGen):
ToPcd.validlists = FromPcd.validlists ToPcd.validlists = FromPcd.validlists
ToPcd.expressions = FromPcd.expressions ToPcd.expressions = FromPcd.expressions
if FromPcd is not None and ToPcd.DatumType == TAB_VOID and ToPcd.MaxDatumSize in ['', None]: if FromPcd is not None and ToPcd.DatumType == TAB_VOID and not ToPcd.MaxDatumSize:
EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \ EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \
% (ToPcd.TokenSpaceGuidCName, TokenCName)) % (ToPcd.TokenSpaceGuidCName, TokenCName))
Value = ToPcd.DefaultValue Value = ToPcd.DefaultValue
if Value in [None, '']: if not Value:
ToPcd.MaxDatumSize = '1' ToPcd.MaxDatumSize = '1'
elif Value[0] == 'L': elif Value[0] == 'L':
ToPcd.MaxDatumSize = str((len(Value) - 2) * 2) ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)
@ -2383,7 +2383,7 @@ class PlatformAutoGen(AutoGen):
# apply default SKU for dynamic PCDS if specified one is not available # apply default SKU for dynamic PCDS if specified one is not available
if (ToPcd.Type in PCD_DYNAMIC_TYPE_SET or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_SET) \ if (ToPcd.Type in PCD_DYNAMIC_TYPE_SET or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_SET) \
and ToPcd.SkuInfoList in [None, {}, '']: and not ToPcd.SkuInfoList:
if self.Platform.SkuName in self.Platform.SkuIds: if self.Platform.SkuName in self.Platform.SkuIds:
SkuName = self.Platform.SkuName SkuName = self.Platform.SkuName
else: else:
@ -2444,10 +2444,10 @@ class PlatformAutoGen(AutoGen):
# use PCD value to calculate the MaxDatumSize when it is not specified # use PCD value to calculate the MaxDatumSize when it is not specified
for Name, Guid in Pcds: for Name, Guid in Pcds:
Pcd = Pcds[Name, Guid] Pcd = Pcds[Name, Guid]
if Pcd.DatumType == TAB_VOID and Pcd.MaxDatumSize in ['', None]: if Pcd.DatumType == TAB_VOID and not Pcd.MaxDatumSize:
Pcd.MaxSizeUserSet = None Pcd.MaxSizeUserSet = None
Value = Pcd.DefaultValue Value = Pcd.DefaultValue
if Value in [None, '']: if not Value:
Pcd.MaxDatumSize = '1' Pcd.MaxDatumSize = '1'
elif Value[0] == 'L': elif Value[0] == 'L':
Pcd.MaxDatumSize = str((len(Value) - 2) * 2) Pcd.MaxDatumSize = str((len(Value) - 2) * 2)

View File

@ -866,7 +866,7 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
def GetPcdSize(Pcd): def GetPcdSize(Pcd):
if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES: if Pcd.DatumType not in TAB_PCD_NUMERIC_TYPES:
Value = Pcd.DefaultValue Value = Pcd.DefaultValue
if Value in [None, '']: if not Value:
return 1 return 1
elif Value[0] == 'L': elif Value[0] == 'L':
return (len(Value) - 2) * 2 return (len(Value) - 2) * 2

View File

@ -297,7 +297,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
# Check value, if value are equal, no need to patch # Check value, if value are equal, no need to patch
if Pcd.DatumType == TAB_VOID: if Pcd.DatumType == TAB_VOID:
if Pcd.InfDefaultValue == DefaultValue or DefaultValue in [None, '']: if Pcd.InfDefaultValue == DefaultValue or not DefaultValue:
continue continue
# Get the string size from FDF or DSC # Get the string size from FDF or DSC
if DefaultValue[0] == 'L': if DefaultValue[0] == 'L':
@ -310,7 +310,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
if DscOverride: if DscOverride:
Pcd.MaxDatumSize = PatchPcd.MaxDatumSize Pcd.MaxDatumSize = PatchPcd.MaxDatumSize
# If no defined the maximum size in DSC, try to get current size from INF # If no defined the maximum size in DSC, try to get current size from INF
if Pcd.MaxDatumSize in ['', None]: if not Pcd.MaxDatumSize:
Pcd.MaxDatumSize = str(len(Pcd.InfDefaultValue.split(','))) Pcd.MaxDatumSize = str(len(Pcd.InfDefaultValue.split(',')))
else: else:
Base1 = Base2 = 10 Base1 = Base2 = 10

View File

@ -102,7 +102,7 @@ class GenFdsGlobalVariable:
TargetTxt.LoadTargetTxtFile(BuildConfigurationFile) TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary: if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:
BuildRuleFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF] BuildRuleFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]
if BuildRuleFile in [None, '']: if not BuildRuleFile:
BuildRuleFile = 'Conf/build_rule.txt' BuildRuleFile = 'Conf/build_rule.txt'
GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile) GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)
ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF] ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
@ -441,15 +441,15 @@ class GenFdsGlobalVariable:
def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None, def GenerateSection(Output, Input, Type=None, CompressionType=None, Guid=None,
GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None, DummyFile=None, IsMakefile=False): GuidHdrLen=None, GuidAttr=[], Ui=None, Ver=None, InputAlign=None, BuildNumber=None, DummyFile=None, IsMakefile=False):
Cmd = ["GenSec"] Cmd = ["GenSec"]
if Type not in [None, '']: if Type:
Cmd += ["-s", Type] Cmd += ["-s", Type]
if CompressionType not in [None, '']: if CompressionType:
Cmd += ["-c", CompressionType] Cmd += ["-c", CompressionType]
if Guid is not None: if Guid is not None:
Cmd += ["-g", Guid] Cmd += ["-g", Guid]
if DummyFile is not None: if DummyFile is not None:
Cmd += ["--dummy", DummyFile] Cmd += ["--dummy", DummyFile]
if GuidHdrLen not in [None, '']: if GuidHdrLen:
Cmd += ["-l", GuidHdrLen] Cmd += ["-l", GuidHdrLen]
if len(GuidAttr) != 0: if len(GuidAttr) != 0:
#Add each guided attribute #Add each guided attribute
@ -461,7 +461,7 @@ class GenFdsGlobalVariable:
Cmd += ["--sectionalign", SecAlign] Cmd += ["--sectionalign", SecAlign]
CommandFile = Output + '.txt' CommandFile = Output + '.txt'
if Ui not in [None, '']: if Ui:
#Cmd += ["-n", '"' + Ui + '"'] #Cmd += ["-n", '"' + Ui + '"']
if IsMakefile: if IsMakefile:
if Ui == "$(MODULE_NAME)": if Ui == "$(MODULE_NAME)":
@ -480,7 +480,7 @@ class GenFdsGlobalVariable:
GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15) GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15)
SaveFileOnChange(Output, SectionData.tostring()) SaveFileOnChange(Output, SectionData.tostring())
elif Ver not in [None, '']: elif Ver:
Cmd += ["-n", Ver] Cmd += ["-n", Ver]
if BuildNumber: if BuildNumber:
Cmd += ["-j", BuildNumber] Cmd += ["-j", BuildNumber]
@ -529,7 +529,7 @@ class GenFdsGlobalVariable:
Cmd += ["-x"] Cmd += ["-x"]
if CheckSum: if CheckSum:
Cmd += ["-s"] Cmd += ["-s"]
if Align not in [None, '']: if Align:
if Align not in mFfsValidAlign: if Align not in mFfsValidAlign:
Align = GenFdsGlobalVariable.GetAlignment (Align) Align = GenFdsGlobalVariable.GetAlignment (Align)
for index in range(0, len(mFfsValidAlign) - 1): for index in range(0, len(mFfsValidAlign) - 1):
@ -541,7 +541,7 @@ class GenFdsGlobalVariable:
Cmd += ["-o", Output] Cmd += ["-o", Output]
for I in range(0, len(Input)): for I in range(0, len(Input)):
Cmd += ("-i", Input[I]) Cmd += ("-i", Input[I])
if SectionAlign not in [None, '', []] and SectionAlign[I] not in [None, '']: if SectionAlign and SectionAlign[I]:
Cmd += ("-n", SectionAlign[I]) Cmd += ("-n", SectionAlign[I])
CommandFile = Output + '.txt' CommandFile = Output + '.txt'
@ -566,7 +566,7 @@ class GenFdsGlobalVariable:
GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input)) GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
Cmd = ["GenFv"] Cmd = ["GenFv"]
if BaseAddress not in [None, '']: if BaseAddress:
Cmd += ["-r", BaseAddress] Cmd += ["-r", BaseAddress]
if ForceRebase == False: if ForceRebase == False:
@ -578,9 +578,9 @@ class GenFdsGlobalVariable:
Cmd += ["-c"] Cmd += ["-c"]
if Dump: if Dump:
Cmd += ["-p"] Cmd += ["-p"]
if AddressFile not in [None, '']: if AddressFile:
Cmd += ["-a", AddressFile] Cmd += ["-a", AddressFile]
if MapFile not in [None, '']: if MapFile:
Cmd += ["-m", MapFile] Cmd += ["-m", MapFile]
if FileSystemGuid: if FileSystemGuid:
Cmd += ["-g", FileSystemGuid] Cmd += ["-g", FileSystemGuid]
@ -597,7 +597,7 @@ class GenFdsGlobalVariable:
GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input)) GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
Cmd = ["GenVtf"] Cmd = ["GenVtf"]
if BaseAddress not in [None, ''] and FvSize not in [None, ''] \ if BaseAddress and FvSize \
and len(BaseAddress) == len(FvSize): and len(BaseAddress) == len(FvSize):
for I in range(0, len(BaseAddress)): for I in range(0, len(BaseAddress)):
Cmd += ["-r", BaseAddress[I], "-s", FvSize[I]] Cmd += ["-r", BaseAddress[I], "-s", FvSize[I]]
@ -618,13 +618,13 @@ class GenFdsGlobalVariable:
Cmd = ["GenFw"] Cmd = ["GenFw"]
if Type.lower() == "te": if Type.lower() == "te":
Cmd += ["-t"] Cmd += ["-t"]
if SubType not in [None, '']: if SubType:
Cmd += ["-e", SubType] Cmd += ["-e", SubType]
if TimeStamp not in [None, '']: if TimeStamp:
Cmd += ["-s", TimeStamp] Cmd += ["-s", TimeStamp]
if Align not in [None, '']: if Align:
Cmd += ["-a", Align] Cmd += ["-a", Align]
if Padding not in [None, '']: if Padding:
Cmd += ["-p", Padding] Cmd += ["-p", Padding]
if Zero: if Zero:
Cmd += ["-z"] Cmd += ["-z"]

View File

@ -635,10 +635,10 @@ class DscBuildData(PlatformBuildClassObject):
self._SkuIds = OrderedDict() self._SkuIds = OrderedDict()
RecordList = self._RawData[MODEL_EFI_SKU_ID, self._Arch] RecordList = self._RawData[MODEL_EFI_SKU_ID, self._Arch]
for Record in RecordList: for Record in RecordList:
if Record[0] in [None, '']: if not Record[0]:
EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number', EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number',
File=self.MetaFile, Line=Record[-1]) File=self.MetaFile, Line=Record[-1])
if Record[1] in [None, '']: if not Record[1]:
EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name', EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name',
File=self.MetaFile, Line=Record[-1]) File=self.MetaFile, Line=Record[-1])
if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]): if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]):
@ -663,10 +663,10 @@ class DscBuildData(PlatformBuildClassObject):
self.DefaultStores = OrderedDict() self.DefaultStores = OrderedDict()
RecordList = self._RawData[MODEL_EFI_DEFAULT_STORES, self._Arch] RecordList = self._RawData[MODEL_EFI_DEFAULT_STORES, self._Arch]
for Record in RecordList: for Record in RecordList:
if Record[0] in [None, '']: if not Record[0]:
EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID number', EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID number',
File=self.MetaFile, Line=Record[-1]) File=self.MetaFile, Line=Record[-1])
if Record[1] in [None, '']: if not Record[1]:
EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID name', EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID name',
File=self.MetaFile, Line=Record[-1]) File=self.MetaFile, Line=Record[-1])
if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]): if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]):

View File

@ -1116,7 +1116,7 @@ class InfBuildData(ModuleBuildClassObject):
Pcd.DatumType = PcdInPackage.DatumType Pcd.DatumType = PcdInPackage.DatumType
Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize
Pcd.InfDefaultValue = Pcd.DefaultValue Pcd.InfDefaultValue = Pcd.DefaultValue
if Pcd.DefaultValue in [None, '']: if not Pcd.DefaultValue:
Pcd.DefaultValue = PcdInPackage.DefaultValue Pcd.DefaultValue = PcdInPackage.DefaultValue
else: else:
try: try: