Skip to content
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

Merged
merged 3 commits into from
Aug 11, 2017

Conversation

ianthehat
Copy link
Contributor

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.

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.
covered_libs = []
for golib in depset([golib]) + golib.transitive:
if golib.cover_vars:
covered_libs += [golib]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 2-space indent

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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
@ianthehat ianthehat merged commit 62d2474 into bazel-contrib:master Aug 11, 2017
@ianthehat ianthehat deleted the cover branch August 11, 2017 19:23
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)]
Copy link
Contributor

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 = []
Copy link
Contributor

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"
Copy link
Contributor

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.

vorburger added a commit to vorburger/rules_go that referenced this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants