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

Consider RCs equivalent to release for bazel_compatibility #19678

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
*
* <ul>
* <li>{RELEASE} is a sequence of decimal numbers separated by dots;
* <li>{SUFFIX} could be: {@code -pre.*}, {@code rc\d+}, or any other string (which compares equal
* to SUFFIX is absent)
* <li>{SUFFIX} could be: {@code -pre.*}, or any other string (which compares equal to SUFFIX
* being absent)
* </ul>
*/
@AutoValue
Expand All @@ -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. */
Expand Down Expand Up @@ -86,7 +86,7 @@ public boolean satisfiesCompatibility(String compatVersion) {
int result =
Objects.compare(
getRelease(), compatSplit, lexicographical(Comparator.<Integer>naturalOrder()));
if (result == 0 && isPrereleaseOrCandidate()) {
if (result == 0 && isPrerelease()) {
result = -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"<root>\" (bazel_compatibility:"
+ " [>5.1.0, <5.1.4])");
}

Expand All @@ -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 \"<root>\" (bazel_compatibility:"
+ " [>5.1.0, <5.1.4])");
}

Expand All @@ -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 \"<root>\" (bazel_compatibility:"
+ " [>5.1.0, <5.1.4])");
}

Expand Down Expand Up @@ -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<BazelModuleResolutionValue> 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<BazelModuleResolutionValue> 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 \"<root>\" (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();
Expand Down