1
0
mirror of https://github.com/golang/go synced 2024-11-26 05:07:59 -07:00

cmd/go/internal/mvs: don't emit duplicates from Req

Req is supposed to return “a minimal requirement list”
that includes each of the module paths listed in base.
Currently, if base contains duplicates Req emits duplicates,
and a list containing duplicates is certainly not minimal.

That, in turn, requires callers to be careful to deduplicate the base
slice, and there are multiple callers that are already quite
complicated to reason about even without the added complication of
deduplicating slices.

For #36460

Change-Id: I391a1dc0641fe1dd424c16b7a1082da0d00c7292
Reviewed-on: https://go-review.googlesource.com/c/go/+/287632
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Bryan C. Mills 2021-01-28 10:18:24 -05:00
parent 609d82b289
commit a76efea1fe
2 changed files with 18 additions and 0 deletions

View File

@ -293,10 +293,15 @@ func Req(target module.Version, base []string, reqs Reqs) ([]module.Version, err
}
// First walk the base modules that must be listed.
var min []module.Version
haveBase := map[string]bool{}
for _, path := range base {
if haveBase[path] {
continue
}
m := module.Version{Path: path, Version: max[path]}
min = append(min, m)
walk(m)
haveBase[path] = true
}
// Now the reverse postorder to bring in anything else.
for i := len(postorder) - 1; i >= 0; i-- {

View File

@ -327,6 +327,19 @@ B1: Cnone D1
E1: Fnone
build M: M B1 D1 E1
req M: B1 E1
name: reqdup
M: A1 B1
A1: B1
B1:
req M A A: A1
name: reqcross
M: A1 B1 C1
A1: B1 C1
B1: C1
C1:
req M A B: A1 B1
`
func Test(t *testing.T) {