aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mintro.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-12-04 17:01:45 -0800
committerDylan Baker <dylan@pnwbakers.com>2021-01-04 12:20:58 -0800
commite81acbd6069e8c1ae8e3be7bb83ddc239009d42d (patch)
treeb08545b2844650ed95e42ade00ecb1cd3fb85b88 /mesonbuild/mintro.py
parent71db6b04a31707674ad776be1cf22f667056d56b (diff)
downloadmeson-e81acbd6069e8c1ae8e3be7bb83ddc239009d42d.zip
meson-e81acbd6069e8c1ae8e3be7bb83ddc239009d42d.tar.gz
meson-e81acbd6069e8c1ae8e3be7bb83ddc239009d42d.tar.bz2
Use a single coredata dictionary for options
This patches takes the options work to it's logical conclusion: A single flat dictionary of OptionKey: UserOptions. This allows us to simplify a large number of cases, as we don't need to check if an option is in this dict or that one (or any of 5 or 6, actually).
Diffstat (limited to 'mesonbuild/mintro.py')
-rw-r--r--mesonbuild/mintro.py42
1 files changed, 23 insertions, 19 deletions
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index b1d2831..9121fc7 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -21,6 +21,7 @@ project files and don't need this info."""
import collections
import json
+from mesonbuild.compilers import d
from . import build, coredata as cdata
from . import mesonlib
from .ast import IntrospectionInterpreter, build_target_functions, AstConditionLevel, AstIDGenerator, AstIndentationGenerator, AstJSONPrinter
@@ -212,21 +213,30 @@ def list_buildoptions_from_source(intr: IntrospectionInterpreter) -> T.List[T.Di
def list_buildoptions(coredata: cdata.CoreData, subprojects: T.Optional[T.List[str]] = None) -> T.List[T.Dict[str, T.Union[str, bool, int, T.List[str]]]]:
optlist = [] # type: T.List[T.Dict[str, T.Union[str, bool, int, T.List[str]]]]
+ subprojects = subprojects or []
dir_option_names = set(cdata.BUILTIN_DIR_OPTIONS)
test_option_names = {OptionKey('errorlogs'),
OptionKey('stdsplit')}
- core_option_names = {k for k in coredata.builtins if k not in dir_option_names | test_option_names}
- dir_options = {str(k): o for k, o in coredata.builtins.items() if k in dir_option_names}
- test_options = {str(k): o for k, o in coredata.builtins.items() if k in test_option_names}
- core_options = {str(k): o for k, o in coredata.builtins.items() if k in core_option_names}
- for s in subprojects or []:
- core_options.update({str(k.evolve(subproject=s)): v for k, v in coredata.builtins.items() if not v.yielding})
-
- def add_keys(options: 'cdata.OptionDictType', section: str, machine: str = 'any') -> None:
+ dir_options: 'cdata.KeyedOptionDictType' = {}
+ test_options: 'cdata.KeyedOptionDictType' = {}
+ core_options: 'cdata.KeyedOptionDictType' = {}
+ for k, v in 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
+ if not v.yielding:
+ for s in subprojects:
+ core_options[k.evolve(subproject=s)] = v
+
+ def add_keys(options: 'cdata.KeyedOptionDictType', section: str) -> None:
for key, opt in sorted(options.items()):
- optdict = {'name': key, 'value': opt.value, 'section': section, 'machine': machine}
+ optdict = {'name': str(key), 'value': opt.value, 'section': section,
+ 'machine': key.machine.get_lower_case_name() if coredata.is_per_machine_option(key) else 'any'}
if isinstance(opt, cdata.UserStringOption):
typestr = 'string'
elif isinstance(opt, cdata.UserBooleanOption):
@@ -245,20 +255,14 @@ def list_buildoptions(coredata: cdata.CoreData, subprojects: T.Optional[T.List[s
optlist.append(optdict)
add_keys(core_options, 'core')
- add_keys({str(k): v for k, v in coredata.backend_options.items()}, 'backend')
- add_keys({str(k): v for k, v in coredata.base_options.items()}, 'base')
- add_keys(
- {str(k): v for k, v in coredata.compiler_options.items() if k.machine is MachineChoice.HOST},
- 'compiler',
- machine='host',
- )
+ add_keys({k: v for k, v in coredata.options.items() if k.is_backend()}, 'backend')
+ add_keys({k: v for k, v in coredata.options.items() if k.is_base()}, 'base')
add_keys(
- {str(k): v for k, v in coredata.compiler_options.items() if k.machine is MachineChoice.BUILD},
+ {k: v for k, v in sorted(coredata.options.items(), key=lambda i: i[0].machine) if k.is_compiler()},
'compiler',
- machine='build',
)
add_keys(dir_options, 'directory')
- add_keys({str(k): v for k, v in coredata.user_options.items()}, 'user')
+ add_keys({k: v for k, v in coredata.options.items() if k.is_project()}, 'user')
add_keys(test_options, 'test')
return optlist