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/link: -ldflags -X does not work for all import paths #16710
Comments
Probably just a bug. |
@iaburton I believe you can work around this by renaming the directory to not have .git in the path and put an HTML page there with a |
Hello @quentinmit, I'm a little confused as to your suggestion. I know renaming the directory to not contain .git will fix the linker issue, but it breaks the import path in all Go files that import it. Having read the link you refer to, a few times, it seems my use case should already work? The code is hosted on a gogs instance which I believe serves content with the meta tag information Go looks for, but I'm not sure if that works over git+ssh which is what I'm using. Although I just remembered in my git config I have it set to use user@domain.com instead of https://domain.com. I think this was to force git+ssh with a specific user. I'm not sure if that factors into this issue |
@iaburton, sorry for the delay in answering your question. The rule is that dot after the final slash in an import path gets escaped to %2e when constructing the actual symbol that cmd/link works on. The -X processing should have applied this transformation itself, but it does not. We will fix that for Go 1.8. There are two workarounds until Go 1.8 is available:
The fix is at https://golang.org/cl/31970. Edit: fixed @ mention. |
Sorry, wrong mention: @iaburton. |
CL https://golang.org/cl/31970 mentions this issue. |
Thank you @rsc, those workarounds will do until Go1.8 arrives 😃 |
CL https://golang.org/cl/34791 mentions this issue. |
It doesn't work if the package name includes a '.' or a non-ASCII character (or '%', '"', or a control character). See #16710 and CL 31970. Update #18246. Change-Id: I1487f462a3dc7b0016fce3aa1ea6239b226e6e39 Reviewed-on: https://go-review.googlesource.com/34791 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Please answer these questions before submitting your issue. Thanks!
go version
)?go1.6.2
go env
)?linux/amd64
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
A program and import similar to these.
Import: https://play.golang.org/p/n_t6GPt_9r
Program/main: https://play.golang.org/p/t9IloQX9Wj
And using -ldflags "-X my/pkg.git.Version=1.0"
1.0
notset
It seems that any import path ending with a dot before the variable name cannot be found by the linker and set using -X. .git in the import path is valid and is the only way to force 'go get' to use git+ssh afaik. I also tried my/pkg.Version and pkg.Version to the -X argument, but the only thing that fixes it is not having .git in the path (renaming the folder to not contain .git, but then this breaks go get). Is this a bug, or is there a workaround for this? I tried looking for similar issues before filing, thanks.
The text was updated successfully, but these errors were encountered: