From 2ef06618e2252fc5fb9262792a3bd544ec182ec5 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 14 Oct 2021 18:17:25 +0200 Subject: [PATCH] pass all outputs of a custom_target as arguments to a test Meson was passing only the first output and warning about it. To do this easily, refactor construct_target_rel_path to return a list. Signed-off-by: Paolo Bonzini --- mesonbuild/backend/backends.py | 31 ++++++++++++------- .../245 custom target index source/main.c | 4 ++- .../meson.build | 5 +-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index bb04feaf3..8633f23fc 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -1143,13 +1143,8 @@ class Backend: cmd_args.append(a) elif isinstance(a, str): cmd_args.append(a) - elif isinstance(a, build.Executable): - p = self.construct_target_rel_path(a, t.workdir) - if p == a.get_filename(): - p = './' + p - cmd_args.append(p) elif isinstance(a, build.Target): - cmd_args.append(self.construct_target_rel_path(a, t.workdir)) + cmd_args.extend(self.construct_target_rel_paths(a, t.workdir)) else: raise MesonException('Bad object in test command.') ts = TestSerialisation(t.get_name(), t.project_name, t.suite, cmd, is_cross, @@ -1166,12 +1161,24 @@ class Backend: def write_test_serialisation(self, tests: T.List['Test'], datafile: T.BinaryIO) -> None: pickle.dump(self.create_test_serialisation(tests), datafile) - def construct_target_rel_path(self, a: build.Target, workdir: T.Optional[str]) -> str: - if workdir is None: - return self.get_target_filename(a) - assert os.path.isabs(workdir) - abs_path = self.get_target_filename_abs(a) - return os.path.relpath(abs_path, workdir) + def construct_target_rel_paths(self, t: build.Target, workdir: T.Optional[str]) -> T.List[str]: + target_dir = self.get_target_dir(t) + # ensure that test executables can be run when passed as arguments + if isinstance(t, build.Executable) and workdir is None: + target_dir = target_dir or '.' + + if isinstance(t, build.BuildTarget): + outputs = [t.get_filename()] + else: + assert isinstance(t, build.CustomTarget) + outputs = t.get_outputs() + + outputs = [os.path.join(target_dir, x) for x in outputs] + if workdir is not None: + assert os.path.isabs(workdir) + outputs = [os.path.join(self.environment.get_build_dir(), x) for x in outputs] + outputs = [os.path.relpath(x, workdir) for x in outputs] + return outputs def generate_depmf_install(self, d: InstallData) -> None: if self.build.dep_manifest_name is None: diff --git a/test cases/common/245 custom target index source/main.c b/test cases/common/245 custom target index source/main.c index c1c2b09eb..48af14199 100644 --- a/test cases/common/245 custom target index source/main.c +++ b/test cases/common/245 custom target index source/main.c @@ -1,6 +1,8 @@ +#include #include "gen.h" -int main(void) +int main(int argc) { + assert(argc == 3); return genfunc(); } diff --git a/test cases/common/245 custom target index source/meson.build b/test cases/common/245 custom target index source/meson.build index 4dc54d440..c7efbd81b 100644 --- a/test cases/common/245 custom target index source/meson.build +++ b/test cases/common/245 custom target index source/meson.build @@ -46,5 +46,6 @@ exe_together = executable('exe_together', install: false, ) -test('exe_separate', exe_separate) -test('exe_together', exe_together) +# also cover passing custom target to tests as arguments +test('exe_separate', exe_separate, args: ['unused1', 'unused2']) +test('exe_together', exe_together, args: gen)