Skip to content

Commit

Permalink
bzlmod: Fix interaction between replace and implicit upgrade check (#…
Browse files Browse the repository at this point in the history
…1492)

Ensures that implicit version upgrade warnings are not emitted for the
root module if it uses replace directives to update versions.
  • Loading branch information
fmeum committed Mar 29, 2023
1 parent e091227 commit 129d0fd
Showing 1 changed file with 19 additions and 11 deletions.
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

0 comments on commit 129d0fd

Please sign in to comment.