summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2018-09-10 15:13:11 +0100
committerTiago Gomes <tiago.avv@gmail.com>2018-09-14 15:43:47 +0000
commit5e3587cd71dbcd82c6f45b297d03022c0156dcb6 (patch)
treedb866139f9c9a4b635554ac7ad714c90348d5b14
parent06001fefa9d1112e4aa440513cd118cd7e64bc07 (diff)
downloadbuildstream-5e3587cd71dbcd82c6f45b297d03022c0156dcb6.tar.gz
element: validate configuration variables
Ensure that protected variables are not being redefined by the user.
-rw-r--r--buildstream/_exceptions.py3
-rw-r--r--buildstream/element.py10
2 files changed, 12 insertions, 1 deletions
diff --git a/buildstream/_exceptions.py b/buildstream/_exceptions.py
index a4e3ce69b..fa595852b 100644
--- a/buildstream/_exceptions.py
+++ b/buildstream/_exceptions.py
@@ -219,6 +219,9 @@ class LoadErrorReason(Enum):
# A recursive variable has been encountered
RECURSIVE_VARIABLE = 22
+ # An attempt so set the value of a protected variable
+ PROTECTED_VARIABLE_REDEFINED = 23
+
# LoadError
#
diff --git a/buildstream/element.py b/buildstream/element.py
index 4f7fc0564..6b0a728e6 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -2166,7 +2166,8 @@ class Element(Plugin):
# substituting command strings to be run in the sandbox
#
def __extract_variables(self, meta):
- default_vars = _yaml.node_get(self.__defaults, Mapping, 'variables', default_value={})
+ default_vars = _yaml.node_get(self.__defaults, Mapping, 'variables',
+ default_value={})
project = self._get_project()
if self.__is_junction:
@@ -2179,6 +2180,13 @@ class Element(Plugin):
_yaml.composite(variables, meta.variables)
_yaml.node_final_assertions(variables)
+ for var in ('project-name', 'element-name', 'max-jobs'):
+ provenance = _yaml.node_get_provenance(variables, var)
+ if provenance and provenance.filename != '':
+ raise LoadError(LoadErrorReason.PROTECTED_VARIABLE_REDEFINED,
+ "{}: invalid redefinition of protected variable '{}'"
+ .format(provenance, var))
+
return variables
# This will resolve the final configuration to be handed