aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/list.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2018-07-11 23:55:39 -0400
committerRuss Cox <rsc@golang.org>2018-07-12 20:46:50 +0000
commitf7248f05946c1804b5519d0b3eb0db054dc9c5d6 (patch)
tree73a9d64a6af33d4feefa5f3acf6eb7f7206a8a95 /src/cmd/go/internal/modload/list.go
parentf22dd66b23ec1a703a3984cad1840bc8692cf1d0 (diff)
downloadgo-f7248f05946c1804b5519d0b3eb0db054dc9c5d6.tar.gz
go-f7248f05946c1804b5519d0b3eb0db054dc9c5d6.zip
cmd/go: merge module support from x/vgo repo
This CL corresponds to CL 123361, the final manual CL in that repo, making this the final manual sync. All future commits will happen in this repo (the main Go repo), and we'll update x/vgo automatically with a fixed patch+script. Change-Id: I572243309c1809727604fd704705a23c30e85d1a Reviewed-on: https://go-review.googlesource.com/123576 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/list.go')
-rw-r--r--src/cmd/go/internal/modload/list.go109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modload/list.go b/src/cmd/go/internal/modload/list.go
new file mode 100644
index 0000000000..69a832de1d
--- /dev/null
+++ b/src/cmd/go/internal/modload/list.go
@@ -0,0 +1,109 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package modload
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ "cmd/go/internal/base"
+ "cmd/go/internal/modinfo"
+ "cmd/go/internal/module"
+ "cmd/go/internal/par"
+ "cmd/go/internal/search"
+)
+
+func ListModules(args []string, listU, listVersions bool) []*modinfo.ModulePublic {
+ mods := listModules(args)
+ if listU || listVersions {
+ var work par.Work
+ for _, m := range mods {
+ work.Add(m)
+ if m.Replace != nil {
+ work.Add(m.Replace)
+ }
+ }
+ work.Do(10, func(item interface{}) {
+ m := item.(*modinfo.ModulePublic)
+ if listU {
+ addUpdate(m)
+ }
+ if listVersions {
+ addVersions(m)
+ }
+ })
+ }
+ return mods
+}
+
+func listModules(args []string) []*modinfo.ModulePublic {
+ LoadBuildList()
+ if len(args) == 0 {
+ return []*modinfo.ModulePublic{moduleInfo(buildList[0], true)}
+ }
+
+ var mods []*modinfo.ModulePublic
+ matchedBuildList := make([]bool, len(buildList))
+ for _, arg := range args {
+ if strings.Contains(arg, `\`) {
+ base.Fatalf("go: module paths never use backslash")
+ }
+ if search.IsRelativePath(arg) {
+ base.Fatalf("go: cannot use relative path %s to specify module", arg)
+ }
+ if i := strings.Index(arg, "@"); i >= 0 {
+ info, err := Query(arg[:i], arg[i+1:], nil)
+ if err != nil {
+ mods = append(mods, &modinfo.ModulePublic{
+ Path: arg[:i],
+ Version: arg[i+1:],
+ Error: &modinfo.ModuleError{
+ Err: err.Error(),
+ },
+ })
+ continue
+ }
+ mods = append(mods, moduleInfo(module.Version{Path: arg[:i], Version: info.Version}, false))
+ continue
+ }
+
+ // Module path or pattern.
+ var match func(string) bool
+ var literal bool
+ if arg == "all" {
+ match = func(string) bool { return true }
+ } else if strings.Contains(arg, "...") {
+ match = search.MatchPattern(arg)
+ } else {
+ match = func(p string) bool { return arg == p }
+ literal = true
+ }
+ matched := false
+ for i, m := range buildList {
+ if match(m.Path) {
+ matched = true
+ if !matchedBuildList[i] {
+ matchedBuildList[i] = true
+ mods = append(mods, moduleInfo(m, true))
+ }
+ }
+ }
+ if !matched {
+ if literal {
+ mods = append(mods, &modinfo.ModulePublic{
+ Path: arg,
+ Error: &modinfo.ModuleError{
+ Err: fmt.Sprintf("module %q is not a known dependency", arg),
+ },
+ })
+ } else {
+ fmt.Fprintf(os.Stderr, "warning: pattern %q matched no module dependencies\n", arg)
+ }
+ }
+ }
+
+ return mods
+}