Repository navigation
Description
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:
load(":args_test.bzl", "args_test")
args_test(name = "y")with args_test.bzl:
def _impl(ctx):
foo = ctx.actions.declare_file("foo")
ctx.actions.run_shell(
outputs = [foo],
command = '${1+"$@"}',
arguments = ['echo', 'a', 'b', 'c'],
)
return [DefaultInfo(executable = foo)]
args_test = rule(
implementation = _impl,
test = True,
)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:
arguments = ['echo', 'a', 'b"123"', 'c'],
Then the output is as follows on Linux:
a b"123" c
but the following on Windows:
a b\123" c
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
Activity
gdeest commentedon Jan 15, 2019
Confirmed on Bazel 0.21.
laurentlb commentedon Jan 17, 2019
cc @laszlocsomor
laszlocsomor commentedon Jan 17, 2019
My unconfirmed suspicion is a bug in the Windows process creation logic.
laszlocsomor commentedon Jan 17, 2019
Reason for this suspicion is my recent discovery about the broken escaping of CreateProcess arguments, while I was debugging #7072.
laszlocsomor commentedon Jan 17, 2019
@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
c:\tools\msys64, setBAZEL_SH=c:\tools\msys64\usr\bin\bash.exe, runbazel shutdown, then try the build again?gdeest commentedon Jan 17, 2019
@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.
laszlocsomor commentedon Jan 24, 2019
@gdeest : did you get a chance to try with MSYS2?
18 remaining items
Windows: remove incompatible_windows_style_arg_escaping
Windows: remove incompatible_windows_style_arg_escaping
Windows: remove incompatible_windows_style_arg_escaping
subprocesses: customizable SubprocessFactory
Windows, subprocesses: correct flag escaping impl.
Add a `run_shell` wrapper and extend its tests
Add a `run_shell` wrapper and extend its tests
Add a `run_shell` wrapper and extend its tests
Add a `run_shell` wrapper and extend its tests
Add a `run_shell` wrapper and extend its tests
Add a `run_shell` wrapper and extend its tests
Add a `run_shell` wrapper and extend its tests
Add a `run_shell` wrapper and extend its tests
Add a `run_shell` wrapper and extend its tests