From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5FFC3226838E7 for ; Wed, 18 Apr 2018 01:48:07 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Apr 2018 01:48:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,464,1517904000"; d="scan'208";a="48810540" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga001.jf.intel.com with ESMTP; 18 Apr 2018 01:48:06 -0700 Received: from fmsmsx122.amr.corp.intel.com (10.18.125.37) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 18 Apr 2018 01:48:06 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx122.amr.corp.intel.com (10.18.125.37) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 18 Apr 2018 01:48:06 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.79]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.40]) with mapi id 14.03.0319.002; Wed, 18 Apr 2018 16:48:03 +0800 From: "Zhu, Yonghong" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH v1 1/3] BaseTools: refactor and remove more keys() usage Thread-Index: AQHT0NcQWWjEz2FQk0ugglkRCNAKD6QGPeDw Date: Wed, 18 Apr 2018 08:48:03 +0000 Message-ID: References: <5a483778fbfbd93317b013c0109324950a05990f.1523369916.git.jaben.carsey@intel.com> In-Reply-To: <5a483778fbfbd93317b013c0109324950a05990f.1523369916.git.jaben.carsey@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v1 1/3] BaseTools: refactor and remove more keys() usage X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Apr 2018 08:48:09 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Jaben, One bug on this patch. Original code it use PcdCName, now it change to use = PcdName , it will cause PcdObject incorrect. - PcdsKeys =3D PcdValueDict.keys() - for PcdCName, TokenSpaceGuid in PcdsKeys: - - PcdSetting =3D PcdValueDict[PcdCName, TokenSpaceGuid] + for ((PcdName,TokenSpaceGuid),PcdSetting) in PcdValueDict.iteritem= s(): Best Regards, Zhu Yonghong -----Original Message----- From: Carsey, Jaben=20 Sent: Tuesday, April 10, 2018 10:20 PM To: edk2-devel@lists.01.org Cc: Gao, Liming ; Zhu, Yonghong Subject: [PATCH v1 1/3] BaseTools: refactor and remove more keys() usage this is no longer required to make dictionary objects iterable. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Workspace/DscBuildData.py | 59 +++++++++----------= - 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index cf9608651269..35ef15262a09 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -593,7 +593,7 @@ class DscBuildData(PlatformBuildClassObject): # # If command line defined, should override the value in DSC file. # - if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines= .keys(): + if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines= : try: self._LoadFixAddress =3D int(GlobalData.gCommandLineDefine= s['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0) except: @@ -682,9 +682,7 @@ class DscBuildData(PlatformBuildClassObject): self.DefaultStores[Record[1].upper()] =3D (self.ToInt(Reco= rd[0]),Record[1].upper()) if TAB_DEFAULT_STORES_DEFAULT not in self.DefaultStores: self.DefaultStores[TAB_DEFAULT_STORES_DEFAULT] =3D (0,TAB_= DEFAULT_STORES_DEFAULT) - GlobalData.gDefaultStores =3D self.DefaultStores.keys() - if GlobalData.gDefaultStores: - GlobalData.gDefaultStores.sort() + GlobalData.gDefaultStores =3D=20 + sorted(self.DefaultStores.keys()) return self.DefaultStores =20 ## Retrieve [Components] section information @@ -1430,11 +1428,11 @@ c= lass DscBuildData(PlatformBuildClassObject): =20 for pcdkey in Pcds: pcd =3D Pcds[pcdkey] - if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in= pcd.SkuInfoList.keys(): + if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.Sk= uInfoList: pcd.SkuInfoList['DEFAULT'] =3D pcd.SkuInfoList['COMMON= '] - del(pcd.SkuInfoList['COMMON']) - elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in p= cd.SkuInfoList.keys(): - del(pcd.SkuInfoList['COMMON']) + del pcd.SkuInfoList['COMMON'] + elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuI= nfoList: + del pcd.SkuInfoList['COMMON'] =20 map(self.FilterSkuSettings,[Pcds[pcdkey] for pcdkey in Pcds if Pcd= s[pcdkey].Type in DynamicPcdType]) return Pcds @@ -1479,10 +1477,7 @@ class DscBuildData(PlatformBuildClassObject): else: PcdValueDict[PcdCName, TokenSpaceGuid] =3D {SkuName:(PcdVa= lue, DatumType, MaxDatumSize)} =20 - PcdsKeys =3D PcdValueDict.keys() - for PcdCName, TokenSpaceGuid in PcdsKeys: - - PcdSetting =3D PcdValueDict[PcdCName, TokenSpaceGuid] + for ((PcdName,TokenSpaceGuid),PcdSetting) in PcdValueDict.iteritem= s(): PcdValue =3D None DatumType =3D None MaxDatumSize =3D None @@ -1883,7 +1878,7 @@ class DscBuildData(PlatformBuildClassObject): OverrideValues =3D {DefaultStore:""} if Pcd.SkuOverrideValues: OverrideValues =3D Pcd.SkuOverrideValues[SkuName] - for DefaultStoreName in OverrideValues.keys(): + for DefaultStoreName in OverrideValues: CApp =3D CApp + 'void\n' CApp =3D CApp + 'Initialize_%s_%s_%s_%s(\n' % (SkuName, Defaul= tStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) CApp =3D CApp + ' void\n' @@ -2261,7 +2256,7 @@ class DscBuildData(PlatformBuildClassObject): =20 PcdValue, DatumType, MaxDatumSize =3D self._ValidatePcd(PcdCNa= me, TokenSpaceGuid, Setting, Type, Dummy4) SkuInfo =3D SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '',= '', '', '', '', PcdValue) - if (PcdCName, TokenSpaceGuid) in Pcds.keys(): + if (PcdCName, TokenSpaceGuid) in Pcds: pcdObject =3D Pcds[PcdCName, TokenSpaceGuid] pcdObject.SkuInfoList[SkuName] =3D SkuInfo if MaxDatumSize.strip(): @@ -2294,15 +2289,15 @@ class DscBuildData(PlatformBuildClassObject): for sku in pcd.SkuInfoList.values(): if (sku.DefaultValue =3D=3D "" or sku.DefaultValue=3D=3DNo= ne): sku.DefaultValue =3D pcdDecObject.DefaultValue - if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in= pcd.SkuInfoList.keys(): + if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.Sk= uInfoList: valuefromDec =3D pcdDecObject.DefaultValue SkuInfo =3D SkuInfoClass('DEFAULT', '0', '', '', '', '', '= ', valuefromDec) pcd.SkuInfoList['DEFAULT'] =3D SkuInfo - elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in p= cd.SkuInfoList.keys(): + elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuI= nfoList: pcd.SkuInfoList['DEFAULT'] =3D pcd.SkuInfoList['COMMON'] - del(pcd.SkuInfoList['COMMON']) - elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.S= kuInfoList.keys(): - del(pcd.SkuInfoList['COMMON']) + del pcd.SkuInfoList['COMMON'] + elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoL= ist: + del pcd.SkuInfoList['COMMON'] =20 map(self.FilterSkuSettings,Pcds.values()) =20 @@ -2311,7 +2306,7 @@ class DscBuildData(PlatformBuildClassObject): def FilterSkuSettings(self, PcdObj): =20 if self.SkuIdMgr.SkuUsageType =3D=3D self.SkuIdMgr.SINGLE: - if 'DEFAULT' in PcdObj.SkuInfoList.keys() and self.SkuIdMgr.Sy= stemSkuId not in PcdObj.SkuInfoList.keys(): + if 'DEFAULT' in PcdObj.SkuInfoList and self.SkuIdMgr.SystemSku= Id not in PcdObj.SkuInfoList: PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId] =3D PcdObj.S= kuInfoList['DEFAULT'] PcdObj.SkuInfoList =3D {'DEFAULT':PcdObj.SkuInfoList[self.SkuI= dMgr.SystemSkuId]} PcdObj.SkuInfoList['DEFAULT'].SkuIdName =3D 'DEFAULT' @@ -2465,7 +2460,7 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFL= ICT_ERROR, "The variable %s.%s for DynamicHii PCDs has conflicting attribut= es [%s] and [%s] " % (VariableGuid, VariableName, VarAttribute, VariableAtt= rs[(VariableName, VariableGuid)])) =20 pcdDecObject =3D self._DecPcds[PcdCName, TokenSpaceGuid] - if (PcdCName, TokenSpaceGuid) in Pcds.keys(): + if (PcdCName, TokenSpaceGuid) in Pcds: pcdObject =3D Pcds[PcdCName, TokenSpaceGuid] if SkuName in pcdObject.SkuInfoList: Skuitem =3D pcdObject.SkuInfoList[SkuName] @@ -2503,15= +2498,15 @@ class DscBuildData(PlatformBuildClassObject): for default_store in sku.DefaultStoreDict: sku.DefaultStoreDict[default_store]=3DpcdDecObject= .DefaultValue pcd.DefaultValue =3D pcdDecObject.DefaultValue - if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in= pcd.SkuInfoList.keys(): + if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.Sk= uInfoList: valuefromDec =3D pcdDecObject.DefaultValue SkuInfo =3D SkuInfoClass('DEFAULT', '0', SkuInfoObj.Variab= leName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec,Va= riableAttribute=3DSkuInfoObj.VariableAttribute,DefaultStore=3D{DefaultStore= :valuefromDec}) pcd.SkuInfoList['DEFAULT'] =3D SkuInfo - elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in p= cd.SkuInfoList.keys(): + elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuI= nfoList: pcd.SkuInfoList['DEFAULT'] =3D pcd.SkuInfoList['COMMON'] - del(pcd.SkuInfoList['COMMON']) - elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.S= kuInfoList.keys(): - del(pcd.SkuInfoList['COMMON']) + del pcd.SkuInfoList['COMMON'] + elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoL= ist: + del pcd.SkuInfoList['COMMON'] =20 if pcd.MaxDatumSize.strip(): MaxSize =3D int(pcd.MaxDatumSize, 0) @@ -2592,7 +2587,7 @@= class DscBuildData(PlatformBuildClassObject): # VpdOffset, MaxDatumSize, InitialValue =3D self._ValidatePcd(Pc= dCName, TokenSpaceGuid, Setting, Type, Dummy4) SkuInfo =3D SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '',= '', '', '', VpdOffset, InitialValue) - if (PcdCName, TokenSpaceGuid) in Pcds.keys(): + if (PcdCName, TokenSpaceGuid) in Pcds: pcdObject =3D Pcds[PcdCName, TokenSpaceGuid] pcdObject.SkuInfoList[SkuName] =3D SkuInfo if MaxDatumSize.strip(): @@ -2626,15 +2621,15 @@ class DscBuildData(PlatformBuildClassObject): for sku in pcd.SkuInfoList.values(): if (sku.DefaultValue =3D=3D "" or sku.DefaultValue=3D=3DNo= ne): sku.DefaultValue =3D pcdDecObject.DefaultValue - if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in= pcd.SkuInfoList.keys(): + if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.Sk= uInfoList: valuefromDec =3D pcdDecObject.DefaultValue SkuInfo =3D SkuInfoClass('DEFAULT', '0', '', '', '', '', S= kuInfoObj.VpdOffset, valuefromDec) pcd.SkuInfoList['DEFAULT'] =3D SkuInfo - elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in p= cd.SkuInfoList.keys(): + elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuI= nfoList: pcd.SkuInfoList['DEFAULT'] =3D pcd.SkuInfoList['COMMON'] - del(pcd.SkuInfoList['COMMON']) - elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.S= kuInfoList.keys(): - del(pcd.SkuInfoList['COMMON']) + del pcd.SkuInfoList['COMMON'] + elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoL= ist: + del pcd.SkuInfoList['COMMON'] =20 =20 map(self.FilterSkuSettings,Pcds.values()) -- 2.16.2.windows.1