summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim MacArthur <jim.macarthur@codethink.co.uk>2018-08-01 17:10:04 +0100
committerJim MacArthur <jim.macarthur@codethink.co.uk>2018-08-15 15:33:05 +0100
commit0213f68daef57be6745a0d554d31bfc8e9ee1271 (patch)
tree262b142ff2648bfb568eff9f0b8e42ae485a6de1
parent0063210825651df13a6a38584661fbe4c73a734b (diff)
downloadbuildstream-0213f68daef57be6745a0d554d31bfc8e9ee1271.tar.gz
Sandbox: Return a CasBasedDirectory when an environment variable is set
-rw-r--r--buildstream/sandbox/sandbox.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py
index 9fe1194bb..87a2fb9c9 100644
--- a/buildstream/sandbox/sandbox.py
+++ b/buildstream/sandbox/sandbox.py
@@ -31,6 +31,7 @@ See also: :ref:`sandboxing`.
import os
from .._exceptions import ImplError, BstError
from ..storage._filebaseddirectory import FileBasedDirectory
+from ..storage._casbaseddirectory import CasBasedDirectory
class SandboxFlags():
@@ -105,6 +106,7 @@ class Sandbox():
self.__scratch = os.path.join(self.__directory, 'scratch')
for directory_ in [self._root, self.__scratch]:
os.makedirs(directory_, exist_ok=True)
+ self._vdir = None
def get_directory(self):
"""Fetches the sandbox root directory
@@ -133,8 +135,14 @@ class Sandbox():
(str): The sandbox root directory
"""
- # For now, just create a new Directory every time we're asked
- return FileBasedDirectory(self._root)
+ if not self._vdir:
+ # BST_CAS_DIRECTORIES is a deliberately hidden environment variable which
+ # can be used to switch on CAS-based directories for testing.
+ if 'BST_CAS_DIRECTORIES' in os.environ:
+ self._vdir = CasBasedDirectory(self.__context, ref=None)
+ else:
+ self._vdir = FileBasedDirectory(self._root)
+ return self._vdir
def set_environment(self, environment):
"""Sets the environment variables for the sandbox