From b1df1a2bec053937ecb09f425248c1dbcee9237a Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sun, 7 May 2017 00:20:29 +0530 Subject: [PATCH] run_command: accept built File objects too The file will always exist by the time run_command() is invoked, so there is no reason why we should forbid it. Also allow using File objects as the command to run since strings are also allowed. --- mesonbuild/interpreter.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index d8f3b2b69..2c6806a11 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1469,28 +1469,33 @@ class Interpreter(InterpreterBase): raise InterpreterException('Not enough arguments') cmd = args[0] cargs = args[1:] + srcdir = self.environment.get_source_dir() + builddir = self.environment.get_build_dir() if isinstance(cmd, ExternalProgramHolder): cmd = cmd.get_command() elif isinstance(cmd, str): cmd = [cmd] + elif isinstance(cmd, mesonlib.File): + cmd = [cmd.absolute_path(srcdir, builddir)] else: - raise InterpreterException('First argument should be find_program() ' - 'or string, not {!r}'.format(cmd)) + m = 'First argument must be a string, or the output of ' \ + 'find_program(), files(), or configure_file(); not {!r}' + raise InterpreterException(m.format(cmd)) expanded_args = [] for a in mesonlib.flatten(cargs): if isinstance(a, str): expanded_args.append(a) elif isinstance(a, mesonlib.File): - if a.is_built: - raise InterpreterException('Can not use generated files in run_command.') - expanded_args.append(os.path.join(self.environment.get_source_dir(), str(a))) + expanded_args.append(a.absolute_path(srcdir, builddir)) else: - raise InterpreterException('Run_command arguments must be strings or the output of files().') + m = 'run_command() arguments must be strings, the output of ' \ + 'files(), or configure_file(); not {!r}' + raise InterpreterException(m.format(a)) args = cmd + expanded_args in_builddir = kwargs.get('in_builddir', False) if not isinstance(in_builddir, bool): raise InterpreterException('in_builddir must be boolean.') - return RunProcess(args, self.environment.source_dir, self.environment.build_dir, self.subdir, + return RunProcess(args, srcdir, builddir, self.subdir, get_meson_script(self.environment, 'mesonintrospect'), in_builddir) @stringArgs