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

fix(bzlmod): fail on unused overrides #1669

Merged
merged 1 commit into from
Nov 21, 2023
Merged
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
17 changes: 10 additions & 7 deletions internal/bzlmod/go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def _fail_on_duplicate_overrides(path, module_name, overrides):
if path in overrides:
fail("Multiple overrides defined for Go module path \"{}\" in module \"{}\".".format(path, module_name))

def _fail_on_unmatched_overrides(override_keys, resolutions, override_name):
unmatched_overrides = [path for path in override_keys if path not in resolutions]
if unmatched_overrides:
fail("Some {} did not target a Go module with a matching path: {}".format(
override_name, ", ".join(unmatched_overrides)
))

def _check_directive(directive):
if directive.startswith("gazelle:") and " " in directive and not directive[len("gazelle:"):][0].isspace():
return
Expand Down Expand Up @@ -313,13 +320,9 @@ def _go_deps_impl(module_ctx):
raw_version = raw_version,
)

unmatched_gazelle_overrides = []
for path in gazelle_overrides.keys():
if path not in module_resolutions:
unmatched_gazelle_overrides.append(path)
if unmatched_gazelle_overrides:
fail("Some gazelle_overrides did not target a Go module with a matching path: {}"
.format(", ".join(unmatched_gazelle_overrides)))
_fail_on_unmatched_overrides(archive_overrides.keys(), module_resolutions, "archive_overrides")
_fail_on_unmatched_overrides(gazelle_overrides.keys(), module_resolutions, "gazelle_overrides")
_fail_on_unmatched_overrides(module_overrides.keys(), module_resolutions, "module_overrides")

# All `replace` directives are applied after version resolution.
# We can simply do this by checking the replace paths' existence
Expand Down
4 changes: 2 additions & 2 deletions tests/bcr/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.