diff options
Diffstat (limited to 'buildstream/element.py')
-rw-r--r-- | buildstream/element.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index 4d3e1bc75..27c5014a3 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1318,7 +1318,9 @@ class Element(Plugin): @contextmanager def _prepare_sandbox(self, scope, directory, deps='run', integrate=True): # bst shell and bst checkout require a local sandbox. - with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False) as sandbox: + bare_directory = True if directory else False + with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False, + bare_directory=bare_directory) as sandbox: # Configure always comes first, and we need it. self.configure_sandbox(sandbox) @@ -1385,6 +1387,7 @@ class Element(Plugin): # the same filing system as the rest of our cache. temp_staging_location = os.path.join(self._get_context().artifactdir, "staging_temp") temp_staging_directory = tempfile.mkdtemp(prefix=temp_staging_location) + import_dir = temp_staging_directory try: workspace = self._get_workspace() @@ -1395,12 +1398,16 @@ class Element(Plugin): with self.timed_activity("Staging local files at {}" .format(workspace.get_absolute_path())): workspace.stage(temp_staging_directory) + elif self._cached(): + # We have a cached buildtree to use, instead + artifact_base, _ = self.__extract() + import_dir = os.path.join(artifact_base, 'buildtree') else: # No workspace, stage directly for source in self.sources(): source._stage(temp_staging_directory) - vdirectory.import_files(temp_staging_directory) + vdirectory.import_files(import_dir) finally: # Staging may produce directories with less than 'rwx' permissions @@ -1566,9 +1573,8 @@ class Element(Plugin): collect = self.assemble(sandbox) # pylint: disable=assignment-from-no-return self.__set_build_result(success=True, description="succeeded") except BstError as e: - # If an error occurred assembling an element in a sandbox, - # then tack on the sandbox directory to the error - e.sandbox = rootdir + # Shelling into a sandbox is useful to debug this error + e.sandbox = True # If there is a workspace open on this element, it will have # been mounted for sandbox invocations instead of being staged. @@ -1683,8 +1689,8 @@ class Element(Plugin): "unable to collect artifact contents" .format(collect)) - # Finally cleanup the build dir - cleanup_rootdir() + # Finally cleanup the build dir + cleanup_rootdir() return artifact_size @@ -2152,12 +2158,14 @@ class Element(Plugin): # stderr (fileobject): The stream for stderr for the sandbox # config (SandboxConfig): The SandboxConfig object # allow_remote (bool): Whether the sandbox is allowed to be remote + # bare_directory (bool): Whether the directory is bare i.e. doesn't have + # a separate 'root' subdir # # Yields: # (Sandbox): A usable sandbox # @contextmanager - def __sandbox(self, directory, stdout=None, stderr=None, config=None, allow_remote=True): + def __sandbox(self, directory, stdout=None, stderr=None, config=None, allow_remote=True, bare_directory=False): context = self._get_context() project = self._get_project() platform = Platform.get_platform() @@ -2188,6 +2196,7 @@ class Element(Plugin): stdout=stdout, stderr=stderr, config=config, + bare_directory=bare_directory, allow_real_directory=not self.BST_VIRTUAL_DIRECTORY) yield sandbox @@ -2197,7 +2206,7 @@ class Element(Plugin): # Recursive contextmanager... with self.__sandbox(rootdir, stdout=stdout, stderr=stderr, config=config, - allow_remote=allow_remote) as sandbox: + allow_remote=allow_remote, bare_directory=False) as sandbox: yield sandbox # Cleanup the build dir |