interpreter: use typed_kwargs for build_target.install_mode

pull/12392/head
Dylan Baker 1 year ago
parent bae2e13b39
commit 2fc8729078
  1. 22
      mesonbuild/interpreter/interpreter.py
  2. 1
      mesonbuild/interpreter/kwargs.py
  3. 1
      mesonbuild/interpreter/type_checking.py

@ -2425,27 +2425,6 @@ class Interpreter(InterpreterBase, HoldableObject):
pass
self.subdir = prev_subdir
def _get_kwarg_install_mode(self, kwargs: T.Dict[str, T.Any]) -> T.Optional[FileMode]:
if kwargs.get('install_mode', None) is None:
return None
if isinstance(kwargs['install_mode'], FileMode):
return kwargs['install_mode']
install_mode: T.List[str] = []
mode = mesonlib.typeslistify(kwargs.get('install_mode', []), (str, int))
for m in mode:
# We skip any arguments that are set to `false`
if m is False:
m = None
install_mode.append(m)
if len(install_mode) > 3:
raise InvalidArguments('Keyword argument install_mode takes at '
'most 3 arguments.')
if len(install_mode) > 0 and install_mode[0] is not None and \
not isinstance(install_mode[0], str):
raise InvalidArguments('Keyword argument install_mode requires the '
'permissions arg to be a string or false')
return FileMode(*install_mode)
# This is either ignored on basically any OS nowadays, or silently gets
# ignored (Solaris) or triggers an "illegal operation" error (FreeBSD).
# It was likely added "because it exists", but should never be used. In
@ -3343,7 +3322,6 @@ class Interpreter(InterpreterBase, HoldableObject):
sources = self.source_strings_to_files(sources)
objs = extract_as_list(kwargs, 'objects')
kwargs['dependencies'] = extract_as_list(kwargs, 'dependencies')
kwargs['install_mode'] = self._get_kwarg_install_mode(kwargs)
if 'extra_files' in kwargs:
ef = extract_as_list(kwargs, 'extra_files')
kwargs['extra_files'] = self.source_strings_to_files(ef)

@ -327,6 +327,7 @@ class _BaseBuildTarget(TypedDict):
build_by_default: bool
install: bool
install_mode: FileMode
override_options: T.Dict[OptionKey, T.Union[str, int, bool, T.List[str]]]
depend_files: NotRequired[T.List[File]]

@ -554,6 +554,7 @@ _ALL_TARGET_KWS: T.List[KwargInfo] = [
OVERRIDE_OPTIONS_KW,
KwargInfo('build_by_default', bool, default=True, since='0.38.0'),
INSTALL_KW,
INSTALL_MODE_KW,
]
# Applies to all build_target classes except jar

Loading…
Cancel
Save