Skip to content

Commit aa20e44

Browse files
committed
Preserve nogo runfiles
1 parent 54ba841 commit aa20e44

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

go/private/actions/archive.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
6060
out_cgo_export_h = None # set if cgo used in c-shared or c-archive mode
6161

6262
nogo = get_nogo(go)
63-
if nogo:
63+
64+
# 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:
6466
out_facts = go.declare_file(go, name = source.name, ext = pre_ext + ".facts")
6567
out_nogo_log = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo.log")
6668
out_nogo_validation = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo")

go/private/actions/compilepkg.bzl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ def emit_compilepkg(
8383
if out_lib == None:
8484
fail("out_lib is a required parameter")
8585

86-
have_nogo = nogo != None
86+
have_nogo = nogo != None and nogo.executable != None
8787
if have_nogo != (out_facts != None):
88-
fail("nogo must be specified if and only if out_facts is specified")
88+
fail("nogo must be specified if and only if out_facts is specified", nogo)
8989
if have_nogo != (out_nogo_log != None):
9090
fail("nogo must be specified if and only if out_nogo_log is specified")
9191
if have_nogo != (out_nogo_validation != None):
@@ -213,7 +213,7 @@ def emit_compilepkg(
213213
execution_requirements = execution_requirements,
214214
)
215215

216-
if nogo:
216+
if have_nogo:
217217
_run_nogo(
218218
go,
219219
shared_args = shared_args,
@@ -242,7 +242,7 @@ def _run_nogo(
242242
"""Runs nogo on Go source files, including those generated by cgo."""
243243
sdk = go.sdk
244244

245-
inputs_direct = (sources + [nogo, sdk.package_list] +
245+
inputs_direct = (sources + [sdk.package_list] +
246246
[archive.data.facts_file for archive in archives if archive.data.facts_file] +
247247
[archive.data.export_file for archive in archives])
248248
inputs_transitive = [sdk.tools, sdk.headers, go.stdlib.libs]
@@ -257,7 +257,7 @@ def _run_nogo(
257257
nogo_args.add("-out_facts", out_facts)
258258
nogo_args.add("-out_log", out_log)
259259
nogo_args.add("-out_fix", out_fix)
260-
nogo_args.add("-nogo", nogo)
260+
nogo_args.add("-nogo", nogo.executable)
261261

262262
# This action runs nogo and produces the facts files for downstream nogo actions.
263263
# It is important that this action doesn't fail if nogo produces findings, which allows users
@@ -268,6 +268,7 @@ def _run_nogo(
268268
# on findings to get the same debugging experience as with other failures.
269269
go.actions.run(
270270
inputs = depset(inputs_direct, transitive = inputs_transitive),
271+
tools = [nogo],
271272
outputs = outputs,
272273
mnemonic = "RunNogo",
273274
executable = go.toolchain._builder,

go/private/context.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,10 @@ def _go_context_data_impl(ctx):
661661
print("WARNING: --features=race is no longer supported. Use --@io_bazel_rules_go//go/config:race instead.")
662662
if "msan" in ctx.features:
663663
print("WARNING: --features=msan is no longer supported. Use --@io_bazel_rules_go//go/config:msan instead.")
664-
nogo = ctx.files.nogo[0] if ctx.files.nogo else None
665664
providers = [
666665
GoContextInfo(
667666
coverdata = ctx.attr.coverdata[0][GoArchive],
668-
nogo = nogo,
667+
nogo = ctx.attr.nogo[DefaultInfo].files_to_run,
669668
),
670669
ctx.attr.stdlib[GoStdLib],
671670
ctx.attr.go_config[GoConfigInfo],

0 commit comments

Comments
 (0)