Also reuse subproject-based fallback dependencies

This allows a project to use the same fallbacks dependency from the same
subproject multiple times in the same way that external dependencies can be.

Also change the format of the dependency identifier to ensure that fallback
checks with different dirname/varname aren't mistakenly reused. We now use
a tuple for this because the format is simpler to construct and it gives us the
same immutability guarantees as a string which is needed for using it as
a dictionary key.
This commit is contained in:
Nirbheek Chauhan 2016-05-30 02:22:20 +05:30
parent f2256ba098
commit c33e7a68a1
2 changed files with 12 additions and 2 deletions

View File

@ -1148,7 +1148,15 @@ def get_dep_identifier(name, kwargs):
modlist = [modlist]
for module in modlist:
elements.append(module)
return '/'.join(elements) + '/main' + str(kwargs.get('main', False)) + '/static' + str(kwargs.get('static', False))
# 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])
return identifier
def find_external_dependency(name, environment, kwargs):
required = kwargs.get('required', True)

View File

@ -1626,7 +1626,9 @@ class Interpreter():
dep = dependencies.find_external_dependency(name, self.environment, kwargs)
except dependencies.DependencyException:
if 'fallback' in kwargs:
return self.dependency_fallback(kwargs)
dep = self.dependency_fallback(kwargs)
self.coredata.deps[identifier] = dep.held_object
return dep
raise
self.coredata.deps[identifier] = dep
return DependencyHolder(dep)