diff options
author | Valentin David <valentin.david@codethink.co.uk> | 2018-06-27 19:12:06 +0200 |
---|---|---|
committer | Valentin David <valentin.david@codethink.co.uk> | 2018-07-02 16:24:53 +0200 |
commit | 63aecde73494e5f830c7b8a3511a76b11a203b91 (patch) | |
tree | b76fef60fb5745548305d8077a02794b2de361aa | |
parent | f221dde148cb7db257e6a10f75ac68ca35ea5979 (diff) | |
download | buildstream-63aecde73494e5f830c7b8a3511a76b11a203b91.tar.gz |
Move loading and cleaning of elements from Pipeline to Project.
-rw-r--r-- | buildstream/_pipeline.py | 36 | ||||
-rw-r--r-- | buildstream/_project.py | 55 | ||||
-rw-r--r-- | buildstream/_stream.py | 4 |
3 files changed, 60 insertions, 35 deletions
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index 909ae2471..22760a49f 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -26,7 +26,6 @@ from operator import itemgetter from ._exceptions import PipelineError from ._message import Message, MessageType from ._profile import Topics, profile_start, profile_end -from .element import Element from . import Scope, Consistency from ._project import ProjectRefStorage @@ -104,28 +103,9 @@ class Pipeline(): profile_start(Topics.LOAD_PIPELINE, "_".join(t.replace(os.sep, '-') for t in targets)) - with self._context.timed_activity("Loading pipeline", silent_nested=True): - meta_elements = self._project.loader.load(targets, rewritable, None, - fetch_subprojects=fetch_subprojects) - - # Resolve the real elements now that we've loaded the project - with self._context.timed_activity("Resolving pipeline"): - elements = [ - Element._new_from_meta(meta, self._artifacts) - for meta in meta_elements - ] - - # Now warn about any redundant source references which may have - # been discovered in the resolve() phase. - redundant_refs = Element._get_redundant_source_refs() - if redundant_refs: - detail = "The following inline specified source references will be ignored:\n\n" - lines = [ - "{}:{}".format(source._get_provenance(), ref) - for source, ref in redundant_refs - ] - detail += "\n".join(lines) - self._message(MessageType.WARN, "Ignoring redundant source references", detail=detail) + elements = self._project.load_elements(targets, self._artifacts, + rewritable=rewritable, + fetch_subprojects=fetch_subprojects) # Now create element groups to match the input target groups elt_iter = iter(elements) @@ -379,16 +359,6 @@ class Pipeline(): detail += " " + element._get_full_name() + "\n" raise PipelineError("Inconsistent pipeline", detail=detail, reason="inconsistent-pipeline") - # cleanup() - # - # Cleans up resources used by the Pipeline. - # - def cleanup(self): - self._project.loader.cleanup() - - # Reset the element loader state - Element._reset_load_state() - ############################################################# # Private Methods # ############################################################# diff --git a/buildstream/_project.py b/buildstream/_project.py index f58a9c91a..7aa72b6e6 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -35,6 +35,8 @@ from ._projectrefs import ProjectRefs, ProjectRefStorage from ._versions import BST_FORMAT_VERSION from ._loader import Loader from ._includes import Includes +from .element import Element +from ._message import Message, MessageType # The separator we use for user specified aliases @@ -350,6 +352,59 @@ class Project(): return self._cache_key + # load_elements() + # + # Loads elements from target names. + # + # Args: + # targets (list): Target names + # artifacts (ArtifactCache): Artifact cache + # rewritable (bool): Whether the loaded files should be rewritable + # this is a bit more expensive due to deep copies + # fetch_subprojects (bool): Whether we should fetch subprojects as a part of the + # loading process, if they are not yet locally cached + # + # Returns: + # (list): A list of loaded Element + # + def load_elements(self, targets, artifacts, *, + rewritable=False, fetch_subprojects=False): + with self._context.timed_activity("Loading elements", silent_nested=True): + meta_elements = self.loader.load(targets, rewritable=rewritable, + ticker=None, + fetch_subprojects=fetch_subprojects) + + with self._context.timed_activity("Resolving elements"): + elements = [ + Element._new_from_meta(meta, artifacts) + for meta in meta_elements + ] + + # Now warn about any redundant source references which may have + # been discovered in the resolve() phase. + redundant_refs = Element._get_redundant_source_refs() + if redundant_refs: + detail = "The following inline specified source references will be ignored:\n\n" + lines = [ + "{}:{}".format(source._get_provenance(), ref) + for source, ref in redundant_refs + ] + detail += "\n".join(lines) + self._context.message( + Message(None, MessageType.WARN, "Ignoring redundant source references", detail=detail)) + + return elements + + # cleanup() + # + # Cleans up resources used loading elements + # + def cleanup(self): + self.loader.cleanup() + + # Reset the element loader state + Element._reset_load_state() + # _load(): # # Loads the project configuration file in the project directory. diff --git a/buildstream/_stream.py b/buildstream/_stream.py index 4801ecc10..28afae3e8 100644 --- a/buildstream/_stream.py +++ b/buildstream/_stream.py @@ -90,8 +90,8 @@ class Stream(): # Cleans up application state # def cleanup(self): - if self._pipeline: - self._pipeline.cleanup() + if self._project: + self._project.cleanup() # load_selection() # |