From edc1f2020d78a8e0ac5b107f153adac0ed7332d3 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Sat, 14 Oct 2017 18:14:41 +0900 Subject: _options: Options can now be exported to variables in string form This patch adds a `variable` attribute to all option definitions, which if specified, can be used to override and declare variable at the project.conf level. A new `get_value()` method was added allowing implementations to create a string for the value of the option - main subclasses updated to support the string conversion with `get_value()` --- buildstream/_options/option.py | 17 ++++++++++++++++- buildstream/_options/optionbool.py | 6 ++++++ buildstream/_options/optionenum.py | 3 +++ buildstream/_options/optionflags.py | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/buildstream/_options/option.py b/buildstream/_options/option.py index 3accddccb..357eb98d3 100644 --- a/buildstream/_options/option.py +++ b/buildstream/_options/option.py @@ -25,7 +25,8 @@ from .. import _yaml # OPTION_SYMBOLS = [ 'type', - 'description' + 'description', + 'variable' ] @@ -46,6 +47,7 @@ class Option(): def __init__(self, name, definition, pool): self.name = name self.description = None + self.variable = None self.value = None self.pool = pool self.load(definition) @@ -60,6 +62,7 @@ class Option(): # the option def load(self, node): self.description = _yaml.node_get(node, str, 'description') + self.variable = _yaml.node_get(node, str, 'variable', default_value='') or None # load_value() # @@ -83,6 +86,18 @@ class Option(): def set_value(self, value): pass # pragma: nocover + # get_value() + # + # Gets the value of an option in string form, this + # is for the purpose of exporting option values to + # variables which must be in string form. + # + # Returns: + # (str): The value in string form + # + def get_value(self): + pass # pragma: nocover + # resolve() # # Called on each option once, after all configuration diff --git a/buildstream/_options/optionbool.py b/buildstream/_options/optionbool.py index d125e2d10..a4619504d 100644 --- a/buildstream/_options/optionbool.py +++ b/buildstream/_options/optionbool.py @@ -48,3 +48,9 @@ class OptionBool(Option): else: raise LoadError(LoadErrorReason.INVALID_DATA, "Invalid value for boolean option {}: {}".format(self.name, value)) + + def get_value(self): + if self.value: + return "1" + else: + return "0" diff --git a/buildstream/_options/optionenum.py b/buildstream/_options/optionenum.py index 912c50ec3..5c4db7ddf 100644 --- a/buildstream/_options/optionenum.py +++ b/buildstream/_options/optionenum.py @@ -57,6 +57,9 @@ class OptionEnum(Option): self.validate(value) self.value = value + def get_value(self): + return self.value + def validate(self, value, provenance=None): if value not in self.values: prefix = "" diff --git a/buildstream/_options/optionflags.py b/buildstream/_options/optionflags.py index 7abb85786..25d2d1c59 100644 --- a/buildstream/_options/optionflags.py +++ b/buildstream/_options/optionflags.py @@ -65,6 +65,9 @@ class OptionFlags(Option): self.validate(list_value) self.value = sorted(list_value) + def get_value(self): + return ",".join(self.value) + def validate(self, value, provenance=None): for flag in value: if flag not in self.values: -- cgit v1.2.1