diff options
author | Bryan C. Mills <bcmills@google.com> | 2020-07-23 00:45:27 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2020-08-24 20:45:05 +0000 |
commit | a9146a49d0db666a7efd5f5d4555cf6117405cf5 (patch) | |
tree | f4767ced3fd89434280a93cbc26b15d17d4a1e5b /src/cmd/go/internal/modload/build.go | |
parent | 2a9636dc2bdbb2865dde686352de528c6953c7bf (diff) | |
download | go-a9146a49d0db666a7efd5f5d4555cf6117405cf5.tar.gz go-a9146a49d0db666a7efd5f5d4555cf6117405cf5.zip |
cmd/go/internal/modload: cache parsed go.mod files globally
Previously they were cached per mvsReqs instance. However, the
contents of the go.mod file of a given dependency version can only
vary if the 'replace' directives that apply to that version have
changed, and the only time we change 'replace' directives is in 'go
mod edit' (which does not care about the build list or MVS).
This not only simplifies the mvsReqs implementation, but also makes
more of the underlying logic independent of mvsReqs.
For #36460
Change-Id: Ieac20c2fcd56f64d847ac8a1b40f9361ece78663
Reviewed-on: https://go-review.googlesource.com/c/go/+/244774
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/build.go')
-rw-r--r-- | src/cmd/go/internal/modload/build.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/cmd/go/internal/modload/build.go b/src/cmd/go/internal/modload/build.go index b6f955d591..7e182b4a4d 100644 --- a/src/cmd/go/internal/modload/build.go +++ b/src/cmd/go/internal/modload/build.go @@ -132,6 +132,8 @@ func moduleInfo(ctx context.Context, m module.Version, fromBuildList bool) *modi // completeFromModCache fills in the extra fields in m using the module cache. completeFromModCache := func(m *modinfo.ModulePublic) { + mod := module.Version{Path: m.Path, Version: m.Version} + if m.Version != "" { if q, err := Query(ctx, m.Path, m.Version, "", nil); err != nil { m.Error = &modinfo.ModuleError{Err: err.Error()} @@ -140,7 +142,6 @@ func moduleInfo(ctx context.Context, m module.Version, fromBuildList bool) *modi m.Time = &q.Time } - mod := module.Version{Path: m.Path, Version: m.Version} gomod, err := modfetch.CachePath(mod, "mod") if err == nil { if info, err := os.Stat(gomod); err == nil && info.Mode().IsRegular() { @@ -152,6 +153,12 @@ func moduleInfo(ctx context.Context, m module.Version, fromBuildList bool) *modi m.Dir = dir } } + + if m.GoVersion == "" { + if summary, err := rawGoModSummary(mod); err == nil && summary.goVersionV != "" { + m.GoVersion = summary.goVersionV[1:] + } + } } if !fromBuildList { @@ -183,9 +190,8 @@ func moduleInfo(ctx context.Context, m module.Version, fromBuildList bool) *modi Path: r.Path, Version: r.Version, } - if goV, ok := rawGoVersion.Load(r); ok { - info.Replace.GoVersion = goV.(string) - info.GoVersion = info.Replace.GoVersion + if v, ok := rawGoVersion.Load(m); ok { + info.Replace.GoVersion = v.(string) } if r.Version == "" { if filepath.IsAbs(r.Path) { @@ -200,6 +206,7 @@ func moduleInfo(ctx context.Context, m module.Version, fromBuildList bool) *modi info.Dir = info.Replace.Dir info.GoMod = info.Replace.GoMod } + info.GoVersion = info.Replace.GoVersion return info } |