Skip to content

Commit

Permalink
Fix Bazel module resolution regression in go_deps
Browse files Browse the repository at this point in the history
2a65ce8 made it so that Bazel modules would no longer override Go modules if their versions don't match exactly.

Also do not report version mismatches for overridden Bazel modules.
  • Loading branch information
fmeum committed Oct 23, 2024
1 parent 5254d18 commit d45893b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module(
name = "gazelle",
# Updated by the Publish to BCR app.
version = "0.30.0",
version = "",
repo_name = "bazel_gazelle",
)

Expand Down
11 changes: 8 additions & 3 deletions internal/bzlmod/go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -566,21 +566,26 @@ def _go_deps_impl(module_ctx):
if path in archive_overrides or path in gazelle_overrides or path in module_overrides or path in replace_map:
continue

# Only use the Bazel module if it is at least as high as the required Go module version.
if path in module_resolutions and bazel_dep.version != module_resolutions[path].version:
# Do not report version mismatches for overridden Bazel modules.
if path in module_resolutions and bazel_dep.version != _HIGHEST_VERSION_SENTINEL and bazel_dep.version != module_resolutions[path].version:
outdated_direct_dep_printer("\n\nMismatch between versions requested for module {module}\nBazel dependency version requested in MODULE.bazel: {bazel_dep_version}\nGo module version requested in go.mod: {go_module_version}\nPlease resolve this mismatch to prevent discrepancies between native Go and Bazel builds\n\n".format(
module = path,
bazel_dep_version = bazel_dep.raw_version,
go_module_version = module_resolutions[path].raw_version,
))

# Only use the Bazel module if it is at least as high as the required Go module version.
if path in module_resolutions and bazel_dep.version < module_resolutions[path].version:
continue

# TODO: We should update root_versions if the bazel_dep is a direct dependency of the root
# module. However, we currently don't have a way to determine that.
module_resolutions[path] = bazel_dep

for path, root_version in root_versions.items():
if semver.to_comparable(root_version) < module_resolutions[path].version:
resolved_version = module_resolutions[path].version
# Do not report version mismatches for overridden Bazel modules.
if resolved_version != _HIGHEST_VERSION_SENTINEL and semver.to_comparable(root_version) < resolved_version:
outdated_direct_dep_printer(
"For Go module \"{path}\", the root module requires module version v{root_version}, but got v{resolved_version} in the resolved dependency graph.".format(
path = path,
Expand Down

0 comments on commit d45893b

Please sign in to comment.