aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-10-01 09:23:32 -0700
committerDylan Baker <dylan@pnwbakers.com>2022-03-07 12:33:33 -0800
commitcbc62e892aaea60a3692797c521672b95be9389d (patch)
treee27a2a0b2d3fdaac4b3c92bf43becb16aa97cc11
parentfd55ff6a725b920e821dd3c2d5179dd0011c216a (diff)
downloadmeson-cbc62e892aaea60a3692797c521672b95be9389d.zip
meson-cbc62e892aaea60a3692797c521672b95be9389d.tar.gz
meson-cbc62e892aaea60a3692797c521672b95be9389d.tar.bz2
interpreter: add an implementation for structured_sources
-rw-r--r--data/syntax-highlighting/vim/syntax/meson.vim1
-rw-r--r--mesonbuild/ast/interpreter.py1
-rw-r--r--mesonbuild/interpreter/interpreter.py26
3 files changed, 28 insertions, 0 deletions
diff --git a/data/syntax-highlighting/vim/syntax/meson.vim b/data/syntax-highlighting/vim/syntax/meson.vim
index 15b47cd..0519bb2 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 f5a1e5e..e5ff266 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 650af03..6627b5e 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',