summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-03-13 13:30:34 -0700
committerDylan Baker <dylan@pnwbakers.com>2024-03-15 09:15:48 -0700
commit6d713e40f81512eadb0cc4654408d90cb22ba774 (patch)
treed4ed6176e425f677abde18e95758f8d4df7c08e9
parent18f8aeda8b59a132f24fa1af800ff65cac2f61f4 (diff)
downloadmeson-6d713e40f81512eadb0cc4654408d90cb22ba774.tar.gz
dependency: define equality and hash operators for Dependency
When a dependency is copied and its name is changed, we still need a way to say "this is the same dependency", which we now have.
-rw-r--r--mesonbuild/dependencies/base.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 0d946b853..29a60b774 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2013-2018 The Meson development team
+# Copyright © 2024 Intel Corporation
# This file contains the detection logic for external dependencies.
# Custom logic for several other packages are in separate files.
@@ -106,6 +107,9 @@ class Dependency(HoldableObject):
return kwargs['include_type']
def __init__(self, type_name: DependencyTypeName, kwargs: T.Dict[str, T.Any]) -> None:
+ # This allows two Dependencies to be compared even after being copied.
+ # The purpose is to allow the name to be changed, but still have a proper comparison
+ self.__id = id(self)
self.name = f'dep{id(self)}'
self.version: T.Optional[str] = None
self.language: T.Optional[str] = None # None means C-like
@@ -124,6 +128,14 @@ class Dependency(HoldableObject):
self.featurechecks: T.List['FeatureCheckBase'] = []
self.feature_since: T.Optional[T.Tuple[str, str]] = None
+ def __eq__(self, other: object) -> bool:
+ if not isinstance(other, Dependency):
+ return NotImplemented
+ return self.__id == other.__id
+
+ def __hash__(self) -> int:
+ return self.__id
+
def __repr__(self) -> str:
return f'<{self.__class__.__name__} {self.name}: {self.is_found}>'