aboutsummaryrefslogtreecommitdiff
path: root/mesonlib.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-10-15 22:20:45 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2015-10-15 22:20:45 +0300
commit172fa2f8ddac5a53ea6fa6632e0cfaeb53344b64 (patch)
tree9c0653bf0e7718f754051555d9e56cd4119280b1 /mesonlib.py
parentc5788548d225b1cf5561244e24da8a8cd6d7f488 (diff)
parent0d56955e9cda7993ef07894fb58bb90ba5b463e6 (diff)
downloadmeson-172fa2f8ddac5a53ea6fa6632e0cfaeb53344b64.zip
meson-172fa2f8ddac5a53ea6fa6632e0cfaeb53344b64.tar.gz
meson-172fa2f8ddac5a53ea6fa6632e0cfaeb53344b64.tar.bz2
Merge pull request #275 from mesonbuild/compileroptions
Compiler options
Diffstat (limited to 'mesonlib.py')
-rw-r--r--mesonlib.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/mesonlib.py b/mesonlib.py
index d7c40f4..0c7c308 100644
--- a/mesonlib.py
+++ b/mesonlib.py
@@ -255,3 +255,79 @@ def replace_if_different(dst, dst_tmp):
pass
os.replace(dst_tmp, dst)
+class UserOption:
+ def __init__(self, name, description):
+ super().__init__()
+ self.name = name
+ self.description = description
+
+ def parse_string(self, valuestring):
+ return valuestring
+
+class UserStringOption(UserOption):
+ def __init__(self, name, description, value):
+ super().__init__(name, description)
+ self.set_value(value)
+
+ def set_value(self, newvalue):
+ if not isinstance(newvalue, str):
+ raise MesonException('Value "%s" for string option "%s" is not a string.' % (str(newvalue), self.name))
+ self.value = newvalue
+
+class UserBooleanOption(UserOption):
+ def __init__(self, name, description, value):
+ super().__init__(name, description)
+ self.set_value(value)
+
+ def tobool(self, thing):
+ if isinstance(thing, bool):
+ return thing
+ if thing.lower() == 'true':
+ return True
+ if thing.lower() == 'false':
+ return False
+ raise MesonException('Value %s is not boolean (true or false).' % thing)
+
+ def set_value(self, newvalue):
+ self.value = self.tobool(newvalue)
+
+ def parse_string(self, valuestring):
+ if valuestring == 'false':
+ return False
+ if valuestring == 'true':
+ return True
+ raise MesonException('Value "%s" for boolean option "%s" is not a boolean.' % (valuestring, self.name))
+
+class UserComboOption(UserOption):
+ def __init__(self, name, description, choices, value):
+ super().__init__(name, description)
+ self.choices = choices
+ if not isinstance(self.choices, list):
+ raise MesonException('Combo choices must be an array.')
+ for i in self.choices:
+ if not isinstance(i, str):
+ raise MesonException('Combo choice elements must be strings.')
+ self.set_value(value)
+
+ def set_value(self, newvalue):
+ if newvalue not in self.choices:
+ optionsstring = ', '.join(['"%s"' % (item,) for item in self.choices])
+ 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
+
+class UserStringArrayOption(UserOption):
+ def __init__(self, name, description, value):
+ super().__init__(name, description)
+ 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.
+ if not isinstance(newvalue, list):
+ raise MesonException('String array value is not an array.')
+ for i in newvalue:
+ if not isinstance(i, str):
+ raise MesonException('String array element not a string.')
+ self.value = newvalue