You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest releases of all the above?
What operating system and processor architecture are you using?
MacOS M1 Ventura and Linux AMD64
Any other potentially useful information about your toolchain?
What did you do?
With nogo setup in monorepo, I'm trying to enable a gochecknoinits analyer, which check that no inits functions are present in Go code. When I ran bazel coverage //..., nogo reports errors for init() functions it found on non-existing lines in some source files.
What did you expect to see?
nogo should not report errors on files where there is no init() function in the original source file.
What did you see instead?
When coverage mode is set, the source file is modified with an init() function added to register files to coverdata, which is where nogo static analysis reported the error.
What version of rules_go are you using?
0.39.1
What version of gazelle are you using?
0.28.0
What version of Bazel are you using?
6.3.0
Does this issue reproduce with the latest releases of all the above?
What operating system and processor architecture are you using?
MacOS M1 Ventura and Linux AMD64
Any other potentially useful information about your toolchain?
What did you do?
With nogo setup in monorepo, I'm trying to enable a
gochecknoinits
analyer, which check that no inits functions are present in Go code. When I ranbazel coverage //...
, nogo reports errors forinit()
functions it found on non-existing lines in some source files.What did you expect to see?
nogo should not report errors on files where there is no init() function in the original source file.
What did you see instead?
When coverage mode is set, the source file is modified with an
init()
function added to register files to coverdata, which is where nogo static analysis reported the error.https://github.com/bazelbuild/rules_go/blob/91e35309c55253d323e072b7a85f33188835903b/go/tools/builders/cover.go#L96-L105
Ideally nogo static analysis should not run against coverage instrumented source files, but the original ones. Under GoCompilePkg actions, the nogoSrcsOrigin map was introduced in #3216 for this purpose. But this mechanism doesn't work when cgo is enabled, as all source files path would change after cgo compilation: https://github.com/bazelbuild/rules_go/blob/91e35309c55253d323e072b7a85f33188835903b/go/tools/builders/compilepkg.go#L342
hence no file would match the nogoSrcsOrigin map, resulting in nogo uses the coverage instrumented source files instead: https://github.com/bazelbuild/rules_go/blob/91e35309c55253d323e072b7a85f33188835903b/go/tools/builders/compilepkg.go#L434-L444
I'd like to propose a fix to this issue by having cgo compile source files that are not coverage instrumented for nogo's use.
The text was updated successfully, but these errors were encountered: