From 6e25548d06966a20bf7e5cc1fef184c4334c42df Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 26 Dec 2021 17:49:42 -0500 Subject: [PATCH] add_*_script: fix incorrect typed_pos_args allowing built targets In commit c239ce31f55579cfe1e29b769a8bda97deca2166 support was added to these functions to accept various non-string types. Despite the commit/PR documenting that only add_install_script is permitted to accept built files, the actual check parameter was set, for all three, to "True" (so the function was never invoked with False at all). This meant that actually attempting to use the allowed types would fail at postconf or dist, with python tracebacks in the former case and "Failed to run dist script" in the latter case. This was partially ameliorated in commit 6c5bfd4c241e94f5e0f4dea9ba7fb5d5090a4802 which added typed_pos_args, but unfortunately those typed_pos_args were all over the place. For postconf: - They banned external programs as additional args (which should be allowed) - They banned built executables (good) - They allowed custom targets as additional args (bad) For dist: - they allowed external programs (good) - they allowed built executables, but only as the first argument (bad, also ???) - they allowed custom targets, but only as additional arguments (bad, also ???) Fix this all to only allow the same argument types for both the script argument and the script-args arguments. That type is known at configure time and restricted to source files, configured files, and found programs. --- mesonbuild/interpreter/mesonmain.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mesonbuild/interpreter/mesonmain.py b/mesonbuild/interpreter/mesonmain.py index 5a7fc74a5..819ff7f60 100644 --- a/mesonbuild/interpreter/mesonmain.py +++ b/mesonbuild/interpreter/mesonmain.py @@ -162,28 +162,28 @@ class MesonMain(MesonInterpreterObject): @typed_pos_args( 'meson.add_postconf_script', (str, mesonlib.File, ExternalProgram), - varargs=(str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex) + varargs=(str, mesonlib.File, ExternalProgram) ) @noKwargs def add_postconf_script_method( self, args: T.Tuple[T.Union[str, mesonlib.File, ExternalProgram], - T.List[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex]]], + T.List[T.Union[str, mesonlib.File, ExternalProgram]]], kwargs: 'TYPE_kwargs') -> None: - script_args = self._process_script_args('add_postconf_script', args[1], allow_built=True) + script_args = self._process_script_args('add_postconf_script', args[1], allow_built=False) script = self._find_source_script('add_postconf_script', args[0], script_args) self.build.postconf_scripts.append(script) @typed_pos_args( 'meson.add_dist_script', - (str, mesonlib.File, build.Executable, ExternalProgram), - varargs=(str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex) + (str, mesonlib.File, ExternalProgram), + varargs=(str, mesonlib.File, ExternalProgram) ) @noKwargs def add_dist_script_method( self, - args: T.Tuple[T.Union[str, mesonlib.File, build.Executable, ExternalProgram], - T.List[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex]]], + args: T.Tuple[T.Union[str, mesonlib.File, ExternalProgram], + T.List[T.Union[str, mesonlib.File, ExternalProgram]]], kwargs: 'TYPE_kwargs') -> None: if args[1]: FeatureNew.single_use('Calling "add_dist_script" with multiple arguments', @@ -191,7 +191,7 @@ class MesonMain(MesonInterpreterObject): if self.interpreter.subproject != '': FeatureNew.single_use('Calling "add_dist_script" in a subproject', '0.58.0', self.interpreter.subproject) - script_args = self._process_script_args('add_dist_script', args[1], allow_built=True) + script_args = self._process_script_args('add_dist_script', args[1], allow_built=False) script = self._find_source_script('add_dist_script', args[0], script_args) self.build.dist_scripts.append(script)