From 18408f82d1ed2f04ef069e8e5836449a9cc5c355 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 14 Oct 2021 18:19:15 +0200 Subject: [PATCH] allow passing a CustomTargetIndex as argument to a test Fixes: #7585 Signed-off-by: Paolo Bonzini --- mesonbuild/backend/backends.py | 8 +++++--- mesonbuild/interpreter/interpreter.py | 2 +- .../common/245 custom target index source/meson.build | 2 +- test cases/failing/116 run_target in test/test.json | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 8633f23fc..718f54c1d 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -1135,6 +1135,8 @@ class Backend: for a in t.cmd_args: if isinstance(a, build.Target): depends.add(a) + elif isinstance(a, build.CustomTargetIndex): + depends.add(a.target) if isinstance(a, build.BuildTarget): extra_paths += self.determine_windows_extra_paths(a, []) @@ -1143,7 +1145,7 @@ class Backend: cmd_args.append(a) elif isinstance(a, str): cmd_args.append(a) - elif isinstance(a, build.Target): + elif isinstance(a, (build.Target, build.CustomTargetIndex)): cmd_args.extend(self.construct_target_rel_paths(a, t.workdir)) else: raise MesonException('Bad object in test command.') @@ -1161,7 +1163,7 @@ 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_paths(self, t: build.Target, workdir: T.Optional[str]) -> T.List[str]: + def construct_target_rel_paths(self, t: T.Union[build.Target, build.CustomTargetIndex], 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: @@ -1170,7 +1172,7 @@ class Backend: if isinstance(t, build.BuildTarget): outputs = [t.get_filename()] else: - assert isinstance(t, build.CustomTarget) + assert isinstance(t, (build.CustomTarget, build.CustomTargetIndex)) outputs = t.get_outputs() outputs = [os.path.join(target_dir, x) for x in outputs] diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index ae6be3bc8..2a68aa044 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -199,7 +199,7 @@ known_build_target_kwargs = ( ) TEST_KWARGS: T.List[KwargInfo] = [ - KwargInfo('args', ContainerTypeInfo(list, (str, mesonlib.File, build.BuildTarget, build.CustomTarget)), + KwargInfo('args', ContainerTypeInfo(list, (str, mesonlib.File, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex)), listify=True, default=[]), KwargInfo('should_fail', bool, default=False), KwargInfo('timeout', int, default=30), 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 c7efbd81b..c8087dd22 100644 --- a/test cases/common/245 custom target index source/meson.build +++ b/test cases/common/245 custom target index source/meson.build @@ -47,5 +47,5 @@ exe_together = executable('exe_together', ) # also cover passing custom target to tests as arguments -test('exe_separate', exe_separate, args: ['unused1', 'unused2']) +test('exe_separate', exe_separate, args: [gen_c, gen_h]) test('exe_together', exe_together, args: gen) diff --git a/test cases/failing/116 run_target in test/test.json b/test cases/failing/116 run_target in test/test.json index e08aa03b2..961c1e4cb 100644 --- a/test cases/failing/116 run_target in test/test.json +++ b/test cases/failing/116 run_target in test/test.json @@ -1,7 +1,7 @@ { "stdout": [ { - "line": "test cases/failing/116 run_target in test/meson.build:4:0: ERROR: test keyword argument 'args' was of type array[RunTarget] but should have been array[str | File | BuildTarget | CustomTarget]" + "line": "test cases/failing/116 run_target in test/meson.build:4:0: ERROR: test keyword argument 'args' was of type array[RunTarget] but should have been array[str | File | BuildTarget | CustomTarget | CustomTargetIndex]" } ] }