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

bzlmod: Fix interaction between replace and implicit upgrade check #1492

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions internal/bzlmod/go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,34 @@ def _go_deps_impl(module_ctx):
fail("Some gazelle_overrides did not target a Go module with a matching path: {}"
.format(", ".join(unmatched_gazelle_overrides)))

for path, root_version in root_versions.items():
if semver.to_comparable(root_version) < module_resolutions[path].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,
root_version = root_version,
resolved_version = module_resolutions[path].raw_version,
),
)

# All `replace` directives are applied after version resolution.
# We can simply do this by checking the replace paths' existence
# in the module resolutions and swapping out the entry.
for path, replace in replace_map.items():
if path in module_resolutions:
new_version = semver.to_comparable(replace.version)
module_resolutions[path] = with_replaced_or_new_fields(module_resolutions[path],
replace = replace.to_path,
version = semver.to_comparable(replace.version),
version = new_version,
raw_version = replace.version,
)
if path in root_versions:
if replace != replace.to_path:
# If the root module replaces a Go module with a completely different one, do
# not ever report an implicit version upgrade.
root_versions.pop(path)
else:
root_versions[path] = new_version

for path, root_version in root_versions.items():
if semver.to_comparable(root_version) < module_resolutions[path].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,
root_version = root_version,
resolved_version = module_resolutions[path].raw_version,
),
)

for path, module in module_resolutions.items():
go_repository(
Expand Down