diff options
author | milloni <milloni@milloni.org> | 2018-05-06 18:37:29 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-05-07 13:51:16 +0000 |
commit | 03823d124f61c18346dd2d8282055ab25d6f9aa6 (patch) | |
tree | 7d3482dd2ec29edf3bfe8cc1ff9d3359126421b2 /buildstream/_site.py | |
parent | e604910518b53aaca90793833d08185d80699fa1 (diff) | |
download | buildstream-03823d124f61c18346dd2d8282055ab25d6f9aa6.tar.gz |
_site.py: Add check_bwrap_version() function
Lazily parse the version of bwrap the first time the function is called.
On subsequent calls, used cached version info.
See: #373
Diffstat (limited to 'buildstream/_site.py')
-rw-r--r-- | buildstream/_site.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/buildstream/_site.py b/buildstream/_site.py index 622839511..f4780ef3d 100644 --- a/buildstream/_site.py +++ b/buildstream/_site.py @@ -19,6 +19,8 @@ # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> import os +import shutil +import subprocess # # Private module declaring some info about where the buildstream @@ -45,3 +47,50 @@ 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"] + version = str(subprocess.check_output(cmd).split()[1], "utf-8") + _bwrap_major, _bwrap_minor, _bwrap_patch = map(int, version.split(".")) + + # Check whether the installed version meets the requirements + if _bwrap_major > major: + return True + elif _bwrap_major < major: + return False + else: + if _bwrap_minor > minor: + return True + elif _bwrap_minor < minor: + return False + else: + return _bwrap_patch >= patch |