Skip to content

Commit 0205c20

Browse files
authored
fix(bzlmod): fail on unused overrides (#1669)
1 parent ed98eaf commit 0205c20

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

internal/bzlmod/go_deps.bzl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ def _fail_on_duplicate_overrides(path, module_name, overrides):
6464
if path in overrides:
6565
fail("Multiple overrides defined for Go module path \"{}\" in module \"{}\".".format(path, module_name))
6666

67+
def _fail_on_unmatched_overrides(override_keys, resolutions, override_name):
68+
unmatched_overrides = [path for path in override_keys if path not in resolutions]
69+
if unmatched_overrides:
70+
fail("Some {} did not target a Go module with a matching path: {}".format(
71+
override_name, ", ".join(unmatched_overrides)
72+
))
73+
6774
def _check_directive(directive):
6875
if directive.startswith("gazelle:") and " " in directive and not directive[len("gazelle:"):][0].isspace():
6976
return
@@ -313,13 +320,9 @@ def _go_deps_impl(module_ctx):
313320
raw_version = raw_version,
314321
)
315322

316-
unmatched_gazelle_overrides = []
317-
for path in gazelle_overrides.keys():
318-
if path not in module_resolutions:
319-
unmatched_gazelle_overrides.append(path)
320-
if unmatched_gazelle_overrides:
321-
fail("Some gazelle_overrides did not target a Go module with a matching path: {}"
322-
.format(", ".join(unmatched_gazelle_overrides)))
323+
_fail_on_unmatched_overrides(archive_overrides.keys(), module_resolutions, "archive_overrides")
324+
_fail_on_unmatched_overrides(gazelle_overrides.keys(), module_resolutions, "gazelle_overrides")
325+
_fail_on_unmatched_overrides(module_overrides.keys(), module_resolutions, "module_overrides")
323326

324327
# All `replace` directives are applied after version resolution.
325328
# We can simply do this by checking the replace paths' existence

tests/bcr/MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)