diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-11 18:19:46 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-15 14:14:02 +0000 |
commit | 7298136642010d4e02a607f4275ffe3ad5657a14 (patch) | |
tree | aab93ac4d78c6d7b85ac2b1de89eb11280829b21 /src/buildstream/_loader | |
parent | ad5aa05826431b1b34c220f20e93bf6e05b292a0 (diff) | |
download | buildstream-7298136642010d4e02a607f4275ffe3ad5657a14.tar.gz |
_yaml: Introduce 'get_sequence()' and 'sequence_at()'/'mapping_at()'
- Adding 'get_sequence' on MappingNode to access sequences in a mapping
- Adding 'sequence_at' on SequenceNode to access sequences in a sequence
- Adding 'mapping_at' on SequenceNode to access mappings in a sequence
Using "*_at" in sequences allows us to quickly understand if we are
dealing with a sequence or a mapping.
Diffstat (limited to 'src/buildstream/_loader')
-rw-r--r-- | src/buildstream/_loader/loader.py | 8 | ||||
-rw-r--r-- | src/buildstream/_loader/types.pyx | 14 |
2 files changed, 10 insertions, 12 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py index 5f533731b..64e7fafd0 100644 --- a/src/buildstream/_loader/loader.py +++ b/src/buildstream/_loader/loader.py @@ -466,13 +466,12 @@ class Loader(): elt_provenance = _yaml.node_get_provenance(node) meta_sources = [] - sources = _yaml.node_get(node, list, Symbol.SOURCES, default_value=[]) + sources = node.get_sequence(Symbol.SOURCES, default=[]) element_kind = node.get_str(Symbol.KIND) # Safe loop calling into _yaml.node_get() for each element ensures # we have good error reporting - for i in range(len(sources)): - source = _yaml.node_get(node, dict, Symbol.SOURCES, indices=[i]) + for index, source in enumerate(sources): kind = source.get_str(Symbol.KIND) _yaml.node_del(source, Symbol.KIND) @@ -481,7 +480,6 @@ class Loader(): if directory: _yaml.node_del(source, Symbol.DIRECTORY) - index = sources.index(source) meta_source = MetaSource(element.name, index, element_kind, kind, source, directory) meta_sources.append(meta_source) @@ -490,7 +488,7 @@ class Loader(): node.get_mapping(Symbol.CONFIG, default={}), node.get_mapping(Symbol.VARIABLES, default={}), node.get_mapping(Symbol.ENVIRONMENT, default={}), - _yaml.node_get(node, list, Symbol.ENV_NOCACHE, default_value=[]), + node.get_sequence(Symbol.ENV_NOCACHE, default=[]).as_str_list(), node.get_mapping(Symbol.PUBLIC, default={}), node.get_mapping(Symbol.SANDBOX, default={}), element_kind == 'junction') diff --git a/src/buildstream/_loader/types.pyx b/src/buildstream/_loader/types.pyx index a3e49b040..dfd8f9046 100644 --- a/src/buildstream/_loader/types.pyx +++ b/src/buildstream/_loader/types.pyx @@ -72,8 +72,8 @@ cdef class Dependency: self.provenance = provenance - if type(dep) is str: - self.name = <str> dep + if type(dep) is _yaml.ScalarNode: + self.name = dep.as_str() self.dep_type = default_dep_type self.junction = None @@ -138,15 +138,15 @@ cdef class Dependency: # acc (list): a list in which to add the loaded dependencies # cdef void _extract_depends_from_node(_yaml.Node node, str key, str default_dep_type, list acc) except *: - cdef list depends = <list> _yaml.node_get(node, list, key, None, []) - cdef int index + cdef _yaml.SequenceNode depends = node.get_sequence(key, []) + cdef _yaml.Node dep_node cdef _yaml.ProvenanceInformation dep_provenance - for index in range(len(depends)): + for dep_node in 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.ProvenanceInformation> _yaml.node_get_provenance(node, key=key, indices=[index]) - dependency = Dependency(depends[index], dep_provenance, default_dep_type=default_dep_type) + dep_provenance = <_yaml.ProvenanceInformation> _yaml.node_get_provenance(dep_node) + dependency = Dependency(dep_node, dep_provenance, default_dep_type=default_dep_type) acc.append(dependency) # Now delete the field, we dont want it anymore |