What version of Go are you using (go version)?
$ go version
go version devel +571d93e977 Thu Dec 13 15:08:48 2018 +0000 darwin/amd64
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mr/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mr/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/mr/gotip/src/github.com/golang/go"
GOTMPDIR=""
GOTOOLDIR="/Users/mr/gotip/src/github.com/golang/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mr/gomod/debug-module-version-demo/go.mod"
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/ct/bl4_z3g51ks8239_r2k07v_40000gn/T/go-build638578617=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Repro case is https://github.com/mark-rushakoff/debug-module-version-demo. It's a module, and its main.go contents are a simple use of debug.ReadBuildInfo:
package main
import (
"fmt"
"runtime/debug"
_ "rsc.io/quote"
)
func main() {
bi, ok := debug.ReadBuildInfo()
if !ok {
panic("couldn't read build info")
}
fmt.Printf("%s version %s\n", bi.Path, bi.Main.Version)
for _, d := range bi.Deps {
fmt.Printf("\tbuilt with %s version %s\n", d.Path, d.Version)
}
}
What did you expect to see?
I expected to see the first line print github.com/mark-rushakoff/debug-module-version-demo version v0.0.0-20181213... when checked out at an arbitrary commit, or github.com/mark-rushakoff/debug-module-version-demo version v0.0.1 when checked out at tag v0.0.1. I tried both go run . and go build . && ./debug-module-version-demo but both cases printed (devel).
What did you see instead?
github.com/mark-rushakoff/debug-module-version-demo version (devel)
built with golang.org/x/text version v0.0.0-20170915032832-14c0d48ead0c
built with rsc.io/quote version v1.5.2
built with rsc.io/sampler version v1.3.0
Based on the behavior I've observed, it looks as though the main module returned by debug.ReadBuildInfo is hardcoded to (devel) for the main module, which I assume is intended behavior. If so, that's unfortunate for use cases like mycmd version to easily print the module version of the software being built; but it should be documented.
The current documentation at https://tip.golang.org/pkg/runtime/debug/#ReadBuildInfo does not mention (devel) in any way, nor does it mention any special behavior of the Main module.
/cc @hyangah since you're on git blame for src/runtime/debug/mod.go.
What version of Go are you using (
go version)?What operating system and processor architecture are you using (
go env)?go envOutputWhat did you do?
Repro case is https://github.com/mark-rushakoff/debug-module-version-demo. It's a module, and its main.go contents are a simple use of
debug.ReadBuildInfo:What did you expect to see?
I expected to see the first line print
github.com/mark-rushakoff/debug-module-version-demo version v0.0.0-20181213...when checked out at an arbitrary commit, orgithub.zcwsr.com/mark-rushakoff/debug-module-version-demo version v0.0.1when checked out at tag v0.0.1. I tried bothgo run .andgo build . && ./debug-module-version-demobut both cases printed(devel).What did you see instead?
Based on the behavior I've observed, it looks as though the main module returned by
debug.ReadBuildInfois hardcoded to(devel)for the main module, which I assume is intended behavior. If so, that's unfortunate for use cases likemycmd versionto easily print the module version of the software being built; but it should be documented.The current documentation at https://tip.golang.org/pkg/runtime/debug/#ReadBuildInfo does not mention
(devel)in any way, nor does it mention any special behavior of theMainmodule./cc @hyangah since you're on git blame for src/runtime/debug/mod.go.