aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2023-06-08 17:55:55 -0400
committerMichael Pratt <mpratt@google.com>2023-06-13 19:31:34 +0000
commit1d85bcea2839f45047f58b5f442cdb728b97e00c (patch)
tree07b012db222925cbf7e9b9afa849e9c55c9c5532
parent3ba9c890b86dc8c3a54c98d32497b7a8012704f9 (diff)
downloadgo-1d85bcea2839f45047f58b5f442cdb728b97e00c.tar.gz
go-1d85bcea2839f45047f58b5f442cdb728b97e00c.zip
[release-branch.go1.19] 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 #60697. Updates #60667. Updates #56222. Change-Id: Ied6ed3e80a62f9cd9a328b43a415a42d14481056 Reviewed-on: https://go-review.googlesource.com/c/go/+/502017 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Bypass: Bryan Mills <bcmills@google.com>
-rw-r--r--src/cmd/go/internal/modload/init.go18
-rw-r--r--src/cmd/go/testdata/script/mod_sum_issue56222.txt4
2 files changed, 19 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 68f5f7ae40..ac46213861 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -1585,7 +1585,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 {
+ keepModSumsForZipSums := true
+ if ld == nil {
+ if cfg.BuildMod != "mod" && semver.Compare("v"+MainModules.GoVersion(), tidyGoModSumVersionV) < 0 {
+ keepModSumsForZipSums = false
+ }
+ } else {
+ keepPkgGoModSums := true
+ if (ld.Tidy || cfg.BuildMod != "mod") && semver.Compare("v"+ld.GoVersion, tidyGoModSumVersionV) < 0 {
+ 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
@@ -1599,7 +1609,7 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
// However, we didn't do so before Go 1.21, and the bug is relatively
// minor, so we maintain the previous (buggy) behavior in 'go mod tidy' to
// avoid introducing unnecessary churn.
- if !ld.Tidy || semver.Compare("v"+ld.GoVersion, tidyGoModSumVersionV) >= 0 {
+ if keepPkgGoModSums {
r := resolveReplacement(pkg.mod)
keep[modkey(r)] = true
}
@@ -1659,7 +1669,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 841553941e..3183f23e2d 100644
--- a/src/cmd/go/testdata/script/mod_sum_issue56222.txt
+++ b/src/cmd/go/testdata/script/mod_sum_issue56222.txt
@@ -22,6 +22,10 @@ stdout 1.18
go mod tidy -go=1.19
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