From a92b41fdcd0691c2efc8222be1cb8d3ea1c29aa7 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 27 Dec 2018 14:44:24 -0500 Subject: [PATCH] dependencies: Remove version from cache key We cannot have 2 different versions with all other kwargs being identical. This simplifies a lot that code. --- mesonbuild/dependencies/base.py | 11 ++++------ mesonbuild/interpreter.py | 38 +++++++++++++++------------------ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 35237d09d..e9f778bb0 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -1984,17 +1984,14 @@ class ExtraFrameworkDependency(ExternalDependency): def get_dep_identifier(name, kwargs, want_cross): - # Need immutable objects since the identifier will be used as a dict key - version_reqs = listify(kwargs.get('version', [])) - if isinstance(version_reqs, list): - version_reqs = frozenset(version_reqs) - identifier = (name, version_reqs, want_cross) + identifier = (name, want_cross) for key, value in kwargs.items(): - # 'version' is embedded above as the second element for easy access + # 'version' is irrelevant for caching; the caller must check version matches # 'native' is handled above with `want_cross` # 'required' is irrelevant for caching; the caller handles it separately # 'fallback' subprojects cannot be cached -- they must be initialized - if key in ('version', 'native', 'required', 'fallback',): + # 'default_options' is only used in fallback case + if key in ('version', 'native', 'required', 'fallback', 'default_options'): continue # All keyword arguments are strings, ints, or lists (or lists of lists) if isinstance(value, list): diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 125d2cf03..1963d3c49 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2851,28 +2851,24 @@ external dependencies (including libraries) must go to "dependencies".''') want_cross = not kwargs['native'] else: want_cross = is_cross + identifier = dependencies.get_dep_identifier(name, kwargs, want_cross) - cached_dep = None - # Check if we've already searched for and found this dep - if identifier in self.coredata.deps: - cached_dep = self.coredata.deps[identifier] - mlog.log('Dependency', mlog.bold(name), - 'found:', mlog.green('YES'), '(cached)') - else: - # Check if exactly the same dep with different version requirements - # was found already. - wanted = identifier[1] - for trial, trial_dep in self.coredata.deps.items(): - # trial[1], identifier[1] are the version requirements - if trial[0] != identifier[0] or trial[2:] != identifier[2:]: - continue - found = trial_dep.get_version() - if not wanted or mesonlib.version_compare_many(found, wanted)[0]: - # We either don't care about the version, or our - # version requirements matched the trial dep's version. - cached_dep = trial_dep - break - return identifier, cached_dep + cached_dep = self.coredata.deps.get(identifier) + if cached_dep: + if not cached_dep.found(): + mlog.log('Dependency', mlog.bold(name), + 'found:', mlog.red('NO'), '(cached)') + return identifier, cached_dep + + # Verify the cached dep version match + wanted = kwargs.get('version', []) + found = cached_dep.get_version() + if not wanted or mesonlib.version_compare_many(found, wanted)[0]: + mlog.log('Dependency', mlog.bold(name), + 'found:', mlog.green('YES'), '(cached)') + return identifier, cached_dep + + return identifier, None @staticmethod def check_subproject_version(wanted, found):