From 094fd0ae55b2d2cbd1ed139ea541b0c1332e5972 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 17 Dec 2018 10:51:38 -0800 Subject: [PATCH] WIP: Add a summary() function for configuration summarization This has been requested multiple times in the mesa/xorg community, and apparently in the GStreamer community as well. This is a very simple function that takes a single dictionary as an argument, that dictionary may define scalar or container values which will be printed as summaries. It treats nested dictionaries as another level of configuration options, which allows grouping options together. For example: ```meson sec1 = {'driver' : 'foobar', 'OS' : 'Linux', 'API' : 1.7} ... sec2 = {'driver' : 'dive comp', 'OS' : 'Minix', 'API' : 1.1.2} summary({ 'Backend' : 'OpenGL', 'Server' : sec1, 'Client' : sec2, }) ``` Which would print something like: ```txt Configuration Summary: Backend = OpenGL Server: driver = foobar OS = Linux API = 1.7 Client: driver = dive comp OS = Minix API = 1.1.2 ``` Fixes #757 --- mesonbuild/interpreter.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 4f09c0f904fe..abe6d4a66411 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2012,6 +2012,7 @@ def build_func_dict(self): 'subdir': self.func_subdir, 'subdir_done': self.func_subdir_done, 'subproject': self.func_subproject, + 'summary': self.func_summary, 'shared_library': self.func_shared_lib, 'shared_module': self.func_shared_module, 'static_library': self.func_static_lib, @@ -2606,6 +2607,32 @@ def func_message(self, node, args, kwargs): argstr = self.get_message_string_arg(node) mlog.log(mlog.bold('Message:'), argstr) + @FeatureNew('summary', '0.50.0') + @noKwargs + def func_summary(self, node, args, kwargs): + if len(args) != 1: + raise InterpreterException('Summary accepts exactly one argument.') + arg = args[0] + if not isinstance(arg, dict): + raise InterpreterException('Summary argument must be a dictionary.') + + seen_dict = False + for v in arg.values(): + if isinstance(v, dict): + seen_dict = True + elif seen_dict: + raise InterpreterException('Summary argument values must be exclusively dictionaries or exclusively not dictionaries.') + + mlog.log('') + mlog.log(mlog.bold('Configuration Summary:')) + for s, t in arg.items(): + if isinstance(t, dict): + mlog.log(' ', mlog.bold(s + ':')) + for k, v in t.items(): + mlog.log(' ', k, '=', v) + else: + mlog.log(' ', s, '=', t) + @FeatureNew('warning', '0.44.0') @noKwargs def func_warning(self, node, args, kwargs):