summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-05 17:59:15 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-15 14:14:03 +0000
commit695eddc069c9803eca5d004e80ca7be7defdd20c (patch)
tree39869eda62d451bb188925f2947872a006e2128d
parent2b1c63b50b11293377e87df802f35489e5f86c12 (diff)
downloadbuildstream-695eddc069c9803eca5d004e80ca7be7defdd20c.tar.gz
_yaml: rework 'assert_symbol_names' to not require provenance
Now that we get scalar Nodes, it is easier to just give the node and extract the provenance as needed.
-rw-r--r--src/buildstream/_frontend/app.py2
-rw-r--r--src/buildstream/_options/option.py3
-rw-r--r--src/buildstream/_options/optionpool.py3
-rw-r--r--src/buildstream/_project.py4
-rw-r--r--src/buildstream/_yaml.pyx10
5 files changed, 11 insertions, 11 deletions
diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py
index cf4ac2b8d..53275d251 100644
--- a/src/buildstream/_frontend/app.py
+++ b/src/buildstream/_frontend/app.py
@@ -349,7 +349,7 @@ class App():
if project_name:
# If project name was specified, user interaction is not desired, just
# perform some validation and write the project.conf
- _yaml.assert_symbol_name(None, project_name, 'project name')
+ _yaml.assert_symbol_name(project_name, 'project name')
self._assert_format_version(format_version)
self._assert_element_path(element_path)
diff --git a/src/buildstream/_options/option.py b/src/buildstream/_options/option.py
index 8fe0cbad6..ae5d56beb 100644
--- a/src/buildstream/_options/option.py
+++ b/src/buildstream/_options/option.py
@@ -66,8 +66,7 @@ class Option():
# Assert valid symbol name for variable name
if self.variable is not None:
- p = _yaml.node_get_provenance(node, 'variable')
- _yaml.assert_symbol_name(p, self.variable, 'variable name')
+ _yaml.assert_symbol_name(self.variable, 'variable name', ref_node=node.get_node('variable'))
# load_value()
#
diff --git a/src/buildstream/_options/optionpool.py b/src/buildstream/_options/optionpool.py
index f695c0acf..cd4bfb6dc 100644
--- a/src/buildstream/_options/optionpool.py
+++ b/src/buildstream/_options/optionpool.py
@@ -68,8 +68,7 @@ class OptionPool():
for option_name, option_definition in options.items():
# Assert that the option name is a valid symbol
- p = _yaml.node_get_provenance(options, option_name)
- _yaml.assert_symbol_name(p, option_name, "option name", allow_dashes=False)
+ _yaml.assert_symbol_name(option_name, "option name", ref_node=option_definition, allow_dashes=False)
opt_type_name = option_definition.get_str('type')
try:
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index c78cfd878..45eae03f9 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -594,8 +594,8 @@ class Project():
self.name = self._project_conf.get_str('name')
# Validate that project name is a valid symbol name
- _yaml.assert_symbol_name(_yaml.node_get_provenance(pre_config_node, 'name'),
- self.name, "project name")
+ _yaml.assert_symbol_name(self.name, "project name",
+ ref_node=pre_config_node.get_node('name'))
self.element_path = os.path.join(
self.directory,
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index 2df6a7d1b..a84c05759 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -1219,9 +1219,9 @@ cdef Node _new_node_from_list(list inlist, Node ref_node):
# are required to be symbols.
#
# Args:
-# provenance (Provenance): The provenance of the loaded symbol, or None
# symbol_name (str): The loaded symbol name
# purpose (str): The purpose of the string, for an error message
+# ref_node (Node): The node of the loaded symbol, or None
# allow_dashes (bool): Whether dashes are allowed for this symbol
#
# Raises:
@@ -1230,7 +1230,7 @@ cdef Node _new_node_from_list(list inlist, Node ref_node):
# Note that dashes are generally preferred for variable names and
# usage in YAML, but things such as option names which will be
# evaluated with jinja2 cannot use dashes.
-def assert_symbol_name(ProvenanceInformation provenance, str symbol_name, str purpose, *, bint allow_dashes=True):
+def assert_symbol_name(str symbol_name, str purpose, *, Node ref_node=None, bint allow_dashes=True):
cdef str valid_chars = string.digits + string.ascii_letters + '_'
if allow_dashes:
valid_chars += '-'
@@ -1250,8 +1250,10 @@ def assert_symbol_name(ProvenanceInformation provenance, str symbol_name, str pu
detail += " or dashes"
message = "Invalid symbol name for {}: '{}'".format(purpose, symbol_name)
- if provenance is not None:
- message = "{}: {}".format(provenance, message)
+ if ref_node:
+ provenance = node_get_provenance(ref_node)
+ if provenance is not None:
+ message = "{}: {}".format(provenance, message)
raise LoadError(LoadErrorReason.INVALID_SYMBOL_NAME,
message, detail=detail)