diff options
-rw-r--r-- | docs/markdown/Reference-manual.md | 4 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 19 | ||||
-rwxr-xr-x | run_unittests.py | 2 | ||||
-rw-r--r-- | test cases/unit/74 summary/meson.build | 2 |
4 files changed, 21 insertions, 6 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index cf5585b..d1fe55b 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -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') diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 2d937e5..e12c0e9 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -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 diff --git a/run_unittests.py b/run_unittests.py index cb5086c..a3a3ac2 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -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. diff --git a/test cases/unit/74 summary/meson.build b/test cases/unit/74 summary/meson.build index 392d940..c689f96 100644 --- a/test cases/unit/74 summary/meson.build +++ b/test cases/unit/74 summary/meson.build @@ -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) |