You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ak...@apache.org on 2022/09/11 20:18:30 UTC
[buildstream] 01/01: sandbox: add dummy sandbox for checking out artifacts from different arches
This is an automated email from the ASF dual-hosted git repository.
akitouni pushed a commit to branch abderrahim/dummy-sandbox
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 4875f1e2e02d700d17be8b087c8c74d42f1d95f1
Author: Abderrahim Kitouni <ab...@codethink.co.uk>
AuthorDate: Sun Sep 11 21:17:20 2022 +0100
sandbox: add dummy sandbox for checking out artifacts from different arches
---
buildstream/_platform/linux.py | 43 +++++++++++++++++++++++++++++++++++-
buildstream/sandbox/__init__.py | 1 +
buildstream/sandbox/_sandboxbwrap.py | 41 +---------------------------------
buildstream/sandbox/_sandboxdummy.py | 15 +++++++++++++
4 files changed, 59 insertions(+), 41 deletions(-)
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py
index b7a3f7f8b..017c3a434 100644
--- a/buildstream/_platform/linux.py
+++ b/buildstream/_platform/linux.py
@@ -22,13 +22,21 @@ import subprocess
from .. import _site
from .. import utils
-from ..sandbox import SandboxBwrap
+from ..sandbox import SandboxBwrap, SandboxDummy
from . import Platform
class Linux(Platform):
+ ARCHITECTURES = {
+ 'amd64': 'x86_64',
+ 'arm64': 'aarch64',
+ 'i386': 'i686',
+ 'armhf': 'armv7l',
+ 'ppc64el': 'ppc64le',
+ }
+
def __init__(self):
super().__init__()
@@ -43,6 +51,39 @@ class Linux(Platform):
# Inform the bubblewrap sandbox as to whether it can use user namespaces or not
kwargs['user_ns_available'] = self._user_ns_available
kwargs['die_with_parent_available'] = self._die_with_parent_available
+ kwargs['linux32'] = False
+
+ host_os, _, _, _, host_arch = os.uname()
+ config = kwargs['config']
+
+ # We can't do builds for another host OS
+ if config.build_os != host_os:
+ return SandboxDummy("Configured and host OS don't match.", *args, **kwargs)
+
+ if config.build_arch != host_arch:
+ try:
+ archtest = utils.get_host_tool('arch-test')
+ supported = subprocess.getoutput(archtest).splitlines()
+ supported_architectures = map(self.ARCHITECTURES.get, supported, supported)
+ except utils.ProgramNotFoundError:
+ supported_architectures = []
+ if host_arch == "x86_64":
+ supported_architectures = ["i686"]
+ elif host_arch == "aarch64":
+ supported_architectures = ["armv7l"]
+
+ if config.build_arch not in supported_architectures:
+ return SandboxDummy("Configured and host architecture don't match.", *args, **kwargs)
+
+ 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')
+ kwargs['linux32'] = True
+ except utils.ProgramNotFoundError as e:
+ return SandboxDummy("Configured and host architecture don't match.", *args, **kwargs)
+
return SandboxBwrap(*args, **kwargs)
def check_sandbox_config(self, config):
diff --git a/buildstream/sandbox/__init__.py b/buildstream/sandbox/__init__.py
index 53e170fbd..afdd7c384 100644
--- a/buildstream/sandbox/__init__.py
+++ b/buildstream/sandbox/__init__.py
@@ -20,3 +20,4 @@
from .sandbox import Sandbox, SandboxFlags
from ._sandboxchroot import SandboxChroot
from ._sandboxbwrap import SandboxBwrap
+from ._sandboxdummy import SandboxDummy
diff --git a/buildstream/sandbox/_sandboxbwrap.py b/buildstream/sandbox/_sandboxbwrap.py
index 2bcb80b07..94490dba3 100644
--- a/buildstream/sandbox/_sandboxbwrap.py
+++ b/buildstream/sandbox/_sandboxbwrap.py
@@ -49,50 +49,11 @@ class SandboxBwrap(Sandbox):
'/dev/zero'
]
- ARCHITECTURES = {
- 'amd64': 'x86_64',
- 'arm64': 'aarch64',
- 'i386': 'i686',
- 'armhf': 'armv7l',
- 'ppc64el': 'ppc64le',
- }
-
def __init__(self, *args, **kwargs):
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 OS
- if config.build_os != host_os:
- raise SandboxError("Configured and host OS don't match.")
-
- if config.build_arch != host_arch:
- try:
- archtest = utils.get_host_tool('arch-test')
- supported = subprocess.getoutput(archtest).splitlines()
- supported_architectures = map(self.ARCHITECTURES.get, supported, supported)
- except utils.ProgramNotFoundError:
- supported_architectures = []
- if host_arch == "x86_64":
- supported_architectures = ["i686"]
- elif host_arch == "aarch64":
- supported_architectures = ["armv7l"]
-
- if config.build_arch not in supported_architectures:
- raise SandboxError("Configured and host architecture don't match.")
-
- 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 as e:
- raise SandboxError("Configured and host architecture don't match.") from e
+ self._linux32 = kwargs['linux32']
def run(self, command, flags, *, cwd=None, env=None):
stdout, stderr = self._get_output()
diff --git a/buildstream/sandbox/_sandboxdummy.py b/buildstream/sandbox/_sandboxdummy.py
new file mode 100644
index 000000000..eb944975c
--- /dev/null
+++ b/buildstream/sandbox/_sandboxdummy.py
@@ -0,0 +1,15 @@
+from .._exceptions import SandboxError
+from . import Sandbox, SandboxFlags
+
+
+# SandboxDummy()
+#
+# Dummy sandbox to use on a different.
+#
+class SandboxDummy(Sandbox):
+ def __init__(self, reason, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self._reason = reason
+
+ def run(self, command, flags, *, cwd=None, env=None):
+ raise SandboxError(reason)