//
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)]
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
}
"os"
"path"
"path/filepath"
+ "sort"
"strconv"
"strings"
"sync"
"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"
// 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)
"cmd/go/internal/imports"
"cmd/go/internal/modfetch"
"cmd/go/internal/search"
+ "cmd/go/internal/str"
"cmd/go/internal/trace"
"golang.org/x/mod/module"
sort.Slice(versions, func(i, j int) bool {
return semver.Compare(versions[i], versions[j]) < 0
})
- uniq := versions[:1]
- for _, v := range versions {
- if v != uniq[len(uniq)-1] {
- uniq = append(uniq, v)
- }
- }
- return uniq, nil
+ str.Uniq(&versions)
+ return versions, nil
}
func (rr *replacementRepo) Stat(rev string) (*modfetch.RevInfo, error) {
return false
}
+// Uniq removes consecutive duplicate strings from ss.
+func Uniq(ss *[]string) {
+ if len(*ss) <= 1 {
+ return
+ }
+ uniq := (*ss)[:1]
+ for _, s := range *ss {
+ if s != uniq[len(uniq)-1] {
+ uniq = append(uniq, s)
+ }
+ }
+ *ss = uniq
+}
+
func isSpaceByte(c byte) bool {
return c == ' ' || c == '\t' || c == '\n' || c == '\r'
}
cmp go.mod go.mod.use
cp go.mod.orig go.mod
+# We can also promote implicit requirements using 'go get' on them, or their
+# packages. This gives us "// indirect" requirements, since 'go get' doesn't
+# know they're needed by the main module. See #43131 for the rationale.
+go get -d indirect-with-pkg indirect-without-pkg
+cmp go.mod go.mod.indirect
+
-- go.mod.orig --
module m