Skip to content

Coverage for java_test doesn't handle external jars #13376

@ulfjack

Description

@ulfjack

Description of the problem / feature request:

In a Java build using jars from external repositories, running coverage may drop some coverage results due to incorrect path computations.

Bazel writes a file containing the runtime classpath using LazyWritePathsFileAction. The collect_coverage.sh script then processes that file to generate another file containing absolute paths by prefixing each of the paths with the runfiles directory and the workspace name. It then runs the singlejar tool on this list of jar files to merge them into a single file.

However, for jar files outside the main repository, this results in incorrect paths such as .../MyTest.runfiles/workspace/guava.jar, where the correct path should be .../MyTest.runfiles/guava/guava.jar.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Replace this line with your answer.

What operating system are you running Bazel on?

Seems to be OS-independent.

What's the output of bazel info release?

This happens with 4.0.0 and also HEAD.

Any other information, logs, or outputs that you want to share?

I have a patch that fixes the paths for coverage w/ java_test. However, the LazyWritePathsFileAction is used in three more places, and I suspect all of them are incorrect.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions