diff options
Diffstat (limited to 'src/cmd/go/internal/modload/init.go')
-rw-r--r-- | src/cmd/go/internal/modload/init.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index f960edd251d..68f5f7ae40e 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -1571,7 +1571,8 @@ func commitRequirements(ctx context.Context) (err error) { // keepSums returns the set of modules (and go.mod file entries) for which // checksums would be needed in order to reload the same set of packages // loaded by the most recent call to LoadPackages or ImportFromFiles, -// including any go.mod files needed to reconstruct the MVS result, +// including any go.mod files needed to reconstruct the MVS result +// or identify go versions, // in addition to the checksums for every module in keepMods. func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums) map[module.Version]bool { // Every module in the full module graph contributes its requirements, @@ -1593,6 +1594,16 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums continue } + // We need the checksum for the go.mod file for pkg.mod + // so that we know what Go version to use to compile pkg. + // 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 { + r := resolveReplacement(pkg.mod) + keep[modkey(r)] = true + } + if rs.pruning == pruned && pkg.mod.Path != "" { if v, ok := rs.rootSelected(pkg.mod.Path); ok && v == pkg.mod.Version { // pkg was loaded from a root module, and because the main module has @@ -1648,6 +1659,7 @@ 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 keep[r] = true } } |