public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
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 v1 02/11] BaseTools: Workspace - create a base class
Date: Wed, 20 Jun 2018 14:08:08 -0700	[thread overview]
Message-ID: <5593fa2769bbde989dad2f9140c37bc2b3517463.1529528784.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1529528783.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1529528783.git.jaben.carsey@intel.com>

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



  parent reply	other threads:[~2018-06-20 21:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-20 21:08 [PATCH v2 00/11] BaseTools Refactoring Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 01/11] BaseTools: decorate base classes to prevent instantiation Jaben Carsey
2018-06-20 21:08 ` Jaben Carsey [this message]
2018-06-20 21:08 ` [PATCH v1 03/11] BaseTools: remove unused code Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 04/11] BaseTools: remove repeated calls to startswith/endswith Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 05/11] BaseTools: use set presence instead of series of equality Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 06/11] BaseTools: refactor section generation Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 07/11] BaseTools: refactor file opening/writing Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 08/11] BaseTools: refactor to change object types Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 09/11] BaseTools: refactor to stop re-allocating strings Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 10/11] BaseTools: change to set for membership testing Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 11/11] BaseTools: remove extra assignment Jaben Carsey
  -- strict thread matches above, loose matches on Subject: below --
2018-05-14 18:09 [PATCH v1 00/11] BaseTools refactoring Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 02/11] BaseTools: Workspace - create a base class Jaben Carsey

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=5593fa2769bbde989dad2f9140c37bc2b3517463.1529528784.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