From 405396cfe8139f81ebc0bf4a2cf716d7a5df4273 Mon Sep 17 00:00:00 2001 From: Abderrahim Kitouni Date: Sun, 17 Nov 2019 10:06:28 +0100 Subject: element.py: add configuration for sandbox architecture and os based on 1ad35fcd1bbb4a89e177da44303cf95e5a3b659d --- buildstream/_versions.py | 2 +- buildstream/element.py | 11 ++++++++--- buildstream/sandbox/_config.py | 10 +++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/buildstream/_versions.py b/buildstream/_versions.py index 383429902..2110c2889 100644 --- a/buildstream/_versions.py +++ b/buildstream/_versions.py @@ -23,7 +23,7 @@ # This version is bumped whenever enhancements are made # to the `project.conf` format or the core element format. # -BST_FORMAT_VERSION = 17 +BST_FORMAT_VERSION = 18 # The base BuildStream artifact version diff --git a/buildstream/element.py b/buildstream/element.py index af0c1a27c..f442d9c85 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -2254,6 +2254,8 @@ class Element(Plugin): project.ensure_fully_loaded() sandbox_config = _yaml.node_chain_copy(project._sandbox) + host_os, _, _, _, host_arch = os.uname() + # The default config is already composited with the project overrides sandbox_defaults = _yaml.node_get(self.__defaults, Mapping, 'sandbox', default_value={}) sandbox_defaults = _yaml.node_chain_copy(sandbox_defaults) @@ -2263,10 +2265,13 @@ class Element(Plugin): _yaml.node_final_assertions(sandbox_config) # Sandbox config, unlike others, has fixed members so we should validate them - _yaml.node_validate(sandbox_config, ['build-uid', 'build-gid']) + _yaml.node_validate(sandbox_config, ['build-uid', 'build-gid', 'build-os', 'build-arch']) - return SandboxConfig(self.node_get_member(sandbox_config, int, 'build-uid'), - self.node_get_member(sandbox_config, int, 'build-gid')) + return SandboxConfig( + int(self.node_subst_member(sandbox_config, 'build-uid')), + int(self.node_subst_member(sandbox_config, 'build-gid')), + self.node_subst_member(sandbox_config, 'build-os', default=host_os), + self.node_subst_member(sandbox_config, 'build-arch', default=host_arch)) # This makes a special exception for the split rules, which # elements may extend but whos defaults are defined in the project. diff --git a/buildstream/sandbox/_config.py b/buildstream/sandbox/_config.py index 5debe24b2..457f92b3c 100644 --- a/buildstream/sandbox/_config.py +++ b/buildstream/sandbox/_config.py @@ -16,7 +16,6 @@ # # Authors: # Jim MacArthur -import os # SandboxConfig @@ -24,9 +23,11 @@ import os # A container for sandbox configuration data. We want the internals # of this to be opaque, hence putting it in its own private file. class SandboxConfig(): - def __init__(self, build_uid, build_gid): + def __init__(self, build_uid, build_gid, build_os=None, build_arch=None): self.build_uid = build_uid self.build_gid = build_gid + self.build_os = build_os + self.build_arch = build_arch # get_unique_key(): # @@ -45,10 +46,9 @@ class SandboxConfig(): # However this should be the right place to support # such configurations in the future. # - operating_system, _, _, _, machine_arch = os.uname() unique_key = { - 'os': operating_system, - 'arch': machine_arch + 'os': self.build_os, + 'arch': self.build_arch } # Avoid breaking cache key calculation with -- cgit v1.2.1 From d70ff708945ef8c0fff99cd217b2801fdaeeacc6 Mon Sep 17 00:00:00 2001 From: Abderrahim Kitouni Date: Sat, 16 May 2020 18:59:36 +0100 Subject: sandbox: check for os and architecture only allow builds of the same os and architecture and 32-bit on 64-bit based on e5d8c7d8a0ddbee8ff14 and b0603fb014c51660860c --- buildstream/sandbox/_sandboxbwrap.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/buildstream/sandbox/_sandboxbwrap.py b/buildstream/sandbox/_sandboxbwrap.py index 450f1913f..7aa8f31c8 100644 --- a/buildstream/sandbox/_sandboxbwrap.py +++ b/buildstream/sandbox/_sandboxbwrap.py @@ -53,6 +53,25 @@ class SandboxBwrap(Sandbox): super().__init__(*args, **kwargs) self.user_ns_available = kwargs['user_ns_available'] self.die_with_parent_available = kwargs['die_with_parent_available'] + self.linux32 = False + + host_os, _, _, _, host_arch = os.uname() + config = self._get_config() + + # We can't do builds for another host or architecture except 32 bit on 64 bit + if config.build_os != host_os: + raise SandboxError("Configured and host OS don't match.") + elif config.build_arch != host_arch: + if ((config.build_arch == "i686" and host_arch == "x86_64") or + (config.build_arch == "armv7l" and host_arch == "aarch64")): + # check whether linux32 is available + try: + utils.get_host_tool('linux32') + self._linux32 = True + except utils.ProgramNotFoundError: + raise SandboxError("Configured and host architecture don't match.") + else: + raise SandboxError("Configured and host architecture don't match.") def run(self, command, flags, *, cwd=None, env=None): stdout, stderr = self._get_output() @@ -84,8 +103,14 @@ class SandboxBwrap(Sandbox): if cwd is None: cwd = '/' + # start command with linux32 if needed + if self.linux32: + bwrap_command = [utils.get_host_tool('linux32')] + else: + bwrap_command = [] + # Grab the full path of the bwrap binary - bwrap_command = [utils.get_host_tool('bwrap')] + bwrap_command += [utils.get_host_tool('bwrap')] for k, v in env.items(): bwrap_command += ['--setenv', k, v] -- cgit v1.2.1