summary: Allow section with no title, and passing key/value separately

pull/4649/head
Xavier Claessens 5 years ago
parent 6e865a2330
commit 49082f9669
  1. 17
      docs/markdown/Reference-manual.md
  2. 32
      mesonbuild/interpreter.py
  3. 11
      run_unittests.py
  4. 6
      test cases/unit/74 summary/meson.build
  5. 3
      test cases/unit/74 summary/subprojects/sub/meson.build

@ -1209,6 +1209,9 @@ This function prints its argument to stdout prefixed with WARNING:.
### summary()
``` meson
void summary(key, value)
void summary(dictionary)
void summary(section_name, key, value)
void summary(section_name, dictionary)
```
@ -1216,12 +1219,16 @@ This function is used to summarize build configuration at the end of the build
process. This function provides a way for projects (and subprojects) to report
this information in a clear way.
The first argument is a section name, the second argument is a dictionary.
`summary()` can be called multiple times as long as the same dict key doesn't
appear twice in the same section. All sections will be collected and printed at
the end of the configuration in the same order as they have been called.
The content is a serie of key/value pairs grouped into sections. If the section
argument is omitted, those key/value pairs are implicitly grouped into a section
with no title. key/value pairs can optionally be grouped into a dictionary,
but keep in mind that dictionaries does not guarantee ordering.
`section_name` and `key` must be strings, `value` can only be lists, integers,
booleans or strings.
Dictionary values can only be lists, integers, booleans or strings.
`summary()` can be called multiple times as long as the same section_name/key
pair doesn't appear twice. All sections will be collected and printed at
the end of the configuration in the same order as they have been called.
Example:
```meson

@ -1775,7 +1775,8 @@ class Summary:
mlog.log(self.project_name, mlog.normal_cyan(self.project_version))
for section, values in self.sections.items():
mlog.log('') # newline
mlog.log(' ', mlog.bold(section))
if section:
mlog.log(' ', mlog.bold(section))
for k, v in values.items():
indent = self.max_key_len - len(k) + 3
mlog.log(' ' * indent, k + ':', v[0])
@ -2871,13 +2872,28 @@ external dependencies (including libraries) must go to "dependencies".''')
@noKwargs
@FeatureNew('summary', '0.53.0')
def func_summary(self, node, args, kwargs):
if len(args) != 2:
raise InterpreterException('Summary accepts exactly two arguments.')
section, values = args
if not isinstance(section, str):
raise InterpreterException('Argument 1 must be a string.')
if not isinstance(values, dict):
raise InterpreterException('Argument 2 must be a dictionary.')
if len(args) == 1:
if not isinstance(args[0], dict):
raise InterpreterException('Argument 1 must be a dictionary.')
section = ''
values = args[0]
elif len(args) == 2:
if not isinstance(args[0], str):
raise InterpreterException('Argument 1 must be a string.')
if isinstance(args[1], dict):
section, values = args
else:
section = ''
values = {args[0]: args[1]}
elif len(args) == 3:
if not isinstance(args[0], str):
raise InterpreterException('Argument 1 must be a string.')
if not isinstance(args[1], str):
raise InterpreterException('Argument 2 must be a string.')
section, key, value = args
values = {key: value}
else:
raise InterpreterException('Summary accepts at most 3 arguments.')
if self.subproject not in self.summary:
self.summary[self.subproject] = Summary(self.active_projectname, self.project_version)
self.summary[self.subproject].add_section(section, values)

@ -4122,16 +4122,12 @@ recommended as it is not supported on some platforms''')
expected = textwrap.dedent(r'''
Some Subproject 2.0
Features
foo: bar
string: bar
integer: 1
boolean: True
My Project 1.0
Directories
bindir: bin
libdir: lib
datadir: share
Configuration
Some boolean: False
Another boolean: True
@ -4139,6 +4135,7 @@ recommended as it is not supported on some platforms''')
A list: string
1
True
A number: 1
''')
# Dict ordering is not guaranteed and an exact string comparison randomly
# fails on the CI because lines are reordered.

@ -1,10 +1,5 @@
project('My Project', version : '1.0')
summary('Directories', {'bindir': get_option('bindir'),
'libdir': get_option('libdir'),
'datadir': get_option('datadir'),
})
subproject('sub')
subproject('sub2', required : false)
@ -13,3 +8,4 @@ summary('Configuration', {'Some boolean': false,
'Some string': 'Hello World',
'A list': ['string', 1, true],
})
summary('Configuration', 'A number', 1)

@ -1,3 +1,4 @@
project('Some Subproject', version : '2.0')
summary('Features', {'foo': 'bar'})
summary('string', 'bar')
summary({'integer': 1, 'boolean': true})

Loading…
Cancel
Save