diff options
-rw-r--r-- | docs/markdown/Reference-manual.md | 3 | ||||
-rw-r--r-- | docs/markdown/snippets/summary.md | 5 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 21 | ||||
-rwxr-xr-x | run_unittests.py | 3 | ||||
-rw-r--r-- | test cases/unit/72 summary/meson.build | 1 |
5 files changed, 23 insertions, 10 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 475b711..ff82164 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -1239,9 +1239,10 @@ 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: +- `section` title to group a set of key/value pairs. - `bool_yn` if set to true, all boolean values will be replaced by green YES or red NO. -- `section` title to group a set of key/value pairs. +- `list_sep` *Since 0.54.0* string used to separate list values (e.g. `', '`). Example: ```meson diff --git a/docs/markdown/snippets/summary.md b/docs/markdown/snippets/summary.md new file mode 100644 index 0000000..2ab7996 --- /dev/null +++ b/docs/markdown/snippets/summary.md @@ -0,0 +1,5 @@ +## Summary improvements + +A new `list_sep` keyword argument has been added to `summary()` function. +If defined and the value is a list, elements will be separated by the provided +string instead of being aligned on a new line. diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index c29ed89..c9e559c 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1791,6 +1791,9 @@ class Summary: bool_yn = kwargs.get('bool_yn', False) if not isinstance(bool_yn, bool): raise InterpreterException('bool_yn keyword argument must be boolean') + list_sep = kwargs.get('list_sep') + if list_sep is not None and not isinstance(list_sep, str): + raise InterpreterException('list_sep keyword argument must be string') for k, v in values.items(): if k in self.sections[section]: raise InterpreterException('Summary section {!r} already have key {!r}'.format(section, k)) @@ -1803,9 +1806,7 @@ class Summary: formatted_values.append(mlog.green('YES') if i else mlog.red('NO')) else: formatted_values.append(i) - if not formatted_values: - formatted_values = [''] - self.sections[section][k] = formatted_values + self.sections[section][k] = (formatted_values, list_sep) self.max_key_len = max(self.max_key_len, len(k)) def dump(self): @@ -1815,11 +1816,14 @@ class Summary: if section: mlog.log(' ', mlog.bold(section)) for k, v in values.items(): + v, list_sep = v indent = self.max_key_len - len(k) + 3 - mlog.log(' ' * indent, k + ':', v[0]) - indent = self.max_key_len + 5 - for i in v[1:]: - mlog.log(' ' * indent, i) + end = ' ' if v else '' + mlog.log(' ' * indent, k + ':', end=end) + if list_sep is None: + indent = self.max_key_len + 6 + list_sep = '\n' + ' ' * indent + mlog.log(*v, sep=list_sep) mlog.log('') # newline @@ -2949,7 +2953,8 @@ external dependencies (including libraries) must go to "dependencies".''') mlog.log(mlog.bold('Message:'), *args) @noArgsFlattening - @permittedKwargs({'section', 'bool_yn'}) + @FeatureNewKwargs('summary', '0.54.0', ['list_sep']) + @permittedKwargs({'section', 'bool_yn', 'list_sep'}) @FeatureNew('summary', '0.53.0') def func_summary(self, node, args, kwargs): if len(args) == 1: diff --git a/run_unittests.py b/run_unittests.py index aa27a1d..09bdcf1 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4347,10 +4347,11 @@ recommended as it is not supported on some platforms''') A list: string 1 True - empty list: + empty list: A number: 1 yes: YES no: NO + coma list: a, b, c Subprojects sub: YES diff --git a/test cases/unit/72 summary/meson.build b/test cases/unit/72 summary/meson.build index c155889..df4540d 100644 --- a/test cases/unit/72 summary/meson.build +++ b/test cases/unit/72 summary/meson.build @@ -12,3 +12,4 @@ summary({'Some boolean': false, summary('A number', 1, section: 'Configuration') summary('yes', true, bool_yn : true, section: 'Configuration') summary('no', false, bool_yn : true, section: 'Configuration') +summary('coma list', ['a', 'b', 'c'], list_sep: ', ', section: 'Configuration') |