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

bazel coverage with $GOOS.go causes the file to be dropped on non-$GOOS environment. #1771

Open
yasushi-saito opened this issue Oct 17, 2018 · 1 comment

Comments

@yasushi-saito
Copy link
Contributor

Imagine a package with two files:

main.go:

package main
import "log"
func main() {log.Printf("Foo=%d\n", Foo)}

linux.go

package main
const Foo = 100

Running "bazel coverage ..." on Linux works, but the same on Darwin fails with

main.go:3: undefined: Foo

The reason seems to be:

  • In coverage mode, rules_go generates a new file, "Coverage_linux.go" that contains coverage-specific stuff.

  • It then passes Coverage_linux.go to https://golang.org/src/go/build/build.go:1671, which causes the file to be dropped on non-Linux OS.

Looking at the comment in build.go, the file "linux.go" should be accepted on non-linux platforms.

We can easily work around this problem so no hurry to fix it, but I think it's still a bug.

@jayconrod
Copy link
Contributor

Good catch and good analysis. Thanks for reporting. We declare new cover files and apply coverage as a separate action before compilation. We should probably filter first, then apply coverage, then compile in the same action. Cgo needs to be done in there too, before coverage.

A proper fix may end up being a large refactoring, but we need to rewrite a lot of the cgo logic anyway. A simpler, faster fix should be possible, too.

I wonder if this means build tags in covered files get stripped out, too? I think coverage removes comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants