versions: Don't fail on Bazel dev builds (#463)

Dev builds of Bazel are assumed to be more recent than any released
version.
This commit is contained in:
Fabian Meumertzheim 2023-09-26 03:25:37 +02:00 committed by GitHub
parent 6bf7bae2f4
commit 652c8f0b28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -26,6 +26,9 @@ Parses a version string into a 3-tuple of ints
int tuples can be compared directly using binary operators (<, >). int tuples can be compared directly using binary operators (<, >).
For a development build of Bazel, this returns an unspecified version tuple
that compares higher than any released version.
**PARAMETERS** **PARAMETERS**

View File

@ -44,6 +44,9 @@ def _parse_bazel_version(bazel_version):
int tuples can be compared directly using binary operators (<, >). int tuples can be compared directly using binary operators (<, >).
For a development build of Bazel, this returns an unspecified version tuple
that compares higher than any released version.
Args: Args:
bazel_version: the Bazel version string bazel_version: the Bazel version string
@ -52,6 +55,8 @@ def _parse_bazel_version(bazel_version):
""" """
version = _extract_version_number(bazel_version) version = _extract_version_number(bazel_version)
if not version:
return (999999, 999999, 999999)
return tuple([int(n) for n in version.split(".")]) return tuple([int(n) for n in version.split(".")])
def _is_at_most(threshold, version): def _is_at_most(threshold, version):

View File

@ -26,6 +26,9 @@ def _parse_test(ctx):
asserts.equals(env, (0, 4, 0), versions.parse("0.4.0")) asserts.equals(env, (0, 4, 0), versions.parse("0.4.0"))
asserts.equals(env, (0, 4, 0), versions.parse("0.4.0rc")) asserts.equals(env, (0, 4, 0), versions.parse("0.4.0rc"))
# Verify that this doesn't fail - it corresponds to a dev build of Bazel.
versions.parse("")
return unittest.end(env) return unittest.end(env)
def _version_comparison_test(ctx): def _version_comparison_test(ctx):
@ -36,11 +39,13 @@ def _version_comparison_test(ctx):
asserts.true(env, versions.is_at_least("0.9.0", "0.10.0rc2")) asserts.true(env, versions.is_at_least("0.9.0", "0.10.0rc2"))
asserts.true(env, versions.is_at_least("0.9.0", "0.9.0rc3")) asserts.true(env, versions.is_at_least("0.9.0", "0.9.0rc3"))
asserts.true(env, versions.is_at_least("0.9.0", "1.2.3")) asserts.true(env, versions.is_at_least("0.9.0", "1.2.3"))
asserts.true(env, versions.is_at_least("0.9.0", ""))
asserts.false(env, versions.is_at_most("0.4.0 123abcd", "0.10.0rc1 abcd123")) asserts.false(env, versions.is_at_most("0.4.0 123abcd", "0.10.0rc1 abcd123"))
asserts.true(env, versions.is_at_most("0.4.0", "0.3.0rc2")) asserts.true(env, versions.is_at_most("0.4.0", "0.3.0rc2"))
asserts.true(env, versions.is_at_most("0.4.0", "0.4.0rc3")) asserts.true(env, versions.is_at_most("0.4.0", "0.4.0rc3"))
asserts.true(env, versions.is_at_most("1.4.0", "0.4.0rc3")) asserts.true(env, versions.is_at_most("1.4.0", "0.4.0rc3"))
asserts.false(env, versions.is_at_most("1.4.0", ""))
return unittest.end(env) return unittest.end(env)