Skip to content

Properly handle powershell and batch wrappers#732

Merged
fweikert merged 4 commits intobazelbuild:masterfrom
valco1994:master
Nov 12, 2025
Merged

Properly handle powershell and batch wrappers#732
fweikert merged 4 commits intobazelbuild:masterfrom
valco1994:master

Conversation

@valco1994
Copy link
Contributor

PowerShell scripts should be started using powershell.exe -File ... and batch scripts should be started using cmd.exe /c "..." when they are started via CreateProcessW (it's used under the hood to start processes on Windows in Go, see syscall.StartProcess()). Otherwise PowerShell scripts can't be started at all and batch scripts can't be started in some cases.

It's also important to mention, that cmd.exe requires quite an unusual command line, and regular command line preparation in syscall.StartProcess() (see syscall.makeCmdLine()) is not able to handle it properly and breaks it completely. So, I'm using exec.Cmd.SysProcAttr.CmdLine to prepare the command line myself and use it without changes in syscall.StartProcess() in the case of a batch wrapper.

This pull request fixes #643 and #731.

@valco1994
Copy link
Contributor Author

@fweikert, could you please review it?

@meteorcloudy meteorcloudy requested a review from Copilot November 4, 2025 14:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for executing Windows-specific wrapper scripts (.bat and .ps1 files) on Windows platforms. When bazelisk delegates to a wrapper script on Windows, it now properly invokes cmd.exe for batch files and powershell.exe for PowerShell scripts with appropriate argument escaping and execution policies.

Key Changes

  • Added platform-specific wrapper helper functions to handle Windows batch and PowerShell scripts
  • Modified makeBazelCmd to detect wrapper script types and invoke them through their respective interpreters
  • Created build tag-separated implementations for Windows and non-Windows platforms

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
core/wrapper_helpers.go Windows-specific implementations of batch and PowerShell script command builders
core/wrapper_helpers_nonwindows.go Non-Windows stub implementations that return standard exec.Command
core/core.go Updated makeBazelCmd to route Windows wrapper scripts through appropriate interpreters
core/BUILD Added new source files to the build configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…d use the command line with proper escaping for them.

Without this fix, PowerShell wrappers were not working at all and batch scripts were failing to start if the path contains spaces.
…as the first element in the args array (found by Copilot during automatic review)
@valco1994
Copy link
Contributor Author

valco1994 commented Nov 10, 2025

@fweikert, @meteorcloudy could you, please, take a look at the proposed changes?

It's quite impolite to ignore the pull request for such a long time. After all, it fixes quite annoying bugs in your product.
If you have no resources to handle it right now, please let me know about it and tell me when it can be handled approximately.

@fweikert
Copy link
Member

@valco1994 thanks for the PR! Looks good to me, modulo one small comment.

…per type, as was requested in the code review
@fweikert fweikert merged commit 49f0b12 into bazelbuild:master Nov 12, 2025
2 checks passed
rdesgroppes added a commit to DataDog/datadog-agent-buildimages that referenced this pull request Jan 29, 2026
### What does this PR do?
Update bazelisk from v1.27.0 to v1.28.1 across all supported platform
configurations (Linux amd64/arm64 and Windows amd64).

### Motivation
Ability to use platform-specific `tools/bazel*` wrappers:
- bazelbuild/bazelisk#696 (v1.28.0)

Ability to switch our `tools/bazel.bat` to `tools/bazel.ps1` on Windows:
- bazelbuild/bazelisk#732 (v1.28.0)
- bazelbuild/bazelisk#762 (v1.28.1)
rdesgroppes added a commit to DataDog/datadog-agent-buildimages that referenced this pull request Jan 29, 2026
### What does this PR do?
Update bazelisk from v1.27.0 to v1.28.1 across all supported platform
configurations (Linux amd64/arm64 and Windows amd64).

### Motivation
Ability to use platform-specific `tools/bazel*` wrappers:
- bazelbuild/bazelisk#696 (v1.28.0)

Ability to switch our `tools/bazel.bat` to `tools/bazel.ps1` on Windows:
- bazelbuild/bazelisk#732 (v1.28.0)
- bazelbuild/bazelisk#762 (v1.28.1)
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.

Powershell wrapper does not run

2 participants