diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-05-07 02:01:41 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-05-09 14:23:15 +0530 |
commit | c7d71c79434d98c280121ac1a20faca8fd512e40 (patch) | |
tree | 14fa2b546a8331fb55dc1aa436dacd49a64c7eb5 /mesonbuild | |
parent | bf54383d8aabd076a5893a3e849fd6788db77054 (diff) | |
download | meson-c7d71c79434d98c280121ac1a20faca8fd512e40.zip meson-c7d71c79434d98c280121ac1a20faca8fd512e40.tar.gz meson-c7d71c79434d98c280121ac1a20faca8fd512e40.tar.bz2 |
dependencies: Fix caching of native/cross dependencies
All our cached_dep magic was totally useless since we ended up using
the same identifier for native and cross deps. Just nuke all this
cached_dep code since it is very error-prone and improve the
identifier generation instead.
For instance, this is broken *right now* with the `type_name` kwarg.
Add a bunch of tests to ensure that all this actually works...
Closes https://github.com/mesonbuild/meson/issues/1736
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/dependencies.py | 26 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 12 |
2 files changed, 15 insertions, 23 deletions
diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py index 37e2cbd..2267492 100644 --- a/mesonbuild/dependencies.py +++ b/mesonbuild/dependencies.py @@ -1742,21 +1742,17 @@ class LLVMDependency(Dependency): return True -def get_dep_identifier(name, kwargs): - elements = [name] - modlist = kwargs.get('modules', []) - if isinstance(modlist, str): - modlist = [modlist] - for module in modlist: - elements.append(module) - # We use a tuple because we need a non-mutable structure to use as the key - # of a dictionary and a string has potential for name collisions - identifier = tuple(elements) - identifier += ('main', kwargs.get('main', False)) - identifier += ('static', kwargs.get('static', False)) - if 'fallback' in kwargs: - f = kwargs.get('fallback') - identifier += ('fallback', f[0], f[1]) +def get_dep_identifier(name, kwargs, want_cross): + # Need immutable objects since the identifier will be used as a dict key + identifier = (name, want_cross) + for key, value in kwargs.items(): + # Ignore versions, they will be handled by the caller + if key == 'version': + continue + # All keyword arguments are strings, ints, or lists (or lists of lists) + if isinstance(value, list): + value = frozenset(mesonlib.flatten(value)) + identifier += (key, value) return identifier def find_external_dependency(name, environment, kwargs): diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 80d482e..886f200 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1858,7 +1858,6 @@ class Interpreter(InterpreterBase): if '<' in name or '>' in name or '=' in name: raise InvalidArguments('Characters <, > and = are forbidden in dependency names. To specify' 'version\n requirements use the \'version\' keyword argument instead.') - identifier = dependencies.get_dep_identifier(name, kwargs) # Check if we want this as a cross-dep or a native-dep # FIXME: Not all dependencies support such a distinction right now, # and we repeat this check inside dependencies that do. We need to @@ -1868,10 +1867,14 @@ class Interpreter(InterpreterBase): want_cross = not kwargs['native'] else: want_cross = is_cross + identifier = dependencies.get_dep_identifier(name, kwargs, want_cross) # Check if we've already searched for and found this dep cached_dep = None if identifier in self.coredata.deps: cached_dep = self.coredata.deps[identifier] + # All other kwargs are handled in get_dep_identifier(). We have + # this here as a tiny optimization to avoid searching for + # dependencies that we already have. if 'version' in kwargs: wanted = kwargs['version'] found = cached_dep.get_version() @@ -1880,13 +1883,6 @@ class Interpreter(InterpreterBase): # Cached dep has the wrong version. Check if an external # dependency or a fallback dependency provides it. cached_dep = None - # Don't re-use cached dep if it wasn't required but this one is, - # so we properly go into fallback/error code paths - if kwargs.get('required', True) and not getattr(cached_dep, 'required', False): - cached_dep = None - # Don't reuse cached dep if one is a cross-dep and the other is a native dep - if not getattr(cached_dep, 'want_cross', is_cross) == want_cross: - cached_dep = None if cached_dep: dep = cached_dep |