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: missing result of ReadBuildInfo in init function #29628

Closed
vearutop opened this issue Jan 9, 2019 · 5 comments
Closed

cmd/go: missing result of ReadBuildInfo in init function #29628

vearutop opened this issue Jan 9, 2019 · 5 comments
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@vearutop
Copy link
Contributor

vearutop commented Jan 9, 2019

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

$ go1.12beta1 version
go version go1.12beta1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go1.12beta1 env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/viacheslav.poturaev/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/viacheslav.poturaev/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/viacheslav.poturaev/sdk/go1.12beta1"
GOTMPDIR=""
GOTOOLDIR="/Users/viacheslav.poturaev/sdk/go1.12beta1/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lb/j0gz8jln36z4frqkrzmkdb0c0000gp/T/go-build125908091=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I've tried to read build info in app retrieved with go get:

GO111MODULE=on go1.12beta1 get github.com/vearutop/go-versioning-example@v0.0.1
go: finding github.com/vearutop/go-versioning-example v0.0.1
go: finding go.uber.org/zap v1.3.0
go: finding go.uber.org/atomic v1.3.2

Then run ~/go/bin/go-versioning-example.
Here is a package to reproduce: https://github.com/vearutop/go-versioning-example

main package has two files: main.go and version.go. version.go has // +build go1.12 and init function that checks ReadBuildInfo.

What did you expect to see?

...some deps info...
2019-01-09T12:06:27.232+0100    INFO    go-versioning-example@v0.0.1/main.go:9    App Version: v0.0.1

What did you see instead?

build info not available
2019-01-09T12:06:27.232+0100    INFO    go-versioning-example@v0.0.1/main.go:9    App Version: dev
@vearutop
Copy link
Contributor Author

vearutop commented Jan 9, 2019

If I change init() to init2() and call it explicitly from main() there is no issue.

@agnivade
Copy link
Contributor

agnivade commented Jan 9, 2019

https://tip.golang.org/pkg/go/build/#hdr-Build_Constraints

There are no build tags for beta or minor releases.

I think this is what you are experiencing.

@vearutop
Copy link
Contributor Author

vearutop commented Jan 9, 2019

As mentioned in slack #modules this is likely due to init execution precedence: https://golang.org/src/cmd/go/internal/modload/build.go#L234.

I've put my init code in a goroutine and now it works.

rm -rf ~/go/bin/go-versioning-example && GO111MODULE=on go1.12beta1 get github.com/vearutop/go-versioning-example@v0.0.2 && ~/go/bin/go-versioning-example
Build info: &{Path:github.com/vearutop/go-versioning-example Main:{Path:github.com/vearutop/go-versioning-example Version:v0.0.2 Sum:h1:KbExDVzJ29tWjzdV3PNHOX6o3f0fR0tnDR1zKNQ+Byg= Replace:<nil>} Deps:[0xc0000f0000 0xc0000f0040]}
2019-01-09T12:58:45.135+0100	INFO	go-versioning-example@v0.0.2/main.go:9	App Version: dev

@gopherbot
Copy link

Change https://golang.org/cl/157097 mentions this issue: cmd/go: remove init() to fix precedence issue when setting debug mod info

@julieqiu julieqiu changed the title runtime/debug: missing result of ReadBuildInfo in init function cmd/go: missing result of ReadBuildInfo in init function Jan 10, 2019
@julieqiu julieqiu added NeedsFix The path to resolution is known, but the work has not been done. modules labels Jan 10, 2019
@bcmills bcmills added this to the Go1.12 milestone Jan 14, 2019
@gopherbot
Copy link

Change https://golang.org/cl/158357 mentions this issue: cmd/go/internal/modload: ensure that __debug_modinfo__ is not discarded during linking

gopherbot pushed a commit that referenced this issue Jan 23, 2019
…ed during linking

Fixes #28753
Updates #29628

Change-Id: I4a561be7d491a0d088e656b00151ae1bdbd16a84
Reviewed-on: https://go-review.googlesource.com/c/158357
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
@golang golang locked and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants