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

cmd/go: cannot use ldflags containing spaces #3941

Closed
remyoudompheng opened this issue Aug 10, 2012 · 9 comments
Closed

cmd/go: cannot use ldflags containing spaces #3941

remyoudompheng opened this issue Aug 10, 2012 · 9 comments
Milestone

Comments

@remyoudompheng
Copy link
Contributor

What steps will reproduce the problem?
1. Create main.go with the following contents:

package main

var VERSION = "placeholder"

func main() {
    println(VERSION)
}

2. Run

go run -ldflags "-X main.VERSION 'hello world'" main.go

What is the expected output? What do you see instead?

Expected:
Have some syntax to specify a ldflag with a space inside.

Got:
# command-line-arguments
usage: 6l [-options] [-E entry] [-H head] [-I interpreter] [-L dir] [-T text] [-R rnd]
[-r path] [-o out] main.6

Please use labels and text to provide additional information.
@minux
Copy link
Member

minux commented Aug 11, 2012

Comment 1:

i have been bitten by this too.
do you have any proposals? i can't think of a natural way for this that interoperate with
the shell well.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 2:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 3:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 9, 2012

Comment 4:

I guess we could scan for both ' and " and do what the shell does as far as splitting
text containing them. I don't want to start interpreting escape sequences or anything.

Owner changed to ---.

@remyoudompheng
Copy link
Contributor Author

Comment 5:

Maybe we can allow -ldflags '"-X\\0main.VERSION\\0hello world"' and say "if the argument
begins with a ', ", or ̀  it is parsed as a Go quoted string and split at NUL bytes.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 6:

Labels changed: added size-m.

@minux
Copy link
Member

minux commented Dec 14, 2012

Comment 7:

can we allow -ldflags to appear more than one?
then we can do this:
go run -ldflags -X -ldflags main.VERSION -ldflags "hello world" main.go
another alternative is:
go run -ldflags -- -X main.VERSION "hello world" -- main.go
I prefer we don't embed several arguments into a single argument.
personally, i like the second alternative.

@rsc
Copy link
Contributor

rsc commented Dec 15, 2012

Comment 8:

I still think the quoting will be easiest to implement and use.
Saying -ldflags over and over is annoying.
The -ldflags -- foo -- is interesting but would require support
in the flag parser, which I don't want to extend.

@rsc
Copy link
Contributor

rsc commented Jan 31, 2013

Comment 9:

This issue was closed by revision 8b6534b.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants