diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-03-04 15:27:24 -0800 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-04-02 12:49:07 -0400 |
| commit | 4001d0261933890a59242beb0a26477f4c452e33 (patch) | |
| tree | 89acc2fdd04e48df5705aca8f0ba66143f67d426 | |
| parent | f9c9726ec70fe83a79ac07ee04f077285b666fef (diff) | |
| download | meson-4001d0261933890a59242beb0a26477f4c452e33.tar.gz | |
options: move BASE_OPTIONS to the options module
This makes more sense from a "group all options together" It also allows
us to remove a bunch of imports in functions, a clear code smell.
| -rw-r--r-- | mesonbuild/compilers/__init__.py | 2 | ||||
| -rw-r--r-- | mesonbuild/compilers/compilers.py | 31 | ||||
| -rw-r--r-- | mesonbuild/coredata.py | 22 | ||||
| -rw-r--r-- | mesonbuild/msetup.py | 3 | ||||
| -rw-r--r-- | mesonbuild/options.py | 29 |
5 files changed, 39 insertions, 48 deletions
diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index 98ec13fae..116b3fa7a 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -7,7 +7,6 @@ __all__ = [ 'RunResult', 'all_languages', - 'BASE_OPTIONS', 'clib_langs', 'clink_langs', 'c_suffixes', @@ -48,7 +47,6 @@ from .compilers import ( Compiler, RunResult, all_languages, - BASE_OPTIONS, clib_langs, clink_langs, c_suffixes, diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 9fbde0e49..3398aa4af 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -212,35 +212,6 @@ clike_debug_args: T.Dict[bool, T.List[str]] = { } -MSCRT_VALS = ['none', 'md', 'mdd', 'mt', 'mtd'] - -BASE_OPTIONS: T.Mapping[OptionKey, options.AnyOptionType] = { - OptionKey(o.name): o for o in T.cast('T.List[options.AnyOptionType]', [ - options.UserBooleanOption('b_pch', 'Use precompiled headers', True), - options.UserBooleanOption('b_lto', 'Use link time optimization', False), - options.UserIntegerOption('b_lto_threads', 'Use multiple threads for Link Time Optimization', 0), - options.UserComboOption('b_lto_mode', 'Select between different LTO modes.', 'default', choices=['default', 'thin']), - options.UserBooleanOption('b_thinlto_cache', 'Use LLVM ThinLTO caching for faster incremental builds', False), - options.UserStringOption('b_thinlto_cache_dir', 'Directory to store ThinLTO cache objects', ''), - options.UserStringArrayOption('b_sanitize', 'Code sanitizer to use', []), - options.UserBooleanOption('b_lundef', 'Use -Wl,--no-undefined when linking', True), - options.UserBooleanOption('b_asneeded', 'Use -Wl,--as-needed when linking', True), - options.UserComboOption( - 'b_pgo', 'Use profile guided optimization', 'off', choices=['off', 'generate', 'use']), - options.UserBooleanOption('b_coverage', 'Enable coverage tracking.', False), - options.UserComboOption( - 'b_colorout', 'Use colored output', 'always', choices=['auto', 'always', 'never']), - options.UserComboOption( - 'b_ndebug', 'Disable asserts', 'false', choices=['true', 'false', 'if-release']), - options.UserBooleanOption('b_staticpic', 'Build static libraries as position independent', True), - options.UserBooleanOption('b_pie', 'Build executables as position independent', False), - options.UserBooleanOption('b_bitcode', 'Generate and embed bitcode (only macOS/iOS/tvOS)', False), - options.UserComboOption( - 'b_vscrt', 'VS run-time library type to use.', 'from_buildtype', - choices=MSCRT_VALS + ['from_buildtype', 'static_from_buildtype']), - ]) -} - def option_enabled(boptions: T.Set[OptionKey], target: 'BuildTarget', env: 'Environment', @@ -1109,7 +1080,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): return [] def get_crt_val(self, crt_val: str, buildtype: str) -> str: - if crt_val in MSCRT_VALS: + if crt_val in options.MSCRT_VALS: return crt_val assert crt_val in {'from_buildtype', 'static_from_buildtype'} diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 7cc69a5a7..d2dc4bb2e 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -603,27 +603,25 @@ class CoreData: return dirty def set_default_options(self, default_options: T.MutableMapping[OptionKey, str], subproject: str, env: 'Environment') -> None: - from .compilers import BASE_OPTIONS - # Main project can set default options on subprojects, but subprojects # can only set default options on themselves. # Preserve order: if env.options has 'buildtype' it must come after # 'optimization' if it is in default_options. - options: T.MutableMapping[OptionKey, T.Any] = OrderedDict() + options_: T.MutableMapping[OptionKey, T.Any] = OrderedDict() for k, v in default_options.items(): if isinstance(k, str): k = OptionKey.from_string(k) if not subproject or k.subproject == subproject: - options[k] = v - options.update(env.options) - env.options = options + options_[k] = v + options_.update(env.options) + env.options = options_ # Create a subset of options, keeping only project and builtin # options for this subproject. # Language and backend specific options will be set later when adding # languages and setting the backend (builtin options must be set first # to know which backend we'll use). - options = OrderedDict() + options_ = OrderedDict() for k, v in env.options.items(): if isinstance(k, str): @@ -642,12 +640,12 @@ class CoreData: # adding languages and setting backend. if self.optstore.is_compiler_option(k) or self.optstore.is_backend_option(k): continue - if self.optstore.is_base_option(k) and k.evolve(subproject=None) in BASE_OPTIONS: + if self.optstore.is_base_option(k) and k.evolve(subproject=None) in options.BASE_OPTIONS: # set_options will report unknown base options continue - options[k] = v + options_[k] = v - self.set_options(options, subproject=subproject, first_invocation=env.first_invocation) + self.set_options(options_, subproject=subproject, first_invocation=env.first_invocation) def add_compiler_options(self, c_options: MutableKeyedOptionDictType, lang: str, for_machine: MachineChoice, env: Environment, subproject: str) -> None: @@ -680,8 +678,6 @@ class CoreData: self.optstore.add_compiler_option(lang, gopt_key, gopt_valobj) def process_compiler_options(self, lang: str, comp: Compiler, env: Environment, subproject: str) -> None: - from . import compilers - self.add_compiler_options(comp.get_options(), lang, comp.for_machine, env, subproject) for key in comp.base_options: @@ -690,7 +686,7 @@ class CoreData: else: skey = key if skey not in self.optstore: - self.optstore.add_system_option(skey, copy.deepcopy(compilers.BASE_OPTIONS[key])) + self.optstore.add_system_option(skey, copy.deepcopy(options.BASE_OPTIONS[key])) if skey in env.options: self.optstore.set_option(skey, env.options[skey]) elif subproject and key in env.options: diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py index 26e92ee5d..df5d2398f 100644 --- a/mesonbuild/msetup.py +++ b/mesonbuild/msetup.py @@ -11,7 +11,7 @@ import typing as T from . import build, coredata, environment, interpreter, mesonlib, mintro, mlog from .mesonlib import MesonException -from .options import OptionKey +from .options import BASE_OPTIONS, OptionKey if T.TYPE_CHECKING: from typing_extensions import Protocol @@ -189,7 +189,6 @@ class MesonApp: return self._generate(env, capture, vslite_ctx) def check_unused_options(self, coredata: 'coredata.CoreData', cmd_line_options: T.Any, all_subprojects: T.Any) -> None: - from mesonbuild.compilers import BASE_OPTIONS pending = coredata.optstore.pending_project_options errlist: T.List[str] = [] for opt in pending: diff --git a/mesonbuild/options.py b/mesonbuild/options.py index f219ebda5..acf7b8c31 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -753,6 +753,34 @@ BUILTIN_DIR_NOPREFIX_OPTIONS: T.Dict[OptionKey, T.Dict[str, str]] = { OptionKey('python.purelibdir'): {}, } +MSCRT_VALS = ['none', 'md', 'mdd', 'mt', 'mtd'] + +BASE_OPTIONS: T.Mapping[OptionKey, AnyOptionType] = { + OptionKey(o.name): o for o in T.cast('T.List[AnyOptionType]', [ + UserBooleanOption('b_pch', 'Use precompiled headers', True), + UserBooleanOption('b_lto', 'Use link time optimization', False), + UserIntegerOption('b_lto_threads', 'Use multiple threads for Link Time Optimization', 0), + UserComboOption('b_lto_mode', 'Select between different LTO modes.', 'default', choices=['default', 'thin']), + UserBooleanOption('b_thinlto_cache', 'Use LLVM ThinLTO caching for faster incremental builds', False), + UserStringOption('b_thinlto_cache_dir', 'Directory to store ThinLTO cache objects', ''), + UserStringArrayOption('b_sanitize', 'Code sanitizer to use', []), + UserBooleanOption('b_lundef', 'Use -Wl,--no-undefined when linking', True), + UserBooleanOption('b_asneeded', 'Use -Wl,--as-needed when linking', True), + UserComboOption( + 'b_pgo', 'Use profile guided optimization', 'off', choices=['off', 'generate', 'use']), + UserBooleanOption('b_coverage', 'Enable coverage tracking.', False), + UserComboOption( + 'b_colorout', 'Use colored output', 'always', choices=['auto', 'always', 'never']), + UserComboOption( + 'b_ndebug', 'Disable asserts', 'false', choices=['true', 'false', 'if-release']), + UserBooleanOption('b_staticpic', 'Build static libraries as position independent', True), + UserBooleanOption('b_pie', 'Build executables as position independent', False), + UserBooleanOption('b_bitcode', 'Generate and embed bitcode (only macOS/iOS/tvOS)', False), + UserComboOption( + 'b_vscrt', 'VS run-time library type to use.', 'from_buildtype', + choices=MSCRT_VALS + ['from_buildtype', 'static_from_buildtype']), + ]) +} class OptionStore: DEFAULT_DEPENDENTS = {'plain': ('plain', False), @@ -1058,7 +1086,6 @@ class OptionStore: def get_default_for_b_option(self, key: OptionKey) -> ElementaryOptionValues: assert self.is_base_option(key) - from .compilers.compilers import BASE_OPTIONS try: return T.cast('ElementaryOptionValues', BASE_OPTIONS[key.evolve(subproject=None)].default) except KeyError: |
