diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2021-12-31 15:58:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-31 15:58:30 +0200 |
commit | cf3a23dcce8a1bc2e5b6248e531791b2c1ebea73 (patch) | |
tree | 694e2ede5c64dd4552dec09411571feccec39bb0 | |
parent | 688b4bac767f0a02af125febd49a0e0c5a2fe01e (diff) | |
parent | d46ac459e9233cbb5139257154b16a435298ac49 (diff) | |
download | meson-cf3a23dcce8a1bc2e5b6248e531791b2c1ebea73.zip meson-cf3a23dcce8a1bc2e5b6248e531791b2c1ebea73.tar.gz meson-cf3a23dcce8a1bc2e5b6248e531791b2c1ebea73.tar.bz2 |
Merge pull request #9758 from eli-schwartz/meson_add_foo_script-argchecks
add_*_script: fix validation and do FeatureNew checks
-rw-r--r-- | docs/yaml/builtins/meson.yaml | 31 | ||||
-rw-r--r-- | mesonbuild/interpreter/mesonmain.py | 46 |
2 files changed, 43 insertions, 34 deletions
diff --git a/docs/yaml/builtins/meson.yaml b/docs/yaml/builtins/meson.yaml index 4f2d24d..00ade2e 100644 --- a/docs/yaml/builtins/meson.yaml +++ b/docs/yaml/builtins/meson.yaml @@ -34,18 +34,17 @@ methods: posargs: script_name: - type: str | file | external_program | exe | custom_tgt | custom_idx + type: str | file | external_program description: | The script to execute. - *(since 0.55.0)* The output of [[configure_file]], [[files]], and [[find_program]] - as well as strings are accepted. + *(since 0.55.0)* The output of [[find_program]] as well as strings are accepted. *(since 0.57.0)* [[@file]] objects and the output of [[configure_file]] may be used. varargs: name: arg - type: str | file | external_program | exe | custom_tgt | custom_idx + type: str | file | external_program since: 0.49.0 description: | Additional arguments @@ -53,8 +52,6 @@ methods: *(since 0.55.0)* The output of [[configure_file]], [[files]], and [[find_program]] as well as strings are accepted. - *(since 0.57.0)* [[@file]] objects and the output of [[configure_file]] may be used. - - name: add_install_script returns: void description: | @@ -89,8 +86,26 @@ methods: shell would. If your script uses Python, `shlex.split()` is the easiest correct way to do this. - posargs_inherit: meson.add_dist_script - varargs_inherit: meson.add_dist_script + posargs: + script_name: + type: str | file | external_program | exe | custom_tgt | custom_idx + description: | + The script to execute. + + *(since 0.55.0)* The output of [[find_program]], [[executable]], + [[custom_target]], as well as strings are accepted. + + *(since 0.57.0)* [[@file]] objects and the output of [[configure_file]] may be used. + + varargs: + name: arg + type: str | file | external_program | exe | custom_tgt | custom_idx + since: 0.49.0 + description: | + Additional arguments + + *(since 0.55.0)* The output of [[find_program]], [[executable]], + [[custom_target]], as well as strings are accepted. kwargs: skip_if_destdir: diff --git a/mesonbuild/interpreter/mesonmain.py b/mesonbuild/interpreter/mesonmain.py index e973c5d..be1acc6 100644 --- a/mesonbuild/interpreter/mesonmain.py +++ b/mesonbuild/interpreter/mesonmain.py @@ -79,13 +79,19 @@ class MesonMain(MesonInterpreterObject): }) def _find_source_script( - self, prog: T.Union[str, mesonlib.File, build.Executable, ExternalProgram], + self, name: str, prog: T.Union[str, mesonlib.File, build.Executable, ExternalProgram], args: T.List[str]) -> 'ExecutableSerialisation': largs: T.List[T.Union[str, build.Executable, ExternalProgram]] = [] + if isinstance(prog, (build.Executable, ExternalProgram)): + FeatureNew.single_use(f'Passing executable/found program object to script parameter of {name}', + '0.55.0', self.subproject, location=self.current_node) largs.append(prog) largs.extend(args) return self.interpreter.backend.get_executable_serialisation(largs) + elif isinstance(prog, mesonlib.File): + FeatureNew.single_use(f'Passing file object to script parameter of {name}', + '0.57.0', self.subproject, location=self.current_node) found = self.interpreter.find_program_impl([prog]) largs.append(found) largs.extend(args) @@ -98,7 +104,7 @@ class MesonMain(MesonInterpreterObject): str, mesonlib.File, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, ExternalProgram, - ]], allow_built: bool = False) -> T.List[str]: + ]]) -> T.List[str]: script_args = [] # T.List[str] new = False for a in args: @@ -108,8 +114,6 @@ class MesonMain(MesonInterpreterObject): new = True script_args.append(a.rel_to_builddir(self.interpreter.environment.source_dir)) elif isinstance(a, (build.BuildTarget, build.CustomTarget, build.CustomTargetIndex)): - if not allow_built: - raise InterpreterException(f'Arguments to {name} cannot be built') new = True script_args.extend([os.path.join(a.get_subdir(), o) for o in a.get_outputs()]) @@ -147,12 +151,8 @@ class MesonMain(MesonInterpreterObject): args: T.Tuple[T.Union[str, mesonlib.File, build.Executable, 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.57.0', self.interpreter.subproject) - - script_args = self._process_script_args('add_install_script', args[1], allow_built=True) - script = self._find_source_script(args[0], script_args) + script_args = self._process_script_args('add_install_script', args[1]) + script = self._find_source_script('add_install_script', args[0], script_args) script.skip_if_destdir = kwargs['skip_if_destdir'] script.tag = kwargs['install_tag'] self.build.install_scripts.append(script) @@ -160,43 +160,37 @@ 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: - if isinstance(args[0], mesonlib.File): - FeatureNew.single_use('Passing file object to script parameter of add_postconf_script', - '0.57.0', self.interpreter.subproject) - script_args = self._process_script_args('add_postconf_script', args[1], allow_built=True) - script = self._find_source_script(args[0], script_args) + script_args = self._process_script_args('add_postconf_script', args[1]) + 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', '0.49.0', self.interpreter.subproject) - if isinstance(args[0], mesonlib.File): - FeatureNew.single_use('Passing file object to script parameter of add_dist_script', - '0.57.0', self.interpreter.subproject) 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 = self._find_source_script(args[0], script_args) + script_args = self._process_script_args('add_dist_script', args[1]) + script = self._find_source_script('add_dist_script', args[0], script_args) self.build.dist_scripts.append(script) @noPosargs |