summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-06-01 23:00:24 +0900
committerTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-06-01 23:00:24 +0900
commitabb500b124bb752b0150135258cc9d4da929a97b (patch)
tree2a543abae6e43be19f5a048df9651c6918ccecec
parent32a531747c45fb96df64da6c7e3514cedeaaf53a (diff)
downloadbuildstream-abb500b124bb752b0150135258cc9d4da929a97b.tar.gz
_loader/loader.py: Make collect_element_no_deps() public
Within the _loader module, the LoadElement will need to use this in order to resolve links.
-rw-r--r--src/buildstream/_loader/loader.py153
1 files changed, 78 insertions, 75 deletions
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py
index 49018629e..fecfc8d0f 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -227,7 +227,7 @@ class Loader:
#
# Any task counting *inside* the junction will be handled by
# its loader.
- meta_element = self._collect_element_no_deps(self._elements[filename])
+ meta_element = self.collect_element_no_deps(self._elements[filename])
if meta_element.kind != "junction":
raise LoadError(
"{}{}: Expected junction but element kind is {}".format(provenance_str, filename, meta_element.kind),
@@ -368,6 +368,81 @@ class Loader:
return state
+ # collect_element_no_deps()
+ #
+ # Collect a single element, without its dependencies, into a meta_element
+ #
+ # NOTE: This is declared public in order to share with the LoadElement
+ # and should not be used outside of that `_loader` module.
+ #
+ # Args:
+ # element (LoadElement): The element for which to load a MetaElement
+ # task (Task): A task to write progress information to
+ #
+ # Returns:
+ # (MetaElement): A partially loaded MetaElement
+ #
+ def collect_element_no_deps(self, element, task=None):
+ # Return the already built one, if we already built it
+ meta_element = self._meta_elements.get(element.name)
+ if meta_element:
+ return meta_element
+
+ node = element.node
+ elt_provenance = node.get_provenance()
+ meta_sources = []
+
+ element_kind = node.get_str(Symbol.KIND)
+
+ # if there's a workspace for this element then just append a dummy workspace
+ # metasource.
+ workspace = self._context.get_workspaces().get_workspace(element.name)
+ skip_workspace = True
+ if workspace:
+ workspace_node = {"kind": "workspace"}
+ workspace_node["path"] = workspace.get_absolute_path()
+ workspace_node["last_build"] = str(workspace.to_dict().get("last_build", ""))
+ node[Symbol.SOURCES] = [workspace_node]
+ skip_workspace = False
+
+ sources = node.get_sequence(Symbol.SOURCES, default=[])
+ for index, source in enumerate(sources):
+ kind = source.get_str(Symbol.KIND)
+ # the workspace source plugin cannot be used unless the element is workspaced
+ if kind == "workspace" and skip_workspace:
+ continue
+
+ del source[Symbol.KIND]
+
+ # Directory is optional
+ directory = source.get_str(Symbol.DIRECTORY, default=None)
+ if directory:
+ del source[Symbol.DIRECTORY]
+ meta_source = MetaSource(element.name, index, element_kind, kind, source, directory)
+ meta_sources.append(meta_source)
+
+ meta_element = MetaElement(
+ self.project,
+ element.name,
+ element_kind,
+ elt_provenance,
+ meta_sources,
+ node.get_mapping(Symbol.CONFIG, default={}),
+ node.get_mapping(Symbol.VARIABLES, default={}),
+ node.get_mapping(Symbol.ENVIRONMENT, default={}),
+ node.get_str_list(Symbol.ENV_NOCACHE, default=[]),
+ node.get_mapping(Symbol.PUBLIC, default={}),
+ node.get_mapping(Symbol.SANDBOX, default={}),
+ element_kind == "junction",
+ )
+
+ # Cache it now, make sure it's already there before recursing
+ self._meta_elements[element.name] = meta_element
+ if task:
+ task.add_current_progress()
+
+ return meta_element
+
###########################################
# Private Methods #
###########################################
@@ -581,78 +656,6 @@ class Loader:
check_elements.remove(this_element)
validated.add(this_element)
- # _collect_element_no_deps()
- #
- # Collect a single element, without its dependencies, into a meta_element
- #
- # Args:
- # element (LoadElement): The element for which to load a MetaElement
- # task (Task): A task to write progress information to
- #
- # Returns:
- # (MetaElement): A partially loaded MetaElement
- #
- def _collect_element_no_deps(self, element, task=None):
- # Return the already built one, if we already built it
- meta_element = self._meta_elements.get(element.name)
- if meta_element:
- return meta_element
-
- node = element.node
- elt_provenance = node.get_provenance()
- meta_sources = []
-
- element_kind = node.get_str(Symbol.KIND)
-
- # if there's a workspace for this element then just append a dummy workspace
- # metasource.
- workspace = self._context.get_workspaces().get_workspace(element.name)
- skip_workspace = True
- if workspace:
- workspace_node = {"kind": "workspace"}
- workspace_node["path"] = workspace.get_absolute_path()
- workspace_node["last_build"] = str(workspace.to_dict().get("last_build", ""))
- node[Symbol.SOURCES] = [workspace_node]
- skip_workspace = False
-
- sources = node.get_sequence(Symbol.SOURCES, default=[])
- for index, source in enumerate(sources):
- kind = source.get_str(Symbol.KIND)
- # the workspace source plugin cannot be used unless the element is workspaced
- if kind == "workspace" and skip_workspace:
- continue
-
- del source[Symbol.KIND]
-
- # Directory is optional
- directory = source.get_str(Symbol.DIRECTORY, default=None)
- if directory:
- del source[Symbol.DIRECTORY]
- meta_source = MetaSource(element.name, index, element_kind, kind, source, directory)
- meta_sources.append(meta_source)
-
- meta_element = MetaElement(
- self.project,
- element.name,
- element_kind,
- elt_provenance,
- meta_sources,
- node.get_mapping(Symbol.CONFIG, default={}),
- node.get_mapping(Symbol.VARIABLES, default={}),
- node.get_mapping(Symbol.ENVIRONMENT, default={}),
- node.get_str_list(Symbol.ENV_NOCACHE, default=[]),
- node.get_mapping(Symbol.PUBLIC, default={}),
- node.get_mapping(Symbol.SANDBOX, default={}),
- element_kind == "junction",
- )
-
- # Cache it now, make sure it's already there before recursing
- self._meta_elements[element.name] = meta_element
- if task:
- task.add_current_progress()
-
- return meta_element
-
# _collect_element()
#
# Collect the toplevel elements we have
@@ -666,7 +669,7 @@ class Loader:
#
def _collect_element(self, top_element, task=None):
element_queue = [top_element]
- meta_element_queue = [self._collect_element_no_deps(top_element, task)]
+ meta_element_queue = [self.collect_element_no_deps(top_element, task)]
while element_queue:
element = element_queue.pop()
@@ -683,7 +686,7 @@ class Loader:
name = dep.element.name
if name not in loader._meta_elements:
- meta_dep = loader._collect_element_no_deps(dep.element, task)
+ meta_dep = loader.collect_element_no_deps(dep.element, task)
element_queue.append(dep.element)
meta_element_queue.append(meta_dep)
else: