Skip to content

Commit

Permalink
dependency: define equality and hash operators for Dependency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcbaker committed Mar 15, 2024
1 parent 18f8aed commit 6d713e4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mesonbuild/dependencies/base.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -106,6 +107,9 @@ def _process_include_type_kw(cls, kwargs: T.Dict[str, T.Any]) -> str:
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
Expand All @@ -124,6 +128,14 @@ def __init__(self, type_name: DependencyTypeName, kwargs: T.Dict[str, T.Any]) ->
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}>'

Expand Down

0 comments on commit 6d713e4

Please sign in to comment.