diff options
author | Michael Matloob <matloob@golang.org> | 2021-10-25 16:19:11 -0400 |
---|---|---|
committer | Michael Matloob <matloob@golang.org> | 2021-11-09 22:20:29 +0000 |
commit | 795cb333d94ee7f5632500f3e2ae98012b8d73e6 (patch) | |
tree | c6b1cfdaa1d989dc27a01647f319ea63f67ce22a /src/cmd/go/internal/modload/load.go | |
parent | 1c86beeadfc7a370048ad58f76b1b60b5bcd06ee (diff) | |
download | go-795cb333d94ee7f5632500f3e2ae98012b8d73e6.tar.gz go-795cb333d94ee7f5632500f3e2ae98012b8d73e6.zip |
cmd/go: add go work sync command
Change-Id: I09b22f05035700e1ed90bd066ee8f77c3913286a
Reviewed-on: https://go-review.googlesource.com/c/go/+/358540
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index 83fcafead3c..27bbfb78328 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -231,6 +231,9 @@ type PackageOpts struct { // SilenceUnmatchedWarnings suppresses the warnings normally emitted for // patterns that did not match any packages. SilenceUnmatchedWarnings bool + + // Resolve the query against this module. + MainModule module.Version } // LoadPackages identifies the set of packages matching the given patterns and @@ -256,7 +259,11 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma case m.IsLocal(): // Evaluate list of file system directories on first iteration. if m.Dirs == nil { - matchLocalDirs(ctx, m, rs) + matchModRoots := modRoots + if opts.MainModule != (module.Version{}) { + matchModRoots = []string{MainModules.ModRoot(opts.MainModule)} + } + matchLocalDirs(ctx, matchModRoots, m, rs) } // Make a copy of the directory list and translate to import paths. @@ -309,7 +316,11 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma // The initial roots are the packages in the main module. // loadFromRoots will expand that to "all". m.Errs = m.Errs[:0] - matchPackages(ctx, m, opts.Tags, omitStd, MainModules.Versions()) + matchModules := MainModules.Versions() + if opts.MainModule != (module.Version{}) { + matchModules = []module.Version{opts.MainModule} + } + matchPackages(ctx, m, opts.Tags, omitStd, matchModules) } else { // Starting with the packages in the main module, // enumerate the full list of "all". @@ -441,7 +452,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma // matchLocalDirs is like m.MatchDirs, but tries to avoid scanning directories // outside of the standard library and active modules. -func matchLocalDirs(ctx context.Context, m *search.Match, rs *Requirements) { +func matchLocalDirs(ctx context.Context, modRoots []string, m *search.Match, rs *Requirements) { if !m.IsLocal() { panic(fmt.Sprintf("internal error: resolveLocalDirs on non-local pattern %s", m.Pattern())) } @@ -460,8 +471,8 @@ func matchLocalDirs(ctx context.Context, m *search.Match, rs *Requirements) { modRoot := findModuleRoot(absDir) found := false - for _, mod := range MainModules.Versions() { - if MainModules.ModRoot(mod) == modRoot { + for _, mainModuleRoot := range modRoots { + if mainModuleRoot == modRoot { found = true break } |