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

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

commit 7d35b1312a12884a998a949ea4abf7b96a0a46b8
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Jul 25 15:33:05 2025 +0200

    element.py: Use sandbox environment for logging and shell
    
    Elements can configure additional environment variables in
    `configure_sandbox()`, which will be used by `BuildElement` to support
    `digest-environment`. Use the complete environment for logging and
    `bst shell`.
---
 src/buildstream/element.py         | 12 ++++++------
 src/buildstream/sandbox/sandbox.py | 10 ++++++++++
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index cb680ad38..f267ce7e3 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -1663,11 +1663,6 @@ class Element(Plugin):
         # Assert call ordering
         assert not self._cached_success()
 
-        # Print the environment at the beginning of the log file.
-        env_dump = _yaml.roundtrip_dump_string(self.get_environment())
-
-        self.log("Build environment for element {}".format(self.name), 
detail=env_dump)
-
         context = self._get_context()
         with self._output_file() as output_file:
 
@@ -1693,6 +1688,11 @@ class Element(Plugin):
 
                 # Step 1 - Configure
                 self.__configure_sandbox(sandbox)
+
+                # Print the environment at the beginning of the log file.
+                env_dump = 
_yaml.roundtrip_dump_string(sandbox._get_configured_environment() or 
self.get_environment())
+                self.log("Build environment for element {}".format(self.name), 
detail=env_dump)
+
                 # Step 2 - Stage
                 self.__stage(sandbox)
                 try:
@@ -2037,7 +2037,7 @@ class Element(Plugin):
     def _shell(self, scope=None, *, mounts=None, isolate=False, prompt=None, 
command=None, usebuildtree=False):
 
         with self._prepare_sandbox(scope, shell=True, 
usebuildtree=usebuildtree) as sandbox:
-            environment = self.get_environment()
+            environment = sandbox._get_configured_environment() or 
self.get_environment()
             environment = copy.copy(environment)
             flags = _SandboxFlags.INTERACTIVE | _SandboxFlags.ROOT_READ_ONLY
 
diff --git a/src/buildstream/sandbox/sandbox.py 
b/src/buildstream/sandbox/sandbox.py
index a503ac9f7..3d3164f67 100644
--- a/src/buildstream/sandbox/sandbox.py
+++ b/src/buildstream/sandbox/sandbox.py
@@ -438,6 +438,16 @@ class Sandbox:
 
         return env
 
+    # _get_configured_environment()
+    #
+    # Return the environment exactly as configured with `set_environment()`,
+    # or `None` if `set_environment()` has not been called.
+    #
+    # Returns
+    #   (Dict[str, str]): The configured environment
+    def _get_configured_environment(self):
+        return self.__env
+
     # _get_work_directory()
     #
     # Fetches the working directory for running commands

Reply via email to