Skip to content

util/collect_coverage: Allow overriding TARGET_FILE#3808

Draft
akhramov wants to merge 1 commit intobazelbuild:mainfrom
akhramov:feat/collect_coverage_override_target
Draft

util/collect_coverage: Allow overriding TARGET_FILE#3808
akhramov wants to merge 1 commit intobazelbuild:mainfrom
akhramov:feat/collect_coverage_override_target

Conversation

@akhramov
Copy link

Currently, the instrumented binary is sourced from the TARGET_FILE environment variable. For wrappers around rust_test, this variable points to the wrapper rather than the actual binary, which breaks code coverage.

This change:

  • Introduces the RULES_RUST_TEST_BINARY_OVERRIDE environment variable, which wrapper authors can use to supply the path to the original test binary.

  • Uses the runfiles library to resolve runfiles_dir instead of relying solely on the RUNFILES_DIR variable.

Currently, the instrumented binary is sourced from the `TARGET_FILE`
environment variable. For wrappers around `rust_test`, this variable
points to the wrapper rather than the actual binary, which breaks
code coverage.

This change:

* Introduces the `RULES_RUST_TEST_BINARY_OVERRIDE` environment
  variable, which wrapper authors can use to supply the path to the
  original test binary.

* Uses the runfiles library to resolve `runfiles_dir` instead of
  relying solely on the `RUNFILES_DIR` variable.
@google-cla
Copy link

google-cla bot commented Jan 16, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! But I'm confused at what this change does. Is RUNFILES_DIR not reliable? And what is the use of the override?

@akhramov
Copy link
Author

Thanks for looking. I owe you a repro on bot of these. Will come up with one soon.

In short,

Is RUNFILES_DIR not reliable

in our setup RUNFILES_PATH is not set when we run bazel coverage, will figure out why first.

And what is the use of the override?

Wrapper scripts have TARGET_FILE set to the wrapper, not the wrapee, so the script passes the wrong path to llvm-cov export

@akhramov akhramov marked this pull request as draft February 3, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants