From 9235fd4ec1cfdea9f1c73719c80607ee0cdad39b Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 7 Sep 2016 23:04:11 +0300 Subject: [PATCH 1/2] Permit use of file objects in run targets. --- mesonbuild/backend/ninjabackend.py | 2 ++ mesonbuild/interpreter.py | 4 ++-- test cases/common/58 run target/meson.build | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e81c407b6..adf9b7148 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -424,6 +424,8 @@ int dummy; elif isinstance(i, (build.BuildTarget, build.CustomTarget)): relfname = self.get_target_filename(i) arg_strings.append(os.path.join(self.environment.get_build_dir(), relfname)) + elif isinstance(i, mesonlib.File): + arg_strings.append(i.rel_to_builddir(self.build_to_src)) else: mlog.debug(str(i)) raise MesonException('Unreachable code in generate_run_target.') diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 0c53326fb..361e0aa60 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1873,12 +1873,12 @@ class Interpreter(): raise InterpreterException('Run_target needs at least one positional argument.') cleaned_args = [] - for i in all_args: + for i in mesonlib.flatten(all_args): try: i = i.held_object except AttributeError: pass - if not isinstance(i, (str, build.BuildTarget, build.CustomTarget, dependencies.ExternalProgram)): + if not isinstance(i, (str, build.BuildTarget, build.CustomTarget, dependencies.ExternalProgram, mesonlib.File)): mlog.debug('Wrong type:', str(i)) raise InterpreterException('Invalid argument to run_target.') cleaned_args.append(i) diff --git a/test cases/common/58 run target/meson.build b/test cases/common/58 run target/meson.build index 0febe3565..0ef196680 100644 --- a/test cases/common/58 run target/meson.build +++ b/test cases/common/58 run target/meson.build @@ -34,3 +34,6 @@ run_target('upload2', python3 = find_program('python3') run_target('py3hi', command : [python3, '-c', 'print("I am Python3.")']) + +run_target('ct_in_arg', + command : ['echo', hex, files('helloprinter.c')]) From d26ab47072906d7a28a8843617487e601b56dfb2 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 7 Sep 2016 23:14:14 +0300 Subject: [PATCH 2/2] Can use custom targets as executables to run in a run_target. --- mesonbuild/backend/ninjabackend.py | 3 +++ test cases/common/58 run target/meson.build | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index adf9b7148..481b8001e 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -448,6 +448,9 @@ int dummy; cmd.append(abs_exe) elif isinstance(texe, dependencies.ExternalProgram): cmd += texe.get_command() + elif isinstance(texe, build.CustomTarget): + deps.append(self.get_target_filename(texe)) + cmd += [os.path.join(self.environment.get_build_dir(), self.get_target_filename(texe))] else: cmd.append(target.command) cmd += arg_strings diff --git a/test cases/common/58 run target/meson.build b/test cases/common/58 run target/meson.build index 0ef196680..0ab41b3f5 100644 --- a/test cases/common/58 run target/meson.build +++ b/test cases/common/58 run target/meson.build @@ -37,3 +37,9 @@ run_target('py3hi', run_target('ct_in_arg', command : ['echo', hex, files('helloprinter.c')]) + +# What if the output of a custom_target is the command to +# execute. Obviously this will not work as hex is not an +# executable but test that the output is generated correctly. +run_target('donotrunme', + command : [hex])