diff options
Diffstat (limited to 'mesonbuild/mconf.py')
-rw-r--r-- | mesonbuild/mconf.py | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index 774dc5a..686a336 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -17,8 +17,11 @@ from . import coredata, environment, mesonlib, build, mintro, mlog from .ast import AstIDGenerator import typing as T +from .mesonlib import MachineChoice, OptionKey + if T.TYPE_CHECKING: import argparse + from .coredata import UserOption def add_arguments(parser: 'argparse.ArgumentParser') -> None: coredata.register_builtin_arguments(parser) @@ -26,7 +29,6 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None: parser.add_argument('--clearcache', action='store_true', default=False, help='Clear cached state (e.g. found dependencies)') - def make_lower_case(val: T.Any) -> T.Union[str, T.List[T.Any]]: # T.Any because of recursion... if isinstance(val, bool): return str(val).lower() @@ -52,8 +54,8 @@ class Conf: self.choices_col = [] self.descr_col = [] self.has_choices = False - self.all_subprojects = set() - self.yielding_options = set() + self.all_subprojects: T.Set[str] = set() + self.yielding_options: T.Set[OptionKey] = set() if os.path.isdir(os.path.join(self.build_dir, 'meson-private')): self.build = build.load(self.build_dir) @@ -101,20 +103,20 @@ class Conf: else: print('{0:{width[0]}} {1:{width[1]}} {3}'.format(*line, width=col_widths)) - def split_options_per_subproject(self, options): - result = {} + def split_options_per_subproject(self, options: 'coredata.KeyedOptionDictType') -> T.Dict[str, T.Dict[str, 'UserOption']]: + result: T.Dict[str, T.Dict[str, 'UserOption']] = {} for k, o in options.items(): - subproject = '' - if ':' in k: - subproject, optname = k.split(':') - if o.yielding and optname in options: + subproject = k.subproject + if k.subproject: + k = k.as_root() + if o.yielding and k in options: self.yielding_options.add(k) self.all_subprojects.add(subproject) - result.setdefault(subproject, {})[k] = o + result.setdefault(subproject, {})[str(k)] = o return result - def _add_line(self, name, value, choices, descr): - self.name_col.append(' ' * self.print_margin + name) + def _add_line(self, name: OptionKey, value, choices, descr) -> None: + self.name_col.append(' ' * self.print_margin + str(name)) self.value_col.append(value) self.choices_col.append(choices) self.descr_col.append(descr) @@ -163,7 +165,7 @@ class Conf: self._add_line(section + ':', '', '', '') self.print_margin = 2 - def print_options(self, title, options): + def print_options(self, title: str, options: 'coredata.KeyedOptionDictType') -> None: if not options: return if title: @@ -188,33 +190,34 @@ class Conf: if not self.default_values_only: print(' Build dir ', self.build_dir) - dir_option_names = list(coredata.BUILTIN_DIR_OPTIONS) - test_option_names = ['errorlogs', - 'stdsplit'] - core_option_names = [k for k in self.coredata.builtins if k not in dir_option_names + test_option_names] - - dir_options = {k: o for k, o in self.coredata.builtins.items() if k in dir_option_names} - test_options = {k: o for k, o in self.coredata.builtins.items() if k in test_option_names} - core_options = {k: o for k, o in self.coredata.builtins.items() if k in core_option_names} - - core_options = self.split_options_per_subproject(core_options) - host_compiler_options = self.split_options_per_subproject( - dict(self.coredata.flatten_lang_iterator( - self.coredata.compiler_options.host.items()))) - build_compiler_options = self.split_options_per_subproject( - dict(self.coredata.flatten_lang_iterator( - (self.coredata.insert_build_prefix(k), o) - for k, o in self.coredata.compiler_options.build.items()))) - project_options = self.split_options_per_subproject(self.coredata.user_options) + dir_option_names = set(coredata.BUILTIN_DIR_OPTIONS) + test_option_names = {OptionKey('errorlogs'), + OptionKey('stdsplit')} + + dir_options: 'coredata.KeyedOptionDictType' = {} + test_options: 'coredata.KeyedOptionDictType' = {} + core_options: 'coredata.KeyedOptionDictType' = {} + for k, v in self.coredata.options.items(): + if k in dir_option_names: + dir_options[k] = v + elif k in test_option_names: + test_options[k] = v + elif k.is_builtin(): + core_options[k] = v + + host_core_options = self.split_options_per_subproject({k: v for k, v in core_options.items() if k.machine is MachineChoice.HOST}) + build_core_options = self.split_options_per_subproject({k: v for k, v in core_options.items() if k.machine is MachineChoice.BUILD}) + host_compiler_options = self.split_options_per_subproject({k: v for k, v in self.coredata.options.items() if k.is_compiler() and k.machine is MachineChoice.HOST}) + build_compiler_options = self.split_options_per_subproject({k: v for k, v in self.coredata.options.items() if k.is_compiler() and k.machine is MachineChoice.BUILD}) + project_options = self.split_options_per_subproject({k: v for k, v in self.coredata.options.items() if k.is_project()}) show_build_options = self.default_values_only or self.build.environment.is_cross_build() self.add_section('Main project options') - self.print_options('Core options', core_options['']) - self.print_options('', self.coredata.builtins_per_machine.host) + self.print_options('Core options', host_core_options['']) if show_build_options: - self.print_options('', {self.coredata.insert_build_prefix(k): o for k, o in self.coredata.builtins_per_machine.build.items()}) - self.print_options('Backend options', self.coredata.backend_options) - self.print_options('Base options', self.coredata.base_options) + self.print_options('', build_core_options['']) + self.print_options('Backend options', {str(k): v for k, v in self.coredata.options.items()}) + self.print_options('Base options', {str(k): v for k, v in self.coredata.options.items()}) self.print_options('Compiler options', host_compiler_options.get('', {})) if show_build_options: self.print_options('', build_compiler_options.get('', {})) @@ -251,7 +254,7 @@ def run(options): return 0 save = False - if len(options.cmd_line_options) > 0: + if options.cmd_line_options: c.set_options(options.cmd_line_options) coredata.update_cmd_line_file(builddir, options) save = True |