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 1E76620969670 for ; Mon, 14 May 2018 11:09:25 -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; 14 May 2018 11:09:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,401,1520924400"; d="scan'208";a="55814257" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga001.jf.intel.com with ESMTP; 14 May 2018 11:09:23 -0700 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Liming Gao , Yonghong Zhu Date: Mon, 14 May 2018 11:09:11 -0700 Message-Id: <66919e48fca06bf2e58e529e4b0243beb45e3185.1526321052.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [PATCH v1 02/11] BaseTools: Workspace - create a base class X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 May 2018 18:09:25 -0000 refactor 3 classes and create a new base class for their shared functions. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- 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