interpreter: use typed_kwargs for install_data

pull/8884/head
Dylan Baker 3 years ago
parent a551e76137
commit ea3d85a1c0
  1. 41
      mesonbuild/interpreter/interpreter.py
  2. 10
      mesonbuild/interpreter/kwargs.py

@ -1996,37 +1996,28 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
'permissions arg to be a string or false') 'permissions arg to be a string or false')
return FileMode(*install_mode) return FileMode(*install_mode)
@FeatureNewKwargs('install_data', '0.46.0', ['rename'])
@FeatureNewKwargs('install_data', '0.38.0', ['install_mode'])
@permittedKwargs({'install_dir', 'install_mode', 'rename', 'sources'})
@typed_pos_args('install_data', varargs=(str, mesonlib.File)) @typed_pos_args('install_data', varargs=(str, mesonlib.File))
def func_install_data(self, node: mparser.BaseNode, args: T.Tuple[T.List['mesonlib.FileOrString']], @typed_kwargs(
kwargs: T.Dict[str, T.Any]): 'install_data',
kwsource = mesonlib.stringlistify(kwargs.get('sources', [])) KwargInfo('install_dir', str),
raw_sources = args[0] + kwsource KwargInfo('sources', ContainerTypeInfo(list, (str, mesonlib.File)), listify=True, default=[]),
sources: T.List[mesonlib.File] = [] KwargInfo('rename', ContainerTypeInfo(list, str), default=[], listify=True, since='0.46.0'),
source_strings: T.List[str] = [] _INSTALL_MODE_KW.evolve(since='0.38.0'),
for s in raw_sources: )
if isinstance(s, mesonlib.File): def func_install_data(self, node: mparser.BaseNode,
sources.append(s) args: T.Tuple[T.List['mesonlib.FileOrString']],
elif isinstance(s, str): kwargs: 'kwargs.FuncInstallData') -> build.Data:
source_strings.append(s) sources = self.source_strings_to_files(args[0] + kwargs['sources'])
else: rename = kwargs['rename'] or None
raise InvalidArguments('Argument must be string or file.') if rename:
sources += self.source_strings_to_files(source_strings)
install_dir: T.Optional[str] = kwargs.get('install_dir', None)
if install_dir is not None and not isinstance(install_dir, str):
raise InvalidArguments('Keyword argument install_dir not a string.')
install_mode = self._get_kwarg_install_mode(kwargs)
rename: T.Optional[T.List[str]] = kwargs.get('rename', None)
if rename is not None:
rename = mesonlib.stringlistify(rename)
if len(rename) != len(sources): if len(rename) != len(sources):
raise InvalidArguments( raise InvalidArguments(
'"rename" and "sources" argument lists must be the same length if "rename" is given. ' '"rename" and "sources" argument lists must be the same length if "rename" is given. '
f'Rename has {len(rename)} elements and sources has {len(sources)}.') f'Rename has {len(rename)} elements and sources has {len(sources)}.')
data = build.Data(sources, install_dir, install_mode, self.subproject, rename) data = build.Data(
sources, kwargs['install_dir'], kwargs['install_mode'],
self.subproject, rename)
self.build.data.append(data) self.build.data.append(data)
return data return data

@ -10,7 +10,7 @@ from typing_extensions import TypedDict, Literal
from .. import build from .. import build
from .. import coredata from .. import coredata
from ..mesonlib import MachineChoice, File, FileMode from ..mesonlib import MachineChoice, File, FileMode, FileOrString
from .interpreterobjects import EnvironmentVariablesObject from .interpreterobjects import EnvironmentVariablesObject
@ -110,3 +110,11 @@ class FuncInstallSubdir(TypedDict):
exclude_files: T.List[str] exclude_files: T.List[str]
exclude_directories: T.List[str] exclude_directories: T.List[str]
install_mode: FileMode install_mode: FileMode
class FuncInstallData(TypedDict):
install_dir: str
sources: T.List[FileOrString]
rename: T.List[str]
install_mode: FileMode

Loading…
Cancel
Save