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

bazel coverage support for Scala #7109

Closed
basavaraj29 opened this issue Jan 14, 2019 · 2 comments
Closed

bazel coverage support for Scala #7109

basavaraj29 opened this issue Jan 14, 2019 · 2 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request

Comments

@basavaraj29
Copy link

Description of the problem / feature request:

Code Coverage support for Scala.

Feature requests: what underlying problem are you trying to solve with this feature?

We need to track code coverage statistics for scala. We've seen that bazel coverage works for Java, but we are not able to find any pointers for tracking scala code coverage using bazel.

What operating system are you running Bazel on?

macOS

What's the output of bazel info release?

release 0.18.0

Have you found anything relevant by searching the web?

bazelbuild/rules_scala#184

@lberki lberki added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Mar 13, 2019
@gergelyfabian
Copy link

gergelyfabian commented Dec 20, 2019

I think this feature is already supported by bazel.

Let me summarize the state (as I see it) for December 2019 (Bazel 1.2.0 and rules_scala 26cf9b74fc46f1e9a970c97837447549ed7257b6).

Code coverage is supported by Jacoco for JVM languages in Bazel. Jacoco uses the lcov format for code coverage output.

To run code coverage with Jacoco for Scala code you can run (you need the extra toolchain as the scala support wasn't enabled by default - please see the comments in bazelbuild/rules_scala#692):

bazel coverage --extra_toolchains="@io_bazel_rules_scala//test/coverage:enable_code_coverage_aspect" //...

It will produce several .dat files for your modules.
You should install lcov package to have access to genhtml (e.g. on Ubuntu: sudo apt install lcov), that can be used to convert the .dat files to html for a more readable report.

Then you've got two issues to solve:

  1. bazel does not summarize the coverage statistics for you (for Scala)
  2. when you try running genhtml for the .dat files it won't have access to the source files

Both can be solved by using an approach taken e.g. by Gerrit project.
See #2528 for more information, this also seems to be an issue for Java source code. A possible solution is running a script that moves all source files to a new folder and runs genhtml from that place so that genhtml can have access to them. You can check https://gerrit-review.googlesource.com/c/gerrit/+/106471/6/tools/coverage.sh for inspiration. Current version of this script is also in Gerrit source code: https://gerrit.googlesource.com/gerrit/+/master/tools/coverage.sh.

Using a modified version of this script solved also the html report problem for me (e.g. add copying also Scala source files, not just Java).

For sure some documentation on Scala code coverage would be nice to have, but with some digging it seems to be working.

@basavaraj29
Copy link
Author

Yes, support for coverage was first introduced in 0.23.0 I suppose. We've got it to work with 0.29.0. Closing this issue, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request
Projects
None yet
Development

No branches or pull requests

4 participants