diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-12 09:37:17 +0000 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-12-03 09:46:14 +0000 |
commit | ac60f47a4ce439db785d11b4b31699d1034ca3e7 (patch) | |
tree | d5bec02dab974f2a2425d79a9cf97304996f283b | |
parent | 8ac1e7576f43f691b2f011d2655efe3ddb6984a3 (diff) | |
download | buildstream-ac60f47a4ce439db785d11b4b31699d1034ca3e7.tar.gz |
Refactor and simplify _prepare_sandbox for elements
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.py | 10 | ||||
-rw-r--r-- | buildstream/_stream.py | 6 | ||||
-rw-r--r-- | buildstream/element.py | 20 |
3 files changed, 18 insertions, 18 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index 59c917323..ef0dadb13 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -657,16 +657,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 2f9799178..6a3d2c7fc 100644 --- a/buildstream/_stream.py +++ b/buildstream/_stream.py @@ -370,7 +370,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 @@ -383,7 +383,7 @@ class Stream(): def checkout(self, target, *, location=None, force=False, - deps='run', + scope=Scope.RUN, integrate=True, hardlinks=False, tar=False): @@ -396,7 +396,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 2caac8d3c..2f724f49d 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1339,7 +1339,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. bare_directory = True if directory else False with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False, @@ -1350,26 +1350,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 @@ -1865,7 +1857,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 |