Element.py: Added stage_sources function to stage the sources in a shell sandbox
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index 0680f2a..e4455fe 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -150,7 +150,12 @@
raise StreamError("Elements need to be built or downloaded before staging a shell environment",
detail="\n".join(missing_deps))
- return element._shell(scope, directory, mounts=mounts, isolate=isolate, prompt=prompt, command=command)
+ with element._prepare_sandbox(scope, directory) as sandbox:
+ for dep in self._pipeline.dependencies([element], scope):
+ dep.stage_sources(sandbox, dep.get_variable('build-root'))
+
+ return element._shell(scope, directory, mounts=mounts, isolate=isolate,
+ prompt=prompt, command=command, sandbox=sandbox)
# build()
#
diff --git a/buildstream/element.py b/buildstream/element.py
index e876eb1..e181529 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -78,7 +78,7 @@
import stat
import copy
from collections import Mapping, OrderedDict
-from contextlib import contextmanager
+from contextlib import contextmanager, ExitStack
from enum import Enum
import tempfile
import time
@@ -1243,7 +1243,7 @@
# is used to stage things by the `bst checkout` codepath
#
@contextmanager
- def _prepare_sandbox(self, scope, directory, integrate=True):
+ def _prepare_sandbox(self, scope, directory, integrate=True, dep=False):
with self.__sandbox(directory, config=self.__sandbox_config) as sandbox:
@@ -1263,8 +1263,8 @@
# once they are all staged and ready
if integrate:
with self.timed_activity("Integrating sandbox"):
- for dep in self.dependencies(scope):
- dep.integrate(sandbox)
+ for depend in self.dependencies(scope):
+ depend.integrate(sandbox)
yield sandbox
@@ -1677,9 +1677,12 @@
# Returns: Exit code
#
# If directory is not specified, one will be staged using scope
- def _shell(self, scope=None, directory=None, *, mounts=None, isolate=False, prompt=None, command=None):
+ def _shell(self, scope=None, directory=None, *, mounts=None, isolate=False,
+ prompt=None, command=None, sandbox=None):
- with self._prepare_sandbox(scope, directory) as sandbox:
+ with ExitStack() as stack:
+ if sandbox is None:
+ sandbox = stack.enter_context(self._prepare_sandbox(scope, directory))
environment = self.get_environment()
environment = copy.copy(environment)
flags = SandboxFlags.INTERACTIVE | SandboxFlags.ROOT_READ_ONLY