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: stamped (pseudo) version on build does not work for module in subdirectory #71738

Open
cshubhamrao opened this issue Feb 14, 2025 · 5 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go
Milestone

Comments

@cshubhamrao
Copy link

cshubhamrao commented Feb 14, 2025

Go version

go version go1.24.0 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/shubham/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/shubham/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/6x/n9kd7_ps7wd6cd_2p44mkwsm0000gn/T/go-build2818074136=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/shubham/xyzabc/golang-experiments/go.mod'
GOMODCACHE='/Users/shubham/go/pkg/mod'
GONOPROXY='github.com/xxxxx/*,github.com/cshubhamrao/*'
GONOSUMDB='github.com/xxxxx/*,github.com/cshubhamrao/*'
GOOS='darwin'
GOPATH='/Users/shubham/go'
GOPRIVATE='github.com/xxxxx/*,github.com/cshubhamrao/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.0/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/shubham/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.0/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Original report? #50603 (comment)

  • Create empty git repo,
  • run go mod init github.com/cshubhamrao/golang-experiments
  • create a directory subfolder; run go mod init github.com/cshubhamrao/golang-experiments/subfolder
  • commit code, tag git tag subfolder/v0.0.5 and git tag v0.0.2
  • Run this main.go twice, one at repo root and once inside subfolder
    (...)
    info, ok := debug.ReadBuildInfo()
    if !ok {
            fmt.Println("No build info")
            return
    }
    fmt.Println("Module:", info.Main.Path)
    fmt.Println("Version:", info.Main.Version)
    (...)

Code: https://github.com/cshubhamrao/golang-experiments/

commits and tags:

❯ git --no-pager log --pretty=oneline
090bb9c9161d4b45adfe5d4e683b869d57827c53 (HEAD -> main, tag: v0.0.2, tag: subfolder/v0.0.5, origin/main) subfolder
ef5321f41bb258c2b3a5bc93ed9f449d6f709980 (tag: v0.0.1) try not having a nested module
cc5ab004573866cc22a41d3ccf4089f1442e737c read build info
b45d30a70b2aaf45394e266d7553af70c57bc92f initial commit

What did you see happen?

  • go run from repo root
    ❯ go run -buildvcs=true ./cmd
    H
    Module: github.com/cshubhamrao/golang-experiments
    Version: v0.0.2
    Sum:
    GoVersion: go1.24.0
    Dependencies:
       -buildmode exe
       -compiler gc
       CGO_ENABLED 1
       CGO_CFLAGS
       CGO_CPPFLAGS
       CGO_CXXFLAGS
       CGO_LDFLAGS
       GOARCH arm64
       GOOS darwin
       GOARM64 v8.0
       vcs git
       vcs.revision 090bb9c9161d4b45adfe5d4e683b869d57827c53
       vcs.time 2025-02-14T07:59:06Z
       vcs.modified false
  • go run from subfolder
    (...)
    ❯ pushd subfolder; go run -buildvcs=true ./cmd; popd
    H
    Module: github.com/cshubhamrao/golang-experiments/subfolder
    Version: v0.0.2
    Sum:
    GoVersion: go1.24.0
    Dependencies:
       -buildmode exe
       -compiler gc
       -trimpath true
       CGO_ENABLED 1
       GOARCH arm64
       GOOS darwin
       GOARM64 v8.0
       vcs git
       vcs.revision 090bb9c9161d4b45adfe5d4e683b869d57827c53
       vcs.time 2025-02-14T07:59:06Z
       vcs.modified false
    (...)

What did you expect to see?

When run from subfolder, the module version reported should be v0.0.5 as the repo is also git-tagged as subfolder/v0.0.5

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 14, 2025
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Feb 14, 2025
@dmitshur
Copy link
Contributor

CC @matloob, @samthanawalla.

@Hades32
Copy link

Hades32 commented Mar 12, 2025

Not quite the same, but the VCS info is also missing in this situation:

Project structure

/app
   /.git/...
   /service1/...
   /go.mod

Build command FAIL

/app $ go build -o /tmp/app /app/service1/main.go

Build command WORKS (i.e. VCS info is present)

/app/service1 $ go build -o /tmp/app

Go 1.24.1 Linux amd64

@AlekSi
Copy link
Contributor

AlekSi commented Mar 18, 2025

Not quite the same

I beleive it is #51279

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/661875 mentions this issue: cmd/go: fix version stamping for v2 modules and subdirectories

@samthanawalla samthanawalla added FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 2, 2025
@dmitshur dmitshur added this to the Go1.25 milestone Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. FixPending Issues that have a fix which has not yet been reviewed or submitted. GoCommand cmd/go
Projects
None yet
Development

No branches or pull requests

7 participants