aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/init.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2020-12-16 16:37:56 -0500
committerJay Conrod <jayconrod@google.com>2020-12-23 14:16:32 +0000
commit98a73030b01cc23a292934d09f137a2befa439bf (patch)
treea2b481a011582f0f1bc6b7968128c16e7e1b8688 /src/cmd/go/internal/modload/init.go
parentfd6ba1c8a23d8a3fffb6c475b21f78510152ef5c (diff)
downloadgo-98a73030b01cc23a292934d09f137a2befa439bf.tar.gz
go-98a73030b01cc23a292934d09f137a2befa439bf.zip
cmd/go: in 'go get', promote named implicit dependencies to explicit
'go get pkg@vers' will now add an explicit requirement for the module providing pkg if that version was already indirectly required. 'go get mod@vers' will do the same if mod is a module path but not a package. Requirements promoted this way will be marked "// indirect" because 'go get' doesn't know whether they're needed to build packages in the main module. So users should prefer to run 'go get ./pkg' (where ./pkg is a package in the main module) to promote requirements. Fixes #43131 Change-Id: Ifbb65b71274b3cc752a7a593d6ddd875f7de23b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/278812 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/init.go')
-rw-r--r--src/cmd/go/internal/modload/init.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 3f70d04145..445ebb262f 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -15,6 +15,7 @@ import (
"os"
"path"
"path/filepath"
+ "sort"
"strconv"
"strings"
"sync"
@@ -27,6 +28,7 @@ import (
"cmd/go/internal/modfetch"
"cmd/go/internal/mvs"
"cmd/go/internal/search"
+ "cmd/go/internal/str"
"golang.org/x/mod/modfile"
"golang.org/x/mod/module"
@@ -845,13 +847,15 @@ func AllowWriteGoMod() {
// MinReqs returns a Reqs with minimal additional dependencies of Target,
// as will be written to go.mod.
func MinReqs() mvs.Reqs {
- var retain []string
+ retain := append([]string{}, additionalExplicitRequirements...)
for _, m := range buildList[1:] {
_, explicit := index.require[m]
if explicit || loaded.direct[m.Path] {
retain = append(retain, m.Path)
}
}
+ sort.Strings(retain)
+ str.Uniq(&retain)
min, err := mvs.Req(Target, retain, &mvsReqs{buildList: buildList})
if err != nil {
base.Fatalf("go: %v", err)