diff options
author | Darius Makovsky <traveltissues@protonmail.com> | 2019-09-05 14:20:14 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-09-24 15:58:25 +0000 |
commit | e25da0391352c596d26fe892f3435c38133c500a (patch) | |
tree | 70c207f0ab8ee73d0fbcd90b9efef3b590b40880 | |
parent | a8ca9fcb41e1095e04cc40f1ef09700ad70a3dc0 (diff) | |
download | buildstream-e25da0391352c596d26fe892f3435c38133c500a.tar.gz |
Support loading 'workspace'-kind sources
Add the workspace-kind source to the sources manually to prevent a user
incorrectly loading the source plugin.
-rw-r--r-- | src/buildstream/_loader/loader.py | 35 | ||||
-rw-r--r-- | src/buildstream/element.py | 15 |
2 files changed, 43 insertions, 7 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py index 5599c8b71..6a8db892f 100644 --- a/src/buildstream/_loader/loader.py +++ b/src/buildstream/_loader/loader.py @@ -438,17 +438,38 @@ class Loader(): sources = node.get_sequence(Symbol.SOURCES, default=[]) element_kind = node.get_str(Symbol.KIND) - for index, source in enumerate(sources): - kind = source.get_str(Symbol.KIND) - del source[Symbol.KIND] + def make_metasource(_index, _source, skip_workspace=True): + kind = _source.get_str(Symbol.KIND) + # the workspace source plugin cannot be used unless the element is workspaced + if kind == 'workspace' and skip_workspace: + return None + + del _source[Symbol.KIND] # Directory is optional - directory = source.get_str(Symbol.DIRECTORY, default=None) + directory = _source.get_str(Symbol.DIRECTORY, default=None) if directory: - del source[Symbol.DIRECTORY] + del _source[Symbol.DIRECTORY] + + return MetaSource(element.name, _index, element_kind, kind, _source, directory) - meta_source = MetaSource(element.name, index, element_kind, kind, source, directory) - meta_sources.append(meta_source) + for index, source in enumerate(sources): + meta_source = make_metasource(index, source) + if meta_source: + meta_sources.append(meta_source) + + # if there's a workspace for this element then just append a dummy workspace + # metasources. When sources are instantiated, the workspace will own the + # element sources. These can then be referred to when resetting or similar operations. + workspace = self._context.get_workspaces().get_workspace(element.name) + if workspace: + workspace_node = {'kind': 'workspace'} + workspace_node['path'] = workspace.get_absolute_path() + workspace_node['ref'] = str(workspace.to_dict().get('last_successful', 'ignored')) + sources.append(workspace_node) + meta_source = make_metasource(len(sources), sources.mapping_at(-1), False) + if meta_source: + meta_sources.append(meta_source) meta_element = MetaElement(self.project, element.name, element_kind, elt_provenance, meta_sources, diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 044b97458..711723ebe 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -1023,6 +1023,9 @@ class Element(Plugin): element = meta.project.create_element(meta, first_pass=meta.first_pass) cls.__instantiated_elements[meta] = element + # do the metasources include a workspace source? + _workspace_source = None + # Instantiate sources and generate their keys for meta_source in meta.sources: meta_source.first_pass = meta.is_junction @@ -1030,12 +1033,24 @@ class Element(Plugin): first_pass=meta.first_pass) redundant_ref = source._load_ref() + + if meta_source.kind == 'workspace': + _workspace_source = source + continue + element.__sources.append(source) # Collect redundant refs which occurred at load time if redundant_ref is not None: cls.__redundant_source_refs.append((source, redundant_ref)) + # workspace handling: if the metasources included a workspace source, then + # this should replace the element.__sources and should in turn own those sources + # directly + if _workspace_source is not None: + _workspace_source.set_element_sources(element.__sources) + element.__sources = [_workspace_source] + # Instantiate dependencies for meta_dep in meta.dependencies: dependency = Element._new_from_meta(meta_dep, task) |