aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/init.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-04-09 22:00:14 -0400
committerBryan C. Mills <bcmills@google.com>2021-04-30 18:06:15 +0000
commitee4f9656ac419bb92408f65f082c735a6b82d1fa (patch)
tree47f4bb9c353707a3e0831edc9b717af66e2a4caa /src/cmd/go/internal/modload/init.go
parent4063605e0d0ce2ee2603c70a70c3a918adb7369a (diff)
downloadgo-ee4f9656ac419bb92408f65f082c735a6b82d1fa.tar.gz
go-ee4f9656ac419bb92408f65f082c735a6b82d1fa.zip
cmd/go/internal/modload: avoid loading the full module graph to determine which checksums to add to go.sum
For #36460 Change-Id: I606314054bd9064f7c4053f56049fabbaec54143 Reviewed-on: https://go-review.googlesource.com/c/go/+/309189 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/init.go')
-rw-r--r--src/cmd/go/internal/modload/init.go58
1 files changed, 36 insertions, 22 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index f46c58f474..ef21908064 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -1094,34 +1094,16 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
// that version is selected).
keep := make(map[module.Version]bool)
- if go117LazyTODO {
- // If the main module is lazy, avoid loading the module graph if it hasn't
- // already been loaded.
- }
-
- mg, _ := rs.Graph(ctx)
- mg.WalkBreadthFirst(func(m module.Version) {
- if _, ok := mg.RequiredBy(m); ok {
- // The requirements from m's go.mod file are present in the module graph,
- // so they are relevant to the MVS result regardless of whether m was
- // actually selected.
- keep[modkey(resolveReplacement(m))] = true
- }
- })
-
- if which == addBuildListZipSums {
- for _, m := range mg.BuildList() {
- keep[resolveReplacement(m)] = true
- }
- }
-
// Add entries for modules in the build list with paths that are prefixes of
// 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 {
for _, pkg := range ld.pkgs {
- if pkg.testOf != nil || pkg.inStd || module.CheckImportPath(pkg.path) != nil {
+ // 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
+ // shouldn't force loading the whole module graph).
+ if pkg.testOf != nil || (pkg.mod.Path == "" && pkg.err == nil) || module.CheckImportPath(pkg.path) != nil {
continue
}
@@ -1141,6 +1123,7 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
}
}
+ mg, _ := rs.Graph(ctx)
for prefix := pkg.path; prefix != "."; prefix = path.Dir(prefix) {
if v := mg.Selected(prefix); v != "none" {
m := module.Version{Path: prefix, Version: v}
@@ -1150,6 +1133,37 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums
}
}
+ if rs.depth == lazy && rs.graph.Load() == nil {
+ // The main module is lazy and we haven't needed to load the module graph so
+ // far. Don't incur the cost of loading it now — since we haven't loaded the
+ // graph, we probably don't have any checksums to contribute to the distant
+ // parts of the graph anyway. Instead, just request sums for the roots that
+ // we know about.
+ for _, m := range rs.rootModules {
+ r := resolveReplacement(m)
+ keep[modkey(r)] = true
+ if which == addBuildListZipSums {
+ keep[r] = true
+ }
+ }
+ } else {
+ mg, _ := rs.Graph(ctx)
+ mg.WalkBreadthFirst(func(m module.Version) {
+ if _, ok := mg.RequiredBy(m); ok {
+ // The requirements from m's go.mod file are present in the module graph,
+ // so they are relevant to the MVS result regardless of whether m was
+ // actually selected.
+ keep[modkey(resolveReplacement(m))] = true
+ }
+ })
+
+ if which == addBuildListZipSums {
+ for _, m := range mg.BuildList() {
+ keep[resolveReplacement(m)] = true
+ }
+ }
+ }
+
return keep
}