aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mconf.py
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/mconf.py')
-rw-r--r--mesonbuild/mconf.py57
1 files changed, 28 insertions, 29 deletions
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index 416caf1..7f62ba0 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -33,7 +33,6 @@ if T.TYPE_CHECKING:
builddir: str
clearcache: bool
pager: bool
- unset_opts: T.List[str]
# cannot be TV_Loggable, because non-ansidecorators do direct string concat
LOGLINE = T.Union[str, mlog.AnsiDecorator]
@@ -47,7 +46,7 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None:
help='Clear cached state (e.g. found dependencies)')
parser.add_argument('--no-pager', action='store_false', dest='pager',
help='Do not redirect output to a pager')
- parser.add_argument('-U', action='append', dest='unset_opts', default=[],
+ parser.add_argument('-U', action=coredata.KeyNoneAction, dest='cmd_line_options', default={},
help='Remove a subproject option.')
def stringify(val: T.Any) -> str:
@@ -73,6 +72,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] = []
@@ -125,9 +125,6 @@ class Conf:
def clear_cache(self) -> None:
self.coredata.clear_cache()
- def set_options(self, options: T.Dict[OptionKey, str]) -> bool:
- return self.coredata.set_options(options)
-
def save(self) -> None:
# Do nothing when using introspection
if self.default_values_only:
@@ -149,7 +146,7 @@ class Conf:
Each column will have a specific width, and will be line wrapped.
"""
total_width = shutil.get_terminal_size(fallback=(160, 0))[0]
- _col = max(total_width // 5, 20)
+ _col = max(total_width // 5, 24)
last_column = total_width - (3 * _col) - 3
four_column = (_col, _col, _col, last_column if last_column > 1 else _col)
@@ -194,7 +191,7 @@ class Conf:
) -> T.Dict[str, options.MutableKeyedOptionDictType]:
result: T.Dict[str, options.MutableKeyedOptionDictType] = {}
for k, o in opts.items():
- if k.subproject:
+ if k.subproject is not None:
self.all_subprojects.add(k.subproject)
result.setdefault(k.subproject, {})[k] = o
return result
@@ -209,12 +206,15 @@ class Conf:
self.choices_col.append(choices)
self.descr_col.append(descr)
- def add_option(self, name: str, descr: str, value: T.Any, choices: T.Any) -> None:
+ def add_option(self, key: OptionKey, 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)
+ self._add_line(mlog.green(str(key.evolve(subproject=None))), 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')
@@ -223,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:
@@ -242,7 +248,7 @@ class Conf:
# printable_value = '<inherited from main project>'
#if isinstance(o, options.UserFeatureOption) and o.is_auto():
# printable_value = auto.printable_value()
- self.add_option(k.name, o.description, printable_value, o.printable_choices())
+ self.add_option(k, o.description, printable_value, o.printable_choices())
def print_conf(self, pager: bool) -> None:
if pager:
@@ -291,15 +297,15 @@ class Conf:
project_options = self.split_options_per_subproject({k: v for k, v in self.coredata.optstore.items() if self.coredata.optstore.is_project_option(k)})
show_build_options = self.default_values_only or self.build.environment.is_cross_build()
- self.add_section('Main project options')
+ self.add_section('Global build options')
self.print_options('Core options', host_core_options[None])
if show_build_options and build_core_options:
self.print_options('', build_core_options[None])
self.print_options('Backend options', {k: v for k, v in self.coredata.optstore.items() if self.coredata.optstore.is_backend_option(k)})
self.print_options('Base options', {k: v for k, v in self.coredata.optstore.items() if self.coredata.optstore.is_base_option(k)})
- self.print_options('Compiler options', host_compiler_options.get('', {}))
+ self.print_options('Compiler options', host_compiler_options.get(None, {}))
if show_build_options:
- self.print_options('', build_compiler_options.get('', {}))
+ self.print_options('', build_compiler_options.get(None, {}))
for mod, mod_options in module_options.items():
self.print_options(f'{mod} module options', mod_options)
self.print_options('Directories', dir_options)
@@ -307,8 +313,9 @@ class Conf:
self.print_options('Project options', project_options.get('', {}))
for subproject in sorted(self.all_subprojects):
if subproject == '':
- continue
- self.add_section('Subproject ' + subproject)
+ self.add_section('Main project')
+ else:
+ self.add_section('Subproject ' + subproject)
if subproject in host_core_options:
self.print_options('Core options', host_core_options[subproject])
if subproject in build_core_options and show_build_options:
@@ -317,7 +324,7 @@ class Conf:
self.print_options('Compiler options', host_compiler_options[subproject])
if subproject in build_compiler_options and show_build_options:
self.print_options('', build_compiler_options[subproject])
- if subproject in project_options:
+ if subproject != '' and subproject in project_options:
self.print_options('Project options', project_options[subproject])
self.print_aligned()
@@ -342,16 +349,12 @@ class Conf:
if self.coredata.optstore.augments:
mlog.log('\nCurrently set option augments:')
for k, v in self.coredata.optstore.augments.items():
- mlog.log(f'{k:21}{v:10}')
+ mlog.log(f'{k!s:21}{v:10}')
else:
mlog.log('\nThere are no option augments.')
def has_option_flags(options: CMDOptions) -> bool:
- if options.cmd_line_options:
- return True
- if options.unset_opts:
- return True
- return False
+ return bool(options.cmd_line_options)
def is_print_only(options: CMDOptions) -> bool:
if has_option_flags(options):
@@ -373,11 +376,7 @@ def run_impl(options: CMDOptions, builddir: str) -> int:
save = False
if has_option_flags(options):
- unset_opts = getattr(options, 'unset_opts', [])
- all_D = options.projectoptions[:]
- for keystr, valstr in options.cmd_line_options.items():
- all_D.append(f'{keystr}={valstr}')
- save |= c.coredata.optstore.set_from_configure_command(all_D, unset_opts)
+ save |= c.coredata.set_from_configure_command(options)
coredata.update_cmd_line_file(builddir, options)
if options.clearcache:
c.clear_cache()