summaryrefslogtreecommitdiff
path: root/buildstream/element.py
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-16 19:59:47 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-16 19:59:47 +0900
commitb4f0a52a6a22544b792a2f082a6387cdb988fe3a (patch)
treebb750c8a3b9ef050d98529a61f7a30a591cd7810 /buildstream/element.py
parentcd90fbde079ac42e930c45fcab509d49205fe54c (diff)
downloadbuildstream-b4f0a52a6a22544b792a2f082a6387cdb988fe3a.tar.gz
element.py, _pipeline.py: Moved instantiation codepath to Element class methods.
This will allow the instantiation codepath to be shared by the Loader which also needs to instantiate elements for junctions.
Diffstat (limited to 'buildstream/element.py')
-rw-r--r--buildstream/element.py75
1 files changed, 62 insertions, 13 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index f878c50dc..324efa86c 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -154,8 +154,10 @@ class Element(Plugin):
All elements derive from this class, this interface defines how
the core will be interacting with Elements.
"""
- __defaults = {} # The defaults from the yaml file and project
- __defaults_set = False # Flag, in case there are no defaults at all
+ __defaults = {} # The defaults from the yaml file and project
+ __defaults_set = False # Flag, in case there are no defaults at all
+ __instantiated_elements = {} # A hash of Element by MetaElement
+ __redundant_source_refs = [] # A list of (source, ref) tuples which were redundantly specified
BST_ARTIFACT_VERSION = 0
"""The element plugin's artifact version
@@ -851,22 +853,69 @@ class Element(Plugin):
#############################################################
# Private Methods used in BuildStream #
#############################################################
- # _add_source():
+
+ # _new_from_meta():
+ #
+ # Recursively instantiate a new Element instance, it's sources
+ # and it's dependencies from a meta element.
+ #
+ # Args:
+ # artifacts (ArtifactCache): The artifact cache
+ # meta (MetaElement): The meta element
+ #
+ # Returns:
+ # (Element): A newly created Element instance
+ #
+ @classmethod
+ def _new_from_meta(cls, meta, artifacts):
+
+ if meta in cls.__instantiated_elements:
+ return cls.__instantiated_elements[meta]
+
+ project = meta.project
+ element = project.create_element(artifacts, meta)
+ cls.__instantiated_elements[meta] = element
+
+ # Instantiate sources
+ for meta_source in meta.sources:
+ source = project.create_source(meta_source)
+ redundant_ref = source._load_ref()
+ 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))
+
+ # Instantiate dependencies
+ for meta_dep in meta.dependencies:
+ dependency = Element._new_from_meta(meta_dep, artifacts)
+ element.__runtime_dependencies.append(dependency)
+ for meta_dep in meta.build_dependencies:
+ dependency = Element._new_from_meta(meta_dep, artifacts)
+ element.__build_dependencies.append(dependency)
+
+ return element
+
+ # _get_redundant_source_refs()
#
- # Adds a source, for pipeline construction
+ # Fetches a list of (Source, ref) tuples of all the Sources
+ # which were loaded with a ref specified in the element declaration
+ # for projects which use project.refs ref-storage.
#
- def _add_source(self, source):
- self.__sources.append(source)
+ # This is used to produce a warning
+ @classmethod
+ def _get_redundant_source_refs(cls):
+ return cls.__redundant_source_refs
- # _add_dependency()
+ # _reset_load_state()
#
- # Adds a dependency, for pipeline construction
+ # This is called by Pipeline.cleanup() and is used to
+ # reset the loader state between multiple sessions.
#
- def _add_dependency(self, dependency, scope):
- if scope != Scope.RUN:
- self.__build_dependencies.append(dependency)
- if scope != Scope.BUILD:
- self.__runtime_dependencies.append(dependency)
+ @classmethod
+ def _reset_load_state(cls):
+ cls.__instantiated_elements = {}
+ cls.__redundant_source_refs = []
# _get_consistency()
#