golang / go

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

cmd/go: record -mod=vendor in buildinfo #57782

Open seankhliao opened 1 year ago

seankhliao commented 1 year ago

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

$ go version
go version devel go1.20-245e95dfabd Wed Jan 11 22:29:34 2023 +0000 linux/amd64

Does this issue reproduce with the latest release?

tip

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/arccy/.cache/go-build"
GOENV="/home/arccy/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/arccy/.data/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/arccy/.data/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/arccy/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/arccy/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.20-245e95dfabd Wed Jan 11 22:29:34 2023 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/arccy/tmp/testrepo0078/go.mod"
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1173344524=/tmp/go-build -gno-record-gcc-switches"

What did you do?

14:47:59 ~/tmp/testrepo0078 0:00:00
main » cat go.mod 
module go.seankhliao.com/testrepo0078

go 1.20

require rsc.io/quote/v4 v4.0.1

require (
    golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
    rsc.io/sampler v1.3.0 // indirect
)

14:48:02 ~/tmp/testrepo0078 0:00:00
main » cat main.go         
package main

import (
    "fmt"

    "rsc.io/quote/v4"
)

func main() {
    fmt.Println(quote.Hello())
}

14:48:14 ~/tmp/testrepo0078 0:00:00
main » go mod vendor       

14:48:19 ~/tmp/testrepo0078 0:00:00
main » go build -mod=vendor

14:48:24 ~/tmp/testrepo0078 0:00:00
main » go version -m testrepo0078            
testrepo0078: devel go1.20-245e95dfabd Wed Jan 11 22:29:34 2023 +0000
    path    go.seankhliao.com/testrepo0078
    mod go.seankhliao.com/testrepo0078  (devel) 
    dep golang.org/x/text   v0.0.0-20170915032832-14c0d48ead0c  h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
    dep rsc.io/quote/v4 v4.0.1  h1:i/LHLEinr65wwTCqlP4OnMoMWeCgnFIZFvifdXNK+5M=
    dep rsc.io/sampler  v1.3.0  h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
    build   -buildmode=exe
    build   -compiler=gc
    build   CGO_ENABLED=1
    build   CGO_CFLAGS=
    build   CGO_CPPFLAGS=
    build   CGO_CXXFLAGS=
    build   CGO_LDFLAGS=
    build   GOARCH=amd64
    build   GOOS=linux
    build   GOAMD64=v1
    build   vcs=git
    build   vcs.revision=bfd01d01b57dc4c4d2a0127ee6a38b5a3933eeb8
    build   vcs.time=2023-01-13T14:45:45Z
    build   vcs.modified=true

What did you expect to see?

usage of vendor (and/or -mod flag) recorded in build info

What did you see instead?

no difference from buildinfo built without vendor:

14:50:43 ~/tmp/testrepo0078 0:00:00
main » rm -rf vendor

14:51:07 ~/tmp/testrepo0078 0:00:00
main » go build -mod=readonly     

14:51:10 ~/tmp/testrepo0078 0:00:00
main » go version -m testrepo0078 
testrepo0078: devel go1.20-245e95dfabd Wed Jan 11 22:29:34 2023 +0000
    path    go.seankhliao.com/testrepo0078
    mod go.seankhliao.com/testrepo0078  (devel) 
    dep golang.org/x/text   v0.0.0-20170915032832-14c0d48ead0c  h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
    dep rsc.io/quote/v4 v4.0.1  h1:i/LHLEinr65wwTCqlP4OnMoMWeCgnFIZFvifdXNK+5M=
    dep rsc.io/sampler  v1.3.0  h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
    build   -buildmode=exe
    build   -compiler=gc
    build   CGO_ENABLED=1
    build   CGO_CFLAGS=
    build   CGO_CPPFLAGS=
    build   CGO_CXXFLAGS=
    build   CGO_LDFLAGS=
    build   GOARCH=amd64
    build   GOOS=linux
    build   GOAMD64=v1
    build   vcs=git
    build   vcs.revision=bfd01d01b57dc4c4d2a0127ee6a38b5a3933eeb8
    build   vcs.time=2023-01-13T14:45:45Z
    build   vcs.modified=true
seankhliao commented 1 year ago

cc @bcmills @matloob

bcmills commented 1 year ago

It's probably not important to distinguish -mod=readonly from -mod=mod. -mod=vendor is probably relevant, though, since folks sometimes do make modifications to the vendor directory.

ashishbhate commented 1 year ago

Hello, I was looking through the issue tracker for some easy tickets to work on to get familiar with contributing to Go. AFAICT, the fix for this issue only requires adding a couple lines to https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/load/pkg.go;l=2283;bpv=1;bpt=1

Is anyone working on this ticket? If not, I can send a CL.

gopherbot commented 1 year ago

Change https://go.dev/cl/536415 mentions this issue: cmd/go/internal/load: record build mod in buildinfo

ansaba commented 12 months ago

@quantonganh , CL LGTM. Approved.