diff options
Diffstat (limited to 'buildstream/_platform/linux.py')
-rw-r--r-- | buildstream/_platform/linux.py | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py index 6e488472f..afdf81c79 100644 --- a/buildstream/_platform/linux.py +++ b/buildstream/_platform/linux.py @@ -18,9 +18,9 @@ # Tristan Maat <tristan.maat@codethink.co.uk> import os +import shutil import subprocess -from .. import _site from .. import utils from ..sandbox import SandboxDummy @@ -37,12 +37,19 @@ class Linux(Platform): 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 + bwrap_version = self._get_bwrap_version() - self._die_with_parent_available = _site.check_bwrap_version(0, 1, 8) + if bwrap_version is None: + self._bwrap_exists = False + self._have_good_bwrap = False + self._die_with_parent_available = False + else: + self._bwrap_exists = True + self._have_good_bwrap = (0, 1, 2) <= bwrap_version + self._die_with_parent_available = (0, 1, 8) <= bwrap_version + + self._local_sandbox_available = self._have_fuse and self._have_good_bwrap if self._local_sandbox_available: self._user_ns_available = self._check_user_ns_available() @@ -112,3 +119,21 @@ class Linux(Platform): output = '' return output == 'root' + + def _get_bwrap_version(self): + # Get the current bwrap version + # + # returns None if no bwrap was found + # otherwise returns a tuple of 3 int: major, minor, patch + bwrap_path = shutil.which('bwrap') + + if not bwrap_path: + return None + + cmd = [bwrap_path, "--version"] + try: + version = str(subprocess.check_output(cmd).split()[1], "utf-8") + except subprocess.CalledProcessError: + return None + + return tuple(int(x) for x in version.split(".")) |