summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2020-08-03 10:02:04 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2020-08-03 10:02:04 +0000
commitd901fcf11e43b105c47ac51f5435a24482d06e5f (patch)
treeee8459c27bcad74aa906501080af9a2714ab1140
parentcdee3d0565e2d96952ad6b6c4c9478405f6f178a (diff)
parentd70ff708945ef8c0fff99cd217b2801fdaeeacc6 (diff)
downloadbuildstream-d901fcf11e43b105c47ac51f5435a24482d06e5f.tar.gz
Merge branch 'abderrahim/arch' into 'bst-1'
element.py: add configuration for sandbox architecture and os See merge request BuildStream/buildstream!1934
-rw-r--r--buildstream/_versions.py2
-rw-r--r--buildstream/element.py11
-rw-r--r--buildstream/sandbox/_config.py10
-rw-r--r--buildstream/sandbox/_sandboxbwrap.py27
4 files changed, 40 insertions, 10 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 <jim.macarthur@codethink.co.uk>
-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
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]