Skip to content

Commit

Permalink
[release-branch.go1.20] cmd/go: omit checksums for go.mod files neede…
Browse files Browse the repository at this point in the history
…d 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 #60698.
Updates #60667.
Updates #56222.

Change-Id: Ied6ed3e80a62f9cd9a328b43a415a42d14481056
Reviewed-on: https://go-review.googlesource.com/c/go/+/502016
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
  • Loading branch information
Bryan C. Mills authored and prattmic committed Jun 13, 2023
1 parent 1008486 commit 8b3acef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/cmd/go/internal/modload/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,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
Expand All @@ -1611,7 +1621,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
}
Expand Down Expand Up @@ -1671,7 +1681,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
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/go/testdata/script/mod_sum_issue56222.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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
Expand Down

0 comments on commit 8b3acef

Please sign in to comment.