aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-05-22 20:34:45 +0300
committerGitHub <noreply@github.com>2018-05-22 20:34:45 +0300
commitf4194d4dbc5c48ff9a0d76c779876aab60754230 (patch)
tree4f5a98896a6f808af617e53679bfa3b8dbf156f0 /mesonbuild/interpreter.py
parent710a3f7f20ab2b37bdb5e554d9439e03276de444 (diff)
parent2e2d14c9d7f2d6747eeaced85aba781390d24133 (diff)
downloadmeson-f4194d4dbc5c48ff9a0d76c779876aab60754230.zip
meson-f4194d4dbc5c48ff9a0d76c779876aab60754230.tar.gz
meson-f4194d4dbc5c48ff9a0d76c779876aab60754230.tar.bz2
Merge pull request #3523 from taisei-project/run_command_check
Add 'check' kwarg for run_command
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r--mesonbuild/interpreter.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 49e9381..070845b 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -92,18 +92,18 @@ class TryRunResultHolder(InterpreterObject):
class RunProcess(InterpreterObject):
- def __init__(self, cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir=False):
+ def __init__(self, cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir=False, check=False):
super().__init__()
if not isinstance(cmd, ExternalProgram):
raise AssertionError('BUG: RunProcess must be passed an ExternalProgram')
- pc, self.stdout, self.stderr = self.run_command(cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir)
+ pc, self.stdout, self.stderr = self.run_command(cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir, check)
self.returncode = pc.returncode
self.methods.update({'returncode': self.returncode_method,
'stdout': self.stdout_method,
'stderr': self.stderr_method,
})
- def run_command(self, cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir):
+ def run_command(self, cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir, check=False):
command_array = cmd.get_command() + args
env = {'MESON_SOURCE_ROOT': source_dir,
'MESON_BUILD_ROOT': build_dir,
@@ -124,6 +124,10 @@ class RunProcess(InterpreterObject):
mlog.debug('----stderr----')
mlog.debug(e)
mlog.debug('')
+
+ if check and p.returncode != 0:
+ raise InterpreterException('Command "{}" failed with status {}.'.format(' '.join(command_array), p.returncode))
+
return p, o, e
except FileNotFoundError:
raise InterpreterException('Could not execute command "%s".' % ' '.join(command_array))
@@ -1679,6 +1683,7 @@ permitted_kwargs = {'add_global_arguments': {'language'},
'install_subdir': {'exclude_files', 'exclude_directories', 'install_dir', 'install_mode', 'strip_directory'},
'jar': build.known_jar_kwargs,
'project': {'version', 'meson_version', 'default_options', 'license', 'subproject_dir'},
+ 'run_command': {'check'},
'run_target': {'command', 'depends'},
'shared_library': build.known_shlib_kwargs,
'shared_module': build.known_shmod_kwargs,
@@ -1957,7 +1962,7 @@ external dependencies (including libraries) must go to "dependencies".''')
if not isinstance(actual, wanted):
raise InvalidArguments('Incorrect argument type.')
- @noKwargs
+ @permittedKwargs(permitted_kwargs['run_command'])
def func_run_command(self, node, args, kwargs):
return self.run_command_impl(node, args, kwargs)
@@ -1968,6 +1973,11 @@ external dependencies (including libraries) must go to "dependencies".''')
cargs = args[1:]
srcdir = self.environment.get_source_dir()
builddir = self.environment.get_build_dir()
+
+ check = kwargs.get('check', False)
+ if not isinstance(check, bool):
+ raise InterpreterException('Check must be boolean.')
+
m = 'must be a string, or the output of find_program(), files() '\
'or configure_file(), or a compiler object; not {!r}'
if isinstance(cmd, ExternalProgramHolder):
@@ -2020,7 +2030,7 @@ external dependencies (including libraries) must go to "dependencies".''')
if a not in self.build_def_files:
self.build_def_files.append(a)
return RunProcess(cmd, expanded_args, srcdir, builddir, self.subdir,
- self.environment.get_build_command() + ['introspect'], in_builddir)
+ self.environment.get_build_command() + ['introspect'], in_builddir, check)
@stringArgs
def func_gettext(self, nodes, args, kwargs):