From 1d7acf256578630ba11519084897099792fb1a41 Mon Sep 17 00:00:00 2001 From: Tristan van Berkom Date: Tue, 22 Dec 2020 15:52:17 +0900 Subject: _stream.py: Added internal _load_elements() This replaces the pipeline `load()` method. This does some rewording in `Stream._load_elements_from_targets()` --- src/buildstream/_stream.py | 47 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 1dab4a3f0..a34bbe389 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -19,6 +19,7 @@ # Jürg Billeter # Tristan Maat +import itertools import os import sys import stat @@ -1140,6 +1141,34 @@ class Stream: ArtifactProject.clear_project_cache() return list(artifacts) + # _load_elements() + # + # Loads elements from target names. + # + # This function is called with a list of lists, such that multiple + # target groups may be specified. Element names specified in `targets` + # are allowed to be redundant. + # + # Args: + # target_groups (list of lists): Groups of toplevel targets to load + # + # Returns: + # (tuple of lists): A tuple of Element object lists, grouped corresponding to target_groups + # + def _load_elements(self, target_groups): + + # First concatenate all the lists for the loader's sake + targets = list(itertools.chain(*target_groups)) + + with PROFILER.profile(Topics.LOAD_PIPELINE, "_".join(t.replace(os.sep, "-") for t in targets)): + elements = self._project.load_elements(targets) + + # Now create element groups to match the input target groups + elt_iter = iter(elements) + element_groups = [[next(elt_iter) for i in range(len(group))] for group in target_groups] + + return tuple(element_groups) + # _load_elements_from_targets # # Given the usual set of target element names/artifact refs, load @@ -1166,20 +1195,24 @@ class Stream: rewritable: bool = False, valid_artifact_names: bool = False ) -> Tuple[List[Element], List[Element], List[Element]]: - names, refs = self._expand_and_classify_targets(targets, valid_artifact_names=valid_artifact_names) - loadable = [names, except_targets] + + # First determine which of the user specified targets are artifact + # names and which are element names. + element_names, artifact_names = self._expand_and_classify_targets( + targets, valid_artifact_names=valid_artifact_names + ) self._project.load_context.set_rewritable(rewritable) - # Load and filter elements - if loadable: - elements, except_elements = self._pipeline.load(loadable) + # Load elements and except elements + if element_names: + elements, except_elements = self._load_elements([element_names, except_targets]) else: elements, except_elements = [], [] # Load artifacts - if refs: - artifacts = self._load_artifacts(refs) + if artifact_names: + artifacts = self._load_artifacts(artifact_names) else: artifacts = [] -- cgit v1.2.1