summaryrefslogtreecommitdiff
path: root/buildstream/_yaml.py
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-01-07 22:47:50 -0500
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-01-07 23:08:13 -0500
commita5b605198915e82da0384d676ecd28d201d87a24 (patch)
treeecffd9cc84bd93c30f10fd3690cc08919fdfe3d1 /buildstream/_yaml.py
parent31fd3214a3ece619ab6a6760489b92ed7a01ed6b (diff)
downloadbuildstream-a5b605198915e82da0384d676ecd28d201d87a24.tar.gz
_yaml.py: Be friendly with empty nodes in dictionary compositing
Diffstat (limited to 'buildstream/_yaml.py')
-rw-r--r--buildstream/_yaml.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 3e326219b..ae31d7197 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -372,10 +372,21 @@ def composite(target, source, policy=CompositePolicy.OVERWRITE, typesafe=False):
e.actual_type.__name__)) from e
+# Gives a node a dummy provenance, in case of compositing dictionaries
+# where the target is an empty {}
+def ensure_provenance(node):
+ provenance = node.get(PROVENANCE_KEY)
+ if not provenance:
+ provenance = DictProvenance('', node, node)
+ node[PROVENANCE_KEY] = provenance
+
+ return provenance
+
+
def composite_dict_recurse(target, source, policy=CompositePolicy.OVERWRITE,
typesafe=False, path=None):
- target_provenance = target.get(PROVENANCE_KEY)
- source_provenance = source.get(PROVENANCE_KEY)
+ target_provenance = ensure_provenance(target)
+ source_provenance = ensure_provenance(source)
for key, value in source.items():