summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-12 09:37:17 +0000
committerBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-12 11:10:21 +0000
commit341c3fd6e83c956012ac734c983ad52ee46fbf96 (patch)
tree4e74133803df08dc1b3e32d0c37d78add141ba1e
parenta235d443ade6bbf64a9f84e27cbac8fc68478606 (diff)
downloadbuildstream-chandan/bst-checkout-build.tar.gz
Refactor and simplify _prepare_sandbox for elementschandan/bst-checkout-build
Before we would have a intricate logics with multiple arguments that might get ignored. This simplifies the design and introduces a bool `shell` instead of having two different variables concerned about scope
-rw-r--r--buildstream/_frontend/cli.py10
-rw-r--r--buildstream/_stream.py6
-rw-r--r--buildstream/element.py20
3 files changed, 18 insertions, 18 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 97feb2d87..2145c8672 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -647,16 +647,24 @@ def shell(app, element, sysroot, mount, isolate, build_, command):
def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
"""Checkout a built artifact to the specified location
"""
+ from ..element import Scope
if hardlinks and tar:
click.echo("ERROR: options --hardlinks and --tar conflict", err=True)
sys.exit(-1)
+ if deps == "run":
+ scope = Scope.RUN
+ elif deps == "build":
+ scope = Scope.BUILD
+ elif deps == "none":
+ scope = Scope.NONE
+
with app.initialized():
app.stream.checkout(element,
location=location,
force=force,
- deps=deps,
+ scope=scope,
integrate=integrate,
hardlinks=hardlinks,
tar=tar)
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index e7a71978b..d20f99975 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -357,7 +357,7 @@ class Stream():
# target (str): Target to checkout
# location (str): Location to checkout the artifact to
# force (bool): Whether files can be overwritten if necessary
- # deps (str): The dependencies to checkout
+ # scope (str): The scope of dependencies to checkout
# integrate (bool): Whether to run integration commands
# hardlinks (bool): Whether checking out files hardlinked to
# their artifacts is acceptable
@@ -370,7 +370,7 @@ class Stream():
def checkout(self, target, *,
location=None,
force=False,
- deps='run',
+ scope=Scope.RUN,
integrate=True,
hardlinks=False,
tar=False):
@@ -403,7 +403,7 @@ class Stream():
# Stage deps into a temporary sandbox first
try:
- with target._prepare_sandbox(Scope.RUN, None, deps=deps,
+ with target._prepare_sandbox(scope=scope, directory=None,
integrate=integrate) as sandbox:
# Copy or move the sandbox to the target directory
diff --git a/buildstream/element.py b/buildstream/element.py
index 70c63d66f..c6da38ad2 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1315,7 +1315,7 @@ class Element(Plugin):
# is used to stage things by the `bst checkout` codepath
#
@contextmanager
- def _prepare_sandbox(self, scope, directory, deps='run', integrate=True):
+ def _prepare_sandbox(self, scope, directory, shell=False, integrate=True):
# bst shell and bst checkout require a local sandbox.
with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False) as sandbox:
@@ -1324,26 +1324,18 @@ class Element(Plugin):
# Stage something if we need it
if not directory:
- if scope == Scope.BUILD:
+ if shell and scope == Scope.BUILD:
self.stage(sandbox)
- elif scope == Scope.RUN:
-
- if deps == 'build':
- dependency_scope = Scope.BUILD
- elif deps == 'run':
- dependency_scope = Scope.RUN
- else:
- dependency_scope = Scope.NONE
-
+ else:
# Stage deps in the sandbox root
with self.timed_activity("Staging dependencies", silent_nested=True):
- self.stage_dependency_artifacts(sandbox, dependency_scope)
+ self.stage_dependency_artifacts(sandbox, scope)
# Run any integration commands provided by the dependencies
# once they are all staged and ready
if integrate:
with self.timed_activity("Integrating sandbox"):
- for dep in self.dependencies(dependency_scope):
+ for dep in self.dependencies(scope):
dep.integrate(sandbox)
yield sandbox
@@ -1845,7 +1837,7 @@ class Element(Plugin):
# 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):
- with self._prepare_sandbox(scope, directory) as sandbox:
+ with self._prepare_sandbox(scope, directory, shell=True) as sandbox:
environment = self.get_environment()
environment = copy.copy(environment)
flags = SandboxFlags.INTERACTIVE | SandboxFlags.ROOT_READ_ONLY