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.
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:
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.rules_go/go/tools/builders/cover.go
Lines 96 to 105 in 91e3530
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:
rules_go/go/tools/builders/compilepkg.go
Line 342 in 91e3530
hence no file would match the nogoSrcsOrigin map, resulting in nogo uses the coverage instrumented source files instead:
rules_go/go/tools/builders/compilepkg.go
Lines 434 to 444 in 91e3530
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: