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

Wrong importpath for //go/tools/bazel #1333

Closed
cgrushko opened this issue Feb 16, 2018 · 5 comments
Closed

Wrong importpath for //go/tools/bazel #1333

cgrushko opened this issue Feb 16, 2018 · 5 comments

Comments

@cgrushko
Copy link

In https://github.com/bazelbuild/rules_go/blob/master/go/tools/bazel/BUILD.bazel,

go_library(
    name = "go_default_library",
    srcs = ["bazel.go"],
    importpath = "github.com/bazelbuild/rules_go/go/tools/bazel",
    visibility = ["//visibility:public"],
)

The problem is that if I import this package in my code as github.com/bazelbuild/..., Gazelle creates a dependency to @com_github_bazelbuild_rules_go//go/tools/bazel which doesn't exist because the repository's name is io_bazel_rules_go (and changing it is hard, because everyone uses this name, including Gazelle and Buildozer).

However, if I import it as bazel.io/rules_go/go/tools/bazel, Gazelle doesn't generate any dependency at all (separate bug?) and Bazel complains about a "missing strict dependencies". Adding a manual dependency on @io_bazel_rules_go//go/tools/bazel still fails the build with the same strict deps violation, presumably because of the importpath here.

It seems logical to change the importpath, though I don't know who it affects.
Also, is there a workaround I can use in the meanwhile, other than vendor https://github.com/bazelbuild/rules_go/blob/master/go/tools/bazel/bazel.go?

@jayconrod
Copy link
Contributor

bazel-contrib/bazel-gazelle#132 will provide a way to deal with this. Gazelle already scans WORKSPACE for go_repository rules in order to build a mapping between repository names and import paths. There's not yet a way to tell it about repositories declared with other rules or declared inside macros.

We can't change the importpath of this library, since that would break anyone depending on it with the current path.

For now, I'd recommend marking the deps list that contains that import with a # keep comment. That will prevent Gazelle from modifying that attribute.

@cgrushko
Copy link
Author

cgrushko commented Feb 16, 2018 via email

@jayconrod
Copy link
Contributor

I'm not sure who's depending on it, but I'd rather not break them. I think the problem is that Gazelle is putting the wrong label in deps, so it should be fixed in Gazelle instead.

@cgrushko
Copy link
Author

Adding a dependency doesn't seem to work:

Go file:

...
import "bazel.io/rules_go/go/tools/bazel"
...

BUILD.bazel file:

go_library(
    name = "go_default_library",
    srcs = ["compat.go"],
    importpath = "github.com/bazelbuild/tools_java_autodeps/compat",
    visibility = ["//visibility:public"],
    deps = ["@io_bazel_rules_go//go/tools/bazel:go_default_library"],
)

Error:

2018/02/16 13:26:36 missing strict dependencies:
        compat/compat.go: import of bazel.io/rules_go/go/tools/bazel, which is not a direct dependency

@cgrushko
Copy link
Author

Ah! Got it. I should change the import to github.com/bazelbuild/rules_go/go/tools/bazel, as specified in https://github.com/bazelbuild/rules_go/blob/master/go/tools/bazel/BUILD.bazel

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

No branches or pull requests

2 participants