Rules_go: Gazelle compile error

Created on 30 Aug 2017  路  5Comments  路  Source: bazelbuild/rules_go

I have a local copy of rules_go at 0.5.3 as described in https://github.com/bazelbuild/rules_go/issues/745#issuecomment-325674929.

As of sometime today bazel run //:gazelle fails to compile Gazelle:

$ bazel run //:gazelle
ERROR: /private/var/tmp/_bazel_tom.payne/426382695a0eb57a7825dd83e14df9cd/external/io_bazel_rules_go/go/tools/gazelle/resolve/BUILD:3:1: no such package '@org_golang_x_tools//go/vcs': no such package '@io_bazel_rules_go_repository_tools//': failed to build gazelle: # github.com/bazelbuild/rules_go/go/tools/gazelle/resolve
src/github.com/bazelbuild/rules_go/go/tools/gazelle/resolve/labeler.go:34: c.StructureMode undefined (type *config.Config has no field or method StructureMode)
src/github.com/bazelbuild/rules_go/go/tools/gazelle/resolve/labeler.go:34: undefined: config.FlatMode
 and referenced by '@io_bazel_rules_go//go/tools/gazelle/resolve:go_default_library'.
ERROR: Analysis of target '//:gazelle' failed; build aborted.
INFO: Elapsed time: 3.444s
ERROR: Build failed. Not running target.

This looks like it was broken by recent changes in Gazelle - I believe that "flat mode" was only added in 0.5.4.

I observed that https://codeload.github.com/golang/tools/zip/3d92dd60033c312e3ae7cac319c792271cf67e37 is downloaded each time I run bazel run //:gazelle, even though I have --experimental_repository_cache set.

The relevant lines from my BUILD.bazel are:

load("@io_bazel_rules_go//go:def.bzl", "gazelle", "go_prefix")

go_prefix("github.com/my/project")

# gazelle:exclude bazel-rules
gazelle(
    name = "gazelle",
    command = "fix",
    external = "vendored",
)
bug gazelle

Most helpful comment

For info, the reason for using http_archive instead of git_repository is to take advantage of --experimental_repository_cache to be usually able to build even if GitHub is down (on the assumption that the tarball will already be in the cache).

All 5 comments

I couldn't reproduce this. It sounds like you're getting errors from a different version of Gazelle than the one you have checked out.

In the comment you linked, it looks like you have rules_go checked out inside your repository, and you're referencing it through a local_repository rule. Is it possible this is being overridden somewhere else in your WORKSPACE file? If not, could you provide a minimal reproducible example of this?

(Side note: having local_repository point inside your workspace is very unexpected. I think you will find a lot of weird Bazel issues doing this.)

Thanks. Based on your advice, I've "vendored" rules_go using http_archive instead which moves it outside the workspace. I'll close this issue and re-open it if I see the problem again.

For reference, WORKSPACE now contains

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "0281f223a7a2feca80b17514aff0709611ac1a23a32565c6ea71bac8a98317ba",
    urls = ["https://github.com/bazelbuild/rules_go/archive/0.5.3.tar.gz"],
    strip_prefix = "rules_go-0.5.3",
)

load("@io_bazel_rules_go//go:def.bzl", "go_repositories")

go_repositories()

For info, the reason for using http_archive instead of git_repository is to take advantage of --experimental_repository_cache to be usually able to build even if GitHub is down (on the assumption that the tarball will already be in the cache).

ERROR: /home/test/.cache/bazel/_bazel_test/51bfbc615f4e299f5a95fbb464041a0b/external/io_bazel_rules_go/go/tools/gazelle/gazelle/BUILD.bazel:3:1: no such package '@com_github_bazelbuild_rules_go//go/tools/gazelle/config': The repository could not be resolved and referenced by '@io_bazel_rules_go//go/tools/gazelle/gazelle:go_default_library'.
ERROR: Analysis of target '//:gazelle' failed; build aborted: no such package '@com_github_bazelbuild_rules_go//go/tools/gazelle/config': The repository could not be resolved.

while building go_rules latest version with command bazel run //:gazelle. The file "com_github_bazelbuild_rules_go//go/tools/gazelle/config'" are present but still the same error.Any solution to this?

@kadamvandita Where does the string com_github_bazelbuild_rules_go come from? Is that in your WORKSPACE file? It needs to be io_bazel_rules_go.

Was this page helpful?
0 / 5 - 0 ratings