diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2018-10-02 11:49:19 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2018-10-03 17:03:00 +0100 |
commit | f23e6e80b5c6d653d153a80c6d2fe9bfabdc3aba (patch) | |
tree | 2340c7724e0ba7912fb84e68776e25d39d0e6bf9 | |
parent | 67f3322102b9dbf8b067b9c9f7fa23924f738d3a (diff) | |
download | buildstream-f23e6e80b5c6d653d153a80c6d2fe9bfabdc3aba.tar.gz |
_platform/linux.py: Refactor checks for sandboxing
To better report issues in the absence of a suitable bwrap, or the
FUSE devices, this refactors the checks for sandboxing in the Linux
platform to cover the various possibilities. The reasons are then
collated and passed to the dummy sandbox for later reporting to the
user if a local build is attempted.
Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-rw-r--r-- | buildstream/_platform/linux.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py index 97fbb47be..1e522706a 100644 --- a/buildstream/_platform/linux.py +++ b/buildstream/_platform/linux.py @@ -37,15 +37,31 @@ class Linux(Platform): self._uid = os.geteuid() self._gid = os.getegid() + self._have_fuse = os.path.exists("/dev/fuse") + self._bwrap_exists = _site.check_bwrap_version(0, 0, 0) + self._have_good_bwrap = _site.check_bwrap_version(0, 1, 2) + + self._local_sandbox_available = self._have_fuse and self._have_good_bwrap + self._die_with_parent_available = _site.check_bwrap_version(0, 1, 8) - if self._local_sandbox_available(): + if self._have_fuse and self._have_good_bwrap: self._user_ns_available = self._check_user_ns_available() else: self._user_ns_available = False def create_sandbox(self, *args, **kwargs): - if not self._local_sandbox_available(): + if not self._local_sandbox_available: + reasons = [] + if not self._have_fuse: + reasons.append("FUSE is unavailable") + if not self._have_good_bwrap: + if self._bwrap_exists: + reasons.append("`bwrap` is too old (bst needs at least 0.1.2)") + else: + reasons.append("`bwrap` executable not found") + + kwargs['dummy_reason'] = " and ".join(reasons) return SandboxDummy(*args, **kwargs) else: from ..sandbox._sandboxbwrap import SandboxBwrap @@ -55,7 +71,7 @@ class Linux(Platform): return SandboxBwrap(*args, **kwargs) def check_sandbox_config(self, config): - if not self._local_sandbox_available(): + if not self._local_sandbox_available: # Accept all sandbox configs as it's irrelevant with the dummy sandbox (no Sandbox.run). return True @@ -70,11 +86,6 @@ class Linux(Platform): ################################################ # Private Methods # ################################################ - def _local_sandbox_available(self): - try: - return os.path.exists(utils.get_host_tool('bwrap')) and os.path.exists('/dev/fuse') - except utils.ProgramNotFoundError: - return False def _check_user_ns_available(self): # Here, lets check if bwrap is able to create user namespaces, |