OptionOverrideProxy: Make it immutable to avoid copies

It is always used as an immutable view so there is no point in doing
copies. However, mypy insist it must implement the same APIs as
Dict[OptionKey, UserOption[Any]] so keep faking it.
pull/10165/head
Xavier Claessens 3 years ago committed by Xavier Claessens
parent 86aaac8e42
commit 06d12064d0
  1. 32
      mesonbuild/compilers/c.py
  2. 4
      mesonbuild/compilers/compilers.py
  3. 26
      mesonbuild/compilers/cpp.py
  4. 4
      mesonbuild/compilers/cuda.py
  5. 4
      mesonbuild/compilers/cython.py
  6. 12
      mesonbuild/compilers/fortran.py
  7. 2
      mesonbuild/compilers/mixins/emscripten.py
  8. 2
      mesonbuild/compilers/objc.py
  9. 2
      mesonbuild/compilers/objcpp.py
  10. 4
      mesonbuild/compilers/rust.py
  11. 17
      mesonbuild/coredata.py
  12. 27
      mesonbuild/mesonlib/universal.py
  13. 6
      mesonbuild/mintro.py
  14. 2
      mesonbuild/optinterpreter.py

@ -39,7 +39,7 @@ from .compilers import (
)
if T.TYPE_CHECKING:
from ..coredata import KeyedOptionDictType
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..dependencies import Dependency
from ..envconfig import MachineInfo
from ..environment import Environment
@ -96,7 +96,7 @@ class CCompiler(CLikeCompiler, Compiler):
return self.compiles(t.format(**fargs), env, extra_args=extra_args,
dependencies=dependencies)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
opts.update({
OptionKey('std', machine=self.for_machine, lang=self.language): coredata.UserComboOption(
@ -120,7 +120,7 @@ class _ClangCStds(CompilerMixinBase):
_C18_VERSION = '>=8.0.0'
_C2X_VERSION = '>=9.0.0'
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
c_stds = ['c89', 'c99', 'c11']
g_stds = ['gnu89', 'gnu99', 'gnu11']
@ -154,7 +154,7 @@ class ClangCCompiler(_ClangCStds, ClangCompiler, CCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
if self.info.is_windows() or self.info.is_cygwin():
opts.update({
@ -235,7 +235,7 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c90', 'c99', 'c11', 'gnu90', 'gnu99', 'gnu11']
@ -273,7 +273,7 @@ class GnuCCompiler(GnuCompiler, CCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
c_stds = ['c89', 'c99', 'c11']
g_stds = ['gnu89', 'gnu99', 'gnu11']
@ -348,7 +348,7 @@ class ElbrusCCompiler(ElbrusCompiler, CCompiler):
info, exe_wrapper, linker=linker, full_version=full_version)
ElbrusCompiler.__init__(self)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
stds = ['c89', 'c9x', 'c99', 'gnu89', 'gnu9x', 'gnu99']
stds += ['iso9899:1990', 'iso9899:199409', 'iso9899:1999']
@ -391,7 +391,7 @@ class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
c_stds = ['c89', 'c99']
g_stds = ['gnu89', 'gnu99']
@ -412,7 +412,7 @@ class VisualStudioLikeCCompilerMixin(CompilerMixinBase):
"""Shared methods that apply to MSVC-like C compilers."""
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
opts.update({
OptionKey('winlibs', machine=self.for_machine, lang=self.language): coredata.UserArrayOption(
@ -447,7 +447,7 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi
full_version=full_version)
MSVCCompiler.__init__(self, target)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
c_stds = ['c89', 'c99']
# Need to have these to be compatible with projects
@ -513,7 +513,7 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
full_version=full_version)
IntelVisualStudioLikeCompiler.__init__(self, target)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c89', 'c99', 'c11']
@ -541,7 +541,7 @@ class ArmCCompiler(ArmCompiler, CCompiler):
full_version=full_version)
ArmCompiler.__init__(self)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c89', 'c99', 'c11']
@ -570,7 +570,7 @@ class CcrxCCompiler(CcrxCompiler, CCompiler):
def get_always_args(self) -> T.List[str]:
return ['-nologo']
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c89', 'c99']
@ -617,7 +617,7 @@ class Xc16CCompiler(Xc16Compiler, CCompiler):
info, exe_wrapper, linker=linker, full_version=full_version)
Xc16Compiler.__init__(self)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c89', 'c99', 'gnu89', 'gnu99']
@ -662,7 +662,7 @@ class CompCertCCompiler(CompCertCompiler, CCompiler):
info, exe_wrapper, linker=linker, full_version=full_version)
CompCertCompiler.__init__(self)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c89', 'c99']
@ -699,7 +699,7 @@ class TICCompiler(TICompiler, CCompiler):
def get_always_args(self) -> T.List[str]:
return []
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c89', 'c99', 'c11']

@ -32,7 +32,7 @@ from ..arglist import CompilerArgs
if T.TYPE_CHECKING:
from ..build import BuildTarget
from ..coredata import KeyedOptionDictType
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..envconfig import MachineInfo
from ..environment import Environment
from ..linkers import DynamicLinker, RSPFileSyntax
@ -618,7 +618,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
"""
return []
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
return {}
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:

@ -41,7 +41,7 @@ from .mixins.pgi import PGICompiler
from .mixins.emscripten import EmscriptenMixin
if T.TYPE_CHECKING:
from ..coredata import KeyedOptionDictType
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..dependencies import Dependency
from ..envconfig import MachineInfo
from ..environment import Environment
@ -168,7 +168,7 @@ class CPPCompiler(CLikeCompiler, Compiler):
raise MesonException(f'C++ Compiler does not support -std={cpp_std}')
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts.update({
@ -196,7 +196,7 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
key = OptionKey('key', machine=self.for_machine, lang=self.language)
opts.update({
@ -316,7 +316,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts.update({
@ -362,7 +362,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts = CPPCompiler.get_options(self)
opts.update({
@ -465,7 +465,7 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler):
info, exe_wrapper, linker=linker, full_version=full_version)
ElbrusCompiler.__init__(self)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
cpp_stds = ['none', 'c++98', 'gnu++98']
@ -542,7 +542,7 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
# Every Unix compiler under the sun seems to accept -std=c++03,
# with the exception of ICC. Instead of preventing the user from
@ -618,7 +618,7 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
key = OptionKey('winlibs', machine=self.for_machine, lang=self.language)
return T.cast('T.List[str]', options[key].value[:])
def _get_options_impl(self, opts: 'KeyedOptionDictType', cpp_stds: T.List[str]) -> 'KeyedOptionDictType':
def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List[str]) -> 'MutableKeyedOptionDictType':
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts.update({
key.evolve('eh'): coredata.UserComboOption(
@ -705,7 +705,7 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi
info, exe_wrapper, linker=linker, full_version=full_version)
MSVCCompiler.__init__(self, target)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
cpp_stds = ['none', 'c++11', 'vc++11']
# Visual Studio 2015 and later
if version_compare(self.version, '>=19'):
@ -747,7 +747,7 @@ class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, Cl
info, exe_wrapper, linker=linker, full_version=full_version)
ClangClCompiler.__init__(self, target)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
cpp_stds = ['none', 'c++11', 'vc++11', 'c++14', 'vc++14', 'c++17', 'vc++17', 'c++latest']
return self._get_options_impl(super().get_options(), cpp_stds)
@ -763,7 +763,7 @@ class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLike
info, exe_wrapper, linker=linker, full_version=full_version)
IntelVisualStudioLikeCompiler.__init__(self, target)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
# This has only been tested with version 19.0,
cpp_stds = ['none', 'c++11', 'vc++11', 'c++14', 'vc++14', 'c++17', 'vc++17', 'c++latest']
return self._get_options_impl(super().get_options(), cpp_stds)
@ -782,7 +782,7 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler):
info, exe_wrapper, linker=linker, full_version=full_version)
ArmCompiler.__init__(self)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c++03', 'c++11']
@ -842,7 +842,7 @@ class TICPPCompiler(TICompiler, CPPCompiler):
info, exe_wrapper, linker=linker, full_version=full_version)
TICompiler.__init__(self)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'c++03']

@ -28,7 +28,7 @@ from .compilers import (Compiler, cuda_buildtype_args, cuda_optimization_args,
if T.TYPE_CHECKING:
from ..build import BuildTarget
from ..coredata import KeyedOptionDictType
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..dependencies import Dependency
from ..environment import Environment # noqa: F401
from ..envconfig import MachineInfo
@ -612,7 +612,7 @@ class CudaCompiler(Compiler):
}}'''
return self.compiles(t.format_map(fargs), env, extra_args=extra_args, dependencies=dependencies)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
std_key = OptionKey('std', machine=self.for_machine, lang=self.language)
ccbindir_key = OptionKey('ccbindir', machine=self.for_machine, lang=self.language)

@ -10,7 +10,7 @@ from ..mesonlib import EnvironmentException, OptionKey
from .compilers import Compiler
if T.TYPE_CHECKING:
from ..coredata import KeyedOptionDictType
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..environment import Environment
@ -61,7 +61,7 @@ class CythonCompiler(Compiler):
return new
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
opts.update({
OptionKey('version', machine=self.for_machine, lang=self.language): coredata.UserComboOption(

@ -36,7 +36,7 @@ from mesonbuild.mesonlib import (
)
if T.TYPE_CHECKING:
from ..coredata import KeyedOptionDictType
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..dependencies import Dependency
from ..envconfig import MachineInfo
from ..environment import Environment
@ -152,7 +152,7 @@ class FortranCompiler(CLikeCompiler, Compiler):
def has_multi_link_arguments(self, args: T.List[str], env: 'Environment') -> T.Tuple[bool, bool]:
return self._has_multi_link_arguments(args, env, 'stop; end program')
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts.update({
@ -182,7 +182,7 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic', '-fimplicit-none']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = FortranCompiler.get_options(self)
fortran_stds = ['legacy', 'f95', 'f2003']
if version_compare(self.version, '>=4.4.0'):
@ -244,7 +244,7 @@ class ElbrusFortranCompiler(ElbrusCompiler, FortranCompiler):
info, exe_wrapper, linker=linker, full_version=full_version)
ElbrusCompiler.__init__(self)
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = FortranCompiler.get_options(self)
fortran_stds = ['f95', 'f2003', 'f2008', 'gnu', 'legacy', 'f2008ts']
key = OptionKey('std', machine=self.for_machine, lang=self.language)
@ -326,7 +326,7 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
'2': default_warn_args + ['-warn', 'unused'],
'3': ['-warn', 'all']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = FortranCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018']
@ -373,7 +373,7 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
'2': default_warn_args + ['/warn:unused'],
'3': ['/warn:all']}
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = FortranCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts[key].choices = ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018']

@ -68,7 +68,7 @@ class EmscriptenMixin(Compiler):
args.extend(['-s', f'PTHREAD_POOL_SIZE={count}'])
return args
def get_options(self) -> 'coredata.KeyedOptionDictType':
def get_options(self) -> 'coredata.MutableKeyedOptionDictType':
opts = super().get_options()
key = OptionKey('thread_count', machine=self.for_machine, lang=self.language)
opts.update({

@ -85,7 +85,7 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'coredata.KeyedOptionDictType':
def get_options(self) -> 'coredata.MutableKeyedOptionDictType':
opts = super().get_options()
opts.update({
OptionKey('std', machine=self.for_machine, lang='c'): coredata.UserComboOption(

@ -85,7 +85,7 @@ class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'coredata.KeyedOptionDictType':
def get_options(self) -> 'coredata.MutableKeyedOptionDictType':
opts = super().get_options()
opts.update({
OptionKey('std', machine=self.for_machine, lang='cpp'): coredata.UserComboOption(

@ -24,7 +24,7 @@ from ..mesonlib import (
from .compilers import Compiler, rust_buildtype_args, clike_debug_args
if T.TYPE_CHECKING:
from ..coredata import KeyedOptionDictType
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..envconfig import MachineInfo
from ..environment import Environment # noqa: F401
from ..linkers import DynamicLinker
@ -143,7 +143,7 @@ class RustCompiler(Compiler):
# C compiler for dynamic linking, as such we invoke the C compiler's
# use_linker_args method instead.
def get_options(self) -> 'KeyedOptionDictType':
def get_options(self) -> 'MutableKeyedOptionDictType':
key = OptionKey('std', machine=self.for_machine, lang=self.language)
return {
key: coredata.UserComboOption(

@ -41,7 +41,8 @@ if T.TYPE_CHECKING:
from .cmake.traceparser import CMakeCacheEntry
OptionDictType = T.Union[T.Dict[str, 'UserOption[T.Any]'], OptionOverrideProxy]
KeyedOptionDictType = T.Union[T.Dict['OptionKey', 'UserOption[T.Any]'], OptionOverrideProxy]
MutableKeyedOptionDictType = T.Dict['OptionKey', 'UserOption[T.Any]']
KeyedOptionDictType = T.Union[MutableKeyedOptionDictType, OptionOverrideProxy]
CompilerCheckCacheKey = T.Tuple[T.Tuple[str, ...], str, FileOrString, T.Tuple[str, ...], str]
# typeshed
@ -441,7 +442,7 @@ class CoreData:
self.meson_command = meson_command
self.target_guids = {}
self.version = version
self.options: 'KeyedOptionDictType' = {}
self.options: 'MutableKeyedOptionDictType' = {}
self.cross_files = self.__load_config_files(options, scratch_dir, 'cross')
self.compilers = PerMachine(OrderedDict(), OrderedDict()) # type: PerMachine[T.Dict[str, Compiler]]
@ -589,7 +590,7 @@ class CoreData:
self.add_builtin_option(self.options, key.evolve(subproject=subproject, machine=for_machine), opt)
@staticmethod
def add_builtin_option(opts_map: 'KeyedOptionDictType', key: OptionKey,
def add_builtin_option(opts_map: 'MutableKeyedOptionDictType', key: OptionKey,
opt: 'BuiltinOption') -> None:
if key.subproject:
if opt.yielding:
@ -748,7 +749,7 @@ class CoreData:
def get_external_link_args(self, for_machine: MachineChoice, lang: str) -> T.Union[str, T.List[str]]:
return self.options[OptionKey('link_args', machine=for_machine, lang=lang)].value
def update_project_options(self, options: 'KeyedOptionDictType') -> None:
def update_project_options(self, options: 'MutableKeyedOptionDictType') -> None:
for key, value in options.items():
if not key.is_project():
continue
@ -851,7 +852,7 @@ class CoreData:
self.set_options(options, subproject=subproject)
def add_compiler_options(self, options: 'KeyedOptionDictType', lang: str, for_machine: MachineChoice,
def add_compiler_options(self, options: 'MutableKeyedOptionDictType', lang: str, for_machine: MachineChoice,
env: 'Environment') -> None:
for k, o in options.items():
value = env.options.get(k)
@ -1184,7 +1185,7 @@ class BuiltinOption(T.Generic[_T, _U]):
# Update `docs/markdown/Builtin-options.md` after changing the options below
# Also update mesonlib._BUILTIN_NAMES. See the comment there for why this is required.
BUILTIN_DIR_OPTIONS: 'KeyedOptionDictType' = OrderedDict([
BUILTIN_DIR_OPTIONS: 'MutableKeyedOptionDictType' = OrderedDict([
(OptionKey('prefix'), BuiltinOption(UserStringOption, 'Installation prefix', default_prefix())),
(OptionKey('bindir'), BuiltinOption(UserStringOption, 'Executable directory', 'bin')),
(OptionKey('datadir'), BuiltinOption(UserStringOption, 'Data file directory', 'share')),
@ -1200,7 +1201,7 @@ BUILTIN_DIR_OPTIONS: 'KeyedOptionDictType' = OrderedDict([
(OptionKey('sysconfdir'), BuiltinOption(UserStringOption, 'Sysconf data directory', 'etc')),
])
BUILTIN_CORE_OPTIONS: 'KeyedOptionDictType' = OrderedDict([
BUILTIN_CORE_OPTIONS: 'MutableKeyedOptionDictType' = OrderedDict([
(OptionKey('auto_features'), BuiltinOption(UserFeatureOption, "Override value of all 'auto' features", 'auto')),
(OptionKey('backend'), BuiltinOption(UserComboOption, 'Backend to use', 'ninja', choices=backendlist)),
(OptionKey('buildtype'), BuiltinOption(UserComboOption, 'Build type to use', 'debug',
@ -1232,7 +1233,7 @@ BUILTIN_CORE_OPTIONS: 'KeyedOptionDictType' = OrderedDict([
BUILTIN_OPTIONS = OrderedDict(chain(BUILTIN_DIR_OPTIONS.items(), BUILTIN_CORE_OPTIONS.items()))
BUILTIN_OPTIONS_PER_MACHINE: 'KeyedOptionDictType' = OrderedDict([
BUILTIN_OPTIONS_PER_MACHINE: 'MutableKeyedOptionDictType' = OrderedDict([
(OptionKey('pkg_config_path'), BuiltinOption(UserArrayOption, 'List of additional paths for pkg-config to search', [])),
(OptionKey('cmake_prefix_path'), BuiltinOption(UserArrayOption, 'List of additional prefixes for cmake to search', [])),
])

@ -1938,8 +1938,7 @@ def generate_list(func: T.Callable[..., T.Generator[_T, None, None]]) -> T.Calla
return wrapper
class OptionOverrideProxy(collections.abc.MutableMapping):
class OptionOverrideProxy(collections.abc.Mapping):
'''Mimic an option list but transparently override selected option
values.
'''
@ -1947,13 +1946,11 @@ class OptionOverrideProxy(collections.abc.MutableMapping):
# TODO: the typing here could be made more explicit using a TypeDict from
# python 3.8 or typing_extensions
def __init__(self, overrides: T.Dict['OptionKey', T.Any], *options: 'KeyedOptionDictType'):
self.overrides = overrides.copy()
self.options: T.Dict['OptionKey', UserOption] = {}
for o in options:
self.options.update(o)
def __init__(self, overrides: T.Dict['OptionKey', T.Any], options: 'KeyedOptionDictType'):
self.overrides = overrides
self.options = options
def __getitem__(self, key: 'OptionKey') -> T.Union['UserOption']:
def __getitem__(self, key: 'OptionKey') -> 'UserOption':
if key in self.options:
opt = self.options[key]
if key in self.overrides:
@ -1962,20 +1959,18 @@ class OptionOverrideProxy(collections.abc.MutableMapping):
return opt
raise KeyError('Option not found', key)
def __setitem__(self, key: 'OptionKey', value: T.Union['UserOption']) -> None:
self.overrides[key] = value.value
def __delitem__(self, key: 'OptionKey') -> None:
del self.overrides[key]
def __iter__(self) -> T.Iterator['OptionKey']:
return iter(self.options)
def __len__(self) -> int:
return len(self.options)
def copy(self) -> 'OptionOverrideProxy':
return OptionOverrideProxy(self.overrides.copy(), self.options.copy())
def __eq__(self, other: object) -> bool:
if not isinstance(other, OptionOverrideProxy):
return NotImplemented
t1 = (self.overrides, self.options)
t2 = (other.overrides, other.options)
return t1 == t2
class OptionType(enum.IntEnum):

@ -266,9 +266,9 @@ def list_buildoptions(coredata: cdata.CoreData, subprojects: T.Optional[T.List[s
test_option_names = {OptionKey('errorlogs'),
OptionKey('stdsplit')}
dir_options: 'cdata.KeyedOptionDictType' = {}
test_options: 'cdata.KeyedOptionDictType' = {}
core_options: 'cdata.KeyedOptionDictType' = {}
dir_options: 'cdata.MutableKeyedOptionDictType' = {}
test_options: 'cdata.MutableKeyedOptionDictType' = {}
core_options: 'cdata.MutableKeyedOptionDictType' = {}
for k, v in coredata.options.items():
if k in dir_option_names:
dir_options[k] = v

@ -52,7 +52,7 @@ optname_regex = re.compile('[^a-zA-Z0-9_-]')
class OptionInterpreter:
def __init__(self, subproject: 'SubProject') -> None:
self.options: 'coredata.KeyedOptionDictType' = {}
self.options: 'coredata.MutableKeyedOptionDictType' = {}
self.subproject = subproject
self.option_types = {'string': self.string_parser,
'boolean': self.boolean_parser,

Loading…
Cancel
Save