diff options
author | Bryan C. Mills <bcmills@google.com> | 2020-09-17 16:24:29 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2020-09-22 16:52:00 +0000 |
commit | fd75989f46c80d2446dd9dcefaffbebdb7f7ea87 (patch) | |
tree | ff0ce203b50f1fc75c2be3a3bdee760e0cdb81b6 /src/cmd/go/internal/modget/get.go | |
parent | d42b32e321fa5c5d2c93b2ad22d48e804c9f45d2 (diff) | |
download | go-fd75989f46c80d2446dd9dcefaffbebdb7f7ea87.tar.gz go-fd75989f46c80d2446dd9dcefaffbebdb7f7ea87.zip |
cmd/go/internal/modget: consolidate Load entrypoints
This change replaces ImportPaths, ImportPathsQuiet, LoadALL, and
LoadVendor with a single LoadPackages function, with a LoadOpts struct
that more clearly documents the variations in behavior.
It also eliminates the cmd/go/internal/load.ImportPaths function,
which was undocumented and had only one call site (within its own
package).
The modload.LoadTests global variable is subsumed by a field in the
new LoadOpts struct, and is no longer needed for callers that invoke
LoadPackages directly. It has been (temporarily) replaced with a
similar global variable, load.ModResolveTests, which can itself be
converted to an explicit, local argument.
For #37438
For #36460
Updates #40775
Fixes #26977
Change-Id: I4fb6086c01b04de829d98875db19cf0118d40f8c
Reviewed-on: https://go-review.googlesource.com/c/go/+/255938
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modget/get.go')
-rw-r--r-- | src/cmd/go/internal/modget/get.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go index f7b5cfaf2e..371ba8b690 100644 --- a/src/cmd/go/internal/modget/get.go +++ b/src/cmd/go/internal/modget/get.go @@ -284,7 +284,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) { if cfg.Insecure { fmt.Fprintf(os.Stderr, "go get: -insecure flag is deprecated; see 'go help get' for details\n") } - modload.LoadTests = *getT + load.ModResolveTests = *getT // Do not allow any updating of go.mod until we've applied // all the requested changes and checked that the result matches @@ -314,7 +314,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) { // Add missing modules to the build list. // We call SetBuildList here and elsewhere, since newUpgrader, - // ImportPathsQuiet, and other functions read the global build list. + // LoadPackages, and other functions read the global build list. for _, q := range queries { if _, ok := selectedVersion[q.m.Path]; !ok && q.m.Version != "none" { buildList = append(buildList, q.m) @@ -400,9 +400,16 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) { if len(pkgPatterns) > 0 { // Don't load packages if pkgPatterns is empty. Both - // modload.ImportPathsQuiet and ModulePackages convert an empty list + // modload.LoadPackages and ModulePackages convert an empty list // of patterns to []string{"."}, which is not what we want. - matches = modload.ImportPathsQuiet(ctx, pkgPatterns, imports.AnyTags()) + loadOpts := modload.PackageOpts{ + Tags: imports.AnyTags(), + ResolveMissingImports: true, // dubious; see https://golang.org/issue/32567 + LoadTests: *getT, + AllowErrors: true, // Errors may be fixed by subsequent upgrades or downgrades. + SilenceUnmatchedWarnings: true, // We will warn after iterating below. + } + matches, _ = modload.LoadPackages(ctx, loadOpts, pkgPatterns...) seenPkgs = make(map[string]bool) for i, match := range matches { arg := pkgGets[i] |