You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ak...@apache.org on 2025/07/10 07:08:33 UTC

(buildstream) branch abderrahim/digest-environment created (now a525a2b2b)

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

akitouni pushed a change to branch abderrahim/digest-environment
in repository https://gitbox.apache.org/repos/asf/buildstream.git


      at a525a2b2b _sandboxremote.py: Upload blobs for subsandbox roots

This branch includes the following new commits:

     new 3c69a85a4 sandbox.py: add method to create a sub-sandbox
     new 698b9809b buildelement: Add the digest-environment config property
     new a525a2b2b _sandboxremote.py: Upload blobs for subsandbox roots

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(buildstream) 03/03: _sandboxremote.py: Upload blobs for subsandbox roots

Posted by ak...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a525a2b2b6af078d05e354c81298b765793d7ccd
Author: Abderrahim Kitouni <ab...@codethink.co.uk>
AuthorDate: Wed Jul 9 10:16:41 2025 +0100

    _sandboxremote.py: Upload blobs for subsandbox roots
    
    The subsandboxes can be used to extract a CAS digest that could be used for
    nested remote execution, and thus need to be available in the remote execution
    CAS.
---
 src/buildstream/sandbox/_sandboxremote.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/buildstream/sandbox/_sandboxremote.py b/src/buildstream/sandbox/_sandboxremote.py
index 1b72f8718..9deb87943 100644
--- a/src/buildstream/sandbox/_sandboxremote.py
+++ b/src/buildstream/sandbox/_sandboxremote.py
@@ -261,9 +261,17 @@ class SandboxRemote(SandboxREAPI):
                 "Uploading input root", element_name=self._get_element_name()
             ):
                 # Determine blobs missing on remote
+                root_digests = [action.input_root_digest]
+
+                # Add virtual directories for subsandboxes
+                for subsandbox in self._get_subsandboxes():
+                    vdir = subsandbox.get_virtual_directory()
+                    root_digests.append(vdir._get_digest())
+
+                missing_blobs = []
                 try:
-                    input_root_digest = action.input_root_digest
-                    missing_blobs = list(cascache.missing_blobs_for_directory(input_root_digest, remote=casremote))
+                    for root_digest in root_digests:
+                        missing_blobs.extend(cascache.missing_blobs_for_directory(root_digest, remote=casremote))
                 except grpc.RpcError as e:
                     raise SandboxError("Failed to determine missing blobs: {}".format(e)) from e
 


(buildstream) 02/03: buildelement: Add the digest-environment config property

Posted by ak...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 698b9809bcb3a92c3ede42e8fa71d42a9763d1b5
Author: Abderrahim Kitouni <ab...@codethink.co.uk>
AuthorDate: Tue Jun 17 17:02:10 2025 +0100

    buildelement: Add the digest-environment config property
    
    This allows setting an environment variable inside the sandbox to the CAS
    digest of one or more dependencies.
    
    Co-authored by: Adrien Plazas <ad...@codethink.co.uk>
---
 src/buildstream/buildelement.py | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/buildstream/buildelement.py b/src/buildstream/buildelement.py
index 40355f5cf..06ea67f37 100644
--- a/src/buildstream/buildelement.py
+++ b/src/buildstream/buildelement.py
@@ -219,6 +219,7 @@ class BuildElement(Element):
     def configure_dependencies(self, dependencies):
 
         self.__layout = {}  # pylint: disable=attribute-defined-outside-init
+        self.__digest_environment = {}  # pylint: disable=attribute-defined-outside-init
 
         # FIXME: Currently this forcefully validates configurations
         #        for all BuildElement subclasses so they are unable to
@@ -227,9 +228,18 @@ class BuildElement(Element):
         for dep in dependencies:
             # Determine the location to stage each element, default is "/"
             location = "/"
+
             if dep.config:
-                dep.config.validate_keys(["location"])
-                location = dep.config.get_str("location")
+                dep.config.validate_keys(["digest-environment", "location"])
+
+                location = dep.config.get_str("location", "/")
+
+                digest_var_name = dep.config.get_str("digest-environment", None)
+
+                if digest_var_name is not None:
+                    element_list = self.__digest_environment.setdefault(digest_var_name, [])
+                    element_list.append(dep.element)
+
             try:
                 element_list = self.__layout[location]
             except KeyError:
@@ -285,10 +295,17 @@ class BuildElement(Element):
             command_dir = build_root
         sandbox.set_work_directory(command_dir)
 
+    def stage(self, sandbox):
         # Setup environment
-        sandbox.set_environment(self.get_environment())
+        env = self.get_environment()
 
-    def stage(self, sandbox):
+        for digest_variable, element_list in self.__digest_environment.items():
+            subsandbox = sandbox.create_subsandbox()
+            self.stage_dependency_artifacts(subsandbox, element_list)
+            digest = subsandbox.get_virtual_directory()._get_digest()
+            env[digest_variable] = "{}/{}".format(digest.hash, digest.size_bytes)
+
+        sandbox.set_environment(env)
 
         # First stage it all
         #


(buildstream) 01/03: sandbox.py: add method to create a sub-sandbox

Posted by ak...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3c69a85a40ba85b86135ffc3faabb02b50c4b9fd
Author: Abderrahim Kitouni <ab...@codethink.co.uk>
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 505cc5c1a..36cde8b85 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   #
     #####################################################
@@ -565,6 +588,9 @@ class Sandbox:
     def _disable_run(self):
         self.__allow_run = False
 
+    def _get_subsandboxes(self):
+        return self.__subsandboxes
+
 
 # SandboxFlags()
 #