Skip to content
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

Windows: bash-less run argument quoting is wrong #9106

Closed
laszlocsomor opened this issue Aug 7, 2019 · 0 comments
Closed

Windows: bash-less run argument quoting is wrong #9106

laszlocsomor opened this issue Aug 7, 2019 · 0 comments
Assignees
Labels
area-Windows Windows-specific issues and feature requests P1 I'll work on this now. (Assignee required) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug

Comments

@laszlocsomor
Copy link
Contributor

Description of the problem / feature request:

The Bash-less "bazel run" (see #8240) quotes arguments incorrectly.

It works correctly in --batch mode, but adds extra " " around escaped arguments in server mode.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

foo/BUILD:

py_binary(
    name = "x",
    srcs = ["a.py"],
    main = "a.py",
    args = ["foo", "' '", "bar"],
)

foo/a.py:

from __future__ import print_function
import sys
for i in range(1, len(sys.argv)):
    print("arg%d=(%s)" % (i, sys.argv[i]))
C:\src\gh8240>bazel --nobatch run foo:x --noincompatible_windows_bashless_run_command
(...)
arg1=(foo)
arg2=( )
arg3=(bar)

C:\src\gh8240>bazel --nobatch run foo:x --incompatible_windows_bashless_run_command
(...)
arg1=(foo)
arg2=(" ")
arg3=(bar)

C:\src\gh8240>bazel --batch run foo:x --noincompatible_windows_bashless_run_command
(...)
arg1=(foo)
arg2=( )
arg3=(bar)

C:\src\gh8240>bazel --batch run foo:x --incompatible_windows_bashless_run_command
(...)
arg1=(foo)
arg2=( )
arg3=(bar)

On Linux, the output is always the same for all flag combinations:

arg1=(foo)
arg2=( )
arg3=(bar)

What operating system are you running Bazel on?

windows 10

What's the output of bazel info release?

0.28.1

Have you found anything relevant by searching the web?

This is blocking #8240

@laszlocsomor laszlocsomor self-assigned this Aug 7, 2019
@laszlocsomor laszlocsomor added P1 I'll work on this now. (Assignee required) area-Windows Windows-specific issues and feature requests type: bug labels Aug 7, 2019
katre pushed a commit that referenced this issue Aug 12, 2019
There are two axes of variables:
- server mode vs. batch mode (--[no]batch)
- Windows only: Bash-less vs. Bash-ful bazel run
  (--[no]incompatible_windows_bashless_run_command)

To "bazel run" a target, Bazel first builds the
target then creates a run request. The request is
a protobuf that contains the command line (argv)
and environment (envvars, cwd).

In server mode (--nobatch), the Bazel server sends
the run request to the client, and the client
executes the program (with CreateProcessW on
Windows / execv on Unixes).  In batch mode
(--batch), the Bazel server itself executes the
program using ProcessBuilder.

In Bash-ful bazel run mode the run request is for
"bash -c <program> <args>...", while in Bash-less
more it is for "<program> <args>...". The argument
escaping must be different in both cases, because
bash.exe uses Bash-style quoting/escaping while
most native Windows programs use the MSVC style.

Fixes #9106
Fixes #9108

Closes #9123.

PiperOrigin-RevId: 262519795
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Windows Windows-specific issues and feature requests P1 I'll work on this now. (Assignee required) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants