summary: Add bool_yn keyword argument

pull/4649/head
Xavier Claessens 5 years ago
parent 49082f9669
commit 38953d8ee3
  1. 4
      docs/markdown/Reference-manual.md
  2. 19
      mesonbuild/interpreter.py
  3. 2
      run_unittests.py
  4. 2
      test cases/unit/74 summary/meson.build

@ -1230,6 +1230,10 @@ booleans or strings.
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.
Keyword arguments:
- `bool_yn` if set to true, all boolean values will be replaced by green YES
or red NO.
Example:
```meson
project('My Project', version : '1.0')

@ -1759,16 +1759,23 @@ class Summary:
self.sections = collections.defaultdict(dict)
self.max_key_len = 0
def add_section(self, section, values):
def add_section(self, section, values, kwargs):
bool_yn = kwargs.get('bool_yn', False)
if not isinstance(bool_yn, bool):
raise InterpreterException('bool_yn keyword argument must be boolean')
for k, v in values.items():
if k in self.sections[section]:
raise InterpreterException('Summary section {!r} already have key {!r}'.format(section, k))
v = listify(v)
for i in v:
formatted_values = []
for i in listify(v):
if not isinstance(i, (str, int)):
m = 'Summary value in section {!r}, key {!r}, must be string, integer or boolean'
raise InterpreterException(m.format(section, k))
self.sections[section][k] = v
if bool_yn and isinstance(i, bool):
formatted_values.append(mlog.green('YES') if i else mlog.red('NO'))
else:
formatted_values.append(i)
self.sections[section][k] = formatted_values
self.max_key_len = max(self.max_key_len, len(k))
def dump(self):
@ -2869,7 +2876,7 @@ external dependencies (including libraries) must go to "dependencies".''')
mlog.log(mlog.bold('Message:'), argstr)
@noArgsFlattening
@noKwargs
@permittedKwargs({'bool_yn'})
@FeatureNew('summary', '0.53.0')
def func_summary(self, node, args, kwargs):
if len(args) == 1:
@ -2896,7 +2903,7 @@ external dependencies (including libraries) must go to "dependencies".''')
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)
self.summary[self.subproject].add_section(section, values, kwargs)
def _print_summary(self):
mlog.log('') # newline

@ -4136,6 +4136,8 @@ recommended as it is not supported on some platforms''')
1
True
A number: 1
yes: YES
no: NO
''')
# Dict ordering is not guaranteed and an exact string comparison randomly
# fails on the CI because lines are reordered.

@ -9,3 +9,5 @@ summary('Configuration', {'Some boolean': false,
'A list': ['string', 1, true],
})
summary('Configuration', 'A number', 1)
summary('Configuration', 'yes', true, bool_yn : true)
summary('Configuration', 'no', false, bool_yn : true)

Loading…
Cancel
Save