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

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

commit d48d2608482a34e6985b785b1dc08bf4b92dfd4f
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 don't affect the build.
---
 src/buildstream/sandbox/sandbox.py | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/buildstream/sandbox/sandbox.py 
b/src/buildstream/sandbox/sandbox.py
index 3d3164f67..e266a95c3 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"]
@@ -568,6 +573,28 @@ class Sandbox:
     def _disable_run(self):
         self.__allow_run = False
 
+    # _create_subsandbox()
+    #
+    # Create an empty sandbox
+    #
+    # This allows an element to use a secondary sandbox for manipulating 
artifacts
+    # that does not affect the build sandbox.
+    #
+    def _create_subsandbox(self, **kwargs):
+        sub = Sandbox(
+            self.__context,
+            self.__project,
+            parent=self,
+            stdout=self.__stdout,
+            stderr=self.__stderr,
+            config=self.__config,
+        )
+        self.__subsandboxes.append(sub)
+        return sub
+
+    def _get_subsandboxes(self):
+        return self.__subsandboxes
+
 
 # SandboxFlags()
 #

Reply via email to