summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2018-09-10 15:13:11 +0100
committerTiago Gomes <tiago.gomes@codethink.co.uk>2018-09-10 15:57:41 +0100
commitaf74a3f8fb28413b61208078e78655072cd14389 (patch)
treebb818945eb6f19456f41299a2695ea0185504624
parenta37bc6ce4212972534a7ef16c2e81f6c464a2a0c (diff)
downloadbuildstream-af74a3f8fb28413b61208078e78655072cd14389.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 55c5d6bbf..6fe4f4847 100644
--- a/buildstream/_exceptions.py
+++ b/buildstream/_exceptions.py
@@ -220,6 +220,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 6c01c0dd4..553973d0c 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -2283,7 +2283,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:
@@ -2296,6 +2297,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