rules_scala
rules_scala copied to clipboard
How to run code coverage only for Scala targets
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?
Another possible fix is: --instrumentation_filter="-:java_library"
IIUC the problem is that you get either or? And you’d like to get both?
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?
@iirina as grand master of bazel coverage. Any chance you can lend a hand? Is it a bug in how rules_scala does coverage?
Can you describe the big picture of how rules_scala computes coverage? :)
@borkaehw can you answer Irina's question? I was out of the coverage loop and you've somewhat dabbled into it right now
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...
#