refactor 3 classes and create a new base class for their shared functions.
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/Workspace/BuildClassObject.py | 140 +++++++-------------
1 file changed, 50 insertions(+), 90 deletions(-)
diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index 5f34e8e0bc69..db9518cdff17 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -253,6 +253,47 @@ class LibraryClassObject(object):
if Type is not None:
self.SupModList = CleanString(Type).split(DataType.TAB_SPACE_SPLIT)
+## BuildClassObjectBase
+#
+# This is a base class for classes later in this file. it simplifies by
+# not requiring duplication of standard functions.
+# This class is not intended for use outside of being a base class.
+#
+class BuildClassObjectBase(object):
+ __metaclass__ = ABCMeta
+ # prevent this class from being accidentally instantiated
+ @abstractmethod
+ def __init__(self, *a,**k):
+ super(BuildClassObjectBase,self).__init__(*a,**k)
+
+ ## Convert the class to a string
+ #
+ # Convert member MetaFile of the class to a string
+ #
+ # @retval string Formatted String
+ #
+ def __str__(self):
+ return str(self.MetaFile)
+
+ ## Override __eq__ function
+ #
+ # Check whether ModuleBuildClassObjects are the same
+ #
+ # @retval False The two ModuleBuildClassObjects are different
+ # @retval True The two ModuleBuildClassObjects are the same
+ #
+ def __eq__(self, Other):
+ return Other and self.MetaFile == Other
+
+ ## Override __hash__ function
+ #
+ # Use MetaFile as key in hash table
+ #
+ # @retval string Key for hash table
+ #
+ def __hash__(self):
+ return hash(self.MetaFile)
+
## ModuleBuildClassObject
#
# This Class defines ModuleBuildClass
@@ -297,8 +338,9 @@ class LibraryClassObject(object):
# { [BuildOptionKey] : BuildOptionValue}
# @var Depex: To store value for Depex
#
-class ModuleBuildClassObject(object):
- def __init__(self):
+class ModuleBuildClassObject(BuildClassObjectBase):
+ def __init__(self, *a, **k):
+ super(ModuleBuildClassObject,self).__init__(*a,**k)
self.AutoGenVersion = 0
self.MetaFile = ''
self.BaseName = ''
@@ -330,34 +372,6 @@ class ModuleBuildClassObject(object):
self.BuildOptions = {}
self.Depex = {}
- ## Convert the class to a string
- #
- # Convert member MetaFile of the class to a string
- #
- # @retval string Formatted String
- #
- def __str__(self):
- return str(self.MetaFile)
-
- ## Override __eq__ function
- #
- # Check whether ModuleBuildClassObjects are the same
- #
- # @retval False The two ModuleBuildClassObjects are different
- # @retval True The two ModuleBuildClassObjects are the same
- #
- def __eq__(self, Other):
- return self.MetaFile == Other
-
- ## Override __hash__ function
- #
- # Use MetaFile as key in hash table
- #
- # @retval string Key for hash table
- #
- def __hash__(self):
- return hash(self.MetaFile)
-
## PackageBuildClassObject
#
# This Class defines PackageBuildClass
@@ -381,11 +395,12 @@ class ModuleBuildClassObject(object):
# @var Pcds: To store value for Pcds, it is a set structure as
# { [(PcdCName, PcdGuidCName)] : PcdClassObject}
#
-class PackageBuildClassObject(object):
+class PackageBuildClassObject(BuildClassObjectBase):
__metaclass__ = ABCMeta
# prevent this class from being accidentally instantiated
@abstractmethod
- def __init__(self):
+ def __init__(self, *a, **k):
+ super(PackageBuildClassObject,self).__init__(*a,**k)
self.MetaFile = ''
self.PackageName = ''
self.Guid = ''
@@ -398,34 +413,6 @@ class PackageBuildClassObject(object):
self.LibraryClasses = {}
self.Pcds = {}
- ## Convert the class to a string
- #
- # Convert member MetaFile of the class to a string
- #
- # @retval string Formatted String
- #
- def __str__(self):
- return str(self.MetaFile)
-
- ## Override __eq__ function
- #
- # Check whether PackageBuildClassObjects are the same
- #
- # @retval False The two PackageBuildClassObjects are different
- # @retval True The two PackageBuildClassObjects are the same
- #
- def __eq__(self, Other):
- return self.MetaFile == Other
-
- ## Override __hash__ function
- #
- # Use MetaFile as key in hash table
- #
- # @retval string Key for hash table
- #
- def __hash__(self):
- return hash(self.MetaFile)
-
## PlatformBuildClassObject
#
# This Class defines PlatformBuildClass
@@ -454,11 +441,12 @@ class PackageBuildClassObject(object):
# @var BuildOptions: To store value for BuildOptions, it is a set structure as
# { [BuildOptionKey] : BuildOptionValue }
#
-class PlatformBuildClassObject(object):
+class PlatformBuildClassObject(BuildClassObjectBase):
__metaclass__ = ABCMeta
# prevent this class from being accidentally instantiated
@abstractmethod
- def __init__(self):
+ def __init__(self, *a, **k):
+ super(PlatformBuildClassObject,self).__init__(*a,**k)
self.MetaFile = ''
self.PlatformName = ''
self.Guid = ''
@@ -476,31 +464,3 @@ class PlatformBuildClassObject(object):
self.Libraries = {}
self.Pcds = {}
self.BuildOptions = {}
-
- ## Convert the class to a string
- #
- # Convert member MetaFile of the class to a string
- #
- # @retval string Formatted String
- #
- def __str__(self):
- return str(self.MetaFile)
-
- ## Override __eq__ function
- #
- # Check whether PlatformBuildClassObjects are the same
- #
- # @retval False The two PlatformBuildClassObjects are different
- # @retval True The two PlatformBuildClassObjects are the same
- #
- def __eq__(self, Other):
- return self.MetaFile == Other
-
- ## Override __hash__ function
- #
- # Use MetaFile as key in hash table
- #
- # @retval string Key for hash table
- #
- def __hash__(self):
- return hash(self.MetaFile)
--
2.16.2.windows.1
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel