bazel-gazelle icon indicating copy to clipboard operation
bazel-gazelle copied to clipboard

bazel run //:gazelle failed to build target

Open fgimenez opened this issue 3 years ago • 5 comments

What version of gazelle are you using?

v0.23.0

What version of rules_go are you using?

v0.27.0

What version of Bazel are you using?

4.1.0

Does this issue reproduce with the latest releases of all the above?

Yes, AFAIK they are all the latest versions.

What operating system and processor architecture are you using?

fedora 34, x86_64

What did you do?

bazel run //:gazelle from https://github.com/kubevirt/project-infra/

What did you expect to see?

Normal run, no errors

What did you see instead?

$ bazel clean --expunge
$ rm -rf ~/.cache/bazel/
$ bazel run //:gazelle
Starting local Bazel server and connecting to it...
INFO: SHA256 (https://golang.org/dl/?mode=json&include=all) = 6efc06a1bd0a710df5cbaa2fd314f9a3f702f7d9cd59ee2bd53c2a02aa8c4475
INFO: Analyzed target //:gazelle (74 packages loaded, 7325 targets configured).
INFO: Found 1 target...
ERROR: /home/fgimenez/.cache/bazel/_bazel_fgimenez/efa68c1c533ba83cb0956de4ad99a248/external/bazel_gazelle/rule/BUILD.bazel:3:11: GoCompilePkg external/bazel_gazelle/rule/rule.a [for host] failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src external/bazel_gazelle/rule/directives.go -src external/bazel_gazelle/rule/expr.go -src ... (remaining 33 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
external/bazel_gazelle/rule/expr.go:63:30: kv.Value undefined (type build.Expr has no field or method Value)
external/bazel_gazelle/rule/expr.go:65:52: kv.Key undefined (type build.Expr has no field or method Key)
external/bazel_gazelle/rule/expr.go:66:21: kv.Key undefined (type build.Expr has no field or method Key)
external/bazel_gazelle/rule/expr.go:75:12: cannot use cases (type []*build.KeyValueExpr) as type []build.Expr in assignment
external/bazel_gazelle/rule/expr.go:143:18: kv.Value undefined (type build.Expr has no field or method Value)
external/bazel_gazelle/rule/expr.go:259:16: kv.Key undefined (type build.Expr has no field or method Key)
external/bazel_gazelle/rule/merge.go:194:23: cannot use []*build.KeyValueExpr{} (type []*build.KeyValueExpr) as type []build.Expr in field value
external/bazel_gazelle/rule/merge.go:259:23: cannot use mergedEntries (type []*build.KeyValueExpr) as type []build.Expr in field value
external/bazel_gazelle/rule/merge.go:428:16: cannot use make([]*build.KeyValueExpr, 0, len(cases)) (type []*build.KeyValueExpr) as type []build.Expr in assignment
external/bazel_gazelle/rule/value.go:79:34: cannot use args (type []*build.KeyValueExpr) as type []build.Expr in field value
external/bazel_gazelle/rule/value.go:79:34: too many errors
compilepkg: error running subcommand external/go_sdk/pkg/tool/linux_amd64/compile: exit status 2
Target //:gazelle failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 31.992s, Critical Path: 1.90s
INFO: 44 processes: 14 internal, 30 linux-sandbox.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

fgimenez avatar Jul 04 '21 13:07 fgimenez

I am also facing this issue, is there a workaround for this?

dhiller avatar Sep 10 '21 09:09 dhiller

Running gazelle with go as explained here works for me https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-go

fgimenez avatar Sep 10 '21 09:09 fgimenez

The last change in rules/expr.go is is this one: https://github.com/bazelbuild/bazel-gazelle/pull/818/files but I am not sure if this is responsible. It does not look like there is a fix in HEAD available. What's the plan?

ensonic avatar Sep 21 '21 06:09 ensonic

@fgimenez I ran into the same issue recently. Can you check if you have a go_repository entry somewhere referencing com_github_bazelbuild_buildtools ? I had to pin it to the exact same version as per https://github.com/bazelbuild/bazel-gazelle/blob/release-0.23/go.mod#L7 to make it work like this:

go_repository(
    name = "com_github_bazelbuild_buildtools",
    importpath = "github.com/bazelbuild/buildtools",
    sum = "h1:Et1IIXrXwhpDvR5wH9REPEZ0sUtzUoJSq19nfmBqzBY=",
    version = "v0.0.0-20200718160251-b1667ff58f71",
)

Not sure why an incorrect version slipped in, but this solved it for me.

skymeyer avatar Oct 10 '21 07:10 skymeyer

Thanks a lot for the pointer @skymeyer! We didn't have a go_repository referencing com_github_bazelbuild_buildtools but did have a http_archive getting it and we were later loading buildifier_dependencies. In fact we were not using these deps, removing them fixes the build.

For me all is ok now, let me know if the issue should be kept open.

fgimenez avatar Oct 18 '21 09:10 fgimenez