-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Upgrade Jacoco to 0.8.5+ to fix Scala 2.12 lambda code coverage #11674
Comments
JacocoCoverage is attached to java_toolchains. It should be possible to upgrade the version by configuring the toolchain. |
I tried with 0.8.5, generating coverage data works, but I still see the old output (Scala lambdas - for comprehension lines - are not covered). Here is the example: https://github.com/gergelyfabian/bazel-scala-example/tree/jacoco_coverage_fix Steps:
|
Now I know the reason is rules_scala is not using the jacocorunner from the Java toolchain, but it has the path to the runner hardcoded.
It's the same case if I have built JacocoCoverage_jarjar_deploy.jar with jars that I've built from my branch of jacoco (that only has the Scala fixes backported): https://github.com/gergelyfabian/jacoco/tree/0.8.3-scala-lambda-fix. If someone could kindly highlight how JacocoCoverage_jarjar_deploy.jar should be properly built from jacoco 0.8.5, 0.8.6 or my jacoco 0.8.3-scala-lambda-fix branch I'd be very grateful. |
Customizable jacocorunner in rules_scala: https://github.com/gergelyfabian/rules_scala/tree/custom_jacocorunner I guess rules_scala would need a fix, to automatically take jacocorunner from the Java toolchain. CC: @ittaiz |
I managed to make this solution with java_toolchain work.
I believe the only missing part is to extend rules_scala to use jacocorunner from the Java toolchain (to avoid using a forked rules_scala version), or at least to enable scala_test users to override jacocorunner. |
@comius For the rules_scala fix we'd need to do, do you maybe know how to retrieve |
@comius do you know that it's possible or you assume it's possible? |
I'm working on java toolchains. So it's possible to change jacoco_runner on the toolchain, i.e. by defining a custom default_java_toolchain rule and using it. Problem is that there is currently no Starlark interface so that this setting could be used in Scala directly from the toolchain as it is in Java native rules implementation.
Having java_tools is an alternative that also works. If somebody prepares it in a bazel branch, I could release it. I'm a bit reluctant to update it on the main branch, because Jacoco 0.8.3 is used internally and changing it is far from trivial. But I'm also reluctant to have an extra branch. But this seems to be the easiest/most usable option at the moment.
|
@comius, Do you mean:
? |
@ittaiz I'm not totally sure how I could do that if I already use a solution similar to this one: https://github.com/liucijus/bazel-scala211-jdk8 Can I use a custom java_tool (with custom Jacoco runner) if I also need to ensure my Java toolchain is running on JVM 8? |
How big would that a change be? Exposing to starlark that is. Would you be open to it? |
I think there should be. I haven't dived into the java_tools zip and so I don't know what exactly is java 8 related. |
Latest proposal for rules_scala is to enable providing jacocorunner on Implemented in: bazelbuild/rules_scala#1172 CC: @ittaiz |
Btw. I found out that Jacoco e.g. 0.8.7 seems to be binary incompatible with current Bazel (3.7.1 I checked). |
@gergelyfabian how big is the jacoco jar? Maybe we should commit the patched jar to rules_scala and have that be the default? If it's not too big maybe you should write in one of the relating issues the full repro and Vaidas or me will commit it (given it's binary maybe it's better it will be done by us) |
I think this may be a good idea. I have a script that I use to generate the
jacocorunner jar, so you could use that to build it and then upload it to
rules_scala.
FYI: I use the same script to create a different version as I have gone
further and started applying fixes for Scala itself in Jacoco (e.g branch
coverage for case class generated methods and fixes for Jacoco LCOV
Formatter in java_tools to respect Jacoco filtering for branch coverage).
I could contribute the script to rules_scala and you could use it according
to your wishes.
Ittai Zeidman <notifications@github.com> ezt írta (időpont: 2020. dec. 19.,
Szo 6:34):
… @gergelyfabian <https://github.com/gergelyfabian> how big is the jacoco
jar? Maybe we should commit the patched jar to rules_scala and have that be
the default? If it's not too big maybe you should write in one of the
relating issues the full repro and Vaidas or me will commit it (given it's
binary maybe it's better it will be done by us)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11674 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJGRRJRBUYG5NIOV3BOITTSVQ3OLANCNFSM4OL4D2OA>
.
|
This script could be also used by anyone to generate their own version of
jacocorunner and use it in their workspace (with any further fixes they
wish).
Fábián Gergely <gergo.fb@gmail.com> ezt írta (időpont: 2020. dec. 19., Szo
8:32):
… I think this may be a good idea. I have a script that I use to generate
the jacocorunner jar, so you could use that to build it and then upload it
to rules_scala.
FYI: I use the same script to create a different version as I have gone
further and started applying fixes for Scala itself in Jacoco (e.g branch
coverage for case class generated methods and fixes for Jacoco LCOV
Formatter in java_tools to respect Jacoco filtering for branch coverage).
I could contribute the script to rules_scala and you could use it
according to your wishes.
Ittai Zeidman ***@***.***> ezt írta (időpont: 2020. dec.
19., Szo 6:34):
> @gergelyfabian <https://github.com/gergelyfabian> how big is the jacoco
> jar? Maybe we should commit the patched jar to rules_scala and have that be
> the default? If it's not too big maybe you should write in one of the
> relating issues the full repro and Vaidas or me will commit it (given it's
> binary maybe it's better it will be done by us)
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#11674 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABJGRRJRBUYG5NIOV3BOITTSVQ3OLANCNFSM4OL4D2OA>
> .
>
|
… java_tools tests. Related to bazelbuild#11674
Related to bazelbuild#11674
Related to bazelbuild#11674
Related to bazelbuild#11674
Jacoco upgrade was made in Bazel in: bazelbuild/bazel#11674 bazelbuild/bazel@cb7c1a2
Jacoco upgrade was made in Bazel in: bazelbuild/bazel#11674 bazelbuild/bazel@cb7c1a2
Jacoco upgrade to 0.8.6 was made in Bazel in: bazelbuild/bazel#11674 bazelbuild/bazel@cb7c1a2 Upgraded jacoco and bazel branches and jacoco version.
Jacoco upgrade to 0.8.6 was made in Bazel in: bazelbuild/bazel#11674 bazelbuild/bazel@cb7c1a2 Upgraded jacoco and bazel branches and jacoco version.
Upgraded jacoco package name for Bazel 5.0+. Upgraded jacoco from 0.8.3 to 0.8.6. Jacoco upgrade to 0.8.6 was made in Bazel in: bazelbuild/bazel#11674 bazelbuild/bazel@cb7c1a2 Removed options for workarounds where those have been fixed in the meantime: Bazel's handling for branch coverage was fixed in: bazelbuild/bazel#12696
Upgraded jacoco package name for Bazel 5.0+. Upgraded jacoco from 0.8.3 to 0.8.6. Jacoco upgrade to 0.8.6 was made in Bazel in: bazelbuild/bazel#11674 bazelbuild/bazel@cb7c1a2 Removed options for workarounds where those have been fixed in the meantime: Bazel's handling for branch coverage was fixed in: bazelbuild/bazel#12696 Instead of changing the existing script for building Jacoco, added a new one that can be used for Bazel 5.0.
* JacocoRunner script: update for Bazel 5.0+ Upgraded jacoco package name for Bazel 5.0+. Upgraded jacoco from 0.8.3 to 0.8.6. Jacoco upgrade to 0.8.6 was made in Bazel in: bazelbuild/bazel#11674 bazelbuild/bazel@cb7c1a2 Removed options for workarounds where those have been fixed in the meantime: Bazel's handling for branch coverage was fixed in: bazelbuild/bazel#12696 Instead of changing the existing script for building Jacoco, added a new one that can be used for Bazel 5.0. * build_jacocorunner_bazel_5.0+: update bazel tag to avoid error for Java 17 bazelbuild/bazel#15081 fixed a bug when using coverage with Scala targets on Java 17. Use the tag 6.0.0-pre.20220520.1 where this was fixed.
Issue bazelbuild/bazel#11674 Closes #12829. PiperOrigin-RevId: 352380657
Description of the problem / feature request:
When building Scala 2.12 with https://github.com/bazelbuild/rules_scala coverage has a bug (Scala lambdas are not properly detected). This has been tracked down to a bug in Jacoco 0.8.3 + Scala 2.12 (Jacoco did not properly recognize Scala 2.12 lambdas in 0.8.3).
Jacoco 0.8.5 contains a bugfix for this problem.
To fix this issue Jacoco would need to be upgraded from 0.8.3 to 0.8.5 in Bazel.
Feature requests: what underlying problem are you trying to solve with this feature?
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Reproduction with Bazel:
bazel coverage --extra_toolchains="//scala:code_coverage_toolchain" //test/coverage/...
genhtml -o ${destdir} --ignore-errors source bazel-out/k8-fastbuild/testlogs/test/coverage/test-all/coverage.dat
Outside of Bazel:
Download http://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.5/jacoco-0.8.5.zip and http://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.3/jacoco-0.8.3.zip.
Take https://github.com/bazelbuild/rules_scala/blob/master/test/coverage/D1.scala and add a main method to it:
Steps:
a) Missed instructions: 3 of 32
b) only the first line of veryLongFunctionNameIsHereAaaaaaaaa is covered.
a) Missed instructions: 3 of 295
b) all lines of veryLongFunctionNameIsHereAaaaaaaaa are covered.
What operating system are you running Bazel on?
Ubuntu 18.04.
What's the output of
bazel info release
?release 3.0.0
If
bazel info release
returns "development version" or "(@non-git)", tell us how you built Bazel.What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?https://github.com/bazelbuild/rules_scala
056d5921d2c595e7ce2d54a627e8bc68ece7e28d
056d5921d2c595e7ce2d54a627e8bc68ece7e28d
Have you found anything relevant by searching the web?
Rules scala bug report details:
bazelbuild/rules_scala#1056
bazelbuild/rules_scala#1054
Scala 2.12 changes for lambda bytecode:
https://users.scala-lang.org/t/has-a-loop-recurs-comprehension-been-considered-for-scala/4787/21
https://www.scala-lang.org/news/2.12.0/
Jacoco Java lambda support:
https://stackoverflow.com/questions/45674950/jacoco-need-special-handling-fro-lambdas
https://stackoverflow.com/questions/32284326/code-coverage-for-lambda-function
jacoco/jacoco#232
Jacoco Scala lambda fix:
jacoco/jacoco#912
jacoco/jacoco#922
Any other information, logs, or outputs that you want to share?
More detailed information may be found at:
bazelbuild/rules_scala#1056
bazelbuild/rules_scala#1054
The text was updated successfully, but these errors were encountered: