From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 5EE7421127CB5 for ; Mon, 10 Sep 2018 15:18:14 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2018 15:18:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,357,1531810800"; d="scan'208";a="72138367" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga008.jf.intel.com with ESMTP; 10 Sep 2018 15:18:12 -0700 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Liming Gao , Yonghong Zhu Date: Mon, 10 Sep 2018 15:18:04 -0700 Message-Id: <2771b517ac9874aaf9e9203405be04a661ec7546.1536175710.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [PATCH v2 4/9] BaseTools: refactor class properties X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Sep 2018 22:18:14 -0000 use decorators and auto cache those that were cached manually remove properties never used Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Common/Misc.py | 90 +++++++++----------- 1 file changed, 38 insertions(+), 52 deletions(-) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 2cf9574326d5..372fdf01805b 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -38,6 +38,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open from Common.MultipleWorkspace import MultipleWorkspace as mws import uuid from CommonDataClass.Exceptions import BadExpression +from Common.caching import cached_property import subprocess ## Regular expression used to find out place holders in string template gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE) @@ -1719,8 +1720,6 @@ class PathClass(object): self.ToolCode = ToolCode self.ToolChainFamily = ToolChainFamily - self._Key = None - ## Convert the object of this class to a string # # Convert member Path of the class to a string @@ -1773,12 +1772,12 @@ class PathClass(object): def __hash__(self): return hash(self.Path) - def _GetFileKey(self): - if self._Key is None: - self._Key = self.Path.upper() # + self.ToolChainFamily + self.TagName + self.ToolCode + self.Target - return self._Key + @cached_property + def Key(self): + return self.Path.upper() - def _GetTimeStamp(self): + @property + def TimeStamp(self): return os.stat(self.Path)[8] def Validate(self, Type='', CaseSensitive=True): @@ -1817,9 +1816,6 @@ class PathClass(object): self.Path = os.path.join(RealRoot, RealFile) return ErrorCode, ErrorInfo - Key = property(_GetFileKey) - TimeStamp = property(_GetTimeStamp) - ## Parse PE image to get the required PE informaion. # class PeImageClass(): @@ -1929,8 +1925,8 @@ class DefaultStore(): for sid, name in self.DefaultStores.values(): if sid == minid: return name + class SkuClass(): - DEFAULT = 0 SINGLE = 1 MULTIPLE =2 @@ -1951,8 +1947,8 @@ class SkuClass(): self.SkuIdSet = [] self.SkuIdNumberSet = [] self.SkuData = SkuIds - self.__SkuInherit = {} - self.__SkuIdentifier = SkuIdentifier + self._SkuInherit = {} + self._SkuIdentifier = SkuIdentifier if SkuIdentifier == '' or SkuIdentifier is None: self.SkuIdSet = ['DEFAULT'] self.SkuIdNumberSet = ['0U'] @@ -1976,7 +1972,7 @@ class SkuClass(): EdkLogger.error("build", PARAMETER_INVALID, ExtraData="SKU-ID [%s] is not supported by the platform. [Valid SKU-ID: %s]" % (each, " | ".join(SkuIds.keys()))) - if self.SkuUsageType != self.SINGLE: + if self.SkuUsageType != SkuClass.SINGLE: self.AvailableSkuIds.update({'DEFAULT':0, 'COMMON':0}) if self.SkuIdSet: GlobalData.gSkuids = (self.SkuIdSet) @@ -1990,11 +1986,11 @@ class SkuClass(): GlobalData.gSkuids.sort() def GetNextSkuId(self, skuname): - if not self.__SkuInherit: - self.__SkuInherit = {} + if not self._SkuInherit: + self._SkuInherit = {} for item in self.SkuData.values(): - self.__SkuInherit[item[1]]=item[2] if item[2] else "DEFAULT" - return self.__SkuInherit.get(skuname, "DEFAULT") + self._SkuInherit[item[1]]=item[2] if item[2] else "DEFAULT" + return self._SkuInherit.get(skuname, "DEFAULT") def GetSkuChain(self, sku): if sku == "DEFAULT": @@ -2024,55 +2020,45 @@ class SkuClass(): return skuorder - def __SkuUsageType(self): - - if self.__SkuIdentifier.upper() == "ALL": + @property + def SkuUsageType(self): + if self._SkuIdentifier.upper() == "ALL": return SkuClass.MULTIPLE if len(self.SkuIdSet) == 1: if self.SkuIdSet[0] == 'DEFAULT': return SkuClass.DEFAULT - else: - return SkuClass.SINGLE - elif len(self.SkuIdSet) == 2: - if 'DEFAULT' in self.SkuIdSet: - return SkuClass.SINGLE - else: - return SkuClass.MULTIPLE - else: - return SkuClass.MULTIPLE + return SkuClass.SINGLE + if len(self.SkuIdSet) == 2 and 'DEFAULT' in self.SkuIdSet: + return SkuClass.SINGLE + return SkuClass.MULTIPLE + def DumpSkuIdArrary(self): - + if self.SkuUsageType == SkuClass.SINGLE: + return "{0x0}" ArrayStrList = [] - if self.SkuUsageType == SkuClass.SINGLE: - ArrayStr = "{0x0}" - else: - for skuname in self.AvailableSkuIds: - if skuname == "COMMON": - continue - while skuname != "DEFAULT": - ArrayStrList.append(hex(int(self.AvailableSkuIds[skuname]))) - skuname = self.GetNextSkuId(skuname) - ArrayStrList.append("0x0") - ArrayStr = "{" + ",".join(ArrayStrList) + "}" - return ArrayStr - def __GetAvailableSkuIds(self): + for skuname in self.AvailableSkuIds: + if skuname == "COMMON": + continue + while skuname != "DEFAULT": + ArrayStrList.append(hex(int(self.AvailableSkuIds[skuname]))) + skuname = self.GetNextSkuId(skuname) + ArrayStrList.append("0x0") + return "{{{myList}}}".format(myList=",".join(ArrayStrList)) + + @property + def AvailableSkuIdSet(self): return self.AvailableSkuIds - def __GetSystemSkuID(self): - if self.__SkuUsageType() == SkuClass.SINGLE: + @property + def SystemSkuId(self): + if self.SkuUsageType == SkuClass.SINGLE: if len(self.SkuIdSet) == 1: return self.SkuIdSet[0] else: return self.SkuIdSet[0] if self.SkuIdSet[0] != 'DEFAULT' else self.SkuIdSet[1] else: return 'DEFAULT' - def __GetAvailableSkuIdNumber(self): - return self.SkuIdNumberSet - SystemSkuId = property(__GetSystemSkuID) - AvailableSkuIdSet = property(__GetAvailableSkuIds) - SkuUsageType = property(__SkuUsageType) - AvailableSkuIdNumSet = property(__GetAvailableSkuIdNumber) # # Pack a registry format GUID -- 2.16.2.windows.1