-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/go: CC variable misparsed when set to a path containing spaces #41400
Comments
Your go installation is corrupt and/or the time stamps have been disrupted, possibly by unpacking one version of go over another Please delete c:\go and reinstall from a fresh copy |
I am actually able to repro this. exact command: It's specific to the |
This comment has been minimized.
This comment has been minimized.
@AlexRouSg, thanks for the detail. I can even reproduce it on Linux:
|
So looks like there are multiple places that needs fixing ... I've found Line 1536 in 2963443
which only affects running the cgo binary direcly
|
Yes, there are several places where we're calling But I think we also try to follow the usual C toolchain behavior for the CC environment variable, so I'm trying to figure out if there is a standard format for escaping paths containing spaces. (Perhaps @ianlancetaylor or @jayconrod knows?) |
@XamarinPOC @chaitanyaevoke In the meantime for gomobile, you'll have to install the SDK to a path without spaces |
I just uninstalled and installed fresh Go version 1.15.2 but no luck. I'm trying to run build command => gomobile build -target=android golang.org/x/.............. to generate apk file |
@AlexRouSg Which Sdk?? Can you . please explain it . |
@XamarinPOC |
Change https://golang.org/cl/255018 mentions this issue: |
Yup ,after removing spaces its working now. Can we get this fix in next release. |
Wait. Right now I can run
and all my cgo files will be built with Now, maybe that is a mistake and maybe we should change it. But we definitely shouldn't change that behavior casually. We should discuss it on the mailing list, we should find out whether it will break anybody. In particular there is no documented way to pass C compiler flags when running In other words, we can't just treat this a minor bug that we should just fix. We have to think about how this has worked in the past and how it should work going forward. |
The CL that I mailed preserves the property that space-separated arguments following the executable name are treated as arguments: it uses I believe that preserves the existing behavior for all commands that would successfully invoke a compiler, and also fixes some number of cases that previously would have failed. |
OK, thanks. I'm a bit worried about the possibility of confusion. I guess it should work but it seems pretty complicated. |
Agreed. I was kind of hoping that there would be some existing standard or extension for quoting within As an alternative, I suppose that we could allow shell-style quoting within the CC variable. (Do you think that would be better or worse?) |
Shell style quoting sounds better to me. I can imagine people having args like EDIT: |
Shell quoting sounds a little better to me, I guess. |
I'm looking for a narrow fix of #43808 that can be backported, and it will probably affect the eventual solution to this issue. What I'm thinking right now is that we should support shell quoting using the code in For #43808, we could quote the |
Change https://golang.org/cl/334731 mentions this issue: |
This will let cmd/cgo and cmd/link use this package for argument parsing. For #41400 Change-Id: I12ee21151bf3f00f3e8d427faaaab2453c823117 Reviewed-on: https://go-review.googlesource.com/c/go/+/334730 Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
… args JoinAndQuoteFields does the inverse of SplitQuotedFields: it joins a list of arguments with spaces into one string, quoting arguments that contain spaces or quotes. QuotedStringListFlag uses SplitQuotedFields and JoinAndQuoteFields together to define new flags that accept lists of arguments. For #41400 Change-Id: I4986b753cb5e6fabb5b489bf26aedab889f853f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/334731 Trust: Jay Conrod <jayconrod@google.com> Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
The CC and CXX environment variables now support spaces and quotes (both double and single). This fixes two issues: first, if CC is a single path that contains spaces (like 'c:\Program Files\gcc\bin\gcc.exe'), that should now work if the space is quoted or escaped (#41400). Second, if CC or CXX has multiple arguments (like 'gcc -O2'), they are now split correctly, and the arguments are passed before other arguments when invoking the C compiler. Previously, strings.Fields was used to split arguments, and the arguments were placed later in the command line. (#43078). Fixes #41400 Fixes #43078 Change-Id: I2d5d89ddb19c94adef65982a8137b01f037d5c11 Reviewed-on: https://go-review.googlesource.com/c/go/+/334732 Trust: Jay Conrod <jayconrod@google.com> Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
Change https://golang.org/cl/341934 mentions this issue: |
Change https://golang.org/cl/341935 mentions this issue: |
Change https://golang.org/cl/341936 mentions this issue: |
This will let cmd/cgo and cmd/link use this package for argument parsing. For #41400 Change-Id: I12ee21151bf3f00f3e8d427faaaab2453c823117 Reviewed-on: https://go-review.googlesource.com/c/go/+/334730 Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/341934 Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
JoinAndQuoteFields does the inverse of SplitQuotedFields: it joins a list of arguments with spaces into one string, quoting arguments that contain spaces or quotes. QuotedStringListFlag uses SplitQuotedFields and JoinAndQuoteFields together to define new flags that accept lists of arguments. For #41400 Change-Id: I4986b753cb5e6fabb5b489bf26aedab889f853f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/334731 Trust: Jay Conrod <jayconrod@google.com> Trust: Michael Matloob <matloob@golang.org> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/341935
Change https://go.dev/cl/398058 mentions this issue: |
These fields have been parsed as quoted fields since CL 334732, but we missed the unparsing side in 'go env'. Certain scripts (notably make.ba{sh,t}) expect to be able to set the environment to exactly what 'go env' reports, so for round-trip purposes it is important to match the marshaling and unmarshaling functions. (Noticed while debugging #52009.) Updates #41400 Change-Id: I0ff39b7a6e1328111c285c97cd23f79b723f3c73 Reviewed-on: https://go-review.googlesource.com/c/go/+/398058 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Change https://go.dev/cl/466875 mentions this issue: |
#16455 handled escapes in pkg-config output but only for cflags. The fix for #41400 left a note that we don't need to parse quotes and unescapes, but it is still necessary to handle spaces in pkg-config output. As cflags has already been processed correctly, we apply the same logic to ldflags here. Fixes #35262 Change-Id: Id01d422b103780f67f89e99ff1df0d8f51a7a137 GitHub-Last-Rev: c67e511 GitHub-Pull-Request: #58429 Reviewed-on: https://go-review.googlesource.com/c/go/+/466875 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com>
golang#16455 handled escapes in pkg-config output but only for cflags. The fix for golang#41400 left a note that we don't need to parse quotes and unescapes, but it is still necessary to handle spaces in pkg-config output. As cflags has already been processed correctly, we apply the same logic to ldflags here. Fixes golang#35262 Change-Id: Id01d422b103780f67f89e99ff1df0d8f51a7a137 GitHub-Last-Rev: c67e511 GitHub-Pull-Request: golang#58429 Reviewed-on: https://go-review.googlesource.com/c/go/+/466875 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com>
Why was this issue closed ? |
go build -buildmode=c-shared -o C:\Users\XAMARI~1\AppData\Local\Temp\gomobile-work-285666087\lib\armeabi-v7a\libbasic.so golang.org/x/mobile/example/basic failed: exit status 2
runtime/cgo
exec: "C:\Program": file does not exist
E:\GoWorkDir>go env
set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Xamarin Developer\AppData\Local\go-build
set GOENV=C:\Users\Xamarin Developer\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\GoWorkDir\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\GoWorkDir
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\XAMARI~1\AppData\Local\Temp\go-build823121506=/tmp/go-build -gno-record-gcc-switches
The text was updated successfully, but these errors were encountered: