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

unused_deps failing with bzlmod #1315

Open
fzakaria opened this issue Dec 10, 2024 · 0 comments · May be fixed by #1316
Open

unused_deps failing with bzlmod #1315

fzakaria opened this issue Dec 10, 2024 · 0 comments · May be fixed by #1316

Comments

@fzakaria
Copy link

I'm failing to run unused_deps on our repository which is migrated to bzlmod.

unused_deps  //apps/cts/lib/metadata/src/test/java/io/confluent/metadata/table/impl/simulator:simulator
2024/12/10 09:31:39 running: bazel query --tool_tag=unused_deps --keep_going --color=yes --curses=yes kind('(kt|java|android)_*', //apps/cts/lib/metadata/src/test/java/io/confluent/metadata/table/impl/simulator:simulator)
2024/12/10 09:31:40 running: bazel build --tool_tag=unused_deps --keep_going --color=yes --curses=yes --output_groups=+unused_deps_outputs --override_repository=unused_deps=/var/folders/4w/cclwgg8s5mxc0g4lbsqkkqdh0000gp/T/unused_deps466578042 --aspects=@unused_deps//:unused_deps.bzl%javac_params //apps/cts/lib/metadata/src/test/java/io/confluent/metadata/table/impl/simulator:simulator
INFO: Invocation ID: 35e165fb-53aa-45cf-aaf6-109b665e85b2
ERROR: Unable to find package for @@[unknown repo 'unused_deps' requested from @@]//:unused_deps.bzl: The repository '@@[unknown repo 'unused_deps' requested from @@]' could not be resolved: No repository visible as '@unused_deps' from main repository.

slack thread

culprit

buildCmd = append(buildCmd, "--aspects=@unused_deps//:unused_deps.bzl%javac_params")

This is surprising why it's failing but if I read the documentation for --override_repository on Bazel it says ref:

Note: With Bzlmod, remember to use canonical repo names here. Alternatively, use the --override_module flag to override a module to a local directory, similar to the local_path_override directive in MODULE.bazel.

fix
I applied the following patch and it worked

diff --git a/unused_deps/unused_deps.go b/unused_deps/unused_deps.go
index 6a829c8..ef5d8f4 100644
--- a/unused_deps/unused_deps.go
+++ b/unused_deps/unused_deps.go
@@ -380,7 +380,7 @@ func main() {
 	buildCmd = append(buildCmd, config.DefaultExtraBuildFlags...)
 	buildCmd = append(buildCmd, "--output_groups=+unused_deps_outputs")
 	buildCmd = append(buildCmd, "--override_repository=unused_deps="+aspectDir)
-	buildCmd = append(buildCmd, "--aspects=@unused_deps//:unused_deps.bzl%javac_params")
+	buildCmd = append(buildCmd, "--aspects=@@unused_deps//:unused_deps.bzl%javac_params")
 	buildCmd = append(buildCmd, buildOptions()...)

 	blazeArgs := append(buildCmd, targetPatterns...)
fzakaria added a commit to fzakaria/buildtools that referenced this issue Dec 10, 2024
unused_deps seems to be broken for repositories that have migrated over
to bzlmod.

Specifically, the reference to the aspect must be done via the canonical
name for the workspace now.
(This probably even needs to change once WORKSPACE is defunct in Bazel 9)

This will break users of unused_deps if they are not on bzlmod but given
the latest release of Bazel 8 this is the direction we are headed.
Existing WORKSPACE users can pin to a previous version.
(Alternatively we could maybe support a flag)

fixes bazelbuild#1315
@fzakaria fzakaria linked a pull request Dec 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant