aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-10-12 21:45:24 -0400
committerXavier Claessens <xclaesse@gmail.com>2022-03-22 17:20:48 -0400
commit06d12064d0ccb1477fadf1d62492a493fb2fb947 (patch)
treea405725996ecfcad94fdd242ebc6da7b246497ae
parent86aaac8e4229608b25508027267f49624a9a8cb5 (diff)
downloadmeson-06d12064d0ccb1477fadf1d62492a493fb2fb947.zip
meson-06d12064d0ccb1477fadf1d62492a493fb2fb947.tar.gz
meson-06d12064d0ccb1477fadf1d62492a493fb2fb947.tar.bz2
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.
-rw-r--r--mesonbuild/compilers/c.py32
-rw-r--r--mesonbuild/compilers/compilers.py4
-rw-r--r--mesonbuild/compilers/cpp.py26
-rw-r--r--mesonbuild/compilers/cuda.py4
-rw-r--r--mesonbuild/compilers/cython.py4
-rw-r--r--mesonbuild/compilers/fortran.py12
-rw-r--r--mesonbuild/compilers/mixins/emscripten.py2
-rw-r--r--mesonbuild/compilers/objc.py2
-rw-r--r--mesonbuild/compilers/objcpp.py2
-rw-r--r--mesonbuild/compilers/rust.py4
-rw-r--r--mesonbuild/coredata.py17
-rw-r--r--mesonbuild/mesonlib/universal.py27
-rw-r--r--mesonbuild/mintro.py6
-rw-r--r--mesonbuild/optinterpreter.py2
14 files changed, 70 insertions, 74 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 610473d..513a8e2 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.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']
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 7c0a2ec..17c9f36 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -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]:
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index e6410c8..fe09b6b 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -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']
diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py
index fc9d52a..78a58c7 100644
--- a/mesonbuild/compilers/cuda.py
+++ b/mesonbuild/compilers/cuda.py
@@ -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)
diff --git a/mesonbuild/compilers/cython.py b/mesonbuild/compilers/cython.py
index 34ddff1..ac5c934 100644
--- a/mesonbuild/compilers/cython.py
+++ b/mesonbuild/compilers/cython.py
@@ -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(
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index a5d4b6a..0a0c3ec 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -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']
diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py
index cac28b9..0796d6f 100644
--- a/mesonbuild/compilers/mixins/emscripten.py
+++ b/mesonbuild/compilers/mixins/emscripten.py
@@ -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({
diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py
index 7afa44f..22a2012 100644
--- a/mesonbuild/compilers/objc.py
+++ b/mesonbuild/compilers/objc.py
@@ -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(
diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py
index 7ee2077..3d2ed25 100644
--- a/mesonbuild/compilers/objcpp.py
+++ b/mesonbuild/compilers/objcpp.py
@@ -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(
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index 399570d..a460b78 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -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(
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index d985844..f7d5ec0 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -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', [])),
])
diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py
index d4f51c1..f0253b2 100644
--- a/mesonbuild/mesonlib/universal.py
+++ b/mesonbuild/mesonlib/universal.py
@@ -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):
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 7b4f8aa..223c31d 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -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
diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py
index 46a4445..eeb7cf8 100644
--- a/mesonbuild/optinterpreter.py
+++ b/mesonbuild/optinterpreter.py
@@ -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,