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 842129e214449a57247d659a050e606a12cbea65 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 | 33 ++++++++++++++++++++++---- src/buildstream/sandbox/_sandboxbuildboxrun.py | 3 +++ src/buildstream/sandbox/_sandboxreapi.py | 3 +++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/buildstream/sandbox/_config.py b/src/buildstream/sandbox/_config.py index 654f16454..587e7a4ca 100644 --- a/src/buildstream/sandbox/_config.py +++ b/src/buildstream/sandbox/_config.py @@ -45,12 +45,19 @@ 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 ): 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 # to_dict(): # @@ -66,7 +73,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 +81,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 +94,9 @@ 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 + return sandbox_dict # new_from_node(): @@ -108,7 +118,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 +142,17 @@ 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"]) + remote_apis_socket_path = remote_apis_socket.get_str("path") + else: + remote_apis_socket_path = None + + 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, + ) diff --git a/src/buildstream/sandbox/_sandboxbuildboxrun.py b/src/buildstream/sandbox/_sandboxbuildboxrun.py index 25d200262..5ba3d7727 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() diff --git a/src/buildstream/sandbox/_sandboxreapi.py b/src/buildstream/sandbox/_sandboxreapi.py index 17997b355..262cb3f04 100644 --- a/src/buildstream/sandbox/_sandboxreapi.py +++ b/src/buildstream/sandbox/_sandboxreapi.py @@ -131,6 +131,9 @@ 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) + # Create Platform message with properties sorted by name in code point order platform = remote_execution_pb2.Platform() for key, value in sorted(platform_dict.items()):
