From dda00c7ab2cfdc6d07ef19639b0feaaf1a4dfb78 Mon Sep 17 00:00:00 2001 From: "bazel.build machine account" <15028808+bazel-io@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:17:35 -0400 Subject: [PATCH] [6.4.0] Consider RCs equivalent to release for `bazel_compatibility` (#19689) We want `bazel_compatibiliy = [">=6.4.0"]` to match `6.4.0rc1` so that release candidates are indistinguishable from the actual release via Bazel version compatibility requirements. This allows more realistic testing of releases via RCs without having users to rely on hacks such as `bazel_compatibility = [">=6.3.9999"]`. Along the way change the error message on incompatibility to include the standard module key identifier, which is `` for the root module instead of `@`, both of which can be empty. Closes #19678. Commit https://github.com/bazelbuild/bazel/commit/21cd4efaa8c766ac9f1d930c7b10052d91a3958e PiperOrigin-RevId: 569982709 Change-Id: I7dce89ac1c62c1539d71704f048dca65232c119c Co-authored-by: Fabian Meumertzheim Co-authored-by: Yun Peng --- .../build/lib/bazel/BazelVersion.java | 12 +++---- .../bzlmod/BazelModuleResolutionFunction.java | 8 ++--- .../BazelModuleResolutionFunctionTest.java | 36 +++++++++++++++++-- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelVersion.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelVersion.java index b8c1359c53d0ee..13b52434a83a02 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BazelVersion.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelVersion.java @@ -33,8 +33,8 @@ * *
    *
  • {RELEASE} is a sequence of decimal numbers separated by dots; - *
  • {SUFFIX} could be: {@code -pre.*}, {@code rc\d+}, or any other string (which compares equal - * to SUFFIX is absent) + *
  • {SUFFIX} could be: {@code -pre.*}, or any other string (which compares equal to SUFFIX + * being absent) *
*/ @AutoValue @@ -52,9 +52,9 @@ public abstract class BazelVersion { /** Returns the original version string. */ public abstract String getOriginal(); - /** Whether this is a prerelease or a release candidate */ - boolean isPrereleaseOrCandidate() { - return getSuffix().startsWith("-pre") || getSuffix().startsWith("rc"); + /** Whether this is a prerelease */ + boolean isPrerelease() { + return getSuffix().startsWith("-pre"); } /** Parses a version string into a {@link BazelVersion} object. */ @@ -86,7 +86,7 @@ public boolean satisfiesCompatibility(String compatVersion) { int result = Objects.compare( getRelease(), compatSplit, lexicographical(Comparator.naturalOrder())); - if (result == 0 && isPrereleaseOrCandidate()) { + if (result == 0 && isPrerelease()) { result = -1; } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunction.java index 249f9f1578bd48..79ad773b82b307 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunction.java @@ -216,12 +216,8 @@ public static void checkBazelCompatibility( if (!curVersion.satisfiesCompatibility(compatVersion)) { String message = String.format( - "Bazel version %s is not compatible with module \"%s@%s\" (bazel_compatibility:" - + " %s)", - curVersion.getOriginal(), - module.getName(), - module.getVersion().getOriginal(), - module.getBazelCompatibility()); + "Bazel version %s is not compatible with module \"%s\" (bazel_compatibility: %s)", + curVersion.getOriginal(), module.getKey(), module.getBazelCompatibility()); if (mode == BazelCompatibilityMode.WARNING) { eventHandler.handle(Event.warn(message)); diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java index 11041182aa9c00..5bb2835c390476 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java @@ -162,7 +162,7 @@ public void testSimpleBazelCompatibilityFailure() throws Exception { assertThat(result.hasError()).isTrue(); assertContainsEvent( - "Bazel version 5.1.4 is not compatible with module \"mod@1.0\" (bazel_compatibility:" + "Bazel version 5.1.4 is not compatible with module \"\" (bazel_compatibility:" + " [>5.1.0, <5.1.4])"); } @@ -180,7 +180,7 @@ public void testBazelCompatibilityWarning() throws Exception { assertThat(result.hasError()).isFalse(); assertContainsEvent( - "Bazel version 5.1.4 is not compatible with module \"mod@1.0\" (bazel_compatibility:" + "Bazel version 5.1.4 is not compatible with module \"\" (bazel_compatibility:" + " [>5.1.0, <5.1.4])"); } @@ -198,7 +198,7 @@ public void testDisablingBazelCompatibility() throws Exception { assertThat(result.hasError()).isFalse(); assertDoesNotContainEvent( - "Bazel version 5.1.4 is not compatible with module \"mod@1.0\" (bazel_compatibility:" + "Bazel version 5.1.4 is not compatible with module \"\" (bazel_compatibility:" + " [>5.1.0, <5.1.4])"); } @@ -227,6 +227,36 @@ public void testBazelCompatibilityFailure() throws Exception { + " [<=5.1.4, -5.1.2])"); } + @Test + public void testRcIsCompatibleWithReleaseRequirement() throws Exception { + scratch.file( + rootDirectory.getRelative("MODULE.bazel").getPathString(), + "module(name='mod', version='1.0', bazel_compatibility=['>=6.4.0'])"); + + embedBazelVersion("6.4.0rc1"); + EvaluationResult result = + evaluator.evaluate(ImmutableList.of(BazelModuleResolutionValue.KEY), evaluationContext); + + assertThat(result.hasError()).isFalse(); + } + + @Test + public void testPrereleaseIsNotCompatibleWithReleaseRequirement() throws Exception { + scratch.file( + rootDirectory.getRelative("MODULE.bazel").getPathString(), + "module(name='mod', version='1.0', bazel_compatibility=['>=6.4.0'])"); + + embedBazelVersion("6.4.0-pre-1"); + reporter.removeHandler(failFastHandler); + EvaluationResult result = + evaluator.evaluate(ImmutableList.of(BazelModuleResolutionValue.KEY), evaluationContext); + + assertThat(result.hasError()).isTrue(); + assertContainsEvent( + "Bazel version 6.4.0-pre-1 is not compatible with module \"\" (bazel_compatibility:" + + " [>=6.4.0])"); + } + private void embedBazelVersion(String version) { // Double-get version-info to determine if it's the cached instance or not, and if not cache it. BlazeVersionInfo blazeInfo1 = BlazeVersionInfo.instance();