diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-04-28 12:57:55 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-04-30 18:05:38 +0000 |
commit | 4063605e0d0ce2ee2603c70a70c3a918adb7369a (patch) | |
tree | 2b6f334a4f924d8432cad11e3edb763f6ca576d1 /src/cmd/go/internal/modload/load.go | |
parent | 8d8abb3b8a80d341ce2d7c6dd3f2a43fd586bed8 (diff) | |
download | go-4063605e0d0ce2ee2603c70a70c3a918adb7369a.tar.gz go-4063605e0d0ce2ee2603c70a70c3a918adb7369a.zip |
cmd/go/internal/modload: avoid loading the full module graph for imports satisfied by lazy roots
For #36460
Change-Id: Ibdbaa893ded772617e22f12db7a0463604db5195
Reviewed-on: https://go-review.googlesource.com/c/go/+/308516
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index b822e74eb5..ddacf49ead 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -1236,7 +1236,7 @@ func (ld *loader) updateRequirements(ctx context.Context) (changed bool, err err // // In some sense, we can think of this as ‘upgraded the module providing // pkg.path from "none" to a version higher than "none"’. - if _, _, err = importFromModules(ctx, pkg.path, rs); err == nil { + if _, _, err = importFromModules(ctx, pkg.path, rs, nil); err == nil { changed = true break } @@ -1429,7 +1429,7 @@ func (ld *loader) preloadRootModules(ctx context.Context, rootPkgs []string) (ch // If the main module is tidy and the package is in "all" — or if we're // lucky — we can identify all of its imports without actually loading the // full module graph. - m, _, err := importFromModules(ctx, path, ld.requirements) + m, _, err := importFromModules(ctx, path, ld.requirements, nil) if err != nil { var missing *ImportMissingError if errors.As(err, &missing) && ld.ResolveMissingImports { @@ -1516,7 +1516,24 @@ func (ld *loader) load(ctx context.Context, pkg *loadPkg) { return } - pkg.mod, pkg.dir, pkg.err = importFromModules(ctx, pkg.path, ld.requirements) + var mg *ModuleGraph + if ld.requirements.depth == eager { + var err error + mg, err = ld.requirements.Graph(ctx) + if err != nil { + // We already checked the error from Graph in loadFromRoots and/or + // updateRequirements, so we ignored the error on purpose and we should + // keep trying to push past it. + // + // However, because mg may be incomplete (and thus may select inaccurate + // versions), we shouldn't use it to load packages. Instead, we pass a nil + // *ModuleGraph, which will cause mg to first try loading from only the + // main module and root dependencies. + mg = nil + } + } + + pkg.mod, pkg.dir, pkg.err = importFromModules(ctx, pkg.path, ld.requirements, mg) if pkg.dir == "" { return } |