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.
pull/9565/head
Paolo Bonzini 3 years ago
parent 36c390e08e
commit 9a8c2d23f1
  1. 10
      mesonbuild/interpreter/mesonmain.py
  2. 4
      test cases/failing/117 run_target in add_install_script/meson.build
  3. 8
      test cases/failing/117 run_target in add_install_script/test.json
  4. 11
      test cases/failing/117 run_target in add_install_script/trivial.c

@ -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',

@ -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)

@ -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\""
}
]
}

@ -0,0 +1,11 @@
#include<stdio.h>
int main(int argc, char **argv) {
FILE *fp = fopen(argv[1], "r");
if (fp == NULL) {
perror("fopen");
return 1;
} else {
return 0;
}
}
Loading…
Cancel
Save