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: bazel --batch run //foo:sh_binary argument quoting is wrong #9108

Closed
laszlocsomor opened this issue Aug 7, 2019 · 1 comment
Closed
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

laszlocsomor commented Aug 7, 2019

Description of the problem / feature request:

On Windows, in --batch mode, either bazel run or the sh_binary launcher incorrectly quote arguments for sh_binary.

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

BUILD:

sh_binary(
    name = "y",
    srcs = ["a.sh"],
    args = ["foo", "'\"'", "bar"],
)

a.sh:

#!/bin/bash
i=1
total=$#
while [[ "$i" -le "$total" ]]; do
  echo "arg$i=($1)"
  i=$((i+1))
  shift
done

On Windows, bazel run fails for this in --batch mode:

C:\src\gh8240>bazel run foo:y
(...)
arg1=(foo)
arg2=(")
arg3=(bar)

C:\src\gh8240>bazel --batch run foo:y
(...)
/usr/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/usr/bin/bash: -c: line 1: syntax error: unexpected end of file

It's also broken with --incompatible_windows_bashless_run_command:

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

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

On Linux, the output is always:

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?

Related: #9106, #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
@laszlocsomor
Copy link
Contributor Author

#9123 will fix this

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

No branches or pull requests

2 participants