From 8c34ea645dfcc2e5043be93fa0f692c24a153a56 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 30 May 2016 03:30:53 +0530 Subject: interpreter: Compare the version of a cached dependency() before using it Without this, checks with incompatible versions but the same library would return true. Example: dependency('zlib', version : '>=1.2') dependency('zlib', version : '<1.0') # this will return the same dep again! Example: https://github.com/mesonbuild/meson/issues/568 --- mesonbuild/interpreter.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'mesonbuild') diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index a45c767..f0d22c5 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1617,11 +1617,21 @@ class Interpreter(): self.validate_arguments(args, 1, [str]) name = args[0] identifier = dependencies.get_dep_identifier(name, kwargs) + # Check if we've already searched for and found this dep + cached_dep = None if identifier in self.coredata.deps: - dep = self.coredata.deps[identifier] + cached_dep = self.coredata.deps[identifier] + if 'version' in kwargs: + wanted = kwargs['version'] + found = cached_dep.get_version() + if not found or not mesonlib.version_compare(found, wanted): + # Cached dep has the wrong version. Check if an external + # dependency or a fallback dependency provides it. + cached_dep = None + if cached_dep: + dep = cached_dep else: - dep = dependencies.Dependency() # Returns always false for dep.found() - if not dep.found(): + # We need to actually search for this dep try: dep = dependencies.find_external_dependency(name, self.environment, kwargs) except dependencies.DependencyException: -- cgit v1.1