From fd260eac817c80105597149f615b71323602e949 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 25 Oct 2016 11:16:22 +0530 Subject: Don't ignore invalid code related to subproject calls We should only silently return from a dependency() call if the error is transient (old version, wrap failed to download etc), not if the subproject invocation or dependency name are incorrect. For instance, if you use a dependency(..., fallback : ...) call in a meson.build not in the root directory, we would always ignore the call instead of erroring out due to invalid usage. We should consider categorising our exceptions in this manner elsewhere too. --- mesonbuild/interpreter.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 3044d51..8fa9385 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1555,7 +1555,7 @@ class Interpreter(): if dirname in self.subproject_stack: fullstack = self.subproject_stack + [dirname] incpath = ' => '.join(fullstack) - raise InterpreterException('Recursive include of subprojects: %s.' % incpath) + raise InvalidCode('Recursive include of subprojects: %s.' % incpath) if dirname in self.subprojects: return self.subprojects[dirname] r = wrap.Resolver(os.path.join(self.build.environment.get_source_dir(), self.subproject_dir)) @@ -1908,8 +1908,14 @@ requirements use the version keyword argument instead.''') def dependency_fallback(self, name, kwargs): dirname, varname = self.get_subproject_infos(kwargs) + # Try to execute the subproject try: self.do_subproject(dirname, {}) + # Invalid code is always an error + except InvalidCode: + raise + # If the subproject execution failed in a non-fatal way, don't raise an + # exception; let the caller handle things. except: mlog.log('Also couldn\'t find a fallback subproject in', mlog.bold(os.path.join(self.subproject_dir, dirname)), @@ -1918,13 +1924,11 @@ requirements use the version keyword argument instead.''') try: dep = self.subprojects[dirname].get_variable_method([varname], {}) except KeyError: - mlog.log('Fallback variable', mlog.bold(varname), - 'in the subproject', mlog.bold(dirname), 'does not exist') - return None + raise InvalidCode('Fallback variable {!r} in the subproject ' + '{!r} does not exist'.format(varname, dirname)) if not isinstance(dep, DependencyHolder): - mlog.log('Fallback variable', mlog.bold(varname), - 'in the subproject', mlog.bold(dirname), - 'is not a dependency object.') + raise InvalidCode('Fallback variable {!r} in the subproject {!r} is ' + 'not a dependency object.'.format(varname, dirname)) return None # Check if the version of the declared dependency matches what we want if 'version' in kwargs: -- cgit v1.1 From 52b589fd55b9fdd62bc07ebc958b3bea2908ac96 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Tue, 25 Oct 2016 11:23:38 +0530 Subject: Test that invalid subproject code in dependency() errors out --- test cases/failing/34 non-root subproject/meson.build | 3 +++ test cases/failing/34 non-root subproject/some/meson.build | 1 + 2 files changed, 4 insertions(+) create mode 100644 test cases/failing/34 non-root subproject/meson.build create mode 100644 test cases/failing/34 non-root subproject/some/meson.build diff --git a/test cases/failing/34 non-root subproject/meson.build b/test cases/failing/34 non-root subproject/meson.build new file mode 100644 index 0000000..c84dce7 --- /dev/null +++ b/test cases/failing/34 non-root subproject/meson.build @@ -0,0 +1,3 @@ +project('non-root subproject', 'c') + +subdir('some') diff --git a/test cases/failing/34 non-root subproject/some/meson.build b/test cases/failing/34 non-root subproject/some/meson.build new file mode 100644 index 0000000..d82f451 --- /dev/null +++ b/test cases/failing/34 non-root subproject/some/meson.build @@ -0,0 +1 @@ +dependency('definitely-doesnt-exist', fallback : ['someproj', 'some_dep']) -- cgit v1.1