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: compile environment variable into binary during `go get' #22216

Closed
VojtechVitek opened this issue Oct 11, 2017 · 7 comments
Closed

cmd/go: compile environment variable into binary during `go get' #22216

VojtechVitek opened this issue Oct 11, 2017 · 7 comments

Comments

@VojtechVitek
Copy link

VojtechVitek commented Oct 11, 2017

Hi gophers,

there are lots of "go get"-able CLI programs out there on Github but most of them don't have a built-in version flag/sub-command, just because it's almost impossible to compile an environment variable into a binary during the go get -u <pkg/cmd> invocation.

I wonder, are there any plans on making go get more robust and let it

  1. Invoke go:generate automatically on go get?
  2. Or set an environment variable during go get, an equivalent of explicit -ldflags "-X main.Version=$(git describe --tags)"?
  3. Any other ideas?

I know this all can be "automated" in Makefile, but the question is if we can ever expect the go get command to get this right too?

This would naturally provide a simple solution for issues like golang/dep#209 (comment)

@ianlancetaylor ianlancetaylor changed the title Compile environment variable into binary during `go get'? cmd/go: compile environment variable into binary during `go get' Oct 11, 2017
@ianlancetaylor
Copy link
Contributor

There are no such plans.

Any discussion should take place on golang-dev.

This seems like a set of possible solutions rather than a problem. Do you want to restate this in the form of a problem?

@VojtechVitek
Copy link
Author

@ianlancetaylor thanks, let me try:

Problem:
There is no way to bake in VERSION string (such as git describe --tags) into a binary when installing the CLI tool via standard go get -u <pkg/cmd> command.

@ianlancetaylor
Copy link
Contributor

I'm sure I'm missing something, but it seems to me that any version number ought to be set in the master source code. I don't see why I would want the version to depend on the characteristics of the machine where the program happens to be built.

@VojtechVitek
Copy link
Author

@ianlancetaylor I understand your point of view.

So, is the recommended practice to commit the VERSION string directly to the source code of the repository (master branch), rather than providing it on the build time?

@ianlancetaylor
Copy link
Contributor

That is what I would do, yes.

@mvdan
Copy link
Member

mvdan commented Oct 11, 2017

Likely a dup of #22147, which is a more narrow proposal and would not require running arbitrary code. Both seem to be looking at the same root problem.

@VojtechVitek
Copy link
Author

You're right, I think it is dup of #22147.

@mvdan mvdan closed this as completed Oct 11, 2017
@golang golang locked and limited conversation to collaborators Oct 11, 2018
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