Skip to content

Commit

Permalink
WIP: Add a summary() function for configuration summarization
Browse files Browse the repository at this point in the history
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 mesonbuild#757
  • Loading branch information
dcbaker committed Dec 17, 2018
1 parent c208e81 commit 094fd0a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mesonbuild/interpreter.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 094fd0a

Please sign in to comment.