diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-06-18 13:38:37 +0200 |
|---|---|---|
| committer | Jussi Pakkanen <jussi.pakkanen@mailbox.org> | 2025-06-20 15:02:06 +0300 |
| commit | 3b52f339ba23aa6aa03130cb350d8318ec9f27f0 (patch) | |
| tree | 0184d021b2fa2c710d02a7b5a6ba8ba76aa1153d | |
| parent | 3d4c9154b21b4414efaa7b3f15b75c7e49596764 (diff) | |
| download | meson-3b52f339ba23aa6aa03130cb350d8318ec9f27f0.tar.gz | |
mconf: print sections lazily
To the user, toplevel project options are the same as global options
because they are not prefixed by ":". So, even if we starting printing
toplevel project overrides, we want to keep project options outside of
that section. Then one would end up with:
...
Project options
---------------
Main project:
Subproject foo:
The "Main project" line is printed because '' is in self.all_subprojects,
but there is nothing below because project options have been printed before.
To fix this, print section names lazily, together with their first content
item.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | mesonbuild/mconf.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index 7e6ca7ba7..84dc9ac69 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -73,6 +73,7 @@ class Conf: self.build_dir = os.path.dirname(self.build_dir) self.build = None self.max_choices_line_length = 60 + self.pending_section: T.Optional[str] = None self.name_col: T.List[LOGLINE] = [] self.value_col: T.List[LOGLINE] = [] self.choices_col: T.List[LOGLINE] = [] @@ -207,11 +208,13 @@ class Conf: self.descr_col.append(descr) def add_option(self, name: str, descr: str, value: T.Any, choices: T.Any) -> None: + self._add_section() value = stringify(value) choices = stringify(choices) self._add_line(mlog.green(name), mlog.yellow(value), mlog.blue(choices), descr) def add_title(self, title: str) -> None: + self._add_section() newtitle = mlog.cyan(title) descr = mlog.cyan('Description') value = mlog.cyan('Default Value' if self.default_values_only else 'Current Value') @@ -220,11 +223,17 @@ class Conf: self._add_line(newtitle, value, choices, descr) self._add_line('-' * len(newtitle), '-' * len(value), '-' * len(choices), '-' * len(descr)) - def add_section(self, section: str) -> None: + def _add_section(self) -> None: + if not self.pending_section: + return self.print_margin = 0 self._add_line('', '', '', '') - self._add_line(mlog.normal_yellow(section + ':'), '', '', '') + self._add_line(mlog.normal_yellow(self.pending_section + ':'), '', '', '') self.print_margin = 2 + self.pending_section = None + + def add_section(self, section: str) -> None: + self.pending_section = section def print_options(self, title: str, opts: T.Union[options.MutableKeyedOptionDictType, options.OptionStore]) -> None: if not opts: |
