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: vcs info not stamped when built listing .go files directly #51279

Open
mlcdf opened this issue Feb 20, 2022 · 6 comments
Open

cmd/go: vcs info not stamped when built listing .go files directly #51279

mlcdf opened this issue Feb 20, 2022 · 6 comments
Labels
GoCommand cmd/go help wanted modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mlcdf
Copy link

mlcdf commented Feb 20, 2022

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

$ go version
go version go1.18rc1 windows/amd64

Does this issue reproduce with the latest release?

N/A

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\max\AppData\Local\go-build
set GOENV=C:\Users\max\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\max\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\max\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\max\sdk\go1.18rc1
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\max\sdk\go1.18rc1\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18rc1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\max\Code\go-vcs-issue-repro\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\max\AppData\Local\Temp\go-build2053103368=/tmp/go-build -gno-record-gcc-switches

What did you do?

git clone https://github.com/mlcdf/go-vcs-issue-repro.git
cd go-vcs-issue-repro
go1.18rc1 build main.go
.\main.exe

What did you expect to see?

VCS info appearing in the console :
[{-compiler gc} {CGO_ENABLED 1} {CGO_CFLAGS } {CGO_CPPFLAGS } {CGO_CXXFLAGS } {CGO_LDFLAGS } {GOARCH amd64} {GOOS windows} {GOAMD64 v1} {vcs git} {vcs.revision 2d1c081410d0f5f23fd1dd7e08794041955a2119} {vcs.time 2022-02-20T11:01:47Z} {vcs.modified false}]

What did you see instead?

[{-compiler gc} {CGO_ENABLED 1} {CGO_CFLAGS } {CGO_CPPFLAGS } {CGO_CXXFLAGS } {CGO_LDFLAGS } {GOARCH amd64} {GOOS windows} {GOAMD64 v1}]

If I run go1.18rc1 build instead of go1.18rc1 build main.go and run the .\go-vcs-issue-repro.exe binary, it works fine. Is it expected behavior?

@mlcdf mlcdf changed the title runtime/debug: not vcs info in ReadBuildInfo().Settings if build via go1.18rc1 build main.go [1.18rc1] runtime/debug: not vcs info in ReadBuildInfo().Settings if built via go1.18rc1 build main.go [1.18rc1] Feb 20, 2022
@mlcdf mlcdf changed the title runtime/debug: not vcs info in ReadBuildInfo().Settings if built via go1.18rc1 build main.go [1.18rc1] runtime/debug: no vcs info in ReadBuildInfo().Settings if built via go1.18rc1 build main.go [1.18rc1] Feb 20, 2022
@seankhliao seankhliao changed the title runtime/debug: no vcs info in ReadBuildInfo().Settings if built via go1.18rc1 build main.go [1.18rc1] cmd/go: vcs info not stamped when built listing .go files directly Feb 20, 2022
@seankhliao seankhliao added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 20, 2022
@seankhliao
Copy link
Member

cc @bcmills @matloob

@bcmills bcmills added this to the Backlog milestone Feb 22, 2022
@bcmills
Copy link
Member

bcmills commented Feb 22, 2022

In general we stamp the VCS metadata only if the requested package is within a module in the workspace:
https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/load/pkg.go;l=2362;drc=master

Since CL 339170 (CC @matloob), the fake package constructed from a list of source files is not considered to be in a module, because its source files are not in general guaranteed to be scanned by go mod tidy or go mod vendor.

Perhaps we could adjust that check to instead compare the package's directory with the directories containing the modules in the workspace.

@module17
Copy link

Not seeing the VCS metadata being populated with go 1.19.2 darwin/amd64 as well.

@agmt
Copy link

agmt commented Jun 19, 2023

The bug is still in go version go1.20.4 linux/arm64: vcs* is presented only if go build is called with the full path to the directory, not relative path to *.go files.

@bcmills
Copy link
Member

bcmills commented Jun 20, 2023

@agmt, @module17: since this issue is still open, it should not be at all surprising that it is still present.

If you would like to contribute a fix, see https://go.dev/doc/contribute.

@gopherbot
Copy link

Change https://go.dev/cl/541777 mentions this issue: cmd/go: stamp VCS info when building .go files directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go help wanted modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants