-
-
Notifications
You must be signed in to change notification settings - Fork 641
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
Scoverage in Pants OSS Proposal #8026
Comments
Thanks @sammy-1234! This is a great overview. A few comments:
I'd suggest looking at what cobertura and jacoco do here: my understanding is that rather than having separate settings per coverage subsystem (Cobertura and Jacoco are the existing subsystem names), there are global settings in pants/src/python/pants/backend/jvm/tasks/coverage/manager.py Lines 53 to 81 in 056e60f
The reportDir would probably not be a per-coverage-implementation setting: it looks like the pants/src/python/pants/backend/jvm/tasks/coverage/jacoco.py Lines 124 to 133 in 056e60f
This cannot be a user-configurable setting. The |
Thanks @stuhood for this! It helps greatly. I'll look into it and update the issue accordingly. |
It should be noted that the releases for OSS scalac-scoverage-plugin is not frequent (~2 years between releases, with the current release happening ~a month ago). There is potential risk that the patch is never merged with OSS or having to wait significantly a long time for the merge to be released. |
Problem
The current code coverage framework offered by Pants for JVM targets (via Cobertura or Jacoco) works well for Java targets but doesn’t provide accurate results when using code coverage for Scala targets. Some of the common issues faced while building code coverage for scala targets include Case classes and traits being incorrectly measured or being missed altogether.
Solution
Adding Scoverage
Current issues with Scoverage
Instrumentation of binaries done during compile time instead of runtime
Unlike Jacoco and Cobertura, Scoverage instruments the target binaries for generating coverage during compile time instead of runtime. These instruments are then stored at a location specified by the dataDir provided by the user. Consequently, this demands the user to specify the dataDir for each target at compile time. Furthermore, since compilation of targets may run in a different/unique sandbox and tests may run in another different/unique sandbox, this compile time instrumentation of targets also breaks remoting as discussed below as discussed below.
No support for remoting compilation #265
Since scoverage does not put the created dataDir into the classpath, it does not allow for remoting. It would be beneficial to add an option in OSS Scoverage to include the dataDir in the classpath. This would provide more flexibility in systems that do not guarantee a local filesystem. Classpaths are well-known and would provide a better and more stable future extensibility for the scalac-scoverage-plugin.
Resolving issues with Scoverage
This PR attempts at resolving the remoting issue with scoverage. As specified in the comments in #265, we store the instrumented binaries at the output classpath specified by the compiler and at runtime, the measurements directory is specified by an environment variable
SCOVERAGE_MEASUREMENT_PATH
where the coverage measurements are stored.Until the suggested changes are merged into OSS scalac-scoverage-plugin, the issue can be resolved by making the necessary changes into a Twitter forked scalac-scoverage-plugin and updating Pants to point to the forked scoverage repo rather than the upstream one. Once the changes are committed into OSS scoverage, pants can again point to the upstream version.
Generating scoverage instruments and measurements in Pants
Instrumentation can be done with the help of a new subsystem scala_coverage_platform.py that overrides scalac_plugins and scalac_plugin_args in scala targets when scoverage is enabled.
As recommended by @stuhood below,
Scoverage would generates measurements in the same way as Jacoco or Cobertura, i.e by modifying
run_modifications
method insidescoverage.py
undercoverage
directory. Scoverage sets the System propertyscoverage_measurement_path
to theoutput_dir
where the measurements will be stored.Generating scoverage reports in Pants
Once the instruments and measurements have been generated, we can pass those to ReportGenerator.scala to generate the scoverage reports. This too can be done by modifying
report
method inscoverage.py
(similar to how Jacoco and Cobertura generate reports).Running scoverage with pants
If scoverage is sucsessfuly installed, you can get scala coverage reports by running the following command:
./pants --scoverage-enable-scoverage=True test <test-target>
The text was updated successfully, but these errors were encountered: