diff --git a/interpreter.py b/interpreter.py index 99238920f..2d86454e3 100644 --- a/interpreter.py +++ b/interpreter.py @@ -1451,11 +1451,18 @@ class Interpreter(): self.add_target(name, tg.held_object) return tg - @stringArgs @noKwargs def func_run_target(self, node, args, kwargs): if len(args) < 2: raise InterpreterException('Incorrect number of arguments') + for i in args: + try: + i = i.held_object + except AttributeError: + pass + if not isinstance(i, (str, build.BuildTarget)): + mlog.debug('Wrong type:', str(i)) + raise InterpreterException('Invalid argument to run_target.') name = args[0] command = args[1] cmd_args = args[2:] diff --git a/ninjabackend.py b/ninjabackend.py index ebf0a9403..3e15a3154 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -312,9 +312,32 @@ class NinjaBackend(backends.Backend): def generate_run_target(self, target, outfile): runnerscript = os.path.join(self.environment.get_script_dir(), 'commandrunner.py') - elem = NinjaBuildElement(target.name, 'CUSTOM_COMMAND', []) - cmd = [sys.executable, runnerscript, self.environment.get_source_dir(), self.environment.get_build_dir(), - target.subdir, target.command] + target.args + deps = [] + arg_strings = [] + for i in target.args: + if isinstance(i, str): + arg_strings.append(i) + elif isinstance(i, build.BuildTarget): + deps.append(self.get_target_filename(i)) + else: + raise MesonException('Unreachable code.') + elem = NinjaBuildElement(target.name, 'CUSTOM_COMMAND', deps) + cmd = [sys.executable, runnerscript, self.environment.get_source_dir(), self.environment.get_build_dir(), target.subdir] + texe = target.command + try: + texe = texe.held_object + except AttributeError: + pass + if isinstance(texe, build.Executable): + deps.append(self.get_target_filename(texe)) + if self.environment.is_cross_build() \ + and wrapper is not self.environment.cross_info.config['binaries'].get('exe_wrapper', None): + cmd += [self.environment.cross_info.config['binaries']['exe_wrapper'], self.get_target_filename(texe)] + else: + cmd += [os.path.join(self.environment.get_build_dir(), self.get_target_filename(texe))] + else: + cmd.append(target.command) + cmd += target.args elem.add_item('COMMAND', cmd) elem.add_item('description', 'Running external command %s.' % target.name) elem.add_item('pool', 'console') diff --git a/test cases/common/58 run target/helloprinter.c b/test cases/common/58 run target/helloprinter.c new file mode 100644 index 000000000..7f94b19fa --- /dev/null +++ b/test cases/common/58 run target/helloprinter.c @@ -0,0 +1,10 @@ +#include + +int main(int argc, char **argv) { + if(argc != 2) { + printf("I can not haz argument.\n"); + } else { + printf("I can haz argument: %s\n", argv[1]); + } + return 0; +} diff --git a/test cases/common/58 run target/meson.build b/test cases/common/58 run target/meson.build index 3ae80d217..519adf5df 100644 --- a/test cases/common/58 run target/meson.build +++ b/test cases/common/58 run target/meson.build @@ -1,3 +1,9 @@ project('run target', 'c') run_target('mycommand', 'scripts/script.sh') + +# Make it possible to run built programs. +# In cross builds exe_wrapper should be added if it exists. + +exe = executable('helloprinter', 'helloprinter.c') +run_target('runhello', exe, 'argument')