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: escape quoted strings in GOFLAGS #26849

Open
bcmills opened this Issue Aug 7, 2018 · 6 comments

Comments

Projects
None yet
7 participants
@bcmills
Member

bcmills commented Aug 7, 2018

In https://golang.org/cl/126656, @rsc added the GOFLAGS environment variable.

The variable is space-separated, but it is sometimes useful to include spaces within flags passed to the go command (for example, as the final argument to list -f). It would be nice to recognize at least a subset of the usual quoting conventions when parsing GOFLAGS.

~/go/src/cmd/go$ go list -e -deps -f="{{if .Error}}{{.Error}}{{end}}"

~/go/src/cmd/go$ export GOFLAGS='-e -deps -f="{{if .Error}}{{.Error}}{{end}}"'

~/go/src/cmd/go$ go list
go: parsing $GOFLAGS: non-flag ".Error}}{{.Error}}{{end}}\""

@bcmills bcmills added this to the Go1.11 milestone Aug 7, 2018

@alexbrainman

This comment has been minimized.

Member

alexbrainman commented Aug 8, 2018

@bcmills if you want to support cmd.exe users on Windows, you should consider how quoting works in cmd.exe. For example, this http://daviddeley.com/autohotkey/parameters/parameters.htm#WINCMDRULES shows cmd.exe rules.

Alex

@rsc

This comment has been minimized.

Contributor

rsc commented Aug 9, 2018

Sorry, but no. I looked at this when I added GOFLAGS, and we don't do any special quoting for the other environment variables (go help environment | grep FLAGS)

This means you cant use GOFLAGS for your example.
That's OK, GOFLAGS is for things like -ldflags=-w.

@rsc rsc closed this Aug 9, 2018

@tianon

This comment has been minimized.

tianon commented Oct 3, 2018

That's OK, GOFLAGS is for things like -ldflags=-w.

My usage of -ldflags almost always also includes spaces -- I frequently use -d -s -w in order to get smaller static binaries (where size is the primary concern); combined with -tags netgo and CGO_ENABLED=0, this works pretty well.

I think -tags is another great problematic example -- multiple instances of -tags replace each other, and the argument to -tags is space separated, so -tags can't easily be used via GOFLAGS today except for the absolute simplest cases.

Respectfully, I would request that this be reopened and reconsidered, especially since the primary use case where this feature got me excited (building the same binary for a load of different architectures in a row) aren't actually helped by this feature today. ❤️ 😅

(I commented on the CL and was redirected here. ❤️)

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Oct 3, 2018

@rsc I'm not sure I understand the argument for not permitting quoting in the environment variable given the special support we have for quoting in -gcflags and friends. It seems to me that there are clear uses for passing multiple options to all builds, such as the -l -N that delve uses.

@andybons

This comment has been minimized.

Member

andybons commented Dec 5, 2018

Ping @rsc @bcmills.

@rsc

This comment has been minimized.

Contributor

rsc commented Dec 6, 2018

Leaving for Go 1.13. GOFLAGS is relatively new and the workaround is to use the command line, like you had to do before Go 1.11.

@rsc rsc modified the milestones: Go1.12, Go1.13 Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment