-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
nogo: use bazel validations and don't fail compile #3707
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,9 +62,17 @@ 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 | ||
|
||
# capture the nogo_log output but don't fail the compile, later we assert that the log is empty | ||
out_nogo_log = None | ||
out_nogo_validation = None | ||
if go.nogo: | ||
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 | ||
data_files = runfiles.files | ||
validations = [] | ||
|
||
files = [] | ||
for a in direct: | ||
|
@@ -106,6 +114,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d | |
out_lib = out_lib, | ||
out_export = out_export, | ||
out_cgo_export_h = out_cgo_export_h, | ||
out_nogo_log = out_nogo_log, | ||
gc_goopts = source.gc_goopts, | ||
cgo = True, | ||
cgo_inputs = cgo.inputs, | ||
|
@@ -129,12 +138,28 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d | |
archives = direct, | ||
out_lib = out_lib, | ||
out_export = out_export, | ||
out_nogo_log = out_nogo_log, | ||
gc_goopts = source.gc_goopts, | ||
cgo = False, | ||
testfilter = testfilter, | ||
recompile_internal_deps = recompile_internal_deps, | ||
) | ||
|
||
if go.nogo: | ||
validations.append(out_nogo_validation) | ||
go.actions.run_shell( | ||
inputs = [out_nogo_log], | ||
outputs = [out_nogo_validation], | ||
# Create the expected output file if there are no errors, otherwise print the errors to stderr. | ||
command = '[ -s "$1" ] && cat <(echo) "$1" <(echo) 1>&2 || touch $2', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this approach. The actual nogo is still running as part of GoCompilePkg action, producing an output that is consumed by this no-ops command. I would prefer if you start with separating Not quite sure if it's a thing, but ideally user should be able to request for a |
||
arguments = [ | ||
out_nogo_log.path, | ||
out_nogo_validation.path, | ||
], | ||
progress_message = "Nogo Static Analysis", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is slightly misleading as the action just processes the results, it doesn't analyze anything. Also, purely from a stylistic point of view, progress messages typically start with a verb in progressive form, e.g. |
||
mnemonic = "GoNogo", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future in which we have moved out the nogo analysis into its own action, this is exactly the mnemonic we would like to use for that. Since mnemonics are public API, please use something else here. |
||
) | ||
|
||
data = GoArchiveData( | ||
# TODO(#2578): reconsider the provider API. There's a lot of redundant | ||
# information here. Some fields are tuples instead of lists or dicts | ||
|
@@ -198,4 +223,5 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d | |
cgo_exports = cgo_exports, | ||
runfiles = runfiles, | ||
mode = go.mode, | ||
validations = validations, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ def emit_compilepkg( | |
clinkopts = [], | ||
out_lib = None, | ||
out_export = None, | ||
out_nogo_log = None, | ||
out_cgo_export_h = None, | ||
gc_goopts = [], | ||
testfilter = None, # TODO: remove when test action compiles packages | ||
|
@@ -112,6 +113,9 @@ def emit_compilepkg( | |
if go.nogo: | ||
args.add("-nogo", go.nogo) | ||
inputs.append(go.nogo) | ||
if out_nogo_log: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this ever validly be |
||
args.add("-nogo_log", out_nogo_log.path) | ||
outputs.append(out_nogo_log) | ||
if out_cgo_export_h: | ||
args.add("-cgoexport", out_cgo_export_h) | ||
outputs.append(out_cgo_export_h) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid relying on
run_shell
on Windows. Can you think of a way to replace this with arun
?For example, could this logic be moved into https://github.com/bazelbuild/rules_go/blob/master/go/tools/builders/generate_nogo_main.go?