summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-06-05 21:58:04 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-06-07 17:28:11 +0000
commita4b7eb30b67f49715a074f9b0aed53b3d9129b3e (patch)
tree73cac0c55b96a78892972cd7bae3a8849cd1c5e3
parent3659d48af434adbeda573fe7eb6dca8179139212 (diff)
downloadbuildstream-a4b7eb30b67f49715a074f9b0aed53b3d9129b3e.tar.gz
_loader/types: Use helper function for extract_depends_from_node
extract_depends_from_node has two different behaviors depending on whether it is calling itself or something else is calling it. Extracting the inner calls to a helper function helps speed up the code and makes it more understandable.
-rw-r--r--src/buildstream/_loader/types.pyx47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/buildstream/_loader/types.pyx b/src/buildstream/_loader/types.pyx
index 069d439a2..b54545dcd 100644
--- a/src/buildstream/_loader/types.pyx
+++ b/src/buildstream/_loader/types.pyx
@@ -122,7 +122,9 @@ cdef class Dependency:
self.junction, self.name = self.name.split(':')
-# extract_depends_from_node():
+# _extract_depends_from_node():
+#
+# Helper for extract_depends_from_node to get dependencies of a particular type
#
# Creates an array of Dependency objects from a given dict node 'node',
# allows both strings and dicts for expressing the dependency and
@@ -131,30 +133,20 @@ cdef class Dependency:
# After extracting depends, the symbol is deleted from the node
#
# Args:
-# node (dict): A YAML loaded dictionary
+# node (Node): A YAML loaded dictionary
+# key (str): the key on the Node corresponding to the dependency type
+# default_dep_type (str): type to give to the dependency
#
# Returns:
# (list): a list of Dependency objects
#
-def extract_depends_from_node(node, *, key=None):
- if key is None:
- build_depends = extract_depends_from_node(node, key=Symbol.BUILD_DEPENDS)
- runtime_depends = extract_depends_from_node(node, key=Symbol.RUNTIME_DEPENDS)
- depends = extract_depends_from_node(node, key=Symbol.DEPENDS)
- return build_depends + runtime_depends + depends
- elif key == Symbol.BUILD_DEPENDS:
- default_dep_type = Symbol.BUILD
- elif key == Symbol.RUNTIME_DEPENDS:
- default_dep_type = Symbol.RUNTIME
- elif key == Symbol.DEPENDS:
- default_dep_type = None
- else:
- assert False, "Unexpected value of key '{}'".format(key)
-
+cdef _extract_depends_from_node(node, key, default_dep_type):
depends = _yaml.node_get(node, list, key, None, [])
output_deps = []
for index, dep in enumerate(depends):
+ # FIXME: the provenance information would be obtainable from the Node directly if we stop
+ # stripping provenance and have proper nodes for str elements
dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[index])
dependency = Dependency(dep, dep_provenance, default_dep_type=default_dep_type)
output_deps.append(dependency)
@@ -163,3 +155,24 @@ def extract_depends_from_node(node, *, key=None):
_yaml.node_del(node, key, safe=True)
return output_deps
+
+
+# extract_depends_from_node():
+#
+# Creates an array of Dependency objects from a given dict node 'node',
+# allows both strings and dicts for expressing the dependency and
+# throws a comprehensive LoadError in the case that the node is malformed.
+#
+# After extracting depends, the symbol is deleted from the node
+#
+# Args:
+# node (Node): A YAML loaded dictionary
+#
+# Returns:
+# (list): a list of Dependency objects
+#
+def extract_depends_from_node(node):
+ build_depends = _extract_depends_from_node(node, Symbol.BUILD_DEPENDS, Symbol.BUILD)
+ runtime_depends = _extract_depends_from_node(node, Symbol.RUNTIME_DEPENDS, Symbol.RUNTIME)
+ depends = _extract_depends_from_node(node, Symbol.DEPENDS, None)
+ return build_depends + runtime_depends + depends