summaryrefslogtreecommitdiff
path: root/buildstream/_options
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2017-11-23 08:11:13 +0100
committerJürg Billeter <j@bitron.ch>2018-02-08 14:04:04 +0100
commitb5f101a2ac19ff4e64de17a18230e351137c1884 (patch)
tree27606cf67c26b26523b1d1dbb8117f0e53725537 /buildstream/_options
parenta83c94b74e0f65aa3cee328bc37be57b9ae7a5c3 (diff)
downloadbuildstream-b5f101a2ac19ff4e64de17a18230e351137c1884.tar.gz
_options: Support transform function for variable substitution
Diffstat (limited to 'buildstream/_options')
-rw-r--r--buildstream/_options/option.py3
-rw-r--r--buildstream/_options/optionbool.py7
-rw-r--r--buildstream/_options/optionenum.py4
-rw-r--r--buildstream/_options/optionflags.py4
-rw-r--r--buildstream/_options/optionpool.py4
5 files changed, 15 insertions, 7 deletions
diff --git a/buildstream/_options/option.py b/buildstream/_options/option.py
index 357eb98d3..05c56e582 100644
--- a/buildstream/_options/option.py
+++ b/buildstream/_options/option.py
@@ -71,8 +71,9 @@ class Option():
# Args:
# node (Mapping): The YAML loaded key/value dictionary
# to load the value from
+ # transform (callbable): Transform function for variable substitution
#
- def load_value(self, node):
+ def load_value(self, node, *, transform=None):
pass # pragma: nocover
# set_value()
diff --git a/buildstream/_options/optionbool.py b/buildstream/_options/optionbool.py
index db01340e4..e0e1474d9 100644
--- a/buildstream/_options/optionbool.py
+++ b/buildstream/_options/optionbool.py
@@ -37,8 +37,11 @@ class OptionBool(Option):
_yaml.node_validate(node, OPTION_SYMBOLS + ['default'])
self.value = _yaml.node_get(node, bool, 'default')
- def load_value(self, node):
- self.value = _yaml.node_get(node, bool, self.name)
+ def load_value(self, node, *, transform=None):
+ if transform:
+ self.set_value(transform(_yaml.node_get(node, str, self.name)))
+ else:
+ self.value = _yaml.node_get(node, bool, self.name)
def set_value(self, value):
if value == 'True' or value == 'true':
diff --git a/buildstream/_options/optionenum.py b/buildstream/_options/optionenum.py
index 2ba8552d7..bc21bd81c 100644
--- a/buildstream/_options/optionenum.py
+++ b/buildstream/_options/optionenum.py
@@ -49,8 +49,10 @@ class OptionEnum(Option):
# Allow subclass to define the default value
self.value = self.load_default_value(node)
- def load_value(self, node):
+ def load_value(self, node, *, transform=None):
self.value = _yaml.node_get(node, str, self.name)
+ if transform:
+ self.value = transform(self.value)
self.validate(self.value, _yaml.node_get_provenance(node, self.name))
def set_value(self, value):
diff --git a/buildstream/_options/optionflags.py b/buildstream/_options/optionflags.py
index 49ec70d85..84ecc1360 100644
--- a/buildstream/_options/optionflags.py
+++ b/buildstream/_options/optionflags.py
@@ -50,8 +50,10 @@ class OptionFlags(Option):
self.value = _yaml.node_get(node, list, 'default', default_value=[])
self.validate(self.value, _yaml.node_get_provenance(node, 'default'))
- def load_value(self, node):
+ def load_value(self, node, *, transform=None):
self.value = _yaml.node_get(node, list, self.name)
+ if transform:
+ self.value = [transform(x) for x in self.value]
self.value = sorted(self.value)
self.validate(self.value, _yaml.node_get_provenance(node, self.name))
diff --git a/buildstream/_options/optionpool.py b/buildstream/_options/optionpool.py
index f38682aec..9d7228f27 100644
--- a/buildstream/_options/optionpool.py
+++ b/buildstream/_options/optionpool.py
@@ -82,7 +82,7 @@ class OptionPool():
# Args:
# node (dict): The loaded YAML options
#
- def load_yaml_values(self, node):
+ def load_yaml_values(self, node, *, transform=None):
for option_name, _ in _yaml.node_items(node):
try:
option = self.options[option_name]
@@ -90,7 +90,7 @@ class OptionPool():
p = _yaml.node_get_provenance(node, option_name)
raise LoadError(LoadErrorReason.INVALID_DATA,
"{}: Unknown option '{}' specified".format(p, option_name))
- option.load_value(node)
+ option.load_value(node, transform=transform)
# load_cli_values()
#