From 805baf7d96ade33c8bbe3f38122283e705000d81 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Thu, 10 Jan 2019 11:09:40 +0000 Subject: Download buildtrees on demand for bst shell --use-buildtree Provide bst shell --use-buildtree the ability to attempt to acquire missing buildtrees, given respective option, user pull-buildtree context and remote availability. _frontend/cli.py: Refactor logic for determining --use-buildtree option with given opportunity to attempt pulling a non-local buildtree. Element loaded with artifact_config to allow remote querying. _stream.py: With given user option and element state, construct PullQueue to fetch remote buildtree. Continue or Error without buildtree if cannot be attained. tests/integration/build-tree.py: Update to support new usecases --- buildstream/_stream.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'buildstream/_stream.py') diff --git a/buildstream/_stream.py b/buildstream/_stream.py index afb0256b4..af736c96a 100644 --- a/buildstream/_stream.py +++ b/buildstream/_stream.py @@ -115,7 +115,7 @@ class Stream(): elements, _ = self._load(targets, (), selection=selection, except_targets=except_targets, - fetch_subprojects=False + fetch_subprojects=False, use_artifact_config=use_artifact_config) profile_end(Topics.LOAD_SELECTION, "_".join(t.replace(os.sep, '-') for t in targets)) @@ -134,7 +134,7 @@ class Stream(): # mounts (list of HostMount): Additional directories to mount into the sandbox # isolate (bool): Whether to isolate the environment like we do in builds # command (list): An argv to launch in the sandbox, or None - # usebuildtree (bool): Wheather to use a buildtree as the source. + # usebuildtree (str): Whether to use a buildtree as the source, given cli option # # Returns: # (int): The exit code of the launched shell @@ -144,7 +144,7 @@ class Stream(): mounts=None, isolate=False, command=None, - usebuildtree=False): + usebuildtree=None): # Assert we have everything we need built, unless the directory is specified # in which case we just blindly trust the directory, using the element @@ -159,8 +159,31 @@ class Stream(): raise StreamError("Elements need to be built or downloaded before staging a shell environment", detail="\n".join(missing_deps)) + buildtree = False + # Check if we require a pull queue attempt, with given artifact state and context + if usebuildtree: + if not element._cached_buildtree(): + require_buildtree = self._buildtree_pull_required([element]) + # Attempt a pull queue for the given element if remote and context allow it + if require_buildtree: + self._message(MessageType.INFO, "Attempting to fetch missing artifact buildtree") + self._add_queue(PullQueue(self._scheduler)) + self._enqueue_plan(require_buildtree) + self._run() + # Now check if the buildtree was successfully fetched + if element._cached_buildtree(): + buildtree = True + if not buildtree: + if usebuildtree == "always": + raise StreamError("Buildtree is not cached locally or in available remotes") + else: + self._message(MessageType.INFO, """Buildtree is not cached locally or in available remotes, + shell will be loaded without it""") + else: + buildtree = True + return element._shell(scope, directory, mounts=mounts, isolate=isolate, prompt=prompt, command=command, - usebuildtree=usebuildtree) + usebuildtree=buildtree) # build() # -- cgit v1.2.1