-
-
Notifications
You must be signed in to change notification settings - Fork 664
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
Switching coverage to a better mechanism #713
Conversation
This works by tracking all coverage variables from the full transitive dependacy set, which allows multiple packages to be covered at once. This also normalises the names of cover variables so that two separate covers of the same file will produce actions that merge. It also tracks the cover variables directly, rather than inferring them from the file names, which also means the test generator does not need to process the generated files.
go/private/test.bzl
Outdated
covered_libs = [] | ||
for golib in depset([golib]) + golib.transitive: | ||
if golib.cover_vars: | ||
covered_libs += [golib] |
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.
Nit: 2-space indent
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.
Done
@@ -66,7 +75,7 @@ def _go_test_impl(ctx): | |||
library = None, | |||
want_coverage = False, | |||
importpath = ctx.label.name + "~testmain~", | |||
golibs = [golib], | |||
golibs = [golib] + covered_libs, |
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'll end up passing golib
in multiple times here. This could go in another CL, but I think emit_library_actions
should accept a depset instead of a list for this parameter.
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.
It actually does not matter because emit_library_actions immediately collects the libs into depsets internally (direct and transitive)
This was in another cl, it forwards the cover vars from the library attribute of a test
cover_var = "GoCover_%d" % count | ||
out = ctx.new_file(out_object, out_object.basename + '_' + src.basename[:-3] + '_' + cover_var + '.cover.go') | ||
cover_var = "Cover_" + src.basename[:-3].replace("-", "_").replace(".", "_") | ||
cover_vars += ["{}={}".format(cover_var,src.short_path)] |
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.
nit: one space after ",".
'--output', | ||
main_go.path, | ||
] | ||
cover_vars = [] |
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.
Seem not used.
@@ -93,6 +62,7 @@ import ( | |||
"flag" | |||
"log" | |||
"os" | |||
"fmt" |
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.
Move up to line 63.
This works by tracking all coverage variables from the full transitive dependacy
set, which allows multiple packages to be covered at once.
This also normalises the names of cover variables so that two separate covers of
the same file will produce actions that merge.
It also tracks the cover variables directly, rather than inferring them from the
file names, which also means the test generator does not need to process the
generated files.
@linuxerwang you might want to check these changes, as it's based heavily on the work you did.