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

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

commit 1352cb5890088ec8ea00227af83bff2e2460bd92
Author: Jürg Billeter <[email protected]>
AuthorDate: Fri May 2 16:57:24 2025 +0200

    sandbox: Add support for `remote-apis-socket`
---
 src/buildstream/sandbox/_config.py             | 26 +++++++++++++++++++++-----
 src/buildstream/sandbox/_sandboxbuildboxrun.py |  5 ++++-
 src/buildstream/sandbox/_sandboxreapi.py       |  5 +++++
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/src/buildstream/sandbox/_config.py 
b/src/buildstream/sandbox/_config.py
index 654f16454..b8c43adc7 100644
--- a/src/buildstream/sandbox/_config.py
+++ b/src/buildstream/sandbox/_config.py
@@ -45,12 +45,14 @@ if TYPE_CHECKING:
 #
 class SandboxConfig:
     def __init__(
-        self, *, build_os: str, build_arch: str, build_uid: Optional[int] = 
None, build_gid: Optional[int] = None
+        self, *, build_os: str, build_arch: str, build_uid: Optional[int] = 
None, build_gid: Optional[int] = None, remote_apis_socket_path: Optional[str] = 
None, remote_apis_socket_action_cache_update_enabled: bool = False
     ):
         self.build_os = build_os
         self.build_arch = build_arch
         self.build_uid = build_uid
         self.build_gid = build_gid
+        self.remote_apis_socket_path = remote_apis_socket_path
+        self.remote_apis_socket_action_cache_update_enabled = 
remote_apis_socket_action_cache_update_enabled
 
     # to_dict():
     #
@@ -66,7 +68,7 @@ class SandboxConfig:
     # Returns:
     #    A dictionary representation of this SandboxConfig
     #
-    def to_dict(self) -> Dict[str, Union[str, int]]:
+    def to_dict(self) -> Dict[str, Union[str, int, bool]]:
 
         # Assign mandatory portions of the sandbox configuration
         #
@@ -74,7 +76,7 @@ class SandboxConfig:
         #     the sandbox configuration, as that would result in
         #     breaking cache key stability.
         #
-        sandbox_dict: Dict[str, Union[str, int]] = {"build-os": self.build_os, 
"build-arch": self.build_arch}
+        sandbox_dict: Dict[str, Union[str, int, bool]] = {"build-os": 
self.build_os, "build-arch": self.build_arch}
 
         # Assign optional portions of the sandbox configuration
         #
@@ -87,6 +89,11 @@ class SandboxConfig:
         if self.build_gid is not None:
             sandbox_dict["build-gid"] = self.build_gid
 
+        if self.remote_apis_socket_path is not None:
+            sandbox_dict["remote-apis-socket-path"] = 
self.remote_apis_socket_path
+            if self.remote_apis_socket_action_cache_update_enabled:
+                sandbox_dict["remote-apis-socket-action-cache-update-enabled"] 
= True
+
         return sandbox_dict
 
     # new_from_node():
@@ -108,7 +115,7 @@ class SandboxConfig:
     #
     @classmethod
     def new_from_node(cls, config: "MappingNode[Node]", *, platform: 
Optional[Platform] = None) -> "SandboxConfig":
-        config.validate_keys(["build-uid", "build-gid", "build-os", 
"build-arch"])
+        config.validate_keys(["build-uid", "build-gid", "build-os", 
"build-arch", "remote-apis-socket"])
 
         build_os: str
         build_arch: str
@@ -132,4 +139,13 @@ class SandboxConfig:
         build_uid = config.get_int("build-uid", None)
         build_gid = config.get_int("build-gid", None)
 
-        return cls(build_os=build_os, build_arch=build_arch, 
build_uid=build_uid, build_gid=build_gid)
+        remote_apis_socket = config.get_mapping("remote-apis-socket", 
default=None)
+        if remote_apis_socket:
+            remote_apis_socket.validate_keys(["path", 
"action-cache-update-enabled"])
+            remote_apis_socket_path = remote_apis_socket.get_str("path")
+            remote_apis_socket_action_cache_update_enabled = 
remote_apis_socket.get_bool("action-cache-update-enabled", default=False)
+        else:
+            remote_apis_socket_path = None
+            remote_apis_socket_action_cache_update_enabled = False
+
+        return cls(build_os=build_os, build_arch=build_arch, 
build_uid=build_uid, build_gid=build_gid, 
remote_apis_socket_path=remote_apis_socket_path, 
remote_apis_socket_action_cache_update_enabled=remote_apis_socket_action_cache_update_enabled)
diff --git a/src/buildstream/sandbox/_sandboxbuildboxrun.py 
b/src/buildstream/sandbox/_sandboxbuildboxrun.py
index d6eb2dc2d..83612cd42 100644
--- a/src/buildstream/sandbox/_sandboxbuildboxrun.py
+++ b/src/buildstream/sandbox/_sandboxbuildboxrun.py
@@ -83,6 +83,9 @@ class SandboxBuildBoxRun(SandboxREAPI):
         if config.build_gid is not None and "platform:unixGID" not in 
cls._capabilities:
             raise SandboxUnavailableError("Configuring sandbox GID is not 
supported by buildbox-run.")
 
+        if config.remote_apis_socket_path is not None and 
"platform:remoteApisSocketPath" not in cls._capabilities:
+            raise SandboxUnavailableError("Configuring Remote APIs socket path 
is not supported by buildbox-run.")
+
     def _execute_action(self, action, flags):
         stdout, stderr = self._get_output()
 
@@ -240,4 +243,4 @@ class SandboxBuildBoxRun(SandboxREAPI):
                 raise SandboxError("buildbox-run failed with returncode 
{}".format(returncode))
 
     def _supported_platform_properties(self):
-        return {"OSFamily", "ISA", "unixUID", "unixGID", "network"}
+        return {"OSFamily", "ISA", "unixUID", "unixGID", "network", 
"remoteApisSocketPath", "remoteApisSocketFeatures"}
diff --git a/src/buildstream/sandbox/_sandboxreapi.py 
b/src/buildstream/sandbox/_sandboxreapi.py
index 34b6c8892..fd00b2ff8 100644
--- a/src/buildstream/sandbox/_sandboxreapi.py
+++ b/src/buildstream/sandbox/_sandboxreapi.py
@@ -131,6 +131,11 @@ class SandboxREAPI(Sandbox):
         if flags & _SandboxFlags.NETWORK_ENABLED:
             platform_dict["network"] = "on"
 
+        if config.remote_apis_socket_path:
+            platform_dict["remoteApisSocketPath"] = 
config.remote_apis_socket_path.lstrip(os.path.sep)
+            if config.remote_apis_socket_action_cache_update_enabled:
+                platform_dict["remoteApisSocketFeatures"] = 
"ActionCacheUpdateEnabled"
+
         # Remove unsupported platform properties from the dict
         supported_properties = self._supported_platform_properties()
         platform_dict = {key: value for (key, value) in platform_dict.items() 
if key in supported_properties}

Reply via email to