From 31be890cf12e004d6600723d95bfc5d838aebf63 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sun, 14 Nov 2021 09:00:10 +0100 Subject: [PATCH] interpreter: disallow RunTarget in meson.add_install_script Without this patch, the name of the RunTarget is passed to the install script; for the enclosed test, meson setup (incorrectly) succeeds, but installation fails. --- mesonbuild/interpreter/mesonmain.py | 10 +++++----- .../117 run_target in add_install_script/meson.build | 4 ++++ .../117 run_target in add_install_script/test.json | 8 ++++++++ .../117 run_target in add_install_script/trivial.c | 11 +++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test cases/failing/117 run_target in add_install_script/meson.build create mode 100644 test cases/failing/117 run_target in add_install_script/test.json create mode 100644 test cases/failing/117 run_target in add_install_script/trivial.c diff --git a/mesonbuild/interpreter/mesonmain.py b/mesonbuild/interpreter/mesonmain.py index 5d3541076..2d25779d8 100644 --- a/mesonbuild/interpreter/mesonmain.py +++ b/mesonbuild/interpreter/mesonmain.py @@ -95,9 +95,9 @@ class MesonMain(MesonInterpreterObject): def _process_script_args( self, name: str, args: T.Sequence[T.Union[ - str, mesonlib.File, build.Target, + str, mesonlib.File, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, - ExternalProgram, build.Executable, + ExternalProgram, ]], allow_built: bool = False) -> T.List[str]: script_args = [] # T.List[str] new = False @@ -107,7 +107,7 @@ class MesonMain(MesonInterpreterObject): elif isinstance(a, mesonlib.File): new = True script_args.append(a.rel_to_builddir(self.interpreter.environment.source_dir)) - elif isinstance(a, (build.Target, build.CustomTargetIndex)): + elif isinstance(a, (build.BuildTarget, build.CustomTarget, build.CustomTargetIndex)): if not allow_built: raise InterpreterException(f'Arguments to {name} cannot be built') new = True @@ -135,7 +135,7 @@ class MesonMain(MesonInterpreterObject): @typed_pos_args( 'meson.add_install_script', (str, mesonlib.File, build.Executable, ExternalProgram), - varargs=(str, mesonlib.File, build.Target, build.CustomTargetIndex, ExternalProgram) + varargs=(str, mesonlib.File, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, ExternalProgram) ) @typed_kwargs( 'meson.add_install_script', @@ -145,7 +145,7 @@ class MesonMain(MesonInterpreterObject): def add_install_script_method( self, args: T.Tuple[T.Union[str, mesonlib.File, build.Executable, ExternalProgram], - T.List[T.Union[str, mesonlib.File, build.Target, build.CustomTargetIndex, ExternalProgram]]], + T.List[T.Union[str, mesonlib.File, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, ExternalProgram]]], kwargs: 'AddInstallScriptKW') -> None: if isinstance(args[0], mesonlib.File): FeatureNew.single_use('Passing file object to script parameter of add_install_script', diff --git a/test cases/failing/117 run_target in add_install_script/meson.build b/test cases/failing/117 run_target in add_install_script/meson.build new file mode 100644 index 000000000..9d37a390b --- /dev/null +++ b/test cases/failing/117 run_target in add_install_script/meson.build @@ -0,0 +1,4 @@ +project('trivial test', 'c') +exe = executable('trivialprog', 'trivial.c') +runt = run_target('invalid', command: ['echo', 'run_target']) +meson.add_install_script(exe, runt) diff --git a/test cases/failing/117 run_target in add_install_script/test.json b/test cases/failing/117 run_target in add_install_script/test.json new file mode 100644 index 000000000..fec19410d --- /dev/null +++ b/test cases/failing/117 run_target in add_install_script/test.json @@ -0,0 +1,8 @@ +{ + "stdout": [ + { + "line": "test cases/failing/117 run_target in add_install_script/meson.build:4:6: ERROR: meson.add_install_script argument 2 was of type \"RunTarget\" but should have been one of: \"str\", \"File\", \"BuildTarget\", \"CustomTarget\", \"CustomTargetIndex\", \"ExternalProgram\"" + } + ] +} + diff --git a/test cases/failing/117 run_target in add_install_script/trivial.c b/test cases/failing/117 run_target in add_install_script/trivial.c new file mode 100644 index 000000000..1b14571ed --- /dev/null +++ b/test cases/failing/117 run_target in add_install_script/trivial.c @@ -0,0 +1,11 @@ +#include + +int main(int argc, char **argv) { + FILE *fp = fopen(argv[1], "r"); + if (fp == NULL) { + perror("fopen"); + return 1; + } else { + return 0; + } +}