Skip to content

Commit 31a81f9

Browse files
committed
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.
1 parent 0b7b4a3 commit 31a81f9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

mesonbuild/dependencies/base.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright 2013-2018 The Meson development team
3+
# Copyright © 2024 Intel Corporation
34

45
# This file contains the detection logic for external dependencies.
56
# Custom logic for several other packages are in separate files.
@@ -106,6 +107,9 @@ def _process_include_type_kw(cls, kwargs: T.Dict[str, T.Any]) -> str:
106107
return kwargs['include_type']
107108

108109
def __init__(self, type_name: DependencyTypeName, kwargs: T.Dict[str, T.Any]) -> None:
110+
# This allows two Dependencies to be compared even after being copied.
111+
# The purpose is to allow the name to be changed, but still have a proper comparison
112+
self.__id = id(self)
109113
self.name = f'dep{id(self)}'
110114
self.version: T.Optional[str] = None
111115
self.language: T.Optional[str] = None # None means C-like
@@ -124,6 +128,14 @@ def __init__(self, type_name: DependencyTypeName, kwargs: T.Dict[str, T.Any]) ->
124128
self.featurechecks: T.List['FeatureCheckBase'] = []
125129
self.feature_since: T.Optional[T.Tuple[str, str]] = None
126130

131+
def __eq__(self, other: object) -> bool:
132+
if not isinstance(other, Dependency):
133+
return NotImplemented
134+
return self.__id == other.__id
135+
136+
def __hash__(self) -> int:
137+
return self.__id
138+
127139
def __repr__(self) -> str:
128140
return f'<{self.__class__.__name__} {self.name}: {self.is_found}>'
129141

0 commit comments

Comments
 (0)