From 1e2a70f0a2522b36b234e1b30a792c205cc15de3 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Mon, 8 Feb 2021 21:46:00 +0200 Subject: Fix exe wrapper detection for run targets. --- mesonbuild/backend/backends.py | 12 +++++++++++- mesonbuild/backend/ninjabackend.py | 2 +- mesonbuild/backend/vs2010backend.py | 2 +- run_unittests.py | 3 +-- test cases/common/52 run target/meson.build | 9 +++++++-- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index e19afca..df9c9eb 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -397,9 +397,17 @@ class Backend: if isinstance(exe, dependencies.ExternalProgram): exe_cmd = exe.get_command() exe_for_machine = exe.for_machine - elif isinstance(exe, (build.BuildTarget, build.CustomTarget)): + elif isinstance(exe, build.BuildTarget): exe_cmd = [self.get_target_filename_abs(exe)] exe_for_machine = exe.for_machine + elif isinstance(exe, build.CustomTarget): + # The output of a custom target can either be directly runnable + # or not, that is, a script, a native binary or a cross compiled + # binary when exe wrapper is available and when it is not. + # This implementation is not exhaustive but it works in the + # common cases. + exe_cmd = [self.get_target_filename_abs(exe)] + exe_for_machine = MachineChoice.BUILD else: exe_cmd = [exe] exe_for_machine = MachineChoice.BUILD @@ -470,6 +478,8 @@ class Backend: if isinstance(exe, (dependencies.ExternalProgram, build.BuildTarget, build.CustomTarget)): basename = exe.name + elif isinstance(exe, mesonlib.File): + basename = os.path.basename(exe.fname) else: basename = os.path.basename(exe) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index b93ac39..96ba4fa 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -995,7 +995,7 @@ int dummy; target_env = self.get_run_target_env(target) _, _, cmd = self.eval_custom_target_command(target) desc = 'Running external command {}{}' - meson_exe_cmd, reason = self.as_meson_exe_cmdline(target_name, cmd[0], cmd[1:], + meson_exe_cmd, reason = self.as_meson_exe_cmdline(target_name, target.command[0], cmd[1:], force_serialize=True, env=target_env, verbose=True) cmd_type = ' (wrapped by meson {})'.format(reason) diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index e94ab49..7bbd2b6 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -536,7 +536,7 @@ class Vs2010Backend(backends.Backend): _, _, cmd_raw = self.eval_custom_target_command(target) depend_files = self.get_custom_target_depend_files(target) target_env = self.get_run_target_env(target) - wrapper_cmd, _ = self.as_meson_exe_cmdline(target.name, cmd_raw[0], cmd_raw[1:], + wrapper_cmd, _ = self.as_meson_exe_cmdline(target.name, target.command[0], cmd_raw[1:], force_serialize=True, env=target_env, verbose=True) self.add_custom_build(root, 'run_target', ' '.join(self.quote_arguments(wrapper_cmd)), diff --git a/run_unittests.py b/run_unittests.py index 23bdff4..e53f0c7 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -7881,7 +7881,6 @@ class LinuxCrossMingwTests(BaseLinuxCrossTests): # Force tracebacks so we can detect them properly env = {'MESON_FORCE_BACKTRACE': '1'} error_message = "An exe_wrapper is needed but was not found. Please define one in cross file and check the command and/or add it to PATH." - error_message2 = "The exe_wrapper 'broken' defined in the cross file is needed by run target 'run-prog', but was not found. Please check the command and/or add it to PATH." with self.assertRaises(MesonException) as cm: # Must run in-process or we'll get a generic CalledProcessError @@ -7895,7 +7894,7 @@ class LinuxCrossMingwTests(BaseLinuxCrossTests): self.init(testdir, extra_args='-Dcustom-target=false', inprocess=True, override_envvars=env) - self.assertEqual(str(cm.exception), error_message2) + self.assertEqual(str(cm.exception), error_message) self.init(testdir, extra_args=['-Dcustom-target=false', '-Drun-target=false'], override_envvars=env) diff --git a/test cases/common/52 run target/meson.build b/test cases/common/52 run target/meson.build index a28d218..49e8d75 100644 --- a/test cases/common/52 run target/meson.build +++ b/test cases/common/52 run target/meson.build @@ -4,8 +4,11 @@ project('run target', 'c') # In cross builds exe_wrapper should be added if it exists. exe = executable('helloprinter', 'helloprinter.c') -run_target('runhello', - command : [exe, 'argument']) + +if not meson.is_cross_build() or meson.can_run_host_binaries() + run_target('runhello', + command : [exe, 'argument']) +endif converter = find_program('converter.py') @@ -62,10 +65,12 @@ conf = configure_file( configuration: configuration_data() ) + run_target('configure_script', command : conf ) + # Target names that clash with potential builtin functionality. run_target('ctags', command : converter) -- cgit v1.1