You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by gi...@apache.org on 2020/12/29 13:14:01 UTC

[buildstream] 16/30: Move loading and cleaning of elements from Pipeline to Project.

This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch valentindavid/flatpak-demo
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 63aecde73494e5f830c7b8a3511a76b11a203b91
Author: Valentin David <va...@codethink.co.uk>
AuthorDate: Wed Jun 27 19:12:06 2018 +0200

    Move loading and cleaning of elements from Pipeline to Project.
---
 buildstream/_pipeline.py | 36 +++----------------------------
 buildstream/_project.py  | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
 buildstream/_stream.py   |  4 ++--
 3 files changed, 60 insertions(+), 35 deletions(-)

diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py
index 909ae24..22760a4 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 f58a9c9..7aa72b6 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 4801ecc..28afae3 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()
     #