diff options
| -rw-r--r-- | mesonbuild/compilers/compilers.py | 15 | ||||
| -rw-r--r-- | mesonbuild/options.py | 8 |
2 files changed, 11 insertions, 12 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 424bcc19b..011dacfb7 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2012-2022 The Meson development team -# Copyright © 2023-2024 Intel Corporation +# Copyright © 2023-2025 Intel Corporation from __future__ import annotations @@ -20,9 +20,7 @@ from ..mesonlib import ( EnvironmentException, MesonException, Popen_safe_logged, LibType, TemporaryDirectoryWinProof, ) - from ..options import OptionKey - from ..arglist import CompilerArgs if T.TYPE_CHECKING: @@ -37,9 +35,10 @@ if T.TYPE_CHECKING: from ..dependencies import Dependency CompilerType = T.TypeVar('CompilerType', bound='Compiler') - _T = T.TypeVar('_T') UserOptionType = T.TypeVar('UserOptionType', bound=options.UserOption) +_T = T.TypeVar('_T') + """This file contains the data files of all compilers Meson knows about. To support a new compiler, add its information below. Also add corresponding autodetection code in detect.py.""" @@ -216,19 +215,21 @@ clike_debug_args: T.Dict[bool, T.List[str]] = { MSCRT_VALS = ['none', 'md', 'mdd', 'mt', 'mtd'] + @dataclass -class BaseOption(T.Generic[options._T, options._U]): - opt_type: T.Type[options._U] +class BaseOption(T.Generic[_T]): + opt_type: T.Type[options.UserOption[_T]] description: str default: T.Any = None choices: T.Any = None - def init_option(self, name: OptionKey) -> options._U: + def init_option(self, name: OptionKey) -> options.UserOption[_T]: keywords = {'value': self.default} if self.choices: keywords['choices'] = self.choices return self.opt_type(name.name, self.description, **keywords) + BASE_OPTIONS: T.Mapping[OptionKey, BaseOption] = { OptionKey('b_pch'): BaseOption(options.UserBooleanOption, 'Use precompiled headers', True), OptionKey('b_lto'): BaseOption(options.UserBooleanOption, 'Use link time optimization', False), diff --git a/mesonbuild/options.py b/mesonbuild/options.py index d0cf231dc..ec1db8980 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -283,8 +283,6 @@ class UserOption(T.Generic[_T], HoldableObject): self.value = self.validate_value(newvalue) return self.value != oldvalue -_U = T.TypeVar('_U', bound=UserOption[_T]) - class UserStringOption(UserOption[str]): def __init__(self, name: str, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING, @@ -525,14 +523,14 @@ class UserStdOption(UserComboOption): f'Possible values for option "{self.name}" are {self.choices}') -class BuiltinOption(T.Generic[_T, _U]): +class BuiltinOption(T.Generic[_T]): """Class for a builtin option type. There are some cases that are not fully supported yet. """ - def __init__(self, opt_type: T.Type[_U], description: str, default: T.Any, yielding: bool = True, *, + def __init__(self, opt_type: T.Type[UserOption[_T]], description: str, default: T.Any, yielding: bool = True, *, choices: T.Any = None, readonly: bool = False): self.opt_type = opt_type self.description = description @@ -541,7 +539,7 @@ class BuiltinOption(T.Generic[_T, _U]): self.yielding = yielding self.readonly = readonly - def init_option(self, name: 'OptionKey', value: T.Optional[T.Any], prefix: str) -> _U: + def init_option(self, name: 'OptionKey', value: T.Optional[T.Any], prefix: str) -> UserOption[_T]: """Create an instance of opt_type and return it.""" if value is None: value = self.prefixed_default(name, prefix) |
