Commit b0603fb0 authored by Raoul Hidalgo Charman's avatar Raoul Hidalgo Charman
Browse files

Sandbox: use linux32 for x86-32 builds on x86-64 machines

  o _platform/linux.py: Add linux32 flag to send to sandbox bwrap when the
    build arch is x86-32 and the machines arch is x86-64 or similarly with
    aarch32 and aarch64.
  o sandbox/_sandboxbwrap.py: Use flag passed to start bwrap command with
    linux32 if set.
parent e5d8c7d8
Loading
Loading
Loading
Loading
+22 −4
Original line number Original line Diff line number Diff line
@@ -59,6 +59,9 @@ class Linux(Platform):
        else:
        else:
            self._user_ns_available = False
            self._user_ns_available = False


        # Set linux32 option
        self._linux32 = False

    def create_sandbox(self, *args, **kwargs):
    def create_sandbox(self, *args, **kwargs):
        if not self._local_sandbox_available:
        if not self._local_sandbox_available:
            return self._create_dummy_sandbox(*args, **kwargs)
            return self._create_dummy_sandbox(*args, **kwargs)
@@ -78,11 +81,25 @@ class Linux(Platform):
            # will match the host UID/GID.
            # will match the host UID/GID.
            return False
            return False


        # We can't do builds for another host or architecture
        # We can't do builds for another host or architecture except x86-32 on
        if config.build_os != self.get_host_os():
        # x86-64
        host_os = self.get_host_os()
        host_arch = self.get_host_arch()
        if config.build_os != host_os:
            raise PlatformError("Configured and host OS don't match.")
            raise PlatformError("Configured and host OS don't match.")
        elif config.build_arch != self.get_host_arch():
        elif config.build_arch != host_arch:
            raise PlatformError("Configured and host architecture don't match.")
            # We can use linux32 for building 32bit on 64bit machines
            if (host_os == "Linux" and
                    ((config.build_arch == "x86-32" and host_arch == "x86-64") or
                     (config.build_arch == "aarch32" and host_arch == "aarch64"))):
                # check linux32 is available
                try:
                    utils.get_host_tool('linux32')
                    self._linux32 = True
                except utils.ProgramNotFoundError:
                    pass
            else:
                raise PlatformError("Configured architecture and host architecture don't match.")


        return True
        return True


@@ -109,6 +126,7 @@ class Linux(Platform):
        kwargs['user_ns_available'] = self._user_ns_available
        kwargs['user_ns_available'] = self._user_ns_available
        kwargs['die_with_parent_available'] = self._die_with_parent_available
        kwargs['die_with_parent_available'] = self._die_with_parent_available
        kwargs['json_status_available'] = self._json_status_available
        kwargs['json_status_available'] = self._json_status_available
        kwargs['linux32'] = self._linux32
        return SandboxBwrap(*args, **kwargs)
        return SandboxBwrap(*args, **kwargs)


    def _check_user_ns_available(self):
    def _check_user_ns_available(self):
+8 −1
Original line number Original line Diff line number Diff line
@@ -57,6 +57,7 @@ class SandboxBwrap(Sandbox):
        self.user_ns_available = kwargs['user_ns_available']
        self.user_ns_available = kwargs['user_ns_available']
        self.die_with_parent_available = kwargs['die_with_parent_available']
        self.die_with_parent_available = kwargs['die_with_parent_available']
        self.json_status_available = kwargs['json_status_available']
        self.json_status_available = kwargs['json_status_available']
        self.linux32 = kwargs['linux32']


    def _run(self, command, flags, *, cwd, env):
    def _run(self, command, flags, *, cwd, env):
        stdout, stderr = self._get_output()
        stdout, stderr = self._get_output()
@@ -74,8 +75,14 @@ class SandboxBwrap(Sandbox):
        mount_map = MountMap(self, flags & SandboxFlags.ROOT_READ_ONLY)
        mount_map = MountMap(self, flags & SandboxFlags.ROOT_READ_ONLY)
        root_mount_source = mount_map.get_mount_source('/')
        root_mount_source = mount_map.get_mount_source('/')


        # 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
        # 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():
        for k, v in env.items():
            bwrap_command += ['--setenv', k, v]
            bwrap_command += ['--setenv', k, v]