summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-08-28 12:37:22 +0100
committerJames Ennis <james.ennis@codethink.co.uk>2019-08-28 16:14:47 +0100
commitfaf675b13994838792f71f3f3f8677548e8c4a5e (patch)
tree52e0bd168ef29bf92239d43b5a40b2e127960e45
parent132396fd065c3b401fe26b23b20aa998b53cc6be (diff)
downloadbuildstream-jennis/test_failure.tar.gz
_stream.py: Remove separate handling of ArtifactElementsjennis/test_failure
ArtifactElement inherits Element, both have an Artifact object as a member, thus we should not need to handle these separately. This change has resulted in introducing a configure_sandbox() method in ArtifactElement. The method is similar to BuildElement.configure_sandbox() but does not configure the sandbox to actually be used for building.
-rw-r--r--src/buildstream/_artifactelement.py16
-rw-r--r--src/buildstream/_stream.py28
2 files changed, 24 insertions, 20 deletions
diff --git a/src/buildstream/_artifactelement.py b/src/buildstream/_artifactelement.py
index cfd3c29c8..b8ea4c1e8 100644
--- a/src/buildstream/_artifactelement.py
+++ b/src/buildstream/_artifactelement.py
@@ -119,6 +119,22 @@ class ArtifactElement(Element):
artifact = self._get_artifact()
return artifact.get_dependency_refs(deps=scope)
+ # configure_sandbox()
+ #
+ # Configure a sandbox for installing artifacts into
+ #
+ # Args:
+ # sandbox (Sandbox)
+ #
+ def configure_sandbox(self, sandbox):
+ install_root = self.get_variable('install-root')
+
+ # Tell the sandbox to mount the build root and install root
+ sandbox.mark_directory(install_root)
+
+ # Tell sandbox which directory is preserved in the finished artifact
+ sandbox.set_output_directory(install_root)
+
# Override Element._calculate_cache_key
def _calculate_cache_key(self, dependencies=None):
return self._key
diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py
index 0567b3ceb..ca8ca7863 100644
--- a/src/buildstream/_stream.py
+++ b/src/buildstream/_stream.py
@@ -29,7 +29,6 @@ import tempfile
from contextlib import contextmanager, suppress
from fnmatch import fnmatch
-from ._artifact import Artifact
from ._artifactelement import verify_artifact_ref, ArtifactElement
from ._exceptions import StreamError, ImplError, BstError, ArtifactElementError, ArtifactError
from ._message import Message, MessageType
@@ -559,26 +558,15 @@ class Stream():
self._context.disable_fork()
- # Stage deps into a temporary sandbox first
- if isinstance(target, ArtifactElement):
- try:
- key = target._get_cache_key()
- artifact = Artifact(target, self._context, strong_key=key)
- virdir = artifact.get_files()
+ try:
+ with target._prepare_sandbox(scope=scope, directory=None,
+ integrate=integrate) as sandbox:
+ # Copy or move the sandbox to the target directory
+ virdir = sandbox.get_virtual_directory()
self._export_artifact(tar, location, compression, target, hardlinks, virdir)
- except AttributeError as e:
- raise ArtifactError("Artifact reference '{}' seems to be invalid. "
- "Note that an Element name can also be used.".format(artifact))from e
- else:
- try:
- with target._prepare_sandbox(scope=scope, directory=None,
- integrate=integrate) as sandbox:
- # Copy or move the sandbox to the target directory
- virdir = sandbox.get_virtual_directory()
- self._export_artifact(tar, location, compression, target, hardlinks, virdir)
- except BstError as e:
- raise StreamError("Error while staging dependencies into a sandbox"
- ": '{}'".format(e), detail=e.detail, reason=e.reason) from e
+ except BstError as e:
+ raise StreamError("Error while staging dependencies into a sandbox"
+ ": '{}'".format(e), detail=e.detail, reason=e.reason) from e
def _export_artifact(self, tar, location, compression, target, hardlinks, virdir):
if not tar: