diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-05-03 02:43:08 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-05-03 16:24:20 -0400 |
commit | 5a9b2cb8f8c8154e62b392ef3f1dbc94e8e1b319 (patch) | |
tree | 1b3616f4779282f7d8a8eda53364d2e24b03351a /mesonbuild | |
parent | 4ed5c0eefa731cd9e1ca6f432874536d101973db (diff) | |
download | meson-5a9b2cb8f8c8154e62b392ef3f1dbc94e8e1b319.zip meson-5a9b2cb8f8c8154e62b392ef3f1dbc94e8e1b319.tar.gz meson-5a9b2cb8f8c8154e62b392ef3f1dbc94e8e1b319.tar.bz2 |
cmake module: use more typed_pos_args for consistency
It's shorter and more descriptive. Although we always enforce the same
rules either way, a unified decorator is one less line of code for each
location, and also tells you how many "too few" arguments you *did*
pass.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/cmake/common.py | 8 | ||||
-rw-r--r-- | mesonbuild/modules/cmake.py | 22 |
2 files changed, 10 insertions, 20 deletions
diff --git a/mesonbuild/cmake/common.py b/mesonbuild/cmake/common.py index 32a8c68..3de6c16 100644 --- a/mesonbuild/cmake/common.py +++ b/mesonbuild/cmake/common.py @@ -23,6 +23,7 @@ import typing as T if T.TYPE_CHECKING: from ..environment import Environment + from ..interpreterbase import TYPE_var language_map = { 'c': 'C', @@ -121,16 +122,11 @@ def cmake_get_generator_args(env: 'Environment') -> T.List[str]: assert backend_name in backend_generator_map return ['-G', backend_generator_map[backend_name]] -def cmake_defines_to_args(raw: T.Any, permissive: bool = False) -> T.List[str]: +def cmake_defines_to_args(raw: T.List[T.Dict[str, TYPE_var]], permissive: bool = False) -> T.List[str]: res = [] # type: T.List[str] - if not isinstance(raw, list): - raw = [raw] for i in raw: - if not isinstance(i, dict): - raise MesonException('Invalid CMake defines. Expected a dict, but got a {}'.format(type(i).__name__)) for key, val in i.items(): - assert isinstance(key, str) if key in blacklist_cmake_defs: mlog.warning('Setting', mlog.bold(key), 'is not supported. See the meson docs for cross compilation support:') mlog.warning(' - URL: https://mesonbuild.com/CMake-module.html#cross-compilation') diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py index a178b23..bbae033 100644 --- a/mesonbuild/modules/cmake.py +++ b/mesonbuild/modules/cmake.py @@ -205,36 +205,30 @@ class CMakeSubprojectOptions(ModuleObject): return self.target_options[kwargs['target']] return self.target_options.global_options + @typed_pos_args('subproject_options.add_cmake_defines', varargs=dict) @noKwargs def add_cmake_defines(self, state, args, kwargs) -> None: - self.cmake_options += cmake_defines_to_args(args) + self.cmake_options += cmake_defines_to_args(args[0]) - @stringArgs + @typed_pos_args('subproject_options.set_override_option', str, str) @permittedKwargs({'target'}) def set_override_option(self, state, args, kwargs) -> None: - if len(args) != 2: - raise InvalidArguments('set_override_option takes exactly 2 positional arguments') self._get_opts(kwargs).set_opt(args[0], args[1]) + @typed_pos_args('subproject_options.set_install', bool) @permittedKwargs({'target'}) def set_install(self, state, args, kwargs) -> None: - if len(args) != 1 or not isinstance(args[0], bool): - raise InvalidArguments('set_install takes exactly 1 boolean argument') self._get_opts(kwargs).set_install(args[0]) - @stringArgs + @typed_pos_args('subproject_options.append_compile_args', str, varargs=str, min_varargs=1) @permittedKwargs({'target'}) def append_compile_args(self, state, args, kwargs) -> None: - if len(args) < 2: - raise InvalidArguments('append_compile_args takes at least 2 positional arguments') - self._get_opts(kwargs).append_args(args[0], args[1:]) + self._get_opts(kwargs).append_args(args[0], args[1]) - @stringArgs + @typed_pos_args('subproject_options.append_compile_args', varargs=str, min_varargs=1) @permittedKwargs({'target'}) def append_link_args(self, state, args, kwargs) -> None: - if not args: - raise InvalidArguments('append_link_args takes at least 1 positional argument') - self._get_opts(kwargs).append_link_args(args) + self._get_opts(kwargs).append_link_args(args[0]) @noPosargs @noKwargs |