summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim MacArthur <jim.macarthur@codethink.co.uk>2018-07-03 17:55:54 +0100
committerMartin Blanchard <martin.blanchard@codethink.co.uk>2018-09-07 13:57:29 +0100
commite7659c298ee0a251cacb3689cd7fd951ecbea219 (patch)
tree6e2bdece5721e1b7cdb4607755d05dfdfdbc761e
parent853e0af71f1bf2b0793ebbc3b7dfd7a44ceae8a3 (diff)
downloadbuildstream-e7659c298ee0a251cacb3689cd7fd951ecbea219.tar.gz
sandbox.py: Allow setting the virtual directory
This is for use after remote execution has finished, since remote execution produces a new output directory rather than modifying the initial directory. https://gitlab.com/BuildStream/buildstream/issues/454
-rw-r--r--buildstream/buildelement.py3
-rw-r--r--buildstream/sandbox/sandbox.py23
2 files changed, 23 insertions, 3 deletions
diff --git a/buildstream/buildelement.py b/buildstream/buildelement.py
index 180bb86ab..5447c13be 100644
--- a/buildstream/buildelement.py
+++ b/buildstream/buildelement.py
@@ -155,6 +155,9 @@ class BuildElement(Element):
command_dir = build_root
sandbox.set_work_directory(command_dir)
+ # Tell sandbox which directory is preserved in the finished artifact
+ sandbox.set_output_directory(install_root)
+
# Setup environment
sandbox.set_environment(self.get_environment())
diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py
index 87a2fb9c9..9d34f0195 100644
--- a/buildstream/sandbox/sandbox.py
+++ b/buildstream/sandbox/sandbox.py
@@ -99,9 +99,11 @@ class Sandbox():
self.__stdout = kwargs['stdout']
self.__stderr = kwargs['stderr']
- # Setup the directories. Root should be available to subclasses, hence
- # being single-underscore. The others are private to this class.
+ # Setup the directories. Root and output_directory should be
+ # available to subclasses, hence being single-underscore. The
+ # others are private to this class.
self._root = os.path.join(directory, 'root')
+ self._output_directory = None
self.__directory = directory
self.__scratch = os.path.join(self.__directory, 'scratch')
for directory_ in [self._root, self.__scratch]:
@@ -144,11 +146,17 @@ class Sandbox():
self._vdir = FileBasedDirectory(self._root)
return self._vdir
+ def _set_virtual_directory(self, virtual_directory):
+ """ Sets virtual directory. Useful after remote execution
+ has rewritten the working directory.
+ """
+ self._vdir = virtual_directory
+
def set_environment(self, environment):
"""Sets the environment variables for the sandbox
Args:
- directory (dict): The environment variables to use in the sandbox
+ environment (dict): The environment variables to use in the sandbox
"""
self.__env = environment
@@ -160,6 +168,15 @@ class Sandbox():
"""
self.__cwd = directory
+ def set_output_directory(self, directory):
+ """Sets the output directory - the directory which is preserved
+ as an artifact after assembly.
+
+ Args:
+ directory (str): An absolute path within the sandbox
+ """
+ self._output_directory = directory
+
def mark_directory(self, directory, *, artifact=False):
"""Marks a sandbox directory and ensures it will exist