diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 3e64a6750..7896f5113 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -3585,13 +3585,15 @@ external dependencies (including libraries) must go to "dependencies".''') return self.notfound_dependency() has_fallback = 'fallback' in kwargs - if not has_fallback and name and required: + if not has_fallback and 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. + # with a fallback. If the fallback has already been configured then we have to use it + # even if the dependency is not required. provider = self.environment.wrap_resolver.find_dep_provider(name) - if provider: + dirname = mesonlib.listify(provider)[0] + if provider and (required or dirname in self.subprojects): kwargs['fallback'] = provider has_fallback = True diff --git a/test cases/common/102 subproject subdir/meson.build b/test cases/common/102 subproject subdir/meson.build index 6faff753f..93093bf42 100644 --- a/test cases/common/102 subproject subdir/meson.build +++ b/test cases/common/102 subproject subdir/meson.build @@ -40,3 +40,10 @@ assert(d.found(), 'Should implicitly fallback') # sub_implicit_provide2. d = dependency('sub_implicit_provide2') assert(d.found(), 'Should implicitly fallback') + +# sub_implicit.wrap provides glib-2.0 and we already configured that subproject, +# so we must not return the system dependency here. Using glib-2.0 here because +# some CI runners have it installed. +d = dependency('glib-2.0', required : false) +assert(d.found()) +assert(d.type_name() == 'internal') diff --git a/test cases/common/102 subproject subdir/subprojects/sub_implicit.wrap b/test cases/common/102 subproject subdir/subprojects/sub_implicit.wrap index e668a8da3..6f2dab6e5 100644 --- a/test cases/common/102 subproject subdir/subprojects/sub_implicit.wrap +++ b/test cases/common/102 subproject subdir/subprojects/sub_implicit.wrap @@ -1,5 +1,6 @@ [wrap-file] [provide] +glib-2.0 = glib_dep dependency_names = sub_implicit_provide1 sub_implicit_provide2 = sub_implicit_provide2_dep diff --git a/test cases/common/102 subproject subdir/subprojects/sub_implicit/meson.build b/test cases/common/102 subproject subdir/subprojects/sub_implicit/meson.build index 64374d30d..24609ae09 100644 --- a/test cases/common/102 subproject subdir/subprojects/sub_implicit/meson.build +++ b/test cases/common/102 subproject subdir/subprojects/sub_implicit/meson.build @@ -6,3 +6,6 @@ meson.override_dependency('sub_implicit_provide1', dep) # This one is not overriden but the wrap file tells the variable name to use. sub_implicit_provide2_dep = dep + +# This one is not overriden but the wrap file tells the variable name to use. +glib_dep = dep