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

Comments

Projects
None yet
4 participants
@iterion
Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Feb 8, 2017

@iterion

This comment has been minimized.

Copy link
Author

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 Feb 8, 2017

@davecheney

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2017

@minux

This comment has been minimized.

Copy link
Member

commented Feb 9, 2017

@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.
You can’t perform that action at this time.