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.100; helo=mga07.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 DCC3021106C63 for ; Wed, 29 Aug 2018 08:50:30 -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 orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2018 08:50:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,303,1531810800"; d="scan'208";a="85959632" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga001.jf.intel.com with ESMTP; 29 Aug 2018 08:50:30 -0700 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Liming Gao , Yonghong Zhu Date: Wed, 29 Aug 2018 08:45:39 -0700 Message-Id: X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [PATCH v1 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: Wed, 29 Aug 2018 15:50:31 -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 5a63c83a2a0c..cb97fbae2a10 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) @@ -1717,8 +1718,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 @@ -1771,12 +1770,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): @@ -1815,9 +1814,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(): @@ -1927,8 +1923,8 @@ class DefaultStore(): for sid, name in self.DefaultStores.values(): if sid == minid: return name + class SkuClass(): - DEFAULT = 0 SINGLE = 1 MULTIPLE =2 @@ -1949,8 +1945,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'] @@ -1974,7 +1970,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) @@ -1988,11 +1984,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": @@ -2022,55 +2018,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