diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-07 15:52:29 +0000 |
---|---|---|
committer | Benjamin Schubert <bschubert15@bloomberg.net> | 2018-11-08 10:21:12 +0000 |
commit | 9f0e12f15f29ea48f1d8b242d233889806942cf8 (patch) | |
tree | 3adb73b4a28af227273fd8e1831359cbf1e1c072 /buildstream | |
parent | 83d153506691b8f6bdd161f5c71154df755f8b2d (diff) | |
download | buildstream-9f0e12f15f29ea48f1d8b242d233889806942cf8.tar.gz |
Move bwrap checks in platform/linux.py
Remove the bwraps checks from _site.py and put them in platform.linux
which is the only place where they are run.
This allows the removal of a double level of caching, making
reasoning about tests easier
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_platform/linux.py | 35 | ||||
-rw-r--r-- | buildstream/_site.py | 43 |
2 files changed, 30 insertions, 48 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(".")) diff --git a/buildstream/_site.py b/buildstream/_site.py index 30e1000d4..d64390b5d 100644 --- a/buildstream/_site.py +++ b/buildstream/_site.py @@ -18,8 +18,6 @@ # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> import os -import shutil -import subprocess # # Private module declaring some info about where the buildstream @@ -46,44 +44,3 @@ build_all_template = os.path.join(root, 'data', 'build-all.sh.in') # Module building script template build_module_template = os.path.join(root, 'data', 'build-module.sh.in') - -# Cached bwrap version -_bwrap_major = None -_bwrap_minor = None -_bwrap_patch = None - - -# check_bwrap_version() -# -# Checks the version of installed bwrap against the requested version -# -# Args: -# major (int): The required major version -# minor (int): The required minor version -# patch (int): The required patch level -# -# Returns: -# (bool): Whether installed bwrap meets the requirements -# -def check_bwrap_version(major, minor, patch): - # pylint: disable=global-statement - - global _bwrap_major - global _bwrap_minor - global _bwrap_patch - - # Parse bwrap version and save into cache, if not already cached - if _bwrap_major is None: - bwrap_path = shutil.which('bwrap') - if not bwrap_path: - return False - cmd = [bwrap_path, "--version"] - try: - version = str(subprocess.check_output(cmd).split()[1], "utf-8") - except subprocess.CalledProcessError: - # Failure trying to run bubblewrap - return False - _bwrap_major, _bwrap_minor, _bwrap_patch = map(int, version.split(".")) - - # Check whether the installed version meets the requirements - return (_bwrap_major, _bwrap_minor, _bwrap_patch) >= (major, minor, patch) |