Skip to content

Commit 55932be

Browse files
authored
Allow targets to fully opt out of nogo (#4403)
**What type of PR is this?** Feature **What does this PR do? Why is it needed?** By tagging a target with `"no-nogo"`, `nogo` isn't run at all, not even for fact generation. **Which issues(s) does this PR fix?** Work towards #4327 **Other notes for review**
1 parent 9badb60 commit 55932be

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

go/nogo.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ by default. You could exclude the external repositories from ``nogo`` by using t
145145
not validated with ``nogo`` by default. See the Bzlmod_ guide for more information
146146
on how to configure the ``nogo`` scope in this case.
147147

148+
You can prevent ``nogo`` from running for a particular target by adding ``"no-nogo"`` to
149+
``tags``. This can be useful for generated code, which is often large but not interesting
150+
for static analysis.
151+
148152
Fixes
149153
--------------------------------
150154

go/private/actions/archive.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
6262
nogo = go.nogo
6363

6464
# nogo is a FilesToRunProvider and some targets don't have it, some have it but no executable.
65-
if nogo != None and nogo.executable != None:
65+
if nogo != None and nogo.executable != None and not "no-nogo" in go._ctx.attr.tags:
6666
out_facts = go.declare_file(go, name = source.name, ext = pre_ext + ".facts")
6767
out_diagnostics = go.declare_directory(go, name = source.name, ext = pre_ext + "_nogo")
6868
if validate_nogo(go):
6969
out_nogo_validation = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo")
7070
else:
7171
out_nogo_validation = None
7272
else:
73+
nogo = None
7374
out_facts = None
7475
out_diagnostics = None
7576
out_nogo_validation = None

tests/core/nogo/custom/custom_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,22 @@ go_library(
134134
)
135135
136136
go_binary(
137-
name = "type_check_fail",
138-
srcs = ["type_check_fail.go"],
139-
pure = "on",
137+
name = "type_check_fail",
138+
srcs = ["type_check_fail.go"],
139+
pure = "on",
140140
)
141141
142142
go_library(
143143
name = "panics",
144144
srcs = ["panics.go"],
145-
importpath = "panics",
145+
importpath = "panics",
146+
)
147+
148+
go_library(
149+
name = "panics_no_nogo",
150+
srcs = ["panics.go"],
151+
importpath = "panics_no_nogo",
152+
tags = ["no-nogo"],
146153
)
147154
148155
-- foofuncname.go --
@@ -609,6 +616,10 @@ func Test(t *testing.T) {
609616
includes: []string{
610617
"panic: function must not be named ShouldPanic",
611618
},
619+
}, {
620+
desc: "panics_no_nogo",
621+
target: "//:panics_no_nogo",
622+
wantSuccess: true,
612623
},
613624
} {
614625
t.Run(test.desc, func(t *testing.T) {

0 commit comments

Comments
 (0)