From cd757db89964bd39f6aeaa3763b216f14dc03c9e Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 8 Feb 2015 15:22:21 +0200 Subject: Can specify version requirements to dependencies. --- mesonlib.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'mesonlib.py') diff --git a/mesonlib.py b/mesonlib.py index c30057e29..7e1577047 100644 --- a/mesonlib.py +++ b/mesonlib.py @@ -14,7 +14,7 @@ """A library of random helper functionality.""" -import platform, subprocess +import platform, subprocess, operator def is_osx(): return platform.system().lower() == 'darwin' @@ -41,3 +41,31 @@ def exe_exists(arglist): except FileNotFoundError: pass return False + +def version_compare(vstr1, vstr2): + if vstr2.startswith('>='): + cmpop = operator.ge + vstr2 = vstr2[2:] + elif vstr2.startswith('<='): + cmpop = operator.le + vstr2 = vstr2[2:] + elif vstr2.startswith('!='): + cmpop = operator.ne + vstr2 = vstr2[2:] + elif vstr2.startswith('=='): + cmpop = operator.eq + vstr2 = vstr2[2:] + elif vstr2.startswith('='): + cmpop = operator.eq + vstr2 = vstr2[1:] + elif vstr2.startswith('>'): + cmpop = operator.gt + vstr2 = vstr2[1:] + elif vstr2.startswith('<'): + cmpop = operator.lt + vstr2 = vstr2[1:] + else: + cmpop = operator.eq + varr1 = [int(x) for x in vstr1.split('.')] + varr2 = [int(x) for x in vstr2.split('.')] + return cmpop(varr1, varr2) -- cgit v1.2.3