diff options
author | milloni <milloni@milloni.org> | 2018-05-06 19:28:11 +0100 |
---|---|---|
committer | milloni <milloni@milloni.org> | 2018-05-06 23:14:43 +0100 |
commit | 83fc9a1af55ccc30a8b1552f30f1e779d0b787de (patch) | |
tree | 56557791e94de6bbe770da14ae95353a83ab7143 | |
parent | 630123dacf2f989dbf76a047c454077f5b3c920a (diff) | |
download | buildstream-milloni/bwrap-feature-checks.tar.gz |
Replace bwrap checks with calls to check_bwrap_versionmilloni/bwrap-feature-checks
See: #373
-rw-r--r-- | buildstream/_platform/linux.py | 35 | ||||
-rwxr-xr-x | setup.py | 24 |
2 files changed, 9 insertions, 50 deletions
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py index c4e87de1d..8ef059233 100644 --- a/buildstream/_platform/linux.py +++ b/buildstream/_platform/linux.py @@ -18,9 +18,7 @@ # Authors: # Tristan Maat <tristan.maat@codethink.co.uk> -import subprocess - -from .. import utils +from .. import _site from .._artifactcache.ostreecache import OSTreeCache from .._message import Message, MessageType from ..sandbox import SandboxBwrap @@ -57,23 +55,9 @@ class Linux(Platform): # issue a warning if it's not available, and save the state # locally so that we can inform the sandbox to not try it # later on. - bwrap = utils.get_host_tool('bwrap') - whoami = utils.get_host_tool('whoami') - try: - output = subprocess.check_output([ - bwrap, - '--ro-bind', '/', '/', - '--unshare-user', - '--uid', '0', '--gid', '0', - whoami, - ]) - output = output.decode('UTF-8').strip() - except subprocess.CalledProcessError: - output = '' - - if output == 'root': + # This requires '--unshare-user', available since bwrap 0.1.0. + if _site.check_bwrap_version(0, 1, 0): return True - else: context.message( Message(None, MessageType.WARN, @@ -86,15 +70,4 @@ class Linux(Platform): # bwrap supports --die-with-parent since 0.1.8. # Let's check whether the host bwrap supports it. - bwrap = utils.get_host_tool('bwrap') - - try: - subprocess.check_call([ - bwrap, - '--ro-bind', '/', '/', - '--die-with-parent', - 'true' - ], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - return True - except subprocess.CalledProcessError: - return False + return _site.check_bwrap_version(0, 1, 8) @@ -20,10 +20,11 @@ import os import shutil -import subprocess import sys import versioneer +from buildstream import _site + if sys.version_info[0] != 3 or sys.version_info[1] < 4: print("BuildStream requires Python >= 3.4") sys.exit(1) @@ -54,20 +55,6 @@ def exit_bwrap(reason): sys.exit(1) -def bwrap_too_old(major, minor, patch): - if major < REQUIRED_BWRAP_MAJOR: - return True - elif major == REQUIRED_BWRAP_MAJOR: - if minor < REQUIRED_BWRAP_MINOR: - return True - elif minor == REQUIRED_BWRAP_MINOR: - return patch < REQUIRED_BWRAP_PATCH - else: - return False - else: - return False - - def assert_bwrap(): platform = os.environ.get('BST_FORCE_BACKEND', '') or sys.platform if platform.startswith('linux'): @@ -75,10 +62,9 @@ def assert_bwrap(): if not bwrap_path: exit_bwrap("Bubblewrap not found") - version_bytes = subprocess.check_output([bwrap_path, "--version"]).split()[1] - version_string = str(version_bytes, "utf-8") - major, minor, patch = map(int, version_string.split(".")) - if bwrap_too_old(major, minor, patch): + too_old = not _site.check_bwrap_version( + REQUIRED_BWRAP_MAJOR, REQUIRED_BWRAP_MINOR, REQUIRED_BWRAP_PATCH) + if too_old: exit_bwrap("Bubblewrap too old") |