rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

How to run code coverage only for Scala targets

Open gergelyfabian opened this issue 5 years ago • 7 comments

I have a project with three targets (among others):

java_library(...)

scala_library(...)

scala_test(...)

Where the scala_library depends on the java_library and the scala_test depends on scala_library. If I run code coverage with this setup, if will execute that only for the java_library and scala code coverage won't be executed.

If I remove the java_library target, then everything works ok.

There is one solution I found: add "--instrumentation_filter=//*:scala_library" as a parameter when running coverage. Is there any better way to fix this problem?

gergelyfabian avatar Jan 02 '20 14:01 gergelyfabian

Another possible fix is: --instrumentation_filter="-:java_library"

gergelyfabian avatar Jan 02 '20 14:01 gergelyfabian

IIUC the problem is that you get either or? And you’d like to get both?

ittaiz avatar Jan 04 '20 05:01 ittaiz

The problem is, that without additional parameters I get only Java coverage. I need to disable instrumentation for java_library to get coverage for scala_library. I could also live with getting coverage for both.

All targets are in the same project. Maybe I should move the java_library to a different project and leave only scala_library and scala_test in the same project?

gergelyfabian avatar Jan 04 '20 11:01 gergelyfabian

@iirina as grand master of bazel coverage. Any chance you can lend a hand? Is it a bug in how rules_scala does coverage?

ittaiz avatar Jan 04 '20 12:01 ittaiz

Can you describe the big picture of how rules_scala computes coverage? :)

iirina avatar Jan 28 '20 09:01 iirina

@borkaehw can you answer Irina's question? I was out of the coverage loop and you've somewhat dabbled into it right now

ittaiz avatar Jan 31 '20 10:01 ittaiz

I poked around the code a bit, but I couldn't find the issue. We haven't adopted bazelbuild/rules_scala so not sure. But it's a known issue in test/coverage/BUILD

#
# As it stands I can't seem to generate coverage for Java libraries pulled into
# a scala_test target.
#
# The java_library is instrumented, but doesn't have the .uninstrumented files
# that Bazel seems to expect. There are a few code paths for code coverage, so
# down the road we can explore how to fix this...
#

borkaehw avatar Jan 31 '20 17:01 borkaehw