From 9f0cb743cf459deb9f83574272ced2c4d4d4fa37 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Mon, 12 Nov 2018 09:37:17 +0000 Subject: 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 --- buildstream/_frontend/cli.py | 10 +++++++++- buildstream/_stream.py | 6 +++--- buildstream/element.py | 20 ++++++-------------- 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 6e2e8b25b..f8e7422d1 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 3637d8d60..ab716b92f 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. bare_directory = True if directory else False with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False, @@ -1326,26 +1326,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 @@ -1844,7 +1836,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 -- cgit v1.2.1