From f54f27b1a8d0b3ea842ed8981f4f56cd305f9794 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 24 Jan 2020 13:26:27 -0500 Subject: [PATCH] Fix required dependency() not failing when wrap-mode=nofallback When a dependency is required, not found on the system, and its fallback is disabled with --wrap-mode=nofallback, meson should abort instead of returning not-found. --- mesonbuild/interpreter.py | 6 +++++- run_unittests.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index d936455fe..9f661b698 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -3326,10 +3326,14 @@ external dependencies (including libraries) must go to "dependencies".''') return fbinfo def dependency_fallback(self, display_name, kwargs): + required = kwargs.get('required', True) if self.coredata.get_builtin_option('wrap_mode') == WrapMode.nofallback: mlog.log('Not looking for a fallback subproject for the dependency', mlog.bold(display_name), 'because:\nUse of fallback ' 'dependencies is disabled.') + if required: + m = 'Dependency {!r} not found and fallback is disabled' + raise DependencyException(m.format(display_name)) return self.notfound_dependency() elif self.coredata.get_builtin_option('wrap_mode') == WrapMode.forcefallback: mlog.log('Looking for a fallback subproject for the dependency', @@ -3340,7 +3344,7 @@ external dependencies (including libraries) must go to "dependencies".''') dirname, varname = self.get_subproject_infos(kwargs) sp_kwargs = { 'default_options': kwargs.get('default_options', []), - 'required': kwargs.get('required', True), + 'required': required, } self.do_subproject(dirname, 'meson', sp_kwargs) return self.get_subproject_dep(display_name, dirname, varname, kwargs) diff --git a/run_unittests.py b/run_unittests.py index b8f6172a5..da18a8bdd 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4529,6 +4529,11 @@ class FailureTests(BasePlatformTests): "}['a'] == 2)\n", r"Assert failed: {k1 : 1}\['a'\] == 2") + def test_wrap_nofallback(self): + self.assertMesonRaises("dependency('notfound', fallback : ['foo', 'foo_dep'])", + r"Dependency \'notfound\' not found and fallback is disabled", + extra_args=['--wrap-mode=nofallback']) + @unittest.skipUnless(is_windows() or is_cygwin(), "requires Windows (or Windows via Cygwin)") class WindowsTests(BasePlatformTests): '''