Skip to content

Commit

Permalink
Refactor out file definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jul 26, 2024
1 parent e1ed6fe commit 80ba35c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
14 changes: 11 additions & 3 deletions go/private/actions/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
out_export = go.declare_file(go, name = source.library.name, ext = pre_ext + ".x")
out_cgo_export_h = None # set if cgo used in c-shared or c-archive mode
out_facts = None
out_nogo_log = None
out_nogo_validation = None
nogo = go.get_nogo(go)
if nogo:
out_facts = go.declare_file(go, name = source.library.name, ext = pre_ext + ".facts")
out_nogo_log = go.declare_file(go, name = source.library.name, ext = pre_ext + ".nogo.log")
out_nogo_validation = go.declare_file(go, name = source.library.name, ext = pre_ext + ".nogo")

direct = [get_archive(dep) for dep in source.deps]
runfiles = source.runfiles
Expand Down Expand Up @@ -99,7 +103,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
out_cgo_export_h = go.declare_file(go, path = "_cgo_install.h")
cgo_deps = cgo.deps
runfiles = runfiles.merge(cgo.runfiles)
validation_output = emit_compilepkg(
emit_compilepkg(
go,
sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers + split.syso,
cover = source.cover,
Expand All @@ -110,6 +114,8 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
out_lib = out_lib,
out_export = out_export,
out_facts = out_facts,
out_nogo_log = out_nogo_log,
out_nogo_validation = out_nogo_validation,
nogo = nogo,
out_cgo_export_h = out_cgo_export_h,
gc_goopts = source.gc_goopts,
Expand All @@ -126,7 +132,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
)
else:
cgo_deps = depset()
validation_output = emit_compilepkg(
emit_compilepkg(
go,
sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers + split.syso,
cover = source.cover,
Expand All @@ -137,6 +143,8 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
out_lib = out_lib,
out_export = out_export,
out_facts = out_facts,
out_nogo_log = out_nogo_log,
out_nogo_validation = out_nogo_validation,
nogo = nogo,
gc_goopts = source.gc_goopts,
cgo = False,
Expand Down Expand Up @@ -185,7 +193,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
export_file = out_export,
facts_file = out_facts,
data_files = as_tuple(data_files),
_validation_output = validation_output,
_validation_output = out_nogo_validation,
_cgo_deps = as_tuple(cgo_deps),
)
x_defs = dict(source.x_defs)
Expand Down
18 changes: 11 additions & 7 deletions go/private/actions/compilepkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def emit_compilepkg(
out_lib = None,
out_export = None,
out_facts = None,
out_nogo_log = None,
out_nogo_validation = None,
nogo = None,
out_cgo_export_h = None,
gc_goopts = [],
Expand All @@ -81,6 +83,10 @@ def emit_compilepkg(
fail("out_lib is a required parameter")
if bool(nogo) != bool(out_facts):
fail("nogo must be specified if and only if out_facts is specified")
if bool(nogo) != bool(out_nogo_log):
fail("nogo must be specified if and only if out_nogo_log is specified")
if bool(nogo) != bool(out_nogo_validation):
fail("nogo must be specified if and only if out_nogo_validation is specified")

inputs = (sources + embedsrcs + [go.package_list] +
[archive.data.export_file for archive in archives] +
Expand Down Expand Up @@ -194,18 +200,18 @@ def emit_compilepkg(
)

if nogo:
return _run_nogo(
_run_nogo(
go,
sources = sources,
importpath = importpath,
importmap = importmap,
archives = archives,
cgo_go_srcs = cgo_go_srcs,
out_facts = out_facts,
out_log = out_nogo_log,
out_validation = out_nogo_validation,
nogo = nogo,
)
else:
return None

def _run_nogo(
go,
Expand All @@ -216,10 +222,11 @@ def _run_nogo(
archives,
cgo_go_srcs,
out_facts,
out_log,
out_validation,
nogo):
"""Runs nogo on Go source files, including those generated by cgo."""
basename = out_facts.basename.removesuffix(".facts")
out_log = go.actions.declare_file(basename + ".nogo", sibling = out_facts)
inputs = (sources + [nogo, go.package_list] +
[archive.data.facts_file for archive in archives if archive.data.facts_file] +
[archive.data.export_file for archive in archives] +
Expand Down Expand Up @@ -256,7 +263,6 @@ def _run_nogo(
progress_message = "Running nogo on %{label}",
)

out_validation = go.actions.declare_file(basename + ".nogo.validation", sibling = out_facts)
go.actions.run_shell(
inputs = [out_log],
outputs = [out_validation],
Expand All @@ -276,5 +282,3 @@ fi
mnemonic = "GoNogoValidation",
progress_message = "Validating nogo output for %{label}",
)

return out_validation

0 comments on commit 80ba35c

Please sign in to comment.