Honor dependency `fallback` argument even if the dependency is not required (#735)

You can potentially have a fallback subproject and if that subproject
fails, you can continue without that dependency
This commit is contained in:
Saunier Thibault 2016-08-29 16:31:10 -03:00 committed by Jussi Pakkanen
parent 6475bdbe20
commit e411c0b930
2 changed files with 25 additions and 9 deletions

View File

@ -1717,14 +1717,23 @@ class Interpreter():
dep = cached_dep dep = cached_dep
else: else:
# We need to actually search for this dep # We need to actually search for this dep
exception = None
dep = None
try: try:
dep = dependencies.find_external_dependency(name, self.environment, kwargs) dep = dependencies.find_external_dependency(name, self.environment, kwargs)
except dependencies.DependencyException: except dependencies.DependencyException as e:
exception = e
pass
if not dep or not dep.found():
if 'fallback' in kwargs: if 'fallback' in kwargs:
dep = self.dependency_fallback(name, kwargs) fallback_dep = self.dependency_fallback(name, kwargs)
self.coredata.deps[identifier] = dep.held_object if fallback_dep:
return dep return fallback_dep
raise
if not dep:
raise exception
self.coredata.deps[identifier] = dep self.coredata.deps[identifier] = dep
return DependencyHolder(dep) return DependencyHolder(dep)
@ -1740,7 +1749,10 @@ class Interpreter():
mlog.log('Also couldn\'t find a fallback subproject in', mlog.log('Also couldn\'t find a fallback subproject in',
mlog.bold(os.path.join(self.subproject_dir, dirname)), mlog.bold(os.path.join(self.subproject_dir, dirname)),
'for the dependency', mlog.bold(name)) 'for the dependency', mlog.bold(name))
if kwargs.get('required', True):
raise raise
else:
return None
dep = self.subprojects[dirname].get_variable_method([varname], {}) dep = self.subprojects[dirname].get_variable_method([varname], {})
if not isinstance(dep, (DependencyHolder, InternalDependencyHolder)): if not isinstance(dep, (DependencyHolder, InternalDependencyHolder)):
raise InterpreterException('Fallback variable is not a dependency object.') raise InterpreterException('Fallback variable is not a dependency object.')

View File

@ -1,6 +1,10 @@
project('dep fallback', 'c') project('dep fallback', 'c')
bob = dependency('boblib', fallback : ['boblib', 'bob_dep']) bob = dependency('boblib', fallback : ['boblib', 'bob_dep'], required: false)
if not bob.found()
error('Bob is actually needed')
endif
jimmy = dependency('jimmylib', fallback : ['jimmylib', 'jimmy_dep'], required: false)
exe = executable('bobtester', 'tester.c', dependencies : bob) exe = executable('bobtester', 'tester.c', dependencies : bob)
test('bobtester', exe) test('bobtester', exe)