[8.6.0] Bzlmod: Make compatibility_level and max_compatibility_level noops#28615
Conversation
…noops Increasing `compatibility_level` leads to version conflicts that are difficult for end users to resolve. Therefore, we are making `compatibility_level` and `max_compatibility_level` no-ops. This will be effective from Bazel 8.6.0 and 9.1.0. Module maintainers introducing major breaking changes should ensure that build failures provide clear error messages and actionable migration paths. Fixes #22972 RELNOTES: The `compatibility_level` and `max_compatibility_level` attributes of `module` in MODULE.bazel are now no-ops. Module maintainers should stop specifying those attributes and provide clear build time error messages and actionable migration paths when making major breaking changes. Closes #28600. PiperOrigin-RevId: 868151978 Change-Id: I217e7f0c02e729f7c89ebab140d8bbd754db13be
There was a problem hiding this comment.
Code Review
This pull request makes compatibility_level and max_compatibility_level no-ops, which is a significant simplification for Bzlmod users. The changes to documentation, implementation, and tests are well-aligned with this goal. My main feedback is to broaden the scope of the new deprecation warnings to ensure that maintainers of all modules, not just the root module, are notified of this change. This will help prevent them from unknowingly relying on a feature that no longer works.
| if (compatibilityLevel.toInt("compatibility_level") != -1 | ||
| && context.getModuleBuilder().getKey().equals(ModuleKey.ROOT)) { | ||
| context.addWarning( | ||
| Event.warn( | ||
| thread.getCallerLocation(), | ||
| "The attribute 'compatibility_level' in module() is a no-op and will be removed in a" | ||
| + " future Bazel release. Please remove it from your MODULE.bazel file.")); | ||
| } |
There was a problem hiding this comment.
The check context.getModuleBuilder().getKey().equals(ModuleKey.ROOT) limits the deprecation warning for compatibility_level to only the root module. This prevents maintainers of other modules in the dependency graph from being notified that this attribute is deprecated and now a no-op. The release notes state that "Module maintainers should stop specifying those attributes", which suggests they should be warned.
To ensure module maintainers are aware of this important change, the warning should be displayed for any module that uses this attribute. This will also require updating testModuleFileExecute_compatibilityLevelWarning to check for warnings from non-root modules.
if (compatibilityLevel.toInt("compatibility_level") != -1) {
context.addWarning(
Event.warn(
thread.getCallerLocation(),
"The attribute 'compatibility_level' in module() is a no-op and will be removed in a"
+ " future Bazel release. Please remove it from your MODULE.bazel file."));
}| if (maxCompatibilityLevel.toInt("max_compatibility_level") != -1 | ||
| && context.getModuleBuilder().getKey().equals(ModuleKey.ROOT)) { | ||
| context.addWarning( | ||
| Event.warn( | ||
| thread.getCallerLocation(), | ||
| "The attribute 'max_compatibility_level' in bazel_dep() is a no-op and will be" | ||
| + " removed in a future Bazel release. Please remove it from your MODULE.bazel" | ||
| + " file.")); | ||
| } |
There was a problem hiding this comment.
Similar to the compatibility_level attribute, the deprecation warning for max_compatibility_level is restricted to the root module by the context.getModuleBuilder().getKey().equals(ModuleKey.ROOT) check. This prevents module maintainers from seeing the warning and updating their MODULE.bazel files.
To align with the goal of informing maintainers about this change, this warning should be triggered for any module using the attribute. This will also require updating testModuleFileExecute_compatibilityLevelWarning to check for warnings from non-root modules.
if (maxCompatibilityLevel.toInt("max_compatibility_level") != -1) {
context.addWarning(
Event.warn(
thread.getCallerLocation(),
"The attribute 'max_compatibility_level' in bazel_dep() is a no-op and will be"
+ " removed in a future Bazel release. Please remove it from your MODULE.bazel"
+ " file."));
}
Increasing
compatibility_levelleads to version conflicts that are difficult for end users to resolve. Therefore, we are makingcompatibility_levelandmax_compatibility_levelno-ops. This will be effective from Bazel 8.6.0 and 9.1.0.Module maintainers introducing major breaking changes should ensure that build failures provide clear error messages and actionable migration paths.
Fixes #22972
RELNOTES: The
compatibility_levelandmax_compatibility_levelattributes ofmodulein MODULE.bazel are now no-ops. Module maintainers should stop specifying those attributes and provide clear build time error messages and actionable migration paths when making major breaking changes.Closes #28600.
PiperOrigin-RevId: 868151978
Change-Id: I217e7f0c02e729f7c89ebab140d8bbd754db13be