aboutsummaryrefslogtreecommitdiff
path: root/mesonlib.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-10-04 02:18:26 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2015-10-04 02:18:26 +0300
commit4dff3f9fb3efb1f9c32484cbdc2f0668de782913 (patch)
tree8c563a58788d285e0d9cdfab1d240cdf226287c3 /mesonlib.py
parentc02009a6989710714cc0e2becc9cad11d4b0381d (diff)
downloadmeson-4dff3f9fb3efb1f9c32484cbdc2f0668de782913.zip
meson-4dff3f9fb3efb1f9c32484cbdc2f0668de782913.tar.gz
meson-4dff3f9fb3efb1f9c32484cbdc2f0668de782913.tar.bz2
Refactored option classes to mesonlib.
Diffstat (limited to 'mesonlib.py')
-rw-r--r--mesonlib.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/mesonlib.py b/mesonlib.py
index d7c40f4..0b200ac 100644
--- a/mesonlib.py
+++ b/mesonlib.py
@@ -255,3 +255,55 @@ 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 set_value(self, newvalue):
+ if not isinstance(newvalue, bool):
+ raise MesonException('Value "%s" for boolean option "%s" is not a boolean.' % (str(newvalue), self.name))
+ self.value = 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