This is an automated email from the ASF dual-hosted git repository.

juergbi pushed a commit to branch jbilleter/digest-environment
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 8bcbde0538af850f9594e3523aa2d44fbf0850e5
Author: Abderrahim Kitouni <[email protected]>
AuthorDate: Wed Jul 9 10:11:45 2025 +0100

    sandbox.py: add method to create a sub-sandbox
    
    This allows an element to use a secondary sandbox for manipulating artifacts
    that doesn't affect the build
---
 src/buildstream/sandbox/sandbox.py | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/buildstream/sandbox/sandbox.py 
b/src/buildstream/sandbox/sandbox.py
index a503ac9f7..6483792d4 100644
--- a/src/buildstream/sandbox/sandbox.py
+++ b/src/buildstream/sandbox/sandbox.py
@@ -85,13 +85,18 @@ class Sandbox:
         self.__env = None  # type: Optional[Dict[str, str]]
         self.__mount_sources = {}  # type: Dict[str, str]
         self.__allow_run = True
+        self.__subsandboxes = []  # type: List[Sandbox]
 
         # Plugin element full name for logging
         plugin = kwargs.get("plugin", None)
         if plugin:
             self.__element_name = plugin._get_full_name()
         else:
-            self.__element_name = None
+            parent = kwargs.get("parent", None)
+            if parent:
+                self.__element_name = parent._get_element_name()
+            else:
+                self.__element_name = None
 
         # Configuration from kwargs common to all subclasses
         self.__config = kwargs["config"]
@@ -264,6 +269,24 @@ class Sandbox:
 
             batch.execute()
 
+    def create_subsandbox(self, **kwargs):
+        """Create an empty sandbox
+
+        This allows an element to use a secondary sandbox for manipulating 
artifacts
+        that does not affect the build sandbox
+        """
+
+        sub = Sandbox(
+            self.__context,
+            self.__project,
+            parent=self,
+            stdout=self.__stdout,
+            stderr=self.__stderr,
+            config=self.__config,
+        )
+        self.__subsandboxes.append(sub)
+        return sub
+
     #####################################################
     #    Abstract Methods for Sandbox implementations   #
     #####################################################
@@ -558,6 +581,9 @@ class Sandbox:
     def _disable_run(self):
         self.__allow_run = False
 
+    def _get_subsandboxes(self):
+        return self.__subsandboxes
+
 
 # SandboxFlags()
 #

Reply via email to