golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
120.96k stars 17.36k forks source link

cmd/go: list -m -json often missing .Origin #67363

Open josharian opened 1 month ago

josharian commented 1 month ago

Go version

go version go1.22.3 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/josh/bin'
GOCACHE='/Users/josh/Library/Caches/go-build'
GOENV='/Users/josh/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/josh/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/josh'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/josh/go/1.22'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/josh/go/1.22/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/vm/htvrhp4177v2dfhdjlvl0pqh0000gn/T/go-build2633414260=/tmp/go-build -gno-record-gcc-switches -fno-common'

Bug report

This is a regression. With Go 1.22.3:

$ go list -m -json golang.org/x/tools@latest
{
    "Path": "golang.org/x/tools",
    "Version": "v0.21.0",
    "Query": "latest",
    "Time": "2024-05-06T16:54:44Z",
    "GoMod": "/Users/josh/pkg/mod/cache/download/golang.org/x/tools/@v/v0.21.0.mod",
    "GoVersion": "1.19"
}

Note that there is no Origin field.

With Go 1.21.10:

$ go list -m -json golang.org/x/tools@latest
{
    "Path": "golang.org/x/tools",
    "Version": "v0.21.0",
    "Query": "latest",
    "Time": "2024-05-06T16:54:44Z",
    "GoMod": "/Users/josh/pkg/mod/cache/download/golang.org/x/tools/@v/v0.21.0.mod",
    "GoVersion": "1.19",
    "Origin": {
        "VCS": "git",
        "URL": "https://go.googlesource.com/tools",
        "Ref": "refs/tags/v0.21.0",
        "Hash": "cc29c91ba3acb47c1793da56d919cc40def4ea41"
    }
}

Given the conversation in https://github.com/golang/go/issues/57051, it is clear that the intent is that the Origin field be present.

Relevant to https://github.com/golang/go/issues/18387.

findleyr commented 1 month ago

Interestingly, GOPROXY=direct go list -m -json golang.org/x/tools@latest seems to work every time. The VCS info is present in the proxy: https://proxy.golang.org/golang.org/x/tools/@v/v0.21.0.info.

CC @matloob @samthanawalla

josharian commented 1 month ago

@findleyr thanks! That's 80% of a workaround for me!

Unfortunately, the VCS info doesn't appear to always be present in the proxy: https://proxy.golang.org/rsc.io/edit/@v/v1.0.0.info

findleyr commented 1 month ago

That VCS info is not always present is, I believe, a known limitation. (CC @suzmue to confirm). The decision was made to not reprocess older versions in the proxy--even ignoring compute resources, we can't guarantee that older versions still exist in at the origin.

But for x/tools@latest, VCS info is present, and yet not returned by go list. That seems like a bug.

seankhliao commented 1 month ago

probably related https://github.com/golang/go/issues/66077#issuecomment-1977155854 it does work if the version query is an actual version instead of latest

gopherbot commented 1 month ago

Change https://go.dev/cl/588575 mentions this issue: cmd/go: let list -m -json include an Origin