Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/versions_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Parses a version string into a 3-tuple of ints

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**

Expand Down
5 changes: 5 additions & 0 deletions lib/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def _parse_bazel_version(bazel_version):

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:
bazel_version: the Bazel version string

Expand All @@ -52,6 +55,8 @@ def _parse_bazel_version(bazel_version):
"""

version = _extract_version_number(bazel_version)
if not version:
return (999999, 999999, 999999)
return tuple([int(n) for n in version.split(".")])

def _is_at_most(threshold, version):
Expand Down
5 changes: 5 additions & 0 deletions tests/versions_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.0rc"))

# Verify that this doesn't fail - it corresponds to a dev build of Bazel.
versions.parse("")

return unittest.end(env)

def _version_comparison_test(ctx):
Expand All @@ -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.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", ""))

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.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)

Expand Down