summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildstream/element.py4
-rw-r--r--buildstream/sandbox/sandbox.py22
2 files changed, 16 insertions, 10 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index f9e3c191b..74deda384 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1532,8 +1532,6 @@ class Element(Plugin):
with _signals.terminator(cleanup_rootdir), \
self.__sandbox(rootdir, output_file, output_file, self.__sandbox_config) as sandbox: # nopep8
- sandbox_vroot = sandbox.get_virtual_directory()
-
# By default, the dynamic public data is the same as the static public data.
# The plugin's assemble() method may modify this, though.
self.__dynamic_public = _yaml.node_copy(self.__public)
@@ -1581,7 +1579,6 @@ class Element(Plugin):
finally:
if collect is not None:
try:
- # Sandbox will probably have replaced its virtual directory, so get it again
sandbox_vroot = sandbox.get_virtual_directory()
collectvdir = sandbox_vroot.descend(collect.lstrip(os.sep).split(os.sep))
except VirtualDirectoryError:
@@ -1606,6 +1603,7 @@ class Element(Plugin):
collectvdir.export_files(filesdir, can_link=True)
try:
+ sandbox_vroot = sandbox.get_virtual_directory()
sandbox_build_dir = sandbox_vroot.descend(
self.get_variable('build-root').lstrip(os.sep).split(os.sep))
# Hard link files from build-root dir to buildtreedir directory
diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py
index 9d0b69b73..42cfb9a15 100644
--- a/buildstream/sandbox/sandbox.py
+++ b/buildstream/sandbox/sandbox.py
@@ -110,6 +110,10 @@ class Sandbox():
os.makedirs(directory_, exist_ok=True)
self._vdir = None
+ # This is set if anyone requests access to the underlying
+ # directory via get_directory.
+ self._never_cache_vdirs = False
+
def get_directory(self):
"""Fetches the sandbox root directory
@@ -122,24 +126,28 @@ class Sandbox():
"""
if self.__allow_real_directory:
+ self._never_cache_vdirs = True
return self._root
else:
raise BstError("You can't use get_directory")
def get_virtual_directory(self):
- """Fetches the sandbox root directory
+ """Fetches the sandbox root directory as a virtual Directory.
The root directory is where artifacts for the base
- runtime environment should be staged. Only works if
- BST_VIRTUAL_DIRECTORY is not set.
+ runtime environment should be staged.
+
+ Use caution if you use get_directory and
+ get_virtual_directory. If you alter the contents of the
+ directory returned by get_directory, all objects returned by
+ get_virtual_directory or derived from them are invalid and you
+ must call get_virtual_directory again to get a new copy.
Returns:
- (str): The sandbox root directory
+ (Directory): The sandbox root directory
"""
- 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 self._vdir is None or self._never_cache_vdirs:
if 'BST_CAS_DIRECTORIES' in os.environ:
self._vdir = CasBasedDirectory(self.__context, ref=None)
else: