diff options
author | Jay Conrod <jayconrod@google.com> | 2020-12-16 16:37:56 -0500 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2020-12-23 14:16:32 +0000 |
commit | 98a73030b01cc23a292934d09f137a2befa439bf (patch) | |
tree | a2b481a011582f0f1bc6b7968128c16e7e1b8688 /src/cmd/go/internal/modload/buildlist.go | |
parent | fd6ba1c8a23d8a3fffb6c475b21f78510152ef5c (diff) | |
download | go-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/buildlist.go')
-rw-r--r-- | src/cmd/go/internal/modload/buildlist.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modload/buildlist.go b/src/cmd/go/internal/modload/buildlist.go index 896adebbb1..45f220a6ee 100644 --- a/src/cmd/go/internal/modload/buildlist.go +++ b/src/cmd/go/internal/modload/buildlist.go @@ -28,6 +28,11 @@ import ( // var buildList []module.Version +// additionalExplicitRequirements is a list of modules paths for which +// WriteGoMod should record explicit requirements, even if they would be +// selected without those requirements. Each path must also appear in buildList. +var additionalExplicitRequirements []string + // capVersionSlice returns s with its cap reduced to its length. func capVersionSlice(s []module.Version) []module.Version { return s[:len(s):len(s)] @@ -121,6 +126,12 @@ func EditBuildList(ctx context.Context, add, mustSelect []module.Version) error if !inconsistent { buildList = final + additionalExplicitRequirements = make([]string, 0, len(mustSelect)) + for _, m := range mustSelect { + if m.Version != "none" { + additionalExplicitRequirements = append(additionalExplicitRequirements, m.Path) + } + } return nil } |