@ -28,6 +28,7 @@ from tempfile import TemporaryDirectory
import typing as T
import typing as T
import uuid
import uuid
import textwrap
import textwrap
import copy
from mesonbuild import mlog
from mesonbuild import mlog
@ -61,7 +62,6 @@ __all__ = [
' OptionKey ' ,
' OptionKey ' ,
' dump_conf_header ' ,
' dump_conf_header ' ,
' OptionOverrideProxy ' ,
' OptionOverrideProxy ' ,
' OptionProxy ' ,
' OptionType ' ,
' OptionType ' ,
' OrderedSet ' ,
' OrderedSet ' ,
' PerMachine ' ,
' PerMachine ' ,
@ -1919,16 +1919,6 @@ def run_once(func: T.Callable[..., _T]) -> T.Callable[..., _T]:
return wrapper
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 ) :
class OptionOverrideProxy ( collections . abc . MutableMapping ) :
''' Mimic an option list but transparently override selected option
''' Mimic an option list but transparently override selected option
@ -1944,15 +1934,16 @@ class OptionOverrideProxy(collections.abc.MutableMapping):
for o in options :
for o in options :
self . options . update ( o )
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 :
if key in self . options :
opt = self . options [ key ]
opt = self . options [ key ]
if key in self . overrides :
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
return opt
raise KeyError ( ' Option not found ' , key )
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
self . overrides [ key ] = value . value
def __delitem__ ( self , key : ' OptionKey ' ) - > None :
def __delitem__ ( self , key : ' OptionKey ' ) - > None :