Skip to content

Coverage is broken on Bazel 9 #613

Open

Description

@UebelAndre

As revealed on #612

Macos: https://buildkite.com/bazel/rules-cc/builds/4764/steps/canvas?sid=019ca055-a33b-4f69-86b4-152db7af6ad6

external/bazel_tools/tools/test/collect_cc_coverage.sh: line 99: : command not found
error: coverage collection script failed

Windows: https://buildkite.com/bazel/rules-cc/builds/4764/steps/canvas?sid=019ca055-a33c-4746-aace-efe7a6b88e02

GCov does not exist at the given path: 'external/+cc_configure_extension+local_config_cc/wrapper/bin/msvc_nop.bat'
error: coverage collection script failed

Activity

  1. UebelAndre commented on Feb 27, 2026

    @UebelAndre
    ContributorAuthor

    Maybe it would be worth-while to move @bazel_tools//tools/test/collect_cc_coverage.sh into rules_cc?

  2. fmeum commented on Feb 27, 2026

    @fmeum
    Collaborator

    As far as I remember Windows C++ coverage never worked and macOS is pretty fiddly to set up correctly. I think that they only fail in 9 since failures previously weren't fatal.

  3. UebelAndre commented on Feb 27, 2026

    @UebelAndre
    ContributorAuthor

    As far as I remember Windows C++ coverage never worked and macOS is pretty fiddly to set up correctly. I think that they only fail in 9 since failures previously weren't fatal.

    I'm obviously a fan of coverage failing the action if there was an error (bazelbuild/bazel#18650) but my expectation was that those errors would be fixed before allowing coverage to fail actions. Would it be possible to add an incompatibility flag for this (defaulted to off) that allows silent failures and then allow users to flip it on (to expose errors) if they either only build on linux or a fix is rolled out?

  4. UebelAndre commented on Feb 27, 2026

    @UebelAndre
    ContributorAuthor

    Maybe it would be worth-while to move @bazel_tools//tools/test/collect_cc_coverage.sh into rules_cc?

    For example, rules_rust has it's own coverage collection tool @rules_rust//util/collect_coverage/collect_coverage.rs

  5. fmeum commented on Feb 27, 2026

    @fmeum
    Collaborator
  6. keith commented on Mar 2, 2026

    @keith
    Member

    --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1 would sidestep that behavior if coverage was silently failing before, the assumption being that maybe instead you just shouldn't run bazel coverage and should swap to bazel test

  7. keith commented on Mar 2, 2026

    @keith
    Member

    Is coverage fully broken or is it just that the buildkite env isn't correctly setup for it? I think:

    external/bazel_tools/tools/test/collect_cc_coverage.sh: line 99: : command not found
    

    is a very bad error for a missing env var?

  8. UebelAndre commented on Mar 2, 2026

    @UebelAndre
    ContributorAuthor

    Is coverage fully broken or is it just that the buildkite env isn't correctly setup for it? I think:

    external/bazel_tools/tools/test/collect_cc_coverage.sh: line 99: : command not found
    

    is a very bad error for a missing env var?

    I opened this because I noticed the issue in rules_rust which I was upgrading to run Bazel 9 (bazelbuild/rules_rust#3867) and saw a cc_test fail with this issue. Seeing rules_cc CI fail with the same issue motivated me to start a discussion here.

  9. keith commented on Mar 2, 2026

    @keith
    Member

    ah yea that's an interesting case, sounds like coverage was working fine with some target types, but not cc_test, and so now they all have to work? either way that test_env is a good short term workaround

  10. UebelAndre commented on Mar 2, 2026

    @UebelAndre
    ContributorAuthor

    I added --test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1 to #612 and interestingly there are still some issues though for Bazel 7:

    https://buildkite.com/bazel/rules-cc/builds/4778/steps/canvas?sid=019cb066-921f-4077-9bae-c562cd5e3afd

    (21:14:42) INFO: From Testing //tests/runfiles:runfiles_test:
    ==================== Test output for //tests/runfiles:runfiles_test:
    ERROR(tools/test/windows/tw.cc:1302) ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\b\i3qnbkwl\execroot\_main\bazel-out\x64_windows-fastbuild\bin\tests\runfiles\runfiles_test.exe.runfiles\_main\external\bazel_tools\tools\test\collect_coverage.sh"  tests/runfiles/runfiles_test.exe): The system cannot find the file specified.
     (error: 2)
    ERROR(tools/test/windows/tw.cc:1479) Failed to start test process (arg: C:\b\i3qnbkwl\execroot\_main\bazel-out\x64_windows-fastbuild\bin\tests\runfiles\runfiles_test.exe.runfiles\_main\external\bazel_tools\tools\test\collect_coverage.sh)
    ================================================================================
    (21:14:42) ERROR: C:/b/bk-windows-c1ns/bazel/rules-cc/tests/runfiles/BUILD:5:8: output 'tests/runfiles/runfiles_test/coverage.dat' was not created
    (21:14:42) ERROR: C:/b/bk-windows-c1ns/bazel/rules-cc/tests/runfiles/BUILD:5:8: Testing //tests/runfiles:runfiles_test failed: not all outputs were created or valid
    

    Separately, it looks like HEAD is broken for some tests. Should these tests be flagged as soft_fail: yes?

  11. UebelAndre commented on Mar 2, 2026

    @UebelAndre
    ContributorAuthor

    Maybe it would be worth-while to move @bazel_tools//tools/test/collect_cc_coverage.sh into rules_cc?

    For example, rules_rust has it's own coverage collection tool @rules_rust//util/collect_coverage/collect_coverage.rs

    @keith curious what your thoughts are on this. Seems like it could be a path to providing a more consistent behavior around coverage for rules_cc?

  12. keith commented on Mar 2, 2026

    @keith
    Member

    I think it would be fine to move, maybe a bit weird since it's so intertwined with the other bazel logic tho https://github.com/bazelbuild/bazel/blob/3bdf554c2ff9bbe90dabfdd4d38d8d132e7e61a1/tools/test/collect_coverage.sh#L195

  13. UebelAndre commented on Mar 3, 2026

    @UebelAndre
    ContributorAuthor

    I think it would be fine to move, maybe a bit weird since it's so intertwined with the other bazel logic tho https://github.com/bazelbuild/bazel/blob/3bdf554c2ff9bbe90dabfdd4d38d8d132e7e61a1/tools/test/collect_coverage.sh#L195

    I'm not suggestion removing this from bazel. The script I referenced was collect_cc_coverage.sh which seemed both cc specific and like a fitting candidate to fork into rules_cc so changes can be made at a faster pace than the release of new Bazel versions.

  14. UebelAndre commented on Mar 3, 2026

    @UebelAndre
    ContributorAuthor

    I filed #616 as a concrete example of what I'm thinking about

  15. fmeum commented on Mar 3, 2026

    @fmeum
    Collaborator

    If we move this into rules_cc, we force every ruleset with a *_test rule to add a dep on rules_cc to reference this script. Realistically speaking nobody would ever be able to run a real-world Bazel dep without a transitive dep on rules_cc, but ideally we wouldn't force that direct dep onto every ruleset.

    The proper alternative would unfortunately require quite some design work: figure out a way to allow rulesets to register coverage hooks that run whenever these rulesets are in the transitive closure of a target.

    That said, if we do it, we should not introduce an incompatible flag for this as the change should ideally be fully transparent. Wouldn't we just copy the script over, perhaps with fixes from the latest Bazel commits?

  16. 5 remaining items

  17. c-mita commented on Mar 6, 2026

    @c-mita
    Member

    I still feel like folks aren't understanding what I'm saying

    1. Leave all coverage scripts in bazelbuild/bazel alone
    2. Add a collect_cc_coverage.sh script to bazelbuild/rules_cc
    3. For rules in bazelbuild/rules_cc change the _collect_cc_coverage attribute to point to the new bazelbuild/rules_cc script.

    No other rules are impacted, other rules can continue to either consume @bazel_tools//tools/test:collect_cc_coverage or replace it by defining the _collect_cc_coverage attribute. If rules_cc chooses to use a coverage collection script that lives within bazelbuild/rules_cc how does that have any impact on other rules?

    There would likely be problems when the scripts diverge.

    If there is a difference in the scripts, the rules_cc version would presumably be the "correct" one (since it should reflect the reality of the C++ rules), which means any test that transitively depends on C++ code (e.g. sh_test) should be using that version, which means it needs a dependency on it and thus rules_cc.

    This doesn't mean I don't think collect_cc_coverage.sh belongs in rules_cc, but moving it there has implications for users and rule authors.

  18. UebelAndre commented on Mar 6, 2026

    @UebelAndre
    ContributorAuthor

    There would likely be problems when the scripts diverge.

    If there is a difference in the scripts, the rules_cc version would presumably be the "correct" one (since it should reflect the reality of the C++ rules), which means any test that transitively depends on C++ code (e.g. sh_test) should be using that version, which means it needs a dependency on it and thus rules_cc.

    This doesn't mean I don't think collect_cc_coverage.sh belongs in rules_cc, but moving it there has implications for users and rule authors.

    Yeah, totally understand the consequences of copying collect_cc_coverage.sh to rules_cc in wanting to maintain parity between the two versions. But I think it'd ultimately be beneficial in being able to more quickly make improvements to it. Like, if the script lived here, and I ran into an issue, I would probably put up a pull-request and pull in the next BCR release. But with it living in Bazel, it's far more effort to make changes there and takes too long to come out. So instead I have to make a global change to add IGNORE_COVERAGE_COLLECTION_FAILURES=1 to all my test actions and potentially risk having issues silently ignored again which is kinda sad.

  19. added
    type: bug
    P2
    on Mar 17, 2026
  20. trybka commented on Mar 23, 2026

    @trybka
    Collaborator

    Presumably things that are broken for the cc rules that were silent/non-fatal before are problems for sh_test and friends, too, correct?

    It sounds like the main concern is divergence, but not necessarily with a specific notion of incompatibility, just "these will diverge and rules_cc will be correct, therefore folks will want to use the rules_cc copy."

    Could we have a new repo, "bazelbuild/coverage" or so that provides these scripts?

    For older Bazels we could backport useful/interesting fixes.

    Thoughts? @c-mita @fmeum @keith ?

  21. UebelAndre commented on Mar 24, 2026

    @UebelAndre
    ContributorAuthor

    For the record, #656 contains no fixes. It's just removing flags from CI that previously silenced the issues.

  22. UebelAndre commented on Mar 30, 2026

    @UebelAndre
    ContributorAuthor
  23. fmeum commented on Mar 30, 2026

    @fmeum
    Collaborator

    I think that a separate coverage_support or even test_support module makes sense. We also need a place to host the tw.exe Windows test wrapper for cross-platform test runs.

    cc @meteorcloudy Do you see value in moving the test runner to its own versioned module or would you prefer to keep it in bazel_tools?

  24. meteorcloudy commented on Mar 30, 2026

    @meteorcloudy
    Member

    Eventually, I would like to move things out of bazel_tools as much as possible (test runner, proto libraries, launchers, etcs). bazelbuild/bazel#28434

    But for now, we don't have a good way to set up the release process of those smaller modules and I'm a bit afraid of the maintenance cost. @Wyverald I think we should probably plan this work next quarter or at least before Bazel 10.

  25. keith commented on Mar 30, 2026

    @keith
    Member

    I think if we want to move that script here we should just move it, remove it from bazel, and leave an alias in bazel for other consumers of it. I don't think that would cause any issues today (at least with 9.x+ where users would be forced to get a rules_cc version with the new file)

  26. UebelAndre commented on Mar 31, 2026

    @UebelAndre
    ContributorAuthor

    @trybka your thoughts on the responses? I also don’t know who has final say here.

  27. pzembrod commented on Aug 28, 2026

    @pzembrod
    Collaborator

    @c-mita Do you know what the latest status on this is, after your recent coverage work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2category: core rulestype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions