mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-26 23:24:03 +02:00
BaseTools: refactor class properties
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> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
parent
4c92c81d61
commit
6c204ed4f2
@ -38,6 +38,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
|
|||||||
from Common.MultipleWorkspace import MultipleWorkspace as mws
|
from Common.MultipleWorkspace import MultipleWorkspace as mws
|
||||||
import uuid
|
import uuid
|
||||||
from CommonDataClass.Exceptions import BadExpression
|
from CommonDataClass.Exceptions import BadExpression
|
||||||
|
from Common.caching import cached_property
|
||||||
import subprocess
|
import subprocess
|
||||||
## Regular expression used to find out place holders in string template
|
## Regular expression used to find out place holders in string template
|
||||||
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
|
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
|
||||||
@ -1724,8 +1725,6 @@ class PathClass(object):
|
|||||||
self.ToolCode = ToolCode
|
self.ToolCode = ToolCode
|
||||||
self.ToolChainFamily = ToolChainFamily
|
self.ToolChainFamily = ToolChainFamily
|
||||||
|
|
||||||
self._Key = None
|
|
||||||
|
|
||||||
## Convert the object of this class to a string
|
## Convert the object of this class to a string
|
||||||
#
|
#
|
||||||
# Convert member Path of the class to a string
|
# Convert member Path of the class to a string
|
||||||
@ -1778,12 +1777,12 @@ class PathClass(object):
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.Path)
|
return hash(self.Path)
|
||||||
|
|
||||||
def _GetFileKey(self):
|
@cached_property
|
||||||
if self._Key is None:
|
def Key(self):
|
||||||
self._Key = self.Path.upper() # + self.ToolChainFamily + self.TagName + self.ToolCode + self.Target
|
return self.Path.upper()
|
||||||
return self._Key
|
|
||||||
|
|
||||||
def _GetTimeStamp(self):
|
@property
|
||||||
|
def TimeStamp(self):
|
||||||
return os.stat(self.Path)[8]
|
return os.stat(self.Path)[8]
|
||||||
|
|
||||||
def Validate(self, Type='', CaseSensitive=True):
|
def Validate(self, Type='', CaseSensitive=True):
|
||||||
@ -1822,9 +1821,6 @@ class PathClass(object):
|
|||||||
self.Path = os.path.join(RealRoot, RealFile)
|
self.Path = os.path.join(RealRoot, RealFile)
|
||||||
return ErrorCode, ErrorInfo
|
return ErrorCode, ErrorInfo
|
||||||
|
|
||||||
Key = property(_GetFileKey)
|
|
||||||
TimeStamp = property(_GetTimeStamp)
|
|
||||||
|
|
||||||
## Parse PE image to get the required PE informaion.
|
## Parse PE image to get the required PE informaion.
|
||||||
#
|
#
|
||||||
class PeImageClass():
|
class PeImageClass():
|
||||||
@ -1934,8 +1930,8 @@ class DefaultStore():
|
|||||||
for sid, name in self.DefaultStores.values():
|
for sid, name in self.DefaultStores.values():
|
||||||
if sid == minid:
|
if sid == minid:
|
||||||
return name
|
return name
|
||||||
class SkuClass():
|
|
||||||
|
|
||||||
|
class SkuClass():
|
||||||
DEFAULT = 0
|
DEFAULT = 0
|
||||||
SINGLE = 1
|
SINGLE = 1
|
||||||
MULTIPLE =2
|
MULTIPLE =2
|
||||||
@ -1956,8 +1952,8 @@ class SkuClass():
|
|||||||
self.SkuIdSet = []
|
self.SkuIdSet = []
|
||||||
self.SkuIdNumberSet = []
|
self.SkuIdNumberSet = []
|
||||||
self.SkuData = SkuIds
|
self.SkuData = SkuIds
|
||||||
self.__SkuInherit = {}
|
self._SkuInherit = {}
|
||||||
self.__SkuIdentifier = SkuIdentifier
|
self._SkuIdentifier = SkuIdentifier
|
||||||
if SkuIdentifier == '' or SkuIdentifier is None:
|
if SkuIdentifier == '' or SkuIdentifier is None:
|
||||||
self.SkuIdSet = ['DEFAULT']
|
self.SkuIdSet = ['DEFAULT']
|
||||||
self.SkuIdNumberSet = ['0U']
|
self.SkuIdNumberSet = ['0U']
|
||||||
@ -1981,7 +1977,7 @@ class SkuClass():
|
|||||||
EdkLogger.error("build", PARAMETER_INVALID,
|
EdkLogger.error("build", PARAMETER_INVALID,
|
||||||
ExtraData="SKU-ID [%s] is not supported by the platform. [Valid SKU-ID: %s]"
|
ExtraData="SKU-ID [%s] is not supported by the platform. [Valid SKU-ID: %s]"
|
||||||
% (each, " | ".join(SkuIds.keys())))
|
% (each, " | ".join(SkuIds.keys())))
|
||||||
if self.SkuUsageType != self.SINGLE:
|
if self.SkuUsageType != SkuClass.SINGLE:
|
||||||
self.AvailableSkuIds.update({'DEFAULT':0, 'COMMON':0})
|
self.AvailableSkuIds.update({'DEFAULT':0, 'COMMON':0})
|
||||||
if self.SkuIdSet:
|
if self.SkuIdSet:
|
||||||
GlobalData.gSkuids = (self.SkuIdSet)
|
GlobalData.gSkuids = (self.SkuIdSet)
|
||||||
@ -1995,11 +1991,11 @@ class SkuClass():
|
|||||||
GlobalData.gSkuids.sort()
|
GlobalData.gSkuids.sort()
|
||||||
|
|
||||||
def GetNextSkuId(self, skuname):
|
def GetNextSkuId(self, skuname):
|
||||||
if not self.__SkuInherit:
|
if not self._SkuInherit:
|
||||||
self.__SkuInherit = {}
|
self._SkuInherit = {}
|
||||||
for item in self.SkuData.values():
|
for item in self.SkuData.values():
|
||||||
self.__SkuInherit[item[1]]=item[2] if item[2] else "DEFAULT"
|
self._SkuInherit[item[1]]=item[2] if item[2] else "DEFAULT"
|
||||||
return self.__SkuInherit.get(skuname, "DEFAULT")
|
return self._SkuInherit.get(skuname, "DEFAULT")
|
||||||
|
|
||||||
def GetSkuChain(self, sku):
|
def GetSkuChain(self, sku):
|
||||||
if sku == "DEFAULT":
|
if sku == "DEFAULT":
|
||||||
@ -2029,55 +2025,45 @@ class SkuClass():
|
|||||||
|
|
||||||
return skuorder
|
return skuorder
|
||||||
|
|
||||||
def __SkuUsageType(self):
|
@property
|
||||||
|
def SkuUsageType(self):
|
||||||
if self.__SkuIdentifier.upper() == "ALL":
|
if self._SkuIdentifier.upper() == "ALL":
|
||||||
return SkuClass.MULTIPLE
|
return SkuClass.MULTIPLE
|
||||||
|
|
||||||
if len(self.SkuIdSet) == 1:
|
if len(self.SkuIdSet) == 1:
|
||||||
if self.SkuIdSet[0] == 'DEFAULT':
|
if self.SkuIdSet[0] == 'DEFAULT':
|
||||||
return SkuClass.DEFAULT
|
return SkuClass.DEFAULT
|
||||||
else:
|
return SkuClass.SINGLE
|
||||||
return SkuClass.SINGLE
|
if len(self.SkuIdSet) == 2 and 'DEFAULT' in self.SkuIdSet:
|
||||||
elif len(self.SkuIdSet) == 2:
|
return SkuClass.SINGLE
|
||||||
if 'DEFAULT' in self.SkuIdSet:
|
return SkuClass.MULTIPLE
|
||||||
return SkuClass.SINGLE
|
|
||||||
else:
|
|
||||||
return SkuClass.MULTIPLE
|
|
||||||
else:
|
|
||||||
return SkuClass.MULTIPLE
|
|
||||||
def DumpSkuIdArrary(self):
|
|
||||||
|
|
||||||
ArrayStrList = []
|
def DumpSkuIdArrary(self):
|
||||||
if self.SkuUsageType == SkuClass.SINGLE:
|
if self.SkuUsageType == SkuClass.SINGLE:
|
||||||
ArrayStr = "{0x0}"
|
return "{0x0}"
|
||||||
else:
|
ArrayStrList = []
|
||||||
for skuname in self.AvailableSkuIds:
|
for skuname in self.AvailableSkuIds:
|
||||||
if skuname == "COMMON":
|
if skuname == "COMMON":
|
||||||
continue
|
continue
|
||||||
while skuname != "DEFAULT":
|
while skuname != "DEFAULT":
|
||||||
ArrayStrList.append(hex(int(self.AvailableSkuIds[skuname])))
|
ArrayStrList.append(hex(int(self.AvailableSkuIds[skuname])))
|
||||||
skuname = self.GetNextSkuId(skuname)
|
skuname = self.GetNextSkuId(skuname)
|
||||||
ArrayStrList.append("0x0")
|
ArrayStrList.append("0x0")
|
||||||
ArrayStr = "{" + ",".join(ArrayStrList) + "}"
|
return "{{{myList}}}".format(myList=",".join(ArrayStrList))
|
||||||
return ArrayStr
|
|
||||||
def __GetAvailableSkuIds(self):
|
@property
|
||||||
|
def AvailableSkuIdSet(self):
|
||||||
return self.AvailableSkuIds
|
return self.AvailableSkuIds
|
||||||
|
|
||||||
def __GetSystemSkuID(self):
|
@property
|
||||||
if self.__SkuUsageType() == SkuClass.SINGLE:
|
def SystemSkuId(self):
|
||||||
|
if self.SkuUsageType == SkuClass.SINGLE:
|
||||||
if len(self.SkuIdSet) == 1:
|
if len(self.SkuIdSet) == 1:
|
||||||
return self.SkuIdSet[0]
|
return self.SkuIdSet[0]
|
||||||
else:
|
else:
|
||||||
return self.SkuIdSet[0] if self.SkuIdSet[0] != 'DEFAULT' else self.SkuIdSet[1]
|
return self.SkuIdSet[0] if self.SkuIdSet[0] != 'DEFAULT' else self.SkuIdSet[1]
|
||||||
else:
|
else:
|
||||||
return 'DEFAULT'
|
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
|
# Pack a registry format GUID
|
||||||
|
Loading…
x
Reference in New Issue
Block a user