From 652c8f0b2817daaa2570b7a3b2147643210f7dc7 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 26 Sep 2023 03:25:37 +0200 Subject: [PATCH] versions: Don't fail on Bazel dev builds (#463) Dev builds of Bazel are assumed to be more recent than any released version. --- docs/versions_doc.md | 3 +++ lib/versions.bzl | 5 +++++ tests/versions_tests.bzl | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/docs/versions_doc.md b/docs/versions_doc.md index 337e93c..8986737 100755 --- a/docs/versions_doc.md +++ b/docs/versions_doc.md @@ -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** diff --git a/lib/versions.bzl b/lib/versions.bzl index 0209a6f..87ca73c 100644 --- a/lib/versions.bzl +++ b/lib/versions.bzl @@ -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 @@ -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): diff --git a/tests/versions_tests.bzl b/tests/versions_tests.bzl index 422cb41..a2e2308 100644 --- a/tests/versions_tests.bzl +++ b/tests/versions_tests.bzl @@ -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): @@ -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)