From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v2 4/9] BaseTools: refactor class properties
Date: Mon, 10 Sep 2018 15:18:04 -0700 [thread overview]
Message-ID: <2771b517ac9874aaf9e9203405be04a661ec7546.1536175710.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1536175710.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1536175710.git.jaben.carsey@intel.com>
use decorators and auto cache those that were cached manually
remove properties never used
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/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
next prev parent reply other threads:[~2018-09-10 22:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-10 22:18 [PATCH v2 0/9] BaseTools: refactor Workspace classes Jaben Carsey
2018-09-10 22:18 ` [PATCH v2 1/9] BaseTools: Refactor PlatformAutoGen Jaben Carsey
2018-09-10 22:18 ` [PATCH v2 2/9] BaseTools: AutoGen refactor WorkspaceAutoGen class Jaben Carsey
2018-09-10 22:18 ` [PATCH v2 3/9] BaseTools: AutoGen - refactor class properties Jaben Carsey
2018-09-10 22:18 ` Jaben Carsey [this message]
2018-09-10 22:18 ` [PATCH v2 5/9] BaseTools: Workspace classes refactor properties Jaben Carsey
2018-09-10 22:18 ` [PATCH v2 6/9] BaseTools: refactor Build Database objects Jaben Carsey
2018-09-10 22:18 ` [PATCH v2 7/9] BaseTools: Don't save unused workspace data Jaben Carsey
2018-09-10 22:18 ` [PATCH v2 8/9] BaseTools: refactor to not overcreate ModuleAutoGen objects Jaben Carsey
2018-09-10 22:18 ` [PATCH v2 9/9] BaseTools: refactor to cache InfBuildData data Jaben Carsey
2018-09-20 7:01 ` [PATCH v2 0/9] BaseTools: refactor Workspace classes Zhu, Yonghong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2771b517ac9874aaf9e9203405be04a661ec7546.1536175710.git.jaben.carsey@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox