From 1798559c95c11582afbecd975d811a157d231280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Sat, 2 Mar 2019 09:41:05 +0100 Subject: sandbox.py: Add _disable_run() method This enables use of CasBasedDirectory for faster staging when command execution is not required. --- buildstream/sandbox/sandbox.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/buildstream/sandbox/sandbox.py b/buildstream/sandbox/sandbox.py index 7b10008bc..f11ddea1d 100644 --- a/buildstream/sandbox/sandbox.py +++ b/buildstream/sandbox/sandbox.py @@ -117,6 +117,7 @@ class Sandbox(): self.__env = None self.__mount_sources = {} self.__allow_real_directory = kwargs['allow_real_directory'] + self.__allow_run = True # Plugin ID for logging plugin = kwargs.get('plugin', None) @@ -279,6 +280,9 @@ class Sandbox(): not exist yet, even if a workspace is being used. """ + if not self.__allow_run: + raise SandboxError("Sandbox.run() has been disabled") + # Fallback to the sandbox default settings for # the cwd and env. # @@ -396,6 +400,11 @@ class Sandbox(): # (bool): Whether to use CasBasedDirectory # def _use_cas_based_directory(self): + # Use CasBasedDirectory as sandbox root if neither Sandbox.get_directory() + # nor Sandbox.run() are required. This allows faster staging. + if not self.__allow_real_directory and not self.__allow_run: + return True + return 'BST_CAS_DIRECTORIES' in os.environ ################################################ @@ -574,6 +583,15 @@ class Sandbox(): else: callback() + # _disable_run() + # + # Raise exception if `Sandbox.run()` is called. This enables use of + # CasBasedDirectory for faster staging when command execution is not + # required. + # + def _disable_run(self): + self.__allow_run = False + # _SandboxBatch() # -- cgit v1.2.1