diff options
author | Carsey, Jaben <jaben.carsey@intel.com> | 2018-04-17 22:40:15 +0800 |
---|---|---|
committer | Yonghong Zhu <yonghong.zhu@intel.com> | 2018-04-18 22:15:36 +0800 |
commit | 9eb87141eca12b1f15afa4b769af04d1395891c6 (patch) | |
tree | 82ac481092b68ea3684f94bf7dc90c3c584aea52 /BaseTools/Source/Python/AutoGen | |
parent | 55c84777ee638be8735a5c421941e7eb71633bdf (diff) | |
download | edk2-9eb87141eca12b1f15afa4b769af04d1395891c6.tar.gz edk2-9eb87141eca12b1f15afa4b769af04d1395891c6.tar.bz2 edk2-9eb87141eca12b1f15afa4b769af04d1395891c6.zip |
BaseTools: refactor and remove un-needed use of .keys() on dictionaries
sometimes just delete it.
sometimes the loop needed .values() instead
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>
Diffstat (limited to 'BaseTools/Source/Python/AutoGen')
-rw-r--r-- | BaseTools/Source/Python/AutoGen/AutoGen.py | 32 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/GenMake.py | 24 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/GenVar.py | 2 | ||||
-rw-r--r-- | BaseTools/Source/Python/AutoGen/InfSectionParser.py | 6 |
4 files changed, 31 insertions, 33 deletions
diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index bd443fe626..6152225943 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -762,7 +762,7 @@ class WorkspaceAutoGen(AutoGen): for Module in Pa.ModuleAutoGenList:
if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName):
InfFoundFlag = True
- if not Module.Guid.upper() in _GuidDict.keys():
+ if Module.Guid.upper() not in _GuidDict:
_GuidDict[Module.Guid.upper()] = FfsFile
break
else:
@@ -789,7 +789,7 @@ class WorkspaceAutoGen(AutoGen): # BuildObject from one of AutoGenObjectList is enough.
#
InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, TAB_COMMON, self.BuildTarget, self.ToolChain]
- if not InfObj.Guid.upper() in _GuidDict.keys():
+ if InfObj.Guid.upper() not in _GuidDict:
_GuidDict[InfObj.Guid.upper()] = FfsFile
else:
EdkLogger.error("build",
@@ -837,7 +837,7 @@ class WorkspaceAutoGen(AutoGen): "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue),
ExtraData=self.FdfFile)
- if not _PcdGuidString.upper() in _GuidDict.keys():
+ if _PcdGuidString.upper() not in _GuidDict:
_GuidDict[_PcdGuidString.upper()] = FfsFile
PcdFoundFlag = True
break
@@ -851,7 +851,7 @@ class WorkspaceAutoGen(AutoGen): FfsFile.NameGuid.upper()),
ExtraData=self.FdfFile)
- if not FfsFile.NameGuid.upper() in _GuidDict.keys():
+ if FfsFile.NameGuid.upper() not in _GuidDict:
_GuidDict[FfsFile.NameGuid.upper()] = FfsFile
else:
#
@@ -1402,10 +1402,8 @@ class PlatformAutoGen(AutoGen): PcdFromModule.IsFromBinaryInf = True
# Check the PCD from DSC or not
- if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys():
- PcdFromModule.IsFromDsc = True
- else:
- PcdFromModule.IsFromDsc = False
+ PcdFromModule.IsFromDsc = (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds
+
if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:
if F.Path not in FdfModuleList:
# If one of the Source built modules listed in the DSC is not listed
@@ -1532,8 +1530,8 @@ class PlatformAutoGen(AutoGen): VpdFile = VpdInfoFile.VpdInfoFile()
NeedProcessVpdMapFile = False
- for pcd in self.Platform.Pcds.keys():
- if pcd not in self._PlatformPcds.keys():
+ for pcd in self.Platform.Pcds:
+ if pcd not in self._PlatformPcds:
self._PlatformPcds[pcd] = self.Platform.Pcds[pcd]
for item in self._PlatformPcds:
@@ -1543,7 +1541,7 @@ class PlatformAutoGen(AutoGen): if (self.Workspace.ArchList[-1] == self.Arch):
for Pcd in self._DynamicPcdList:
# just pick the a value to determine whether is unicode string type
- Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]
+ Sku = Pcd.SkuInfoList.values()[0]
Sku.VpdOffset = Sku.VpdOffset.strip()
if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:
@@ -1630,7 +1628,7 @@ class PlatformAutoGen(AutoGen): if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:
if not (self.Platform.VpdToolGuid is None or self.Platform.VpdToolGuid == ''):
FoundFlag = False
- for VpdPcd in VpdFile._VpdArray.keys():
+ for VpdPcd in VpdFile._VpdArray:
# This PCD has been referenced by module
if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \
(VpdPcd.TokenCName == DscPcdEntry.TokenCName):
@@ -1742,7 +1740,7 @@ class PlatformAutoGen(AutoGen): # Delete the DynamicPcdList At the last time enter into this function
for Pcd in self._DynamicPcdList:
# just pick the a value to determine whether is unicode string type
- Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]
+ Sku = Pcd.SkuInfoList.values()[0]
Sku.VpdOffset = Sku.VpdOffset.strip()
if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:
@@ -2482,7 +2480,7 @@ class PlatformAutoGen(AutoGen): for LibraryName in M.Libraries:
Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']
if Library is None:
- for Key in self.Platform.LibraryClasses.data.keys():
+ for Key in self.Platform.LibraryClasses.data:
if LibraryName.upper() == Key.upper():
Library = self.Platform.LibraryClasses[Key, ':dummy:']
break
@@ -3105,7 +3103,7 @@ class ModuleAutoGen(AutoGen): InfObj = InfSectionParser.InfSectionParser(Filename)
DepexExpresionList = InfObj.GetDepexExpresionList()
for DepexExpresion in DepexExpresionList:
- for key in DepexExpresion.keys():
+ for key in DepexExpresion:
Arch, ModuleType = key
DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')]
# the type of build module is USER_DEFINED.
@@ -3123,7 +3121,7 @@ class ModuleAutoGen(AutoGen): #the type of build module is USER_DEFINED.
if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:
for Depex in DepexList:
- for key in Depex.keys():
+ for key in Depex:
DepexStr += '[Depex.%s.%s]\n' % key
DepexStr += '\n'.join(['# '+ val for val in Depex[key]])
DepexStr += '\n\n'
@@ -3233,7 +3231,7 @@ class ModuleAutoGen(AutoGen): InfObj = InfSectionParser.InfSectionParser(Filename)
TianoCoreUserExtenList = InfObj.GetUserExtensionTianoCore()
for TianoCoreUserExtent in TianoCoreUserExtenList:
- for Section in TianoCoreUserExtent.keys():
+ for Section in TianoCoreUserExtent:
ItemList = Section.split(TAB_SPLIT)
Arch = self.Arch
if len(ItemList) == 4:
diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index b7594d8988..1bb5163e73 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -495,11 +495,11 @@ cleanlib: if k not in self._AutoGenObject.Macros:
self._AutoGenObject.Macros[k] = v
- if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():
+ if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros:
self._AutoGenObject.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint
- if 'ARCH_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():
+ if 'ARCH_ENTRY_POINT' not in self._AutoGenObject.Macros:
self._AutoGenObject.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint
- if 'IMAGE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():
+ if 'IMAGE_ENTRY_POINT' not in self._AutoGenObject.Macros:
self._AutoGenObject.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint
PCI_COMPRESS_Flag = False
@@ -540,7 +540,7 @@ cleanlib: RespFileList = os.path.join(self._AutoGenObject.OutputDir, 'respfilelist.txt')
if RespDict:
RespFileListContent = ''
- for Resp in RespDict.keys():
+ for Resp in RespDict:
RespFile = os.path.join(self._AutoGenObject.OutputDir, str(Resp).lower() + '.txt')
StrList = RespDict[Resp].split(' ')
UnexpandMacro = []
@@ -794,7 +794,7 @@ cleanlib: SingleCommandLength = len(SingleCommand)
SingleCommandList = SingleCommand.split()
if len(SingleCommandList) > 0:
- for Flag in FlagDict.keys():
+ for Flag in FlagDict:
if '$('+ Flag +')' in SingleCommandList[0]:
Tool = Flag
break
@@ -807,12 +807,12 @@ cleanlib: if 'FLAGS' not in self._AutoGenObject._BuildOption[Tool]:
EdkLogger.error("build", AUTOGEN_ERROR, "%s_FLAGS doesn't exist in %s ToolChain and %s Arch." %(Tool, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch), ExtraData="[%s]" % str(self._AutoGenObject))
Str = self._AutoGenObject._BuildOption[Tool]['FLAGS']
- for Option in self._AutoGenObject.BuildOption.keys():
+ for Option in self._AutoGenObject.BuildOption:
for Attr in self._AutoGenObject.BuildOption[Option]:
if Str.find(Option + '_' + Attr) != -1:
Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])
while(Str.find('$(') != -1):
- for macro in self._AutoGenObject.Macros.keys():
+ for macro in self._AutoGenObject.Macros:
MacroName = '$('+ macro + ')'
if (Str.find(MacroName) != -1):
Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro])
@@ -824,12 +824,12 @@ cleanlib: SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject._IncludePathList)
elif item.find('$(') != -1:
Str = item
- for Option in self._AutoGenObject.BuildOption.keys():
+ for Option in self._AutoGenObject.BuildOption:
for Attr in self._AutoGenObject.BuildOption[Option]:
if Str.find(Option + '_' + Attr) != -1:
Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])
while(Str.find('$(') != -1):
- for macro in self._AutoGenObject.Macros.keys():
+ for macro in self._AutoGenObject.Macros:
MacroName = '$('+ macro + ')'
if (Str.find(MacroName) != -1):
Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro])
@@ -842,19 +842,19 @@ cleanlib: FlagDict[Tool]['Value'] = True
# generate the response file content by combine the FLAGS and INC
- for Flag in FlagDict.keys():
+ for Flag in FlagDict:
if FlagDict[Flag]['Value']:
Key = Flag + '_RESP'
RespMacro = FlagDict[Flag]['Macro'].replace('FLAGS', 'RESP')
Value = self._AutoGenObject.BuildOption[Flag]['FLAGS']
for inc in self._AutoGenObject._IncludePathList:
Value += ' ' + IncPrefix + inc
- for Option in self._AutoGenObject.BuildOption.keys():
+ for Option in self._AutoGenObject.BuildOption:
for Attr in self._AutoGenObject.BuildOption[Option]:
if Value.find(Option + '_' + Attr) != -1:
Value = Value.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr])
while (Value.find('$(') != -1):
- for macro in self._AutoGenObject.Macros.keys():
+ for macro in self._AutoGenObject.Macros:
MacroName = '$('+ macro + ')'
if (Value.find(MacroName) != -1):
Value = Value.replace(MacroName, self._AutoGenObject.Macros[macro])
diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/Python/AutoGen/GenVar.py index 1c66a9eb05..37c168a84b 100644 --- a/BaseTools/Source/Python/AutoGen/GenVar.py +++ b/BaseTools/Source/Python/AutoGen/GenVar.py @@ -114,8 +114,8 @@ class VariableMgr(object): self.VarInfo = [item[0] for item in indexedvarinfo.values()]
def assemble_variable(self, valuelist):
- ordered_value = [valuelist[k] for k in sorted(valuelist.keys())]
ordered_offset = sorted(valuelist.keys())
+ ordered_value = [valuelist[k] for k in ordered_offset]
var_value = []
num = 0
for offset in ordered_offset:
diff --git a/BaseTools/Source/Python/AutoGen/InfSectionParser.py b/BaseTools/Source/Python/AutoGen/InfSectionParser.py index cdc9e5e8a8..cf4e76159e 100644 --- a/BaseTools/Source/Python/AutoGen/InfSectionParser.py +++ b/BaseTools/Source/Python/AutoGen/InfSectionParser.py @@ -1,7 +1,7 @@ ## @file
# Parser a Inf file and Get specify section data.
#
-# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 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
@@ -70,7 +70,7 @@ class InfSectionParser(): if not self._FileSectionDataList:
return UserExtensionTianoCore
for SectionDataDict in self._FileSectionDataList:
- for key in SectionDataDict.keys():
+ for key in SectionDataDict:
if key.lower().startswith("[userextensions") and key.lower().find('.tianocore.') > -1:
SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END)
SubSectionList = [SectionLine]
@@ -89,7 +89,7 @@ class InfSectionParser(): if not self._FileSectionDataList:
return DepexExpresionList
for SectionDataDict in self._FileSectionDataList:
- for key in SectionDataDict.keys():
+ for key in SectionDataDict:
if key.lower() == "[depex]" or key.lower().startswith("[depex."):
SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END)
SubSectionList = [SectionLine]
|