aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2023-06-08 17:55:55 -0400
committerBryan Mills <bcmills@google.com>2023-06-12 13:58:58 +0000
commit1db23771afc7b9b259e926db35602ecf5047ae23 (patch)
tree6d8f27816e2de1d924ce3b84c0a914ce855d8fc9
parentee46f0b5084461978432aa20df003ac52500b0f0 (diff)
downloadgo-1db23771afc7b9b259e926db35602ecf5047ae23.tar.gz
go-1db23771afc7b9b259e926db35602ecf5047ae23.zip
cmd/go: omit checksums for go.mod files needed for go version lines more often in pre-1.21 modules
This updates the logic from CL 489075 to avoid trying to save extra sums if they aren't already expected to be present and cfg.BuildMod != "mod" (as in the case of "go list -m -u all" with a go.mod file that specifies go < 1.21). Fixes #60667. Updates #56222. Change-Id: Ied6ed3e80a62f9cd9a328b43a415a42d14481056 Reviewed-on: https://go-review.googlesource.com/c/go/+/502015 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
-rw-r--r--src/cmd/go/internal/modload/init.go17
-rw-r--r--src/cmd/go/testdata/script/mod_sum_issue56222.txt4
2 files changed, 18 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 0aedfafefd..1c6f7d9d3a 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -1817,8 +1817,17 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
// paths of loaded packages. We need to retain sums for all of these modules —
// not just the modules containing the actual packages — in order to rule out
// ambiguous import errors the next time we load the package.
- if ld != nil {
- keepPkgGoModSums := !ld.Tidy || gover.Compare(ld.requirements.GoVersion(), gover.TidyGoModSumVersion) >= 0
+ keepModSumsForZipSums := true
+ if ld == nil {
+ if gover.Compare(MainModules.GoVersion(), gover.TidyGoModSumVersion) < 0 && cfg.BuildMod != "mod" {
+ keepModSumsForZipSums = false
+ }
+ } else {
+ keepPkgGoModSums := true
+ if gover.Compare(ld.requirements.GoVersion(), gover.TidyGoModSumVersion) < 0 && (ld.Tidy || cfg.BuildMod != "mod") {
+ keepPkgGoModSums = false
+ keepModSumsForZipSums = false
+ }
for _, pkg := range ld.pkgs {
// We check pkg.mod.Path here instead of pkg.inStd because the
// pseudo-package "C" is not in std, but not provided by any module (and
@@ -1892,7 +1901,9 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
if which == addBuildListZipSums {
for _, m := range mg.BuildList() {
r := resolveReplacement(m)
- keep[modkey(r)] = true // we need the go version from the go.mod file to do anything useful with the zipfile
+ if keepModSumsForZipSums {
+ keep[modkey(r)] = true // we need the go version from the go.mod file to do anything useful with the zipfile
+ }
keep[r] = true
}
}
diff --git a/src/cmd/go/testdata/script/mod_sum_issue56222.txt b/src/cmd/go/testdata/script/mod_sum_issue56222.txt
index 0abddc73b2..12848c9110 100644
--- a/src/cmd/go/testdata/script/mod_sum_issue56222.txt
+++ b/src/cmd/go/testdata/script/mod_sum_issue56222.txt
@@ -42,6 +42,10 @@ stdout 1.18
go mod tidy -go=1.20
go clean -modcache # Remove checksums from the module cache, so that only go.sum is used.
+# Issue 60667: 'go list' without -mod=mod shouldn't report the checksums as
+# dirty either.
+go list -m -u all
+
env OLDSUMDB=$GOSUMDB
env GOSUMDB=bad
go mod tidy