Skip to content

Fix test and shell execution OS logic#28038

Closed
fmeum wants to merge 8 commits intobazelbuild:masterfrom
fmeum:fix-test-exec-platform
Closed

Fix test and shell execution OS logic#28038
fmeum wants to merge 8 commits intobazelbuild:masterfrom
fmeum:fix-test-exec-platform

Conversation

@fmeum
Copy link
Copy Markdown
Collaborator

@fmeum fmeum commented Dec 17, 2025

The execution OS is determined by the specified test exec group, which can differ from the test exec group as well as the test rule's default execution group. Also renames some helper methods to make this class of bugs less likely and clean up ConstraintConstants to support the macos alias for the darwin OS constraint value.

As a consequence of this refactoring, it became clear that the shell path was determined by the host OS when the execution OS is Linux or macOS, resulting in a Windows host trying to use the Windows shell path when running e.g. a genrule on Linux. In a surprising turn of events, this behavior is what holds Bazel's own Java integration tests together on Windows - for now. As a result, the fix is accompanied by a manual override on --shell_executable in BuildIntegrationTest for a Windows host.

@fmeum fmeum requested a review from a team as a code owner December 17, 2025 16:50
@fmeum fmeum requested review from mai93 and tjgq and removed request for a team and mai93 December 17, 2025 16:50
@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 Dec 17, 2025
@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Dec 17, 2025

@bazel-io fork 9.0.0

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly determines the execution OS for tests by using the execution platform associated with the specific test execution group, rather than a default platform. The changes involve refactoring how the ActionOwner and its corresponding PlatformInfo are obtained and passed down to where the execution OS is needed. This fixes a bug where the wrong OS was assumed for tests with custom execution groups. The changes are well-structured and include new tests that validate the corrected logic for different scenarios, including exec_group on the test rule and ExecutionInfo from the implementation. The code is cleaner and more correct.

@fmeum fmeum force-pushed the fix-test-exec-platform branch from ed76374 to 0cffea6 Compare December 17, 2025 17:21
@fmeum fmeum requested a review from lberki as a code owner December 17, 2025 17:21
@fmeum fmeum force-pushed the fix-test-exec-platform branch 2 times, most recently from 24bb4be to fad452c Compare December 17, 2025 17:25
@bharadwaj08-one
Copy link
Copy Markdown

@fmeum Could you please take a look at the failing checks?

@bharadwaj08-one bharadwaj08-one added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels Dec 18, 2025
@fmeum fmeum requested a review from a team as a code owner December 18, 2025 10:15
@fmeum fmeum force-pushed the fix-test-exec-platform branch from 373ad61 to ebe8285 Compare December 18, 2025 10:28
@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Dec 18, 2025

@bharadwaj08-one Fixed!

@fmeum fmeum force-pushed the fix-test-exec-platform branch 2 times, most recently from 4a5ee51 to 17e9685 Compare December 18, 2025 10:55
@fmeum fmeum force-pushed the fix-test-exec-platform branch 2 times, most recently from 3562416 to e3aa5f9 Compare December 18, 2025 15:57
@bharadwaj08-one bharadwaj08-one added the awaiting-review PR is awaiting review from an assigned reviewer label Dec 19, 2025
@fmeum fmeum force-pushed the fix-test-exec-platform branch from e3aa5f9 to bc82e10 Compare January 9, 2026 11:30
@fmeum fmeum requested a review from gregestren January 9, 2026 11:34
@gregestren
Copy link
Copy Markdown
Contributor

Windows CI failures might be relevant?

@fmeum fmeum requested a review from gregestren January 10, 2026 07:20
@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Jan 10, 2026

@gregestren As far as I can tell these tests are failing because Bazel's integration test setup pretends that the host platform is Linux even when running tests on Windows. The logic in ShToolchain was subtly incorrect and fell back to using the host OS to determine the shell path when the exec platform is Linux and that is needed to work with that test setup. Do you have an idea how the setup can be fixed?

@lberki in case you have an idea :-)

@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Jan 11, 2026

#28224 shows the failures with the proper host platform set.

@fmeum fmeum changed the title Fix test execution OS logic Fix test and shell execution OS logic Jan 24, 2026
@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Jan 24, 2026

@gregestren I worked around the test failures for now by preserving the preexisting behavior. PTAL.

@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Feb 12, 2026

@gregestren friendly ping

@VisibleForTesting
public static final ImmutableMap<OS, PathFragment> SHELL_EXECUTABLES =
ImmutableMap.<OS, PathFragment>builder()
.put(OS.WINDOWS, PathFragment.create("c:/msys64/usr/bin/bash.exe"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this related to your thoughts on refactoring shell toolchain selection? i.e. why do we need this hard-coded os -> shell mapping in the first place?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Exactly, this mapping should really be replaced by a toolchain type. But that requires an incompatible change that adds the toolchain requirement to all rules using ctx.actions.run_shell.

@fmeum fmeum requested a review from gregestren February 20, 2026 15:48
Copy link
Copy Markdown
Contributor

@gregestren gregestren left a comment

Choose a reason for hiding this comment

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

Thanks for the helpful walkthrough!

@gregestren gregestren 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 Feb 20, 2026
@iancha1992 iancha1992 removed the soft-release-blocker Soft release blockers that are nice to have, but shouldn't block the release if it's the last one. label Feb 20, 2026
@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 Feb 24, 2026
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Feb 25, 2026
The execution OS is determined by the specified test exec group, which can differ from the `test` exec group as well as the test rule's default execution group. Also renames some helper methods to make this class of bugs less likely and clean up `ConstraintConstants` to support the `macos` alias for the `darwin` OS constraint value.

As a consequence of this refactoring, it became clear that the shell path was determined by the host OS when the execution OS is Linux or macOS, resulting in a Windows host trying to use the Windows shell path when running e.g. a genrule on Linux. In a surprising turn of events, this behavior is what holds Bazel's own Java integration tests together on Windows - for now. As a result, the fix is accompanied by a manual override on `--shell_executable` in `BuildIntegrationTest` for a Windows host.

Closes bazelbuild#28038.

PiperOrigin-RevId: 874626714
Change-Id: Icae167c5e58309258b3c73bac99796a512d2f26d
github-merge-queue Bot pushed a commit that referenced this pull request Feb 26, 2026
The execution OS is determined by the specified test exec group, which
can differ from the `test` exec group as well as the test rule's default
execution group. Also renames some helper methods to make this class of
bugs less likely and clean up `ConstraintConstants` to support the
`macos` alias for the `darwin` OS constraint value.

As a consequence of this refactoring, it became clear that the shell
path was determined by the host OS when the execution OS is Linux or
macOS, resulting in a Windows host trying to use the Windows shell path
when running e.g. a genrule on Linux. In a surprising turn of events,
this behavior is what holds Bazel's own Java integration tests together
on Windows - for now. As a result, the fix is accompanied by a manual
override on `--shell_executable` in `BuildIntegrationTest` for a Windows
host.

Closes #28038.

PiperOrigin-RevId: 874626714
Change-Id: Icae167c5e58309258b3c73bac99796a512d2f26d

Commit
79fb843

Co-authored-by: Fabian Meumertzheim <[email protected]>
iancha1992 pushed a commit to iancha1992/bazel that referenced this pull request Apr 2, 2026
The execution OS is determined by the specified test exec group, which can differ from the `test` exec group as well as the test rule's default execution group. Also renames some helper methods to make this class of bugs less likely and clean up `ConstraintConstants` to support the `macos` alias for the `darwin` OS constraint value.

As a consequence of this refactoring, it became clear that the shell path was determined by the host OS when the execution OS is Linux or macOS, resulting in a Windows host trying to use the Windows shell path when running e.g. a genrule on Linux. In a surprising turn of events, this behavior is what holds Bazel's own Java integration tests together on Windows - for now. As a result, the fix is accompanied by a manual override on `--shell_executable` in `BuildIntegrationTest` for a Windows host.

Closes bazelbuild#28038.

PiperOrigin-RevId: 874626714
Change-Id: Icae167c5e58309258b3c73bac99796a512d2f26d
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.

5 participants