diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-11-29 00:57:01 +0530 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-12-03 21:46:20 +0200 |
commit | e1c9d94708fe4b13986fa61aa3fa308f3b6e8a70 (patch) | |
tree | 6f6e57749addb4f687c6aba3f39a68f35a5c6e34 /mesonbuild/mesonlib.py | |
parent | 2f804e9074f391e8efbf4a2deb9f1cc3ebaaaf2e (diff) | |
download | meson-e1c9d94708fe4b13986fa61aa3fa308f3b6e8a70.zip meson-e1c9d94708fe4b13986fa61aa3fa308f3b6e8a70.tar.gz meson-e1c9d94708fe4b13986fa61aa3fa308f3b6e8a70.tar.bz2 |
Allow many version conditions for pkg-config deps
Sometimes we want to restrict the acceptable versions to a list of
versions, or a smallest-version + largest-version, or both. For
instance, GStreamer's opencv plugin is only compatible with
3.1.0 >= opencv >= 2.3.0
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r-- | mesonbuild/mesonlib.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 4d9cc69..4670685 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -146,21 +146,26 @@ def detect_vcs(source_dir): return vcs return None -def grab_leading_numbers(vstr): +def grab_leading_numbers(vstr, strict=False): result = [] for x in vstr.split('.'): try: result.append(int(x)) - except ValueError: + except ValueError as e: + if strict: + msg = 'Invalid version to compare against: {!r}; only ' \ + 'numeric digits separated by "." are allowed: ' + str(e) + raise MesonException(msg.format(vstr)) break return result numpart = re.compile('[0-9.]+') -def version_compare(vstr1, vstr2): +def version_compare(vstr1, vstr2, strict=False): match = numpart.match(vstr1.strip()) if match is None: - raise MesonException('Uncomparable version string %s.' % vstr1) + msg = 'Uncomparable version string {!r}.' + raise MesonException(msg.format(vstr1)) vstr1 = match.group(0) if vstr2.startswith('>='): cmpop = operator.ge @@ -185,10 +190,22 @@ def version_compare(vstr1, vstr2): vstr2 = vstr2[1:] else: cmpop = operator.eq - varr1 = grab_leading_numbers(vstr1) - varr2 = grab_leading_numbers(vstr2) + varr1 = grab_leading_numbers(vstr1, strict) + varr2 = grab_leading_numbers(vstr2, strict) return cmpop(varr1, varr2) +def version_compare_many(vstr1, conditions): + if not isinstance(conditions, (list, tuple)): + conditions = [conditions] + found = [] + not_found = [] + for req in conditions: + if not version_compare(vstr1, req, strict=True): + not_found.append(req) + else: + found.append(req) + return (not_found == [], not_found, found) + def default_libdir(): if is_debianlike(): try: |