aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-11-03 10:06:22 -0700
committerDylan Baker <dylan@pnwbakers.com>2021-11-22 11:28:43 -0800
commit3295621706d47ca6f4731695e9c9acc0ddcc572b (patch)
tree5a617862dc224208d720d4b413aaa7e0a99d48c3
parentf34013fb08b8d24d570c96084c5d58c5eaf4f5da (diff)
downloadmeson-3295621706d47ca6f4731695e9c9acc0ddcc572b.zip
meson-3295621706d47ca6f4731695e9c9acc0ddcc572b.tar.gz
meson-3295621706d47ca6f4731695e9c9acc0ddcc572b.tar.bz2
interpreter: add typed_kwargs to subdir
-rw-r--r--mesonbuild/interpreter/interpreter.py20
-rw-r--r--mesonbuild/interpreter/kwargs.py17
2 files changed, 30 insertions, 7 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index 76096e9..35c26d8 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -1946,10 +1946,19 @@ This will become a hard error in the future.''', location=self.current_node)
return d
- @FeatureNewKwargs('subdir', '0.44.0', ['if_found'])
- @permittedKwargs({'if_found'})
@typed_pos_args('subdir', str)
- def func_subdir(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> None:
+ @typed_kwargs(
+ 'subdir',
+ KwargInfo(
+ 'if_found',
+ ContainerTypeInfo(list, object),
+ validator=lambda a: 'Objects must have a found() method' if not all(hasattr(x, 'found') for x in a) else None,
+ since='0.44.0',
+ default=[],
+ listify=True,
+ ),
+ )
+ def func_subdir(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs: 'kwargs.Subdir') -> None:
mesonlib.check_direntry_issues(args)
if '..' in args[0]:
raise InvalidArguments('Subdir contains ..')
@@ -1957,11 +1966,10 @@ This will become a hard error in the future.''', location=self.current_node)
raise InvalidArguments('Must not go into subprojects dir with subdir(), use subproject() instead.')
if self.subdir == '' and args[0].startswith('meson-'):
raise InvalidArguments('The "meson-" prefix is reserved and cannot be used for top-level subdir().')
- for i in mesonlib.extract_as_list(kwargs, 'if_found'):
- if not hasattr(i, 'found'):
- raise InterpreterException('Object used in if_found does not have a found method.')
+ for i in kwargs['if_found']:
if not i.found():
return
+
prev_subdir = self.subdir
subdir = os.path.join(prev_subdir, args[0])
if os.path.isabs(subdir):
diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py
index 00dfdfd..50bc5d1 100644
--- a/mesonbuild/interpreter/kwargs.py
+++ b/mesonbuild/interpreter/kwargs.py
@@ -6,7 +6,7 @@
import typing as T
-from typing_extensions import TypedDict, Literal
+from typing_extensions import TypedDict, Literal, Protocol
from .. import build
from .. import coredata
@@ -204,3 +204,18 @@ class Project(TypedDict):
default_options: T.List[str]
license: T.List[str]
subproject_dir: str
+
+
+class _FoundProto(Protocol):
+
+ """Protocol for subdir arguments.
+
+ This allows us to define any objec that has a found(self) -> bool method
+ """
+
+ def found(self) -> bool: ...
+
+
+class Subdir(TypedDict):
+
+ if_found: T.List[_FoundProto]