Skip to content

Preserve nogo runfiles #4270

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

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go/private/actions/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
out_cgo_export_h = None # set if cgo used in c-shared or c-archive mode

nogo = get_nogo(go)
if nogo:

# nogo is a FilesToRunProvider and some targets don't have it, some have it but no executable.
if nogo != None and nogo.executable != None:
out_facts = go.declare_file(go, name = source.name, ext = pre_ext + ".facts")
out_nogo_log = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo.log")
out_nogo_validation = go.declare_file(go, name = source.name, ext = pre_ext + ".nogo")
Expand Down
11 changes: 6 additions & 5 deletions go/private/actions/compilepkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def emit_compilepkg(
if out_lib == None:
fail("out_lib is a required parameter")

have_nogo = nogo != None
have_nogo = nogo != None and nogo.executable != None
if have_nogo != (out_facts != None):
fail("nogo must be specified if and only if out_facts is specified")
fail("nogo must be specified if and only if out_facts is specified", nogo)
if have_nogo != (out_nogo_log != None):
fail("nogo must be specified if and only if out_nogo_log is specified")
if have_nogo != (out_nogo_validation != None):
Expand Down Expand Up @@ -213,7 +213,7 @@ def emit_compilepkg(
execution_requirements = execution_requirements,
)

if nogo:
if have_nogo:
_run_nogo(
go,
shared_args = shared_args,
Expand Down Expand Up @@ -242,7 +242,7 @@ def _run_nogo(
"""Runs nogo on Go source files, including those generated by cgo."""
sdk = go.sdk

inputs_direct = (sources + [nogo, sdk.package_list] +
inputs_direct = (sources + [sdk.package_list] +
[archive.data.facts_file for archive in archives if archive.data.facts_file] +
[archive.data.export_file for archive in archives])
inputs_transitive = [sdk.tools, sdk.headers, go.stdlib.libs]
Expand All @@ -257,7 +257,7 @@ def _run_nogo(
nogo_args.add("-out_facts", out_facts)
nogo_args.add("-out_log", out_log)
nogo_args.add("-out_fix", out_fix)
nogo_args.add("-nogo", nogo)
nogo_args.add("-nogo", nogo.executable)

# This action runs nogo and produces the facts files for downstream nogo actions.
# It is important that this action doesn't fail if nogo produces findings, which allows users
Expand All @@ -268,6 +268,7 @@ def _run_nogo(
# on findings to get the same debugging experience as with other failures.
go.actions.run(
inputs = depset(inputs_direct, transitive = inputs_transitive),
tools = [nogo],
outputs = outputs,
mnemonic = "RunNogo",
executable = go.toolchain._builder,
Expand Down
3 changes: 1 addition & 2 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,10 @@ def _go_context_data_impl(ctx):
print("WARNING: --features=race is no longer supported. Use --@io_bazel_rules_go//go/config:race instead.")
if "msan" in ctx.features:
print("WARNING: --features=msan is no longer supported. Use --@io_bazel_rules_go//go/config:msan instead.")
nogo = ctx.files.nogo[0] if ctx.files.nogo else None
providers = [
GoContextInfo(
coverdata = ctx.attr.coverdata[0][GoArchive],
nogo = nogo,
nogo = ctx.attr.nogo[DefaultInfo].files_to_run,
),
ctx.attr.stdlib[GoStdLib],
ctx.attr.go_config[GoConfigInfo],
Expand Down
Loading