bazel: `bazel coverage` fails over remote ex for java_test

Description of the problem / feature request:

Tooling for coverage fails when running under remote execution (LcovMerger specifically)

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

Run a test target with bazel coverage --spawn_strategy=remote --remote_executor=... //path/to:test

What operating system are you running Bazel on?

Ubuntu 14.04

What’s the output of bazel info release?

release 0.10.1

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

Relevant portion of coverage execution

+ exec bazel-out/k8-fastbuild/bin/external/bazel_tools/tools/test/LcovMerger --coverage_dir=%execroot%/_coverage/path/to/test/test --output_file=%execroot%/bazel-out/k8-fastbuild/testlogs/path/to/test/coverage.dat
%execroot%/bazel-out/k8-fastbuild/bin/external/bazel_tools/tools/test/LcovMerger: Cannot locate runfiles directory. (Set $JAVA_RUNFILES to inhibit searching.)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 71 (52 by maintainers)

Commits related to this issue

Most upvoted comments

I’m working on this. Hopefully, I have a fix soon.

@SimonVleugels - Looks like the patch I originally created it has been changed slightly. I haven’t had time to check but I can try and take a look later: https://github.com/bazelbuild/bazel/blob/5.0.0/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java#L593

Ulf, do you plan to do anything here?

As a workaround, you can do the following (currently requires Bazel built from HEAD):

  1. Clone https://github.com/ulfjack/bazel/tree/coverage-3
  2. Build the coverage output generator
bazel build //tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:coverage_output_generator.zip
  1. Unzip result into a new directory:
unzip path/to/clone/bazel-bin/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/coverage_output_generator.zip
  1. Use --override_repository with bazel coverage:
bazel coverage //java/foo:foo_test --config=remote --override_repository=remote_coverage_tools=/path/to/unzipped/coverage/output/generator/

Alternatively, you can pull back the full coverage outputs and manually post-process them:

bazel coverage //java/foo:foo_test --config=remote --experimental_fetch_all_coverage_outputs

The downside of this second approach is that it also pulls back a bunch of (potentially) large, unnecessary files.

I was just hoping to not have to to pass --test_env=LCOV_MERGER=/bin/true.

I’m still not sure how best to fix it, but I can improve the situation. I’m reluctant to change how the test action stages the coverage tool.

Why the reluctance? Wouldn’t adding the coverage binary properly as a tool to the test action (i.e., fix #4033) be the cleanest resolution?