wrap: Do not fallback implicitly on optional dependency

This fix the following common pattern, we don't want to implicitly
fallback on the first line:

foo_dep = dependency('foo', required: false)
if not foo_dep.found()
  foo_dep = cc.find_library('foo', required : false)
  if not foo_dep.found()
    foo_dep = dependency('foo', fallback: 'foo')
  endif
endif
pull/6902/head
Xavier Claessens 5 years ago
parent 71804e56eb
commit 288d1ae5a5
  1. 7
      mesonbuild/interpreter.py

@ -3552,8 +3552,11 @@ external dependencies (including libraries) must go to "dependencies".''')
return self.notfound_dependency() return self.notfound_dependency()
has_fallback = 'fallback' in kwargs has_fallback = 'fallback' in kwargs
if not has_fallback and name: if not has_fallback and name and required:
# Add an implicit fallback if we have a wrap file or a directory with the same name. # Add an implicit fallback if we have a wrap file or a directory with the same name,
# but only if this dependency is required. It is common to first check for a pkg-config,
# then fallback to use find_library() and only afterward check again the dependency
# with a fallback.
provider = self.environment.wrap_resolver.find_provider(name) provider = self.environment.wrap_resolver.find_provider(name)
if provider: if provider:
kwargs['fallback'] = provider kwargs['fallback'] = provider

Loading…
Cancel
Save