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/link: -X doesn't work for vendored packages #19000

Closed
iterion opened this issue Feb 8, 2017 · 4 comments
Closed

cmd/link: -X doesn't work for vendored packages #19000

iterion opened this issue Feb 8, 2017 · 4 comments

Comments

@iterion
Copy link

iterion commented Feb 8, 2017

What version of Go are you using (go version)?

go version go1.7.3 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/iterion/dev/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build201245685=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="0"

What did you do?

Run this build command with github.com/iterion/remotepkg in the vendor directory:
note: package above doesn't actually exist yet, but I can create it if needed for demonstration purposes.

go build -a -installsuffix cgo -o test -ldflags "-X github.com/iterion/remotepkg.timestamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'`" .

main.go

package main

import (
  "github.com/iterion/remotepkg"
)

func main() {
  remotepkg.PrintEnv()
}

remotepkg.go

package remotepkg

import (
  "log"
)

var timestamp string

func PrintEnv() {
  log.Println(timestamp)
}

What did you expect to see?

Expect ./test to print build time.

What did you see instead?

Nothing is printed.

If the remote package is not in the vendor dir but does exist in your gopath in an expected place then the build time is correctly printed.

@davecheney
Copy link
Contributor

davecheney commented Feb 8, 2017 via email

@iterion
Copy link
Author

iterion commented Feb 8, 2017

@davecheney thanks
I tested this, given main.go is in github.com/iterion/test I changed change it to

"-X  github.com/iterion/test/vendor/github.com/iterion/remotepkg.timestamp=time"

which correctly prints time.

Is there documentation for this anywhere (I struggled to find any aside from stackoverflow)? I'd be up for trying to update it.

Closing this in the meantime as it seems there is no actual issue.

@iterion iterion closed this as completed Feb 8, 2017
@davecheney
Copy link
Contributor

davecheney commented Feb 9, 2017 via email

@minux
Copy link
Member

minux commented Feb 9, 2017 via email

@minux minux changed the title Go ldflags -X doesn't work for vendored packages cmd/link: -X doesn't work for vendored packages Feb 9, 2017
@golang golang locked and limited conversation to collaborators Feb 9, 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