aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-01-12 10:50:22 -0800
committerDylan Baker <dylan@pnwbakers.com>2021-01-13 13:32:48 -0800
commit022632c91b255739c5100601a02b197cb29cd23e (patch)
tree1b624726c0f5d801f7588e054a34bf70c4f8b8cb /mesonbuild/interpreter.py
parent6180992d4939f931aaeae74138dae069a60a3485 (diff)
downloadmeson-022632c91b255739c5100601a02b197cb29cd23e.zip
meson-022632c91b255739c5100601a02b197cb29cd23e.tar.gz
meson-022632c91b255739c5100601a02b197cb29cd23e.tar.bz2
build/interperter: Add annotations and move input validation to interpreter
This moves the user input validation to the interpreter, instead of being in the build module, and adds type annotations.
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r--mesonbuild/interpreter.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 9466fe4..fdb6fa7 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -4300,11 +4300,11 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
@FeatureNewKwargs('install_data', '0.46.0', ['rename'])
@FeatureNewKwargs('install_data', '0.38.0', ['install_mode'])
@permittedKwargs(permitted_kwargs['install_data'])
- def func_install_data(self, node, args, kwargs):
+ def func_install_data(self, node, args: T.List, kwargs: T.Dict[str, T.Any]):
kwsource = mesonlib.stringlistify(kwargs.get('sources', []))
raw_sources = args + kwsource
- sources = []
- source_strings = []
+ sources: T.List[mesonlib.File] = []
+ source_strings: T.List[str] = []
for s in raw_sources:
if isinstance(s, mesonlib.File):
sources.append(s)
@@ -4313,11 +4313,18 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
else:
raise InvalidArguments('Argument must be string or file.')
sources += self.source_strings_to_files(source_strings)
- install_dir = kwargs.get('install_dir', None)
- if not isinstance(install_dir, (str, type(None))):
+ 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 = kwargs.get('rename', None)
+ rename: T.Optional[T.List[str]] = kwargs.get('rename', None)
+ if rename is not None:
+ rename = mesonlib.stringlistify(rename)
+ if len(rename) != len(sources):
+ raise InvalidArguments(
+ '"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)}.')
+
data = DataHolder(build.Data(sources, install_dir, install_mode, rename))
self.build.data.append(data.held_object)
return data