Version: m.Version,
Indirect: fromBuildList && loaded != nil && !loaded.direct[m.Path],
}
- if loaded != nil {
- info.GoVersion = loaded.goVersion[m.Path]
+ if v, ok := rawGoVersion.Load(m); ok {
+ info.GoVersion = v.(string)
}
// completeFromModCache fills in the extra fields in m using the module cache.
}
if !fromBuildList {
+ // If this was an explicitly-versioned argument to 'go mod download' or
+ // 'go list -m', report the actual requested version, not its replacement.
completeFromModCache(info) // Will set m.Error in vendor mode.
return info
}
// worth the cost, and we're going to overwrite the GoMod and Dir from the
// replacement anyway. See https://golang.org/issue/27859.
info.Replace = &modinfo.ModulePublic{
- Path: r.Path,
- Version: r.Version,
- GoVersion: info.GoVersion,
+ Path: r.Path,
+ Version: r.Version,
+ }
+ if goV, ok := rawGoVersion.Load(r); ok {
+ info.Replace.GoVersion = goV.(string)
+ info.GoVersion = info.Replace.GoVersion
}
if r.Version == "" {
if filepath.IsAbs(r.Path) {
pkgCache *par.Cache // map from string to *loadPkg
// computed at end of iterations
- direct map[string]bool // imported directly by main module
- goVersion map[string]string // go version recorded in each module
+ direct map[string]bool // imported directly by main module
}
// LoadTests controls whether the loaders load tests of the root packages.
}
}
- // Add Go versions, computed during walk.
- ld.goVersion = make(map[string]string)
- for _, m := range buildList {
- v, _ := reqs.(*mvsReqs).versions.Load(m)
- ld.goVersion[m.Path], _ = v.(string)
- }
-
// Mix in direct markings (really, lack of indirect markings)
// from go.mod, unless we scanned the whole module
// and can therefore be sure we know better than go.mod.
import (
"cmd/go/internal/base"
"cmd/go/internal/cfg"
+ "sync"
"golang.org/x/mod/modfile"
"golang.org/x/mod/module"
return false
}
+
+// rawGoVersion records the Go version parsed from each module's go.mod file.
+//
+// If a module is replaced, the version of the replacement is keyed by the
+// replacement module.Version, not the version being replaced.
+var rawGoVersion sync.Map // map[module.Version]string
"os"
"path/filepath"
"sort"
- "sync"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
type mvsReqs struct {
buildList []module.Version
cache par.Cache
- versions sync.Map
}
// Reqs returns the current module requirement graph.
func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) {
if mod == Target {
if modFile != nil && modFile.Go != nil {
- r.versions.LoadOrStore(mod, modFile.Go.Version)
+ rawGoVersion.LoadOrStore(mod, modFile.Go.Version)
}
return append([]module.Version(nil), r.buildList[1:]...), nil
}
return nil, fmt.Errorf("parsing %s: %v", base.ShortPath(gomod), err)
}
if f.Go != nil {
- r.versions.LoadOrStore(mod, f.Go.Version)
+ rawGoVersion.LoadOrStore(repl, f.Go.Version)
}
return r.modFileToList(f), nil
}
but was required as: %s`, mpath, origPath))
}
if f.Go != nil {
- r.versions.LoadOrStore(mod, f.Go.Version)
+ rawGoVersion.LoadOrStore(mod, f.Go.Version)
}
return r.modFileToList(f), nil