aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-10-27 10:19:42 -0400
committerXavier Claessens <xclaesse@gmail.com>2021-10-27 15:29:44 -0400
commit8eaa2be5d9f6b8cd19ee6c0bcd737b4ba3a0afc5 (patch)
treed37bf671e1aba2edd891f0b7f68c1857a681924c /mesonbuild/mesonlib
parent6ed13326034f5616b4b886d3831a7168841460c4 (diff)
downloadmeson-8eaa2be5d9f6b8cd19ee6c0bcd737b4ba3a0afc5.zip
meson-8eaa2be5d9f6b8cd19ee6c0bcd737b4ba3a0afc5.tar.gz
meson-8eaa2be5d9f6b8cd19ee6c0bcd737b4ba3a0afc5.tar.bz2
Fix crash when getting cuda options
We could have an OptionOverrideProxy of an OptionOverrideProxy, recursively. This fix is a minimal subset of the refactoring I did in https://github.com/mesonbuild/meson/pull/9394. Instead of faking UserOption we can just do a shallow copy of one and set a new value on it. Fixes: #9448
Diffstat (limited to 'mesonbuild/mesonlib')
-rw-r--r--mesonbuild/mesonlib/universal.py19
1 files changed, 5 insertions, 14 deletions
diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py
index 831cb2a..d93133e 100644
--- a/mesonbuild/mesonlib/universal.py
+++ b/mesonbuild/mesonlib/universal.py
@@ -28,6 +28,7 @@ from tempfile import TemporaryDirectory
import typing as T
import uuid
import textwrap
+import copy
from mesonbuild import mlog
@@ -61,7 +62,6 @@ __all__ = [
'OptionKey',
'dump_conf_header',
'OptionOverrideProxy',
- 'OptionProxy',
'OptionType',
'OrderedSet',
'PerMachine',
@@ -1918,16 +1918,6 @@ def run_once(func: T.Callable[..., _T]) -> T.Callable[..., _T]:
return wrapper
-class OptionProxy(T.Generic[_T]):
- def __init__(self, value: _T, choices: T.Optional[T.List[str]] = None):
- self.value = value
- self.choices = choices
-
- def set_value(self, v: _T) -> None:
- # XXX: should this be an error
- self.value = v
-
-
class OptionOverrideProxy(collections.abc.MutableMapping):
'''Mimic an option list but transparently override selected option
@@ -1943,15 +1933,16 @@ class OptionOverrideProxy(collections.abc.MutableMapping):
for o in options:
self.options.update(o)
- def __getitem__(self, key: 'OptionKey') -> T.Union['UserOption', OptionProxy]:
+ def __getitem__(self, key: 'OptionKey') -> T.Union['UserOption']:
if key in self.options:
opt = self.options[key]
if key in self.overrides:
- return OptionProxy(opt.validate_value(self.overrides[key]), getattr(opt, 'choices', None))
+ opt = copy.copy(opt)
+ opt.set_value(self.overrides[key])
return opt
raise KeyError('Option not found', key)
- def __setitem__(self, key: 'OptionKey', value: T.Union['UserOption', OptionProxy]) -> None:
+ def __setitem__(self, key: 'OptionKey', value: T.Union['UserOption']) -> None:
self.overrides[key] = value.value
def __delitem__(self, key: 'OptionKey') -> None: