add_*_script: fix incorrect typed_pos_args allowing built targets

In commit c239ce31f5 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
6c5bfd4c24 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.
pull/9758/head
Eli Schwartz 3 years ago
parent f6eaf55906
commit 6e25548d06
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 16
      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)

Loading…
Cancel
Save