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.
pull/11764/head
Eli Schwartz 2 years ago
parent 4ed5c0eefa
commit 5a9b2cb8f8
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 8
      mesonbuild/cmake/common.py
  2. 22
      mesonbuild/modules/cmake.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')

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

Loading…
Cancel
Save