Skip to content

unused_deps failing with bzlmod #1315

@fzakaria

Description

@fzakaria

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...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions