diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2019-05-02 15:19:06 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2019-05-02 15:23:19 +0100 |
commit | 6961eec10ab6d375978713ccde83dc12e6ef86db (patch) | |
tree | 431745b808af08a3d2d9034da6f2df5acad92e3d | |
parent | bccb4f15a784a80561c32665ced44554dbd9b5ce (diff) | |
download | buildstream-6961eec10ab6d375978713ccde83dc12e6ef86db.tar.gz |
_yaml.py, source.py: Fix tracking of refs inside conditions
Previously if you had a source of the form:
```yaml
- (?):
somecondition:
url: blah
ref: foo
othercondition:
url: blah
ref: bar
```
And you did `bst source track` on the element then you'd get something
output of the form:
```yaml
- (?)...
...
ref: wibble
```
With this patch, the *correct* ref inside the conditionals is updated
instead.
Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-rw-r--r-- | buildstream/_yaml.py | 11 | ||||
-rw-r--r-- | buildstream/source.py | 7 |
2 files changed, 16 insertions, 2 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py index c1297e9dd..cdab4269e 100644 --- a/buildstream/_yaml.py +++ b/buildstream/_yaml.py @@ -1204,18 +1204,27 @@ def assert_symbol_name(provenance, symbol_name, purpose, *, allow_dashes=True): # This is typically used when trying to walk a path to a given node # for the purpose of then modifying a similar tree of objects elsewhere # +# If the key is provided, then we actually hunt for the node represented by +# target[key] and return its container, rather than hunting for target directly +# # Args: # node (Node): The node at the root of the tree to search # target (Node): The node you are looking for in that tree +# key (str): Optional string key within target node # # Returns: # (list): A path from `node` to `target` or None if `target` is not in the subtree -def node_find_target(node, target): +def node_find_target(node, target, *, key=None): assert type(node) is Node assert type(target) is Node + if key is not None: + target = target[0][key] path = [] if _walk_find_target(node, path, target): + if key: + # Remove key from end of path + path = path[:-1] return path return None diff --git a/buildstream/source.py b/buildstream/source.py index daf2cb27c..0c07dd41e 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -951,10 +951,15 @@ class Source(Plugin): provenance = _yaml.node_get_provenance(node) else: provenance = _yaml.node_get_provenance(node, key=key) + toplevel_node = provenance.toplevel # Get the path to whatever changed - path = _yaml.node_find_target(toplevel_node, node) + if action == 'add': + path = _yaml.node_find_target(toplevel_node, node) + else: + path = _yaml.node_find_target(toplevel_node, node, key=key) + roundtrip_file = roundtrip_cache.get(provenance.filename) if not roundtrip_file: roundtrip_file = roundtrip_cache[provenance.filename] = _yaml.roundtrip_load( |