diff options
Diffstat (limited to 'src/buildstream/sandbox/_sandboxreapi.py')
-rw-r--r-- | src/buildstream/sandbox/_sandboxreapi.py | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/src/buildstream/sandbox/_sandboxreapi.py b/src/buildstream/sandbox/_sandboxreapi.py index fd63ec9cb..1785db662 100644 --- a/src/buildstream/sandbox/_sandboxreapi.py +++ b/src/buildstream/sandbox/_sandboxreapi.py @@ -119,36 +119,49 @@ class SandboxREAPI(Sandbox): # Request read-write directories as output output_directories = [os.path.relpath(dir, start=working_directory) for dir in read_write_directories] - # Get the custom platform properties, if specified. These are not filtered - platform_dict = self._get_custom_platform_properties() - - # Unless explicitly disabled, generate default platform properties - if self._use_default_platform_properties(): - config = self._get_config() - default_dict = {} - default_dict["OSFamily"] = config.build_os - default_dict["ISA"] = config.build_arch - - if flags & SandboxFlags.INHERIT_UID: - uid = os.geteuid() - gid = os.getegid() + # Get the SandoxConfig + config = self._get_config() + default_dict = {} + default_dict["OSFamily"] = config.build_os + default_dict["ISA"] = config.build_arch + + if flags & SandboxFlags.INHERIT_UID: + uid = os.geteuid() + gid = os.getegid() + else: + uid = config.build_uid + gid = config.build_gid + if uid is not None: + default_dict["unixUID"] = str(uid) + if gid is not None: + default_dict["unixGID"] = str(gid) + + if flags & SandboxFlags.NETWORK_ENABLED: + default_dict["network"] = "on" + # Remove unsupported platform properties from the default dict, this filter is derived from the + # local sandbox capabilities + supported_properties = self._supported_platform_properties() + platform_dict = {key: value for (key, value) in default_dict.items() if key in supported_properties} + + # Get the platform properties dict, if specified. These are not filtered as they are specific + # to the remote server + platform_properties = self._get_platform_properties() + + # Apply the properties to the default_dict. k:v pairs in the default_dict + # can be disabled if given a explicit value of `[]` in platform properties + # with a matching key. + for platform_property, value in platform_properties.items(): + if platform_property in platform_dict: + if value != []: + raise SandboxError( + "Platform Property {}:{} should be configured in sandbox config, not remote-execution.".format( + platform_property, value + ), + reason="invalid-platform-property", + ) + del platform_dict[platform_property] else: - uid = config.build_uid - gid = config.build_gid - if uid is not None: - default_dict["unixUID"] = str(uid) - if gid is not None: - default_dict["unixGID"] = str(gid) - - if flags & SandboxFlags.NETWORK_ENABLED: - default_dict["network"] = "on" - # Remove unsupported platform properties from the default dict - supported_properties = self._supported_platform_properties() - default_dict = {key: value for (key, value) in default_dict.items() if key in supported_properties} - - # Apply the defaults to the platform_dict. Default values take precedence - # on key collisions - platform_dict = {**platform_dict, **default_dict} + platform_dict[platform_property] = value # Create Platform message with properties sorted by name in code point order platform = remote_execution_pb2.Platform() @@ -208,12 +221,9 @@ class SandboxREAPI(Sandbox): def _supported_platform_properties(self): return {"OSFamily", "ISA"} - def _get_custom_platform_properties(self): + def _get_platform_properties(self): return {} - def _use_default_platform_properties(self): - return True - # _SandboxREAPIBatch() # |