Skip to content

Conversation

@fmeum
Copy link
Collaborator

@fmeum fmeum commented Jul 22, 2025

The core idea of this change is to make collect_coverage an sh_binary instead of a single .sh file as the former can be executed on Windows via the native launcher it creates. However, this requires a bunch of work in the test framework:

  • Ensure that the collect_coverage script has its runfiles included in TestActionBuilder. Along the way and to ensure consistency, clean up unnecessary cases for the runfiles of the LCOV merger tool.
  • Add support for launching the coverage wrapper to tw, which didn't have any logic for this case.
  • Hide the runfiles env variables meant for the test from the coverage wrapper. The wrapper has its own runfiles tree and would otherwise be mislead to reuse the test's runfiles tree, which doesn't work. Instead, wrap the environment before invoking the wrapper and then unwrap them in the wrapper.
  • Modify the coverage output generator to emit \n line endings on all platforms for consistency (and to get existing tests to pass).

With these changes, bazel_coverage_starlark_test now passes on Windows after adding batch test variants of shell tests. Support for Java and C++ will be added in future PRs.

Work towards #6374
Work towards #18839

@fmeum fmeum force-pushed the windows-coverage branch 4 times, most recently from 26993b5 to 22daa70 Compare July 22, 2025 13:52
@fmeum fmeum force-pushed the windows-coverage branch 2 times, most recently from b781951 to 7df2655 Compare July 23, 2025 08:49
@fmeum fmeum changed the title Run coverage tests on Windows Add basic support for coverage on Windows Jul 23, 2025
@fmeum fmeum force-pushed the windows-coverage branch from 99401e6 to 4d2b079 Compare July 23, 2025 12:20
@fmeum fmeum force-pushed the windows-coverage branch from 7d842d5 to 28195b4 Compare July 23, 2025 15:16
@fmeum fmeum marked this pull request as ready for review July 23, 2025 15:16
@fmeum fmeum requested review from a team and lberki as code owners July 23, 2025 15:16
@fmeum fmeum requested review from gregestren and meisterT and removed request for a team, gregestren and lberki July 23, 2025 15:16
@github-actions github-actions bot added team-Configurability platforms, toolchains, cquery, select(), config transitions awaiting-review PR is awaiting review from an assigned reviewer labels Jul 23, 2025
@fmeum fmeum requested a review from c-mita July 23, 2025 15:17
@fmeum
Copy link
Collaborator Author

fmeum commented Jul 23, 2025

@meisterT for the test logic and tw.exe changes, @c-mita for coverage (and FYI @meteorcloudy for when you are back in office)

@peakschris
Copy link

Love this; thanks for the work; my colleague has tested this PR and it fixes some issues we were having - thank you!

@fmeum fmeum force-pushed the windows-coverage branch 2 times, most recently from 76cca14 to 28195b4 Compare July 27, 2025 21:13
@fmeum
Copy link
Collaborator Author

fmeum commented Jul 28, 2025

I pushed a new commit that should fix a crash with --experimental_split_coverage_postprocessing that @KrishnaM256 made me aware of. I found a bug in coverage logging that made this unnecessarily hard to figure out and sent #26647 to fix that separate problem.

@fmeum
Copy link
Collaborator Author

fmeum commented Jul 28, 2025

@bazel-io fork 8.4.0

@iancha1992
Copy link
Member

Hi @meisterT @c-mita. Is there any update on this?

Copy link
Member

@c-mita c-mita left a comment

Choose a reason for hiding this comment

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

I think this is basically fine. Although I wouldn't be surprised if this broke something internally...


static void print(OutputStream outputStream, Coverage coverage, boolean outputLegacyBranches)
throws IOException {
// Emit consistent line endings across all platforms.
Copy link
Member

Choose a reason for hiding this comment

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

Is this just so a report generated on Windows is identical to one generated on another OS with the same input data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pretty much yes. The execution platform of the CoverageOutputGenerator, which otherwise doesn't matter, should not influence the output. It also simplifies the tests.

@fmeum fmeum requested a review from c-mita August 13, 2025 12:15
@c-mita c-mita added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Aug 13, 2025
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Aug 25, 2025
c-mita pushed a commit to c-mita/bazel that referenced this pull request Sep 9, 2025
The core idea of this change is to make `collect_coverage` an `sh_binary` instead of a single `.sh` file as the former can be executed on Windows via the native launcher it creates. However, this requires a bunch of work in the test framework:
* Ensure that the `collect_coverage` script has its runfiles included in `TestActionBuilder`. Along the way and to ensure consistency, clean up unnecessary cases for the runfiles of the LCOV merger tool.
* Add support for launching the coverage wrapper to `tw`, which didn't have any logic for this case.
* Hide the runfiles env variables meant for the test from the coverage wrapper. The wrapper has its own runfiles tree and would otherwise be mislead to reuse the test's runfiles tree, which doesn't work. Instead, wrap the environment before invoking the wrapper and then unwrap them in the wrapper.
* Modify the coverage output generator to emit `\n` line endings on all platforms for consistency (and to get existing tests to pass).

With these changes, `bazel_coverage_starlark_test` now passes on Windows after adding batch test variants of shell tests. Support for Java and C++ will be added in future PRs.

Work towards bazelbuild#6374
Work towards bazelbuild#18839

Closes bazelbuild#26603.

PiperOrigin-RevId: 799018475
Change-Id: Icdb1e6e4698b2a749fbb17f7e1a9aaa34e895d70
c-mita pushed a commit to c-mita/bazel that referenced this pull request Sep 9, 2025
The core idea of this change is to make `collect_coverage` an `sh_binary` instead of a single `.sh` file as the former can be executed on Windows via the native launcher it creates. However, this requires a bunch of work in the test framework:
* Ensure that the `collect_coverage` script has its runfiles included in `TestActionBuilder`. Along the way and to ensure consistency, clean up unnecessary cases for the runfiles of the LCOV merger tool.
* Add support for launching the coverage wrapper to `tw`, which didn't have any logic for this case.
* Hide the runfiles env variables meant for the test from the coverage wrapper. The wrapper has its own runfiles tree and would otherwise be mislead to reuse the test's runfiles tree, which doesn't work. Instead, wrap the environment before invoking the wrapper and then unwrap them in the wrapper.
* Modify the coverage output generator to emit `\n` line endings on all platforms for consistency (and to get existing tests to pass).

With these changes, `bazel_coverage_starlark_test` now passes on Windows after adding batch test variants of shell tests. Support for Java and C++ will be added in future PRs.

Work towards bazelbuild#6374
Work towards bazelbuild#18839

Closes bazelbuild#26603.

PiperOrigin-RevId: 799018475
Change-Id: Icdb1e6e4698b2a749fbb17f7e1a9aaa34e895d70
iancha1992 pushed a commit that referenced this pull request Sep 9, 2025
The core idea of this change is to make `collect_coverage` an
`sh_binary` instead of a single `.sh` file as the former can be executed
on Windows via the native launcher it creates. However, this requires a
bunch of work in the test framework:
* Ensure that the `collect_coverage` script has its runfiles included in
`TestActionBuilder`. Along the way and to ensure consistency, clean up
unnecessary cases for the runfiles of the LCOV merger tool.
* Add support for launching the coverage wrapper to `tw`, which didn't
have any logic for this case.
* Hide the runfiles env variables meant for the test from the coverage
wrapper. The wrapper has its own runfiles tree and would otherwise be
mislead to reuse the test's runfiles tree, which doesn't work. Instead,
wrap the environment before invoking the wrapper and then unwrap them in
the wrapper.
* Modify the coverage output generator to emit `\n` line endings on all
platforms for consistency (and to get existing tests to pass).

With these changes, `bazel_coverage_starlark_test` now passes on Windows
after adding batch test variants of shell tests. Support for Java and
C++ will be added in future PRs.

Work towards #6374 Work
towards #18839

Closes #26603.

PiperOrigin-RevId: 799018475
Change-Id: Icdb1e6e4698b2a749fbb17f7e1a9aaa34e895d70

Commit: 74285e2

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Configurability platforms, toolchains, cquery, select(), config transitions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants