public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 0/5] BaseTools: remove or change un-needed variables
@ 2018-04-10 23:17 Jaben Carsey
  2018-04-10 23:17 ` [PATCH v1 1/5] BaseTools: use existing shared variable Jaben Carsey
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-04-10 23:17 UTC (permalink / raw)
  To: edk2-devel

use sets instead of lists when doing only "in" testing later
use counts instead of lists when they just get counted after

Jaben Carsey (5):
  BaseTools: use existing shared variable
  BaseTools: no need to save the data
  BaseTools: skip updating temporary variable.
  BaseTools: use set instead of list for a variable to be used with in
  BaseTools: reduce list usage when not needed

 BaseTools/Source/Python/AutoGen/AutoGen.py        | 26 ++++-------
 BaseTools/Source/Python/AutoGen/GenC.py           | 48 +++++++++++---------
 BaseTools/Source/Python/AutoGen/GenVar.py         | 15 +++---
 BaseTools/Source/Python/Common/Misc.py            |  2 +-
 BaseTools/Source/Python/Workspace/DscBuildData.py | 38 ++++++++--------
 5 files changed, 63 insertions(+), 66 deletions(-)

-- 
2.16.2.windows.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v1 1/5] BaseTools: use existing shared variable
  2018-04-10 23:17 [PATCH v1 0/5] BaseTools: remove or change un-needed variables Jaben Carsey
@ 2018-04-10 23:17 ` Jaben Carsey
  2018-04-10 23:17 ` [PATCH v1 2/5] BaseTools: no need to save the data Jaben Carsey
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-04-10 23:17 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

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/GenVar.py         | 15 ++++----
 BaseTools/Source/Python/Common/Misc.py            |  2 +-
 BaseTools/Source/Python/Workspace/DscBuildData.py | 38 ++++++++++----------
 3 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/Python/AutoGen/GenVar.py
index d222e6ed5e7e..7a29a0edca45 100644
--- a/BaseTools/Source/Python/AutoGen/GenVar.py
+++ b/BaseTools/Source/Python/AutoGen/GenVar.py
@@ -20,6 +20,7 @@ import copy
 from Common.VariableAttributes import VariableAttributes
 from Common.Misc import *
 import collections
+import Common.DataType as DataType
 
 var_info = collections.namedtuple("uefi_var", "pcdindex,pcdname,defaultstoragename,skuname,var_name, var_guid, var_offset,var_attribute,pcd_default_value, default_value, data_type")
 NvStorageHeaderSize = 28
@@ -141,7 +142,7 @@ class VariableMgr(object):
             default_data_buffer = ""
             others_data_buffer = ""
             tail = None
-            default_sku_default = indexedvarinfo.get(index).get(("DEFAULT","STANDARD"))
+            default_sku_default = indexedvarinfo.get(index).get(("DEFAULT",DataType.TAB_DEFAULT_STORES_DEFAULT))
 
             if default_sku_default.data_type not in ["UINT8","UINT16","UINT32","UINT64","BOOLEAN"]:
                 var_max_len = max([len(var_item.default_value.split(",")) for var_item in sku_var_info.values()])
@@ -154,13 +155,13 @@ class VariableMgr(object):
             for item in default_data_buffer:
                 default_data_array += unpack("B",item)
 
-            if ("DEFAULT","STANDARD") not in var_data:
-                var_data[("DEFAULT","STANDARD")] = collections.OrderedDict()
-            var_data[("DEFAULT","STANDARD")][index] = (default_data_buffer,sku_var_info[("DEFAULT","STANDARD")])
+            if ("DEFAULT",DataType.TAB_DEFAULT_STORES_DEFAULT) not in var_data:
+                var_data[("DEFAULT",DataType.TAB_DEFAULT_STORES_DEFAULT)] = collections.OrderedDict()
+            var_data[("DEFAULT",DataType.TAB_DEFAULT_STORES_DEFAULT)][index] = (default_data_buffer,sku_var_info[("DEFAULT",DataType.TAB_DEFAULT_STORES_DEFAULT)])
 
             for (skuid,defaultstoragename) in indexedvarinfo.get(index):
                 tail = None
-                if (skuid,defaultstoragename) == ("DEFAULT","STANDARD"):
+                if (skuid,defaultstoragename) == ("DEFAULT",DataType.TAB_DEFAULT_STORES_DEFAULT):
                     continue
                 other_sku_other = indexedvarinfo.get(index).get((skuid,defaultstoragename))
 
@@ -189,7 +190,7 @@ class VariableMgr(object):
         if not var_data:
             return []
 
-        pcds_default_data = var_data.get(("DEFAULT","STANDARD"),{})
+        pcds_default_data = var_data.get(("DEFAULT",DataType.TAB_DEFAULT_STORES_DEFAULT),{})
         NvStoreDataBuffer = ""
         var_data_offset = collections.OrderedDict()
         offset = NvStorageHeaderSize
@@ -219,7 +220,7 @@ class VariableMgr(object):
 
         data_delta_structure_buffer = ""
         for skuname,defaultstore in var_data:
-            if (skuname,defaultstore) == ("DEFAULT","STANDARD"):
+            if (skuname,defaultstore) == ("DEFAULT",DataType.TAB_DEFAULT_STORES_DEFAULT):
                 continue
             pcds_sku_data = var_data.get((skuname,defaultstore))
             delta_data_set = []
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index 23c1a4a0b236..5ffd8cd0223d 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -1922,7 +1922,7 @@ class DefaultStore():
             return (str(minvalue), self.DefaultStores[str(minvalue)])
     def GetMin(self,DefaultSIdList):
         if not DefaultSIdList:
-            return "STANDARD"
+            return TAB_DEFAULT_STORES_DEFAULT
         storeidset = {storeid for storeid, storename in self.DefaultStores.values() if storename in DefaultSIdList}
         if not storeidset:
             return ""
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 6766f059b0f7..fcd3132860d5 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -947,10 +947,10 @@ class DscBuildData(PlatformBuildClassObject):
         for pcd in HiiPcd:
             for skuid in pcd.SkuInfoList:
                 skuobj = pcd.SkuInfoList.get(skuid)
-                if "STANDARD" not in skuobj.DefaultStoreDict:
+                if TAB_DEFAULT_STORES_DEFAULT not in skuobj.DefaultStoreDict:
                     PcdDefaultStoreSet = set([defaultstorename  for defaultstorename in skuobj.DefaultStoreDict])
                     mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet)
-                    skuobj.DefaultStoreDict['STANDARD'] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])
+                    skuobj.DefaultStoreDict[TAB_DEFAULT_STORES_DEFAULT] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename])
         return Pcds
 
     def RecoverCommandLinePcd(self):
@@ -1325,7 +1325,7 @@ class DscBuildData(PlatformBuildClassObject):
                         str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
                 for str_pcd_data in StrPcdSet[str_pcd]:
                     if str_pcd_data[3] in SkuIds:
-                        str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File if self.WorkspaceDir not in self.MetaFile.File else self.MetaFile.File[len(self.WorkspaceDir) if self.WorkspaceDir.endswith(os.path.sep) else len(self.WorkspaceDir)+1:],LineNo=str_pcd_data[5])
+                        str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],TAB_DEFAULT_STORES_DEFAULT if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File if self.WorkspaceDir not in self.MetaFile.File else self.MetaFile.File[len(self.WorkspaceDir) if self.WorkspaceDir.endswith(os.path.sep) else len(self.WorkspaceDir)+1:],LineNo=str_pcd_data[5])
                 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
             else:
                 EdkLogger.error('build', PARSER_ERROR,
@@ -1359,7 +1359,7 @@ class DscBuildData(PlatformBuildClassObject):
                             NoDefault = True
                             break
                         nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)
-                    stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores} if DefaultStores else {'STANDARD':stru_pcd.DefaultValues})
+                    stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores} if DefaultStores else {TAB_DEFAULT_STORES_DEFAULT:stru_pcd.DefaultValues})
                     if not NoDefault:
                         stru_pcd.ValueChain[(skuid,'')]= (nextskuid,'')
             if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
@@ -1744,10 +1744,10 @@ class DscBuildData(PlatformBuildClassObject):
         CApp = CApp + '  UINT32  FieldSize;\n'
         CApp = CApp + '  CHAR8   *Value;\n'
 
-        CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % ('DEFAULT', 'STANDARD')
+        CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % ('DEFAULT', TAB_DEFAULT_STORES_DEFAULT)
         inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName]
-        if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD'):
-            pcddefaultvalue = Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue
+        if (SkuName,DefaultStoreName) == ('DEFAULT',TAB_DEFAULT_STORES_DEFAULT):
+            pcddefaultvalue = Pcd.DefaultFromDSC.get('DEFAULT',{}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue
         else:
             if not Pcd.DscRawValue:
                 # handle the case that structure pcd is not appear in DSC
@@ -1766,14 +1766,14 @@ class DscBuildData(PlatformBuildClassObject):
                                         (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))
                 Value, ValueSize = ParseFieldValue (FieldList)
 
-                if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD'):
+                if (SkuName,DefaultStoreName) == ('DEFAULT',TAB_DEFAULT_STORES_DEFAULT):
                     if isinstance(Value, str):
-                        CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
+                        CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get('DEFAULT',{}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
                     elif IsArray:
                     #
                     # Use memcpy() to copy value into field
                     #
-                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
+                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
                         CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
                 else:
                     if isinstance(Value, str):
@@ -1785,7 +1785,7 @@ class DscBuildData(PlatformBuildClassObject):
                         CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName))
                         CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
                 continue
-            if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD') or (( (SkuName,'') not in Pcd.ValueChain) and ( (SkuName,DefaultStoreName) not in Pcd.ValueChain )):
+            if (SkuName,DefaultStoreName) == ('DEFAULT',TAB_DEFAULT_STORES_DEFAULT) or (( (SkuName,'') not in Pcd.ValueChain) and ( (SkuName,DefaultStoreName) not in Pcd.ValueChain )):
                 for FieldName in FieldList:
                     IsArray = IsFieldValueAnArray(FieldList[FieldName][0])
                     if IsArray:
@@ -1941,7 +1941,7 @@ class DscBuildData(PlatformBuildClassObject):
             if Pcd.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
                 for skuname in self.SkuIdMgr.GetSkuChain(SkuName):
-                    storeset = [DefaultStoreName] if DefaultStoreName == 'STANDARD' else ['STANDARD', DefaultStoreName]
+                    storeset = [DefaultStoreName] if DefaultStoreName == TAB_DEFAULT_STORES_DEFAULT else [TAB_DEFAULT_STORES_DEFAULT, DefaultStoreName]
                     for defaultstorenameitem in storeset:
                         CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)
                         CApp = CApp + self.GenerateInitValueStatement(Pcd,skuname,defaultstorenameitem)
@@ -1949,7 +1949,7 @@ class DscBuildData(PlatformBuildClassObject):
                         break
             else:
                 CApp = CApp + "// SkuName: %s,  DefaultStoreName: STANDARD \n" % self.SkuIdMgr.SystemSkuId
-                CApp = CApp + self.GenerateInitValueStatement(Pcd,self.SkuIdMgr.SystemSkuId,"STANDARD")
+                CApp = CApp + self.GenerateInitValueStatement(Pcd,self.SkuIdMgr.SystemSkuId,TAB_DEFAULT_STORES_DEFAULT)
             CApp = CApp + self.GenerateCommandLineValueStatement(Pcd)
             #
             # Set new PCD value and size
@@ -1991,7 +1991,7 @@ class DscBuildData(PlatformBuildClassObject):
             CApp = CApp + self.GenerateCommandLineValue(Pcd)
             if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
-                CApp = CApp + self.GenerateInitValueFunction(Pcd,self.SkuIdMgr.SystemSkuId, 'STANDARD')
+                CApp = CApp + self.GenerateInitValueFunction(Pcd,self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)
             else:
                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
                     if SkuName not in Pcd.SkuOverrideValues:
@@ -2000,7 +2000,7 @@ class DscBuildData(PlatformBuildClassObject):
                         CApp = CApp + self.GenerateInitValueFunction(Pcd,SkuName,DefaultStoreName)
             if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
-                InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd, InitByteValue, CApp)
+                InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd, InitByteValue, CApp)
             else:
                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
                     if SkuName not in Pcd.SkuOverrideValues:
@@ -2016,7 +2016,7 @@ class DscBuildData(PlatformBuildClassObject):
         CApp = CApp + '{\n'
         for Pcd in StructuredPcds.values():
             if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
-                CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
+                CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
             else:
                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
                     if SkuName not in Pcd.SkuOverrideValues:
@@ -2340,14 +2340,14 @@ class DscBuildData(PlatformBuildClassObject):
         if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
             if self.SkuIdMgr.SystemSkuId not in Pcd.DscRawValue:
                 Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId] = {}
-            Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId]['STANDARD'] = Pcd.DefaultValue
+            Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId][TAB_DEFAULT_STORES_DEFAULT] = Pcd.DefaultValue
         for skuname in Pcd.SkuInfoList:
             Pcd.DscRawValue[skuname] = {}
             if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
                 for defaultstore in Pcd.SkuInfoList[skuname].DefaultStoreDict:
                     Pcd.DscRawValue[skuname][defaultstore] = Pcd.SkuInfoList[skuname].DefaultStoreDict[defaultstore]
             else:
-                Pcd.DscRawValue[skuname]['STANDARD'] = Pcd.SkuInfoList[skuname].DefaultValue
+                Pcd.DscRawValue[skuname][TAB_DEFAULT_STORES_DEFAULT] = Pcd.SkuInfoList[skuname].DefaultValue
     def CompletePcdValues(self,PcdSet):
         Pcds = {}
         DefaultStoreObj = DefaultStore(self._GetDefaultStores())
@@ -2412,7 +2412,7 @@ class DscBuildData(PlatformBuildClassObject):
             SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName
             DefaultStore = DefaultStore.upper()
             if DefaultStore == "COMMON":
-                DefaultStore = "STANDARD"
+                DefaultStore = TAB_DEFAULT_STORES_DEFAULT
             if SkuName not in AvailableSkuIdSet:
                 EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName,
                                             File=self.MetaFile, Line=Dummy5)
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 2/5] BaseTools: no need to save the data
  2018-04-10 23:17 [PATCH v1 0/5] BaseTools: remove or change un-needed variables Jaben Carsey
  2018-04-10 23:17 ` [PATCH v1 1/5] BaseTools: use existing shared variable Jaben Carsey
@ 2018-04-10 23:17 ` Jaben Carsey
  2018-04-10 23:17 ` [PATCH v1 3/5] BaseTools: skip updating temporary variable Jaben Carsey
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-04-10 23:17 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

It's never accessed.

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 | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 9280ae4c7df2..5dd24ffc8720 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -361,13 +361,12 @@ class WorkspaceAutoGen(AutoGen):
             # but the path (self.MetaFile.Path) is the real path
             for key in self.FdfProfile.InfDict:
                 if key == 'ArchTBD':
-                    Platform_cache = {}
                     MetaFile_cache = {}
                     for Arch in self.ArchList:
-                        Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
+                        Current_Platform_cache = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
                         MetaFile_cache[Arch] = set()
-                        for Pkey in Platform_cache[Arch].Modules:
-                            MetaFile_cache[Arch].add(Platform_cache[Arch].Modules[Pkey].MetaFile)
+                        for Pkey in Current_Platform_cache.Modules:
+                            MetaFile_cache[Arch].add(Current_Platform_cache.Modules[Pkey].MetaFile)
                     for Inf in self.FdfProfile.InfDict[key]:
                         ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)
                         for Arch in self.ArchList:
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 3/5] BaseTools: skip updating temporary variable.
  2018-04-10 23:17 [PATCH v1 0/5] BaseTools: remove or change un-needed variables Jaben Carsey
  2018-04-10 23:17 ` [PATCH v1 1/5] BaseTools: use existing shared variable Jaben Carsey
  2018-04-10 23:17 ` [PATCH v1 2/5] BaseTools: no need to save the data Jaben Carsey
@ 2018-04-10 23:17 ` Jaben Carsey
  2018-04-10 23:17 ` [PATCH v1 4/5] BaseTools: use set instead of list for a variable to be used with in Jaben Carsey
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-04-10 23:17 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

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 | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 5dd24ffc8720..8adb2527c79f 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -256,12 +256,6 @@ class WorkspaceAutoGen(AutoGen):
     def _InitWorker(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,
               BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,
               Progress=None, BuildModule=None):
-        if Fds is None:
-            Fds = []
-        if Fvs is None:
-            Fvs = []
-        if Caps is None:
-            Caps = []
         self.BuildDatabase  = MetaFileDb
         self.MetaFile       = ActivePlatform
         self.WorkspaceDir   = WorkspaceDir
@@ -276,9 +270,9 @@ class WorkspaceAutoGen(AutoGen):
         self.TargetTxt      = BuildConfig
         self.ToolDef        = ToolDefinition
         self.FdfFile        = FlashDefinitionFile
-        self.FdTargetList   = Fds
-        self.FvTargetList   = Fvs
-        self.CapTargetList  = Caps
+        self.FdTargetList   = Fds if Fds else []
+        self.FvTargetList   = Fvs if Fvs else []
+        self.CapTargetList  = Caps if Caps else []
         self.AutoGenObjectList = []
         self._BuildDir      = None
         self._FvDir         = None
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 4/5] BaseTools: use set instead of list for a variable to be used with in
  2018-04-10 23:17 [PATCH v1 0/5] BaseTools: remove or change un-needed variables Jaben Carsey
                   ` (2 preceding siblings ...)
  2018-04-10 23:17 ` [PATCH v1 3/5] BaseTools: skip updating temporary variable Jaben Carsey
@ 2018-04-10 23:17 ` Jaben Carsey
  2018-04-10 23:17 ` [PATCH v1 5/5] BaseTools: reduce list usage when not needed Jaben Carsey
  2018-04-17 12:42 ` [PATCH v1 0/5] BaseTools: remove or change un-needed variables Zhu, Yonghong
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-04-10 23:17 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

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 | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 8adb2527c79f..57f1a0d8ba06 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -1450,13 +1450,10 @@ class PlatformAutoGen(AutoGen):
                         self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])
                         PcdFromModule.Pending = False
                         self._NonDynaPcdList_.append (PcdFromModule)
-        # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
-        DscModuleList = []
-        for ModuleInf in self.Platform.Modules.keys():
-            DscModuleList.append (os.path.normpath(ModuleInf.Path))
+        DscModuleSet = {os.path.normpath(ModuleInf.Path) for ModuleInf in self.Platform.Modules}
         # add the PCD from modules that listed in FDF but not in DSC to Database 
         for InfName in FdfModuleList:
-            if InfName not in DscModuleList:
+            if InfName not in DscModuleSet:
                 InfClass = PathClass(InfName)
                 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]
                 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source) 
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 5/5] BaseTools: reduce list usage when not needed
  2018-04-10 23:17 [PATCH v1 0/5] BaseTools: remove or change un-needed variables Jaben Carsey
                   ` (3 preceding siblings ...)
  2018-04-10 23:17 ` [PATCH v1 4/5] BaseTools: use set instead of list for a variable to be used with in Jaben Carsey
@ 2018-04-10 23:17 ` Jaben Carsey
  2018-04-17 12:42 ` [PATCH v1 0/5] BaseTools: remove or change un-needed variables Zhu, Yonghong
  5 siblings, 0 replies; 7+ messages in thread
From: Jaben Carsey @ 2018-04-10 23:17 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

remove not needed lists.  some were just counted and others
should be sets.

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/GenC.py | 48 +++++++++++---------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py
index 58da9e6b1784..c11bbc5716f9 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -813,7 +813,7 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
     # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.
     # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.  
     # Use the Guid pointer to see if it matches any of the token space GUIDs.
-    TokenCNameList = []
+    TokenCNameList = set()
     for TokenCName in ExTokenCNameList:
         if TokenCName in TokenCNameList:
             continue
@@ -836,9 +836,9 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                                     % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))
                 if Index == Count:
                     AutoGenH.Append('0 \\\n  )\n')
-                TokenCNameList.append(TokenCName)
+                TokenCNameList.add(TokenCName)
     
-    TokenCNameList = []
+    TokenCNameList = set()
     for TokenCName in ExTokenCNameList:
         if TokenCName in TokenCNameList:
             continue
@@ -868,7 +868,7 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                     #  COMPAREGUID() will only be used if the Guid passed in is local to the module.
                     AutoGenH.Append('#define _PCD_TOKEN_EX_%s(GuidPtr)   __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr)  \n'
                                     % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))
-                TokenCNameList.append(TokenCName)
+                TokenCNameList.add(TokenCName)
 
 def GetPcdSize(Pcd):
     if Pcd.DatumType not in _NumericDataTypesList:
@@ -962,19 +962,22 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
     SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH['VOID*'] + '_S_' + TokenCName
     GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName
     
-    PcdExCNameList  = []
     if Pcd.Type in gDynamicExPcd:
         if Info.IsLibrary:
             PcdList = Info.LibraryPcdList
         else:
             PcdList = Info.ModulePcdList
+        PcdExCNameTest = 0
         for PcdModule in PcdList:
-            if PcdModule.Type in gDynamicExPcd:
-                PcdExCNameList.append(PcdModule.TokenCName)
+            if PcdModule.Type in gDynamicExPcd and Pcd.TokenCName == PcdModule.TokenCName:
+                PcdExCNameTest += 1
+            # get out early once we found > 1...
+            if PcdExCNameTest > 1:
+                break
         # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
         # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
         # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
-        if PcdExCNameList.count(Pcd.TokenCName) > 1:
+        if PcdExCNameTest > 1:
             AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')
             AutoGenH.Append('// #define %s  %s\n' % (PcdTokenName, PcdExTokenName))
             AutoGenH.Append('// #define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
@@ -996,14 +999,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 AutoGenH.Append('#define %s(Value)  LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
                 AutoGenH.Append('#define %s(Value)  LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
     elif Pcd.Type in gDynamicPcd:
-        PcdList = []
-        PcdCNameList = []
-        PcdList.extend(Info.LibraryPcdList)
-        PcdList.extend(Info.ModulePcdList)
-        for PcdModule in PcdList:
-            if PcdModule.Type in gDynamicPcd:
-                PcdCNameList.append(PcdModule.TokenCName)
-        if PcdCNameList.count(Pcd.TokenCName) > 1:
+        PcdCNameTest = 0
+        for PcdModule in Info.LibraryPcdList + Info.ModulePcdList:
+            if PcdModule.Type in gDynamicPcd and Pcd.TokenCName == PcdModule.TokenCName:
+                PcdCNameTest += 1
+            # get out early once we found > 1...
+            if PcdCNameTest > 1:
+                break
+        if PcdCNameTest > 1:
             EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName. They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))
         else:
             AutoGenH.Append('#define %s  LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))
@@ -1265,7 +1268,6 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
             Type = '(VOID *)'
         Array = '[]'
     PcdItemType = Pcd.Type
-    PcdExCNameList  = []
     if PcdItemType in gDynamicExPcd:
         PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName
         AutoGenH.Append('\n#define %s  %dU\n' % (PcdExTokenName, TokenNumber))
@@ -1274,13 +1276,17 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
             PcdList = Info.LibraryPcdList
         else:
             PcdList = Info.ModulePcdList
+        PcdExCNameTest = 0
         for PcdModule in PcdList:
-            if PcdModule.Type in gDynamicExPcd:
-                PcdExCNameList.append(PcdModule.TokenCName)
+            if PcdModule.Type in gDynamicExPcd and Pcd.TokenCName == PcdModule.TokenCName:
+                PcdExCNameTest += 1
+            # get out early once we found > 1...
+            if PcdExCNameTest > 1:
+                break
         # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
         # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
         # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
-        if PcdExCNameList.count(Pcd.TokenCName) > 1:
+        if PcdExCNameTest > 1:
             AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')
             AutoGenH.Append('// #define %s  %s\n' % (PcdTokenName, PcdExTokenName))
             AutoGenH.Append('// #define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))
@@ -1696,7 +1702,7 @@ def CreatePcdCode(Info, AutoGenC, AutoGenH):
     AutoGenH.Append("\n// Definition of SkuId Array\n")
     AutoGenH.Append("extern UINT64 _gPcd_SkuId_Array[];\n")
     # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
-    if TokenSpaceList <> []:            
+    if TokenSpaceList:
         AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
         if Info.ModuleType in ["USER_DEFINED", "BASE"]:
             GuidType = "GUID"
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 0/5] BaseTools: remove or change un-needed variables
  2018-04-10 23:17 [PATCH v1 0/5] BaseTools: remove or change un-needed variables Jaben Carsey
                   ` (4 preceding siblings ...)
  2018-04-10 23:17 ` [PATCH v1 5/5] BaseTools: reduce list usage when not needed Jaben Carsey
@ 2018-04-17 12:42 ` Zhu, Yonghong
  5 siblings, 0 replies; 7+ messages in thread
From: Zhu, Yonghong @ 2018-04-17 12:42 UTC (permalink / raw)
  To: Carsey, Jaben, edk2-devel@lists.01.org

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jaben Carsey
Sent: Wednesday, April 11, 2018 7:17 AM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH v1 0/5] BaseTools: remove or change un-needed variables

use sets instead of lists when doing only "in" testing later use counts instead of lists when they just get counted after

Jaben Carsey (5):
  BaseTools: use existing shared variable
  BaseTools: no need to save the data
  BaseTools: skip updating temporary variable.
  BaseTools: use set instead of list for a variable to be used with in
  BaseTools: reduce list usage when not needed

 BaseTools/Source/Python/AutoGen/AutoGen.py        | 26 ++++-------
 BaseTools/Source/Python/AutoGen/GenC.py           | 48 +++++++++++---------
 BaseTools/Source/Python/AutoGen/GenVar.py         | 15 +++---
 BaseTools/Source/Python/Common/Misc.py            |  2 +-
 BaseTools/Source/Python/Workspace/DscBuildData.py | 38 ++++++++--------
 5 files changed, 63 insertions(+), 66 deletions(-)

--
2.16.2.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-04-17 12:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-10 23:17 [PATCH v1 0/5] BaseTools: remove or change un-needed variables Jaben Carsey
2018-04-10 23:17 ` [PATCH v1 1/5] BaseTools: use existing shared variable Jaben Carsey
2018-04-10 23:17 ` [PATCH v1 2/5] BaseTools: no need to save the data Jaben Carsey
2018-04-10 23:17 ` [PATCH v1 3/5] BaseTools: skip updating temporary variable Jaben Carsey
2018-04-10 23:17 ` [PATCH v1 4/5] BaseTools: use set instead of list for a variable to be used with in Jaben Carsey
2018-04-10 23:17 ` [PATCH v1 5/5] BaseTools: reduce list usage when not needed Jaben Carsey
2018-04-17 12:42 ` [PATCH v1 0/5] BaseTools: remove or change un-needed variables Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox