Skip to content

Commit 3b52f33

Browse files
bonzinijpakkane
authored andcommitted
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 <[email protected]>
1 parent 3d4c915 commit 3b52f33

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

mesonbuild/mconf.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(self, build_dir: str):
7373
self.build_dir = os.path.dirname(self.build_dir)
7474
self.build = None
7575
self.max_choices_line_length = 60
76+
self.pending_section: T.Optional[str] = None
7677
self.name_col: T.List[LOGLINE] = []
7778
self.value_col: T.List[LOGLINE] = []
7879
self.choices_col: T.List[LOGLINE] = []
@@ -207,11 +208,13 @@ def _add_line(self, name: LOGLINE, value: LOGLINE, choices: LOGLINE, descr: LOGL
207208
self.descr_col.append(descr)
208209

209210
def add_option(self, name: str, descr: str, value: T.Any, choices: T.Any) -> None:
211+
self._add_section()
210212
value = stringify(value)
211213
choices = stringify(choices)
212214
self._add_line(mlog.green(name), mlog.yellow(value), mlog.blue(choices), descr)
213215

214216
def add_title(self, title: str) -> None:
217+
self._add_section()
215218
newtitle = mlog.cyan(title)
216219
descr = mlog.cyan('Description')
217220
value = mlog.cyan('Default Value' if self.default_values_only else 'Current Value')
@@ -220,11 +223,17 @@ def add_title(self, title: str) -> None:
220223
self._add_line(newtitle, value, choices, descr)
221224
self._add_line('-' * len(newtitle), '-' * len(value), '-' * len(choices), '-' * len(descr))
222225

223-
def add_section(self, section: str) -> None:
226+
def _add_section(self) -> None:
227+
if not self.pending_section:
228+
return
224229
self.print_margin = 0
225230
self._add_line('', '', '', '')
226-
self._add_line(mlog.normal_yellow(section + ':'), '', '', '')
231+
self._add_line(mlog.normal_yellow(self.pending_section + ':'), '', '', '')
227232
self.print_margin = 2
233+
self.pending_section = None
234+
235+
def add_section(self, section: str) -> None:
236+
self.pending_section = section
228237

229238
def print_options(self, title: str, opts: T.Union[options.MutableKeyedOptionDictType, options.OptionStore]) -> None:
230239
if not opts:

0 commit comments

Comments
 (0)