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/modcmd/why.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/modcmd/why.go')
-rw-r--r-- | src/cmd/go/internal/modcmd/why.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/cmd/go/internal/modcmd/why.go b/src/cmd/go/internal/modcmd/why.go index ea7c28e0b8..5a6d535700 100644 --- a/src/cmd/go/internal/modcmd/why.go +++ b/src/cmd/go/internal/modcmd/why.go @@ -10,6 +10,7 @@ import ( "strings" "cmd/go/internal/base" + "cmd/go/internal/imports" "cmd/go/internal/modload" "golang.org/x/mod/module" @@ -63,12 +64,14 @@ func init() { func runWhy(ctx context.Context, cmd *base.Command, args []string) { modload.ForceUseModules = true modload.RootMode = modload.NeedRoot - loadALL := modload.LoadALL - if *whyVendor { - loadALL = modload.LoadVendor - } else { - modload.LoadTests = true + + loadOpts := modload.PackageOpts{ + Tags: imports.AnyTags(), + LoadTests: !*whyVendor, + AllowErrors: true, + UseVendorAll: *whyVendor, } + if *whyM { listU := false listVersions := false @@ -80,7 +83,8 @@ func runWhy(ctx context.Context, cmd *base.Command, args []string) { } mods := modload.ListModules(ctx, args, listU, listVersions, listRetractions) byModule := make(map[module.Version][]string) - for _, path := range loadALL(ctx) { + _, pkgs := modload.LoadPackages(ctx, loadOpts, "all") + for _, path := range pkgs { m := modload.PackageModule(path) if m.Path != "" { byModule[m] = append(byModule[m], path) @@ -109,8 +113,11 @@ func runWhy(ctx context.Context, cmd *base.Command, args []string) { sep = "\n" } } else { - matches := modload.ImportPaths(ctx, args) // resolve to packages - loadALL(ctx) // rebuild graph, from main module (not from named packages) + // Resolve to packages. + matches, _ := modload.LoadPackages(ctx, loadOpts, args...) + + modload.LoadPackages(ctx, loadOpts, "all") // rebuild graph, from main module (not from named packages) + sep := "" for _, m := range matches { for _, path := range m.Pkgs { |