Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit dependency fallback when a subproject wrap or dir exists #6902

Merged
merged 12 commits into from
Jul 1, 2020
Merged
Prev Previous commit
Next Next commit
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
  • Loading branch information
xclaesse committed Jul 1, 2020
commit 288d1ae5a5de13c8844635023caf27378df4919b
7 changes: 5 additions & 2 deletions mesonbuild/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3552,8 +3552,11 @@ def dependency_impl(self, name, display_name, kwargs):
return self.notfound_dependency()

has_fallback = 'fallback' in kwargs
if not has_fallback and name:
# Add an implicit fallback if we have a wrap file or a directory with the same 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,
# 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)
if provider:
kwargs['fallback'] = provider
Expand Down