In my WORKSPACE, I have defined the go_repostitory for importpath golang.org/x/net.
go_repository(
name = "org_golang_x_net",
commit = "5ccada7d0a7ba9aeb5d3aca8d3501b4c2a509fec",
importpath = "golang.org/x/net",
)
But when I run gazelle, the dependency added to BUILD.Bazel is not @org_golang_x_net//context:go_default_library. Instead, it is the following: //golang.org/x/net/context:go_default_library
Why does gazelle ignore the defined go_repository? Is there a way for it to consider deps defined in WORKSPACE?
I'm guessing from your previous question this is because you're using an empty prefix.
Gazelle resolves Go imports to Bazel labels in several steps:
go_library
in your workspace with a matching importpath
, Gazelle will use the name of that library.//golang.org/x/net/content:go_default_library
.importpath
attribute on generated rules). I've filed bazelbuild/bazel-gazelle#101 to fix that.For now, you may want to add a directive to your top-level build file like:
# gazelle:prefix __do_not_match__
This will basically disable the second case, since no import will start with that. You'll still have an empty prefix in your src directory (set with # gazelle:prefix
in src/BUILD.bazel), so your libraries will still have the correct importpath
directives. You might want to set that to more specific subdirectories though.