aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-05-04 10:16:41 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2021-05-19 23:28:17 +0300
commitf2ae92368a384cb3cc310f40c2cb43dec5979912 (patch)
tree41edc6154ada78fb48ae32bf7f9345b30581f481
parent4ca9a16288f51cce99624a2ef595d879acdc02d8 (diff)
downloadmeson-f2ae92368a384cb3cc310f40c2cb43dec5979912.zip
meson-f2ae92368a384cb3cc310f40c2cb43dec5979912.tar.gz
meson-f2ae92368a384cb3cc310f40c2cb43dec5979912.tar.bz2
interpreter: Add docstring and fix types of source_strings_to_files
-rw-r--r--mesonbuild/interpreter/interpreter.py28
-rw-r--r--mesonbuild/modules/unstable_rust.py7
2 files changed, 24 insertions, 11 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index c67e840..891f67e 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -64,6 +64,13 @@ if T.TYPE_CHECKING:
from ..envconfig import MachineInfo
from ..environment import Environment
+ # Input source types passed to Targets
+ SourceInputs = T.Union[mesonlib.File, GeneratedListHolder, TargetHolder,
+ CustomTargetIndexHolder, GeneratedObjectsHolder, str]
+ # Input source types passed to the build.Target5 classes
+ SourceOutputs = T.Union[mesonlib.File, GeneratedListHolder, TargetHolder,
+ CustomTargetIndexHolder, GeneratedObjectsHolder]
+
def stringifyUserArguments(args, quote=False):
if isinstance(args, list):
return '[%s]' % ', '.join([stringifyUserArguments(x, True) for x in args])
@@ -2683,20 +2690,25 @@ Try setting b_lundef to false instead.'''.format(self.coredata.options[OptionKey
if project_root / self.subproject_dir in norm.parents:
raise InterpreterException(f'Sandbox violation: Tried to grab {inputtype} {norm.name} from a nested subproject.')
- def source_strings_to_files(self, sources: T.List[str]) -> T.List[mesonlib.File]:
+ def source_strings_to_files(self, sources: T.List['SourceInputs']) -> T.List['SourceOutputs']:
+ """Lower inputs to a list of Targets and Files, replacing any strings.
+
+ :param sources: A raw (Meson DSL) list of inputs (targets, files, and
+ strings)
+ :raises InterpreterException: if any of the inputs are of an invalid type
+ :return: A list of Targets and Files
+ """
mesonlib.check_direntry_issues(sources)
if not isinstance(sources, list):
sources = [sources]
- results: T.List[mesonlib.File] = []
+ results: T.List['SourceOutputs'] = []
for s in sources:
- if isinstance(s, (mesonlib.File, GeneratedListHolder,
- TargetHolder, CustomTargetIndexHolder,
- GeneratedObjectsHolder)):
- pass
- elif isinstance(s, str):
+ if isinstance(s, str):
self.validate_within_subproject(self.subdir, s)
s = mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s)
- else:
+ elif not isinstance(s, (mesonlib.File, GeneratedListHolder,
+ TargetHolder, CustomTargetIndexHolder,
+ GeneratedObjectsHolder)):
raise InterpreterException('Source item is {!r} instead of '
'string or File-type object'.format(s))
results.append(s)
diff --git a/mesonbuild/modules/unstable_rust.py b/mesonbuild/modules/unstable_rust.py
index 7ae12c4..1db6722 100644
--- a/mesonbuild/modules/unstable_rust.py
+++ b/mesonbuild/modules/unstable_rust.py
@@ -27,6 +27,7 @@ if T.TYPE_CHECKING:
from . import ModuleState
from ..interpreter import Interpreter
from ..programs import ExternalProgram
+ from ..interpreter.interpreter import SourceOutputs
class RustModule(ExtensionModule):
@@ -139,8 +140,8 @@ class RustModule(ExtensionModule):
The main thing this simplifies is the use of `include_directory`
objects, instead of having to pass a plethora of `-I` arguments.
"""
- header: T.Union[File, CustomTarget, GeneratedList, CustomTargetIndex]
- _deps: T.Sequence[T.Union[File, CustomTarget, GeneratedList, CustomTargetIndex]]
+ header: 'SourceOutputs'
+ _deps: T.Sequence['SourceOutputs']
try:
header, *_deps = unholder(self.interpreter.source_strings_to_files(listify(kwargs['input'])))
except KeyError:
@@ -158,7 +159,7 @@ class RustModule(ExtensionModule):
bind_args: T.List[str] = stringlistify(listify(kwargs.get('args', [])))
# Split File and Target dependencies to add pass to CustomTarget
- depends: T.List[BuildTarget] = []
+ depends: T.List[T.Union[GeneratedList, BuildTarget, CustomTargetIndex]] = []
depend_files: T.List[File] = []
for d in _deps:
if isinstance(d, File):