]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: do not embed checksums when building with vendor
authorSam Thanawalla <samthanawalla@google.com>
Wed, 14 Feb 2024 21:01:53 +0000 (21:01 +0000)
committerSam Thanawalla <samthanawalla@google.com>
Fri, 16 Feb 2024 17:19:18 +0000 (17:19 +0000)
Fixes #46400

Tested: Ran go test cmd/go
Change-Id: I60655129c55d40a70a13ed23937ef990f315fd73
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/564195
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Sam Thanawalla <samthanawalla@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Commit-Queue: Sam Thanawalla <samthanawalla@google.com>

src/cmd/go/internal/load/pkg.go
src/cmd/go/testdata/script/mod_gomodcache_vendor.txt [new file with mode: 0644]

index 1549800afb5f7e5ceee22cd4d76cb3a4ee9d7209..0e4b6797c6ecdb608847335f487ae8af931857e5 100644 (file)
@@ -2306,7 +2306,7 @@ func (p *Package) setBuildInfo(ctx context.Context, autoVCS bool) {
                }
                if mi.Replace != nil {
                        dm.Replace = debugModFromModinfo(mi.Replace)
-               } else if mi.Version != "" {
+               } else if mi.Version != "" && cfg.BuildMod != "vendor" {
                        dm.Sum = modfetch.Sum(ctx, module.Version{Path: mi.Path, Version: mi.Version})
                }
                return dm
diff --git a/src/cmd/go/testdata/script/mod_gomodcache_vendor.txt b/src/cmd/go/testdata/script/mod_gomodcache_vendor.txt
new file mode 100644 (file)
index 0000000..164460b
--- /dev/null
@@ -0,0 +1,32 @@
+# This test verifies that GOMODCACHE does not affect whether checksums are embedded
+# with vendored files.
+# See issue #46400
+[short] skip 'builds and links a binary twice'
+go mod tidy
+go mod vendor
+
+go build -mod=vendor
+go version -m example$GOEXE
+cp stdout version-m.txt
+
+env GOMODCACHE=$WORK${/}modcache
+go build -mod=vendor
+go version -m example$GOEXE
+cmp stdout version-m.txt
+
+-- go.mod --
+module example
+go 1.22
+require rsc.io/sampler v1.3.0
+
+-- main.go --
+package main
+
+import (
+    "fmt"
+    "rsc.io/sampler"
+)
+
+func main() {
+    fmt.Println(sampler.Hello())
+}
\ No newline at end of file