-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run_shell quoting broken on Windows #7122
Comments
Confirmed on Bazel 0.21.
|
My unconfirmed suspicion is a bug in the Windows process creation logic. |
Reason for this suspicion is my recent discovery about the broken escaping of CreateProcess arguments, while I was debugging #7072. |
@gdeest and @mboes , could it be that you are using MSYS1 or some custom Bash, instead of using MSYS2 64-bit? Do you see the same behavior if you install MSYS2 (https://www.msys2.org/) to |
@laszlocsomor I am indeed using MSYS1 (because MSYS2 is not compatible with Docker, which is required for CI). AFAIK, @mboes is using MSYS2 64-bit. I'll try with MSYS2 and report with the results. |
@gdeest : did you get a chance to try with MSYS2? |
I am using MSYS2. Still seeing the bug there. |
Fix the quoting logic for command line arguments passed to CreateProcessW. Related to bazelbuild#7314 Fixes bazelbuild#7122
This is a plain old Bazel bug. There was even a TODO to fix it... I have a fix pending. |
Add an integration test to assert that subprocesses created with WindowsSubprocessFactory receive arguments as intended. Next steps: - implement the same argument escaping logic in Bazel as windowsEscapeArg2 in bazelbuild#7411 - replace WindowsProcesses.quoteCommandLine with the new escaper See bazelbuild#7122
Add an integration test to assert that subprocesses created with WindowsSubprocessFactory receive arguments as intended. Next steps: - implement the same argument escaping logic in Bazel as windowsEscapeArg2 in bazelbuild#7411 - replace WindowsProcesses.quoteCommandLine with the new escaper See bazelbuild#7122
I'm raising the priority, because the underlying bug is that argument escaping is similarly broken for all subprocesses, not just for run_shell. |
Add an integration test to assert that subprocesses created with WindowsSubprocessFactory receive arguments as intended. Next steps: - implement the same argument escaping logic in Bazel as windowsEscapeArg2 in #7411 - replace WindowsProcesses.quoteCommandLine with the new escaper See #7122 Closes #7413. PiperOrigin-RevId: 233730449
Add correct implementation of flag escaping for subprocesses. This is a follow-up to bazelbuild#7413 Next steps: - replace WindowsProcesses.quoteCommandLine with the new logic See bazelbuild#7122
Individual SubprocessBuilder instances can now use a SubprocessFactory object other than the static SubprocessBuilder.factory. Also, WindowsSubprocessFactory is no longer a singleton because it now stores state: whether to use windows-style argument escaping or to use the (broken) Bash-style escaping (causing #7122). These two changes allow: - a safer way to mock out SubprocessFactory in tests, because it's no longer necessary to change global state (i.e. the static SubprocessBuilder.factory member) - testing old and new argument escaping semantics in WindowsSubprocessTest - adding a flag that switches between old and new semantics in the SubprocessFactory, and thus allows rolling out the bugfix with just a flag flip See #7122 PiperOrigin-RevId: 234105692
Add the --incompatible_windows_style_arg_escaping flag (default: false). This flag has no effect on platforms other than Windows. Semantics: - When true: subprocess arguments are escaped with ShellUtils.windowsEscapeArg. This is the correct behavior. - When false: subprocess arguments are escaped with ShellUtils.quoteCommandLine. This is the default behavior on all platforms, but it is incorrect on Windows. Incompatible flag: #7454 Related: #7122 RELNOTES[NEW]: Added --incompatible_windows_style_arg_escaping flag: enables correct subprocess argument escaping on Windows. (No-op on other platforms.) PiperOrigin-RevId: 234581069
Closing this, because it's fixed at HEAD, see #7454. That bug will be closed when the flag's default value is flipped to true at HEAD. |
In this PR: - Removed the `--incompatible_windows_style_arg_escaping` flag and all code for its "false" case. The flag is flipped to true. - In WindowsProcessesTest, the testDoesNotQuoteArgWithDoubleQuote method is replaced by testQuotesArgWithDoubleQuote, i.e. the test logic is reversed. The new test shows the correct behavior, the old test was wrong. See bazelbuild#7122 See bazelbuild#7454 RELNOTES[INC]: The --incompatible_windows_style_arg_escaping flag is flipped to "true", and the "false" case unsupported. Bazel no longer accepts this flag.
In this PR: - Removed the `--incompatible_windows_style_arg_escaping` flag and all code for its "false" case. The flag is flipped to true. - In WindowsProcessesTest, the testDoesNotQuoteArgWithDoubleQuote method is replaced by testQuotesArgWithDoubleQuote, i.e. the test logic is reversed. The new test shows the correct behavior, the old test was wrong. See bazelbuild#7122 See bazelbuild#7454 RELNOTES[INC]: The --incompatible_windows_style_arg_escaping flag is flipped to "true", and the "false" case unsupported. Bazel no longer accepts this flag.
In this PR: - Removed the `--incompatible_windows_style_arg_escaping` flag and all code for its "false" case. The flag is flipped to true. - In WindowsProcessesTest, the testDoesNotQuoteArgWithDoubleQuote method is replaced by testQuotesArgWithDoubleQuote, i.e. the test logic is reversed. The new test shows the correct behavior, the old test was wrong. See #7122 See #7454 RELNOTES[INC]: The --incompatible_windows_style_arg_escaping flag is flipped to "true", and the "false" case unsupported. Bazel no longer accepts this flag. Closes #8003. PiperOrigin-RevId: 255929367
In this PR: - Removed the `--incompatible_windows_style_arg_escaping` flag and all code for its "false" case. The flag is flipped to true. - In WindowsProcessesTest, the testDoesNotQuoteArgWithDoubleQuote method is replaced by testQuotesArgWithDoubleQuote, i.e. the test logic is reversed. The new test shows the correct behavior, the old test was wrong. See bazelbuild#7122 See bazelbuild#7454 RELNOTES[INC]: The --incompatible_windows_style_arg_escaping flag is flipped to "true", and the "false" case unsupported. Bazel no longer accepts this flag. Closes bazelbuild#8003. PiperOrigin-RevId: 255929367
In this PR: - Removed the `--incompatible_windows_style_arg_escaping` flag and all code for its "false" case. The flag is flipped to true. - In WindowsProcessesTest, the testDoesNotQuoteArgWithDoubleQuote method is replaced by testQuotesArgWithDoubleQuote, i.e. the test logic is reversed. The new test shows the correct behavior, the old test was wrong. See bazelbuild#7122 See bazelbuild#7454 RELNOTES[INC]: The --incompatible_windows_style_arg_escaping flag is flipped to "true", and the "false" case unsupported. Bazel no longer accepts this flag. Closes bazelbuild#8003. PiperOrigin-RevId: 255929367
Individual SubprocessBuilder instances can now use a SubprocessFactory object other than the static SubprocessBuilder.factory. Also, WindowsSubprocessFactory is no longer a singleton because it now stores state: whether to use windows-style argument escaping or to use the (broken) Bash-style escaping (causing bazelbuild/bazel#7122). These two changes allow: - a safer way to mock out SubprocessFactory in tests, because it's no longer necessary to change global state (i.e. the static SubprocessBuilder.factory member) - testing old and new argument escaping semantics in WindowsSubprocessTest - adding a flag that switches between old and new semantics in the SubprocessFactory, and thus allows rolling out the bugfix with just a flag flip See bazelbuild/bazel#7122 PiperOrigin-RevId: 234105692
Add correct implementation of flag escaping for subprocesses. This is a follow-up to bazelbuild/bazel#7413 Next steps: - replace WindowsProcesses.quoteCommandLine with the new logic See bazelbuild/bazel#7122 Closes #7420. PiperOrigin-RevId: 233900149
Description of the problem
Quoting of the command in
ctx.actions.run_shell()
does not work the same way on Windows and on Unix.Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Consider the following
BUILD
file:with
args_test.bzl
:On Linux, we get "a b c" printed on the console, before Bazel complains that executing the command did not create the file "foo". But on Windows, Bash complains that program '$' does not exist. Clearly, the quoting of the command doesn't work the same way.
Now for something even more odd. If instead of
${1+"$@"}
, the command becomes${1+"$@"}
(mind the extra whitespace character), then the Windows behaviour matches the Linux one. That is, it takes there being at least one whitespace character in the command for the quoting to kick in properly. Now, it's very hard to debug these quoting issues because quotes are never displayed in the--verbose_failures
output (not pasted here because hard to extract from my Windows VM).More bizarre still, say the arguments read:
Then the output is as follows on Linux:
but the following on Windows:
That is to say, the first quote gets replaced with a backslash...
The same odd behaviour can also be seen when rerouting the output of the command to a file (e.g.
foo
).What operating system are you running Bazel on?
Linux NixOS 18.09 and Windows Server 2016
What's the output of
bazel info release
?0.20.0
The text was updated successfully, but these errors were encountered: