Bazel: Have a general mechanism for collecting code coverage

Created on 14 Aug 2018  路  3Comments  路  Source: bazelbuild/bazel

Code coverage support in Bazel is poor and one reason is the lack of a general mechanism for collecting the code coverage information.

As briefly described in Bazel coverage design doc, the next steps towards a more general solution are:

  • Design and implement a coverage_toolchain
  • Migrate Bazel builtin C++ code coverage collection to use the new mechanism.
P3 coverage team-Rules-Server feature request

Most helpful comment

@iirina I thought i'd post the instructions you left me here incase someone else is after a way to integrate with bazel coverage in the interm until this is better supported.


If the rules are written in Starlark, something helpful can be:

Bazel generates coverage reports in the lcov format. To work well with Bazel, your test rules also have to generate lcov reports under COVERAGE_DIR directory. Your test rule has to define the $lcov_merger attrbiute (similar to how Java tests do ) https://github.com/bazelbuild/bazel/blob/17794d58cc493d918a98c3250302ca44b1d53e3f/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaTestRule.java#L70

All 3 comments

@iirina I thought i'd post the instructions you left me here incase someone else is after a way to integrate with bazel coverage in the interm until this is better supported.


If the rules are written in Starlark, something helpful can be:

Bazel generates coverage reports in the lcov format. To work well with Bazel, your test rules also have to generate lcov reports under COVERAGE_DIR directory. Your test rule has to define the $lcov_merger attrbiute (similar to how Java tests do ) https://github.com/bazelbuild/bazel/blob/17794d58cc493d918a98c3250302ca44b1d53e3f/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaTestRule.java#L70

One thing that came up today - with this design of coverage collection is it possible to have another rule depend on the coverage output? We would like to write another rule that depends on the output and then creates a script that will upload the report on bazel run.

@iirina I'm taking another look at this but I havn't been able to figure out how to get COVERAGE_DIR defined.
This is this PR im working in and im running the test npx bazel coverage packages/jasmine/test:coverage_test but the only env var that's defined is LCOV_MERGER becasue I set it with coverage --test_env=LCOV_MERGER=/bin/true https://github.com/bazelbuild/rules_nodejs/pull/1135

Was this page helpful?
0 / 5 - 0 ratings