summaryrefslogtreecommitdiff
path: root/mesonbuild/coredata.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-03-10 19:37:45 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2017-04-02 00:04:45 +0300
commite5a6283c4cf288fdfc9b43a92bf0ddd74dbf90f8 (patch)
treee3e320069b7665066336305759032b807b67a63c /mesonbuild/coredata.py
parentd2548e6e839b2058aae7f242db35d6836ccbeef7 (diff)
downloadmeson-e5a6283c4cf288fdfc9b43a92bf0ddd74dbf90f8.tar.gz
Add MVP implementation of overriding options.
Diffstat (limited to 'mesonbuild/coredata.py')
-rw-r--r--mesonbuild/coredata.py45
1 files changed, 39 insertions, 6 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 956221122..1d770e0ad 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -30,6 +30,12 @@ class UserOption:
def parse_string(self, valuestring):
return valuestring
+ # Check that the input is a valid value and return the
+ # "cleaned" or "native" version. For example the Boolean
+ # option could take the string "true" and return True.
+ def validate_value(self, value):
+ raise RuntimeError('Derived option class did not override validate_value.')
+
class UserStringOption(UserOption):
def __init__(self, name, description, value, choices=None):
super().__init__(name, description, choices)
@@ -43,6 +49,10 @@ class UserStringOption(UserOption):
self.validate(newvalue)
self.value = newvalue
+ def validate_value(self, value):
+ self.validate(value)
+ return value
+
class UserBooleanOption(UserOption):
def __init__(self, name, description, value):
super().__init__(name, description, [True, False])
@@ -70,6 +80,9 @@ class UserBooleanOption(UserOption):
def __bool__(self):
return self.value
+ def validate_value(self, value):
+ return self.tobool(value)
+
class UserComboOption(UserOption):
def __init__(self, name, description, choices, value):
super().__init__(name, description, choices)
@@ -86,22 +99,35 @@ class UserComboOption(UserOption):
raise MesonException('Value "%s" for combo option "%s" is not one of the choices. Possible choices are: %s.' % (newvalue, self.name, optionsstring))
self.value = newvalue
+ def validate_value(self, value):
+ if value not in self.choices:
+ raise MesonException('Value %s not one of accepted values.' % value)
+
class UserStringArrayOption(UserOption):
def __init__(self, name, description, value, **kwargs):
super().__init__(name, description, kwargs.get('choices', []))
self.set_value(value)
- def set_value(self, newvalue):
- if isinstance(newvalue, str):
- if not newvalue.startswith('['):
- raise MesonException('Valuestring does not define an array: ' + newvalue)
- newvalue = eval(newvalue, {}, {}) # Yes, it is unsafe.
+ def validate(self, value):
+ if isinstance(value, str):
+ if not value.startswith('['):
+ raise MesonException('Valuestring does not define an array: ' + value)
+ newvalue = eval(value, {}, {}) # Yes, it is unsafe.
+ else:
+ newvalue = value
if not isinstance(newvalue, list):
raise MesonException('"{0}" should be a string array, but it is not'.format(str(newvalue)))
for i in newvalue:
if not isinstance(i, str):
raise MesonException('String array element "{0}" is not a string.'.format(str(newvalue)))
- self.value = newvalue
+ return newvalue
+
+ def set_value(self, newvalue):
+ self.value = self.validate(newvalue)
+
+ def validate_value(self, value):
+ self.validate(value)
+ return value
# This class contains all data that must persist over multiple
# invocations of Meson. It is roughly the same thing as
@@ -203,6 +229,13 @@ class CoreData:
raise RuntimeError('Tried to set unknown builtin option %s.' % optname)
self.builtins[optname].set_value(value)
+ def validate_option_value(self, option_name, override_value):
+ for opts in (self.builtins, self.base_options, self.compiler_options, self.user_options):
+ if option_name in opts:
+ opt = opts[option_name]
+ return opt.validate_value(override_value)
+ raise MesonException('Tried to validate unknown option %s.' % option_name)
+
def load(filename):
load_fail_msg = 'Coredata file {!r} is corrupted. Try with a fresh build tree.'.format(filename)
try: