From cbc62e892aaea60a3692797c521672b95be9389d Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 1 Oct 2021 09:23:32 -0700 Subject: [PATCH] interpreter: add an implementation for structured_sources --- data/syntax-highlighting/vim/syntax/meson.vim | 1 + mesonbuild/ast/interpreter.py | 1 + mesonbuild/interpreter/interpreter.py | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/data/syntax-highlighting/vim/syntax/meson.vim b/data/syntax-highlighting/vim/syntax/meson.vim index 15b47cd47..0519bb279 100644 --- a/data/syntax-highlighting/vim/syntax/meson.vim +++ b/data/syntax-highlighting/vim/syntax/meson.vim @@ -116,6 +116,7 @@ syn keyword mesonBuiltin \ shared_library \ shared_module \ static_library + \ structured_sources \ subdir \ subdir_done \ subproject diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py index f5a1e5e41..e5ff26688 100644 --- a/mesonbuild/ast/interpreter.py +++ b/mesonbuild/ast/interpreter.py @@ -154,6 +154,7 @@ class AstInterpreter(InterpreterBase): 'alias_target': self.func_do_nothing, 'summary': self.func_do_nothing, 'range': self.func_do_nothing, + 'structured_sources': self.func_do_nothing, }) def _unholder_args(self, args: _T, kwargs: _V) -> T.Tuple[_T, _V]: diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 650af0314..6627b5e48 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -385,6 +385,7 @@ class Interpreter(InterpreterBase, HoldableObject): 'run_command': self.func_run_command, 'run_target': self.func_run_target, 'set_variable': self.func_set_variable, + 'structured_sources': self.func_structured_sources, 'subdir': self.func_subdir, 'shared_library': self.func_shared_lib, 'shared_module': self.func_shared_module, @@ -2107,6 +2108,31 @@ external dependencies (including libraries) must go to "dependencies".''') self.build.symlinks.append(l) return l + @FeatureNew('structured_sources', '0.62.0') + @typed_pos_args('structured_sources', object, optargs=[dict]) + @noKwargs + @noArgsFlattening + def func_structured_sources( + self, node: mparser.BaseNode, + args: T.Tuple[object, T.Optional[T.Dict[str, object]]], + kwargs: 'TYPE_kwargs') -> build.StructuredSources: + valid_types = (str, mesonlib.File, build.GeneratedList, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList) + sources: T.Dict[str, T.List[T.Union['mesonlib.FileOrString', 'build.GeneratedTypes']]] = collections.defaultdict(list) + + for arg in mesonlib.listify(args[0]): + if not isinstance(arg, valid_types): + raise InvalidArguments(f'structured_sources: type "{type(arg)}" is not valid') + sources[''].append(arg) + if args[1]: + if '' in args[1]: + raise InvalidArguments('structured_sources: keys to dictionary argument may not be an empty string.') + for k, v in args[1].items(): + for arg in mesonlib.listify(v): + if not isinstance(arg, valid_types): + raise InvalidArguments(f'structured_sources: type "{type(arg)}" is not valid') + sources[k].append(arg) + return build.StructuredSources(sources) + @typed_pos_args('subdir', str) @typed_kwargs( 'subdir',