Skip to content

Commit a005f99

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/mvs: retain modules required by older versions
Fixes #29773 Updates #31248 Change-Id: Ic1923119c8cf3a60c586df1b270c3af0c9095f29 Reviewed-on: https://go-review.googlesource.com/c/go/+/186537 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 4a2d3d0 commit a005f99

File tree

4 files changed

+174
-17
lines changed

4 files changed

+174
-17
lines changed

src/cmd/go/internal/mvs/mvs.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ func buildList(target module.Version, reqs Reqs, upgrade func(module.Version) (m
216216
}
217217
}
218218

219-
// Construct the list by traversing the graph again, replacing older
220-
// modules with required minimum versions.
219+
// The final list is the minimum version of each module found in the graph.
220+
221221
if v := min[target.Path]; v != target.Version {
222222
// TODO(jayconrod): there is a special case in modload.mvsReqs.Max
223223
// that prevents us from selecting a newer version of a module
@@ -228,19 +228,18 @@ func buildList(target module.Version, reqs Reqs, upgrade func(module.Version) (m
228228
}
229229

230230
list := []module.Version{target}
231-
listed := map[string]bool{target.Path: true}
232-
for i := 0; i < len(list); i++ {
233-
n := modGraph[list[i]]
231+
for path, vers := range min {
232+
if path != target.Path {
233+
list = append(list, module.Version{Path: path, Version: vers})
234+
}
235+
236+
n := modGraph[module.Version{Path: path, Version: vers}]
234237
required := n.required
235238
for _, r := range required {
236239
v := min[r.Path]
237240
if r.Path != target.Path && reqs.Max(v, r.Version) != v {
238241
panic(fmt.Sprintf("mistake: version %q does not satisfy requirement %+v", v, r)) // TODO: Don't panic.
239242
}
240-
if !listed[r.Path] {
241-
list = append(list, module.Version{Path: r.Path, Version: v})
242-
listed[r.Path] = true
243-
}
244243
}
245244
}
246245

src/cmd/go/internal/mvs/mvs_test.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ D5: E2
2929
G1: C4
3030
A2: B1 C4 D4
3131
build A: A B1 C2 D4 E2 F1
32-
upgrade* A: A B1 C4 D5 E2 G1
32+
upgrade* A: A B1 C4 D5 E2 F1 G1
3333
upgrade A C4: A B1 C4 D4 E2 F1 G1
3434
downgrade A2 D2: A2 C4 D2
3535
@@ -38,7 +38,7 @@ A: B1 C2
3838
B1: D3
3939
C2: B2
4040
B2:
41-
build A: A B2 C2
41+
build A: A B2 C2 D3
4242
4343
# Cross-dependency between D and E.
4444
# No matter how it arises, should get result of merging all build lists via max,
@@ -157,22 +157,33 @@ D1: E2
157157
E1: D2
158158
build A: A B C D2 E2
159159
160-
# Upgrade from B1 to B2 should drop the transitive dep on D.
160+
# golang.org/issue/31248:
161+
# Even though we select X2, the requirement on I1
162+
# via X1 should be preserved.
163+
name: cross8
164+
M: A1 B1
165+
A1: X1
166+
B1: X2
167+
X1: I1
168+
X2:
169+
build M: M A1 B1 I1 X2
170+
171+
# Upgrade from B1 to B2 should not drop the transitive dep on D.
161172
name: drop
162173
A: B1 C1
163174
B1: D1
164175
B2:
165176
C2:
166177
D2:
167178
build A: A B1 C1 D1
168-
upgrade* A: A B2 C2
179+
upgrade* A: A B2 C2 D2
169180
170181
name: simplify
171182
A: B1 C1
172183
B1: C2
173184
C1: D1
174185
C2:
175-
build A: A B1 C2
186+
build A: A B1 C2 D1
176187
177188
name: up1
178189
A: B1 C1
@@ -254,8 +265,9 @@ build A: A B1
254265
upgrade A B2: A B2
255266
upgrade* A: A B3
256267
268+
# golang.org/issue/29773:
257269
# Requirements of older versions of the target
258-
# must not be carried over.
270+
# must be carried over.
259271
name: cycle2
260272
A: B1
261273
A1: C1
@@ -265,8 +277,8 @@ B2: A2
265277
C1: A2
266278
C2:
267279
D2:
268-
build A: A B1
269-
upgrade* A: A B2
280+
build A: A B1 C1 D1
281+
upgrade* A: A B2 C2 D2
270282
271283
# Requirement minimization.
272284
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
env GO111MODULE=on
2+
3+
# golang.org/issue/31248: module requirements imposed by dependency versions
4+
# older than the selected version must still be taken into account.
5+
6+
env GOFLAGS=-mod=readonly
7+
8+
# Indirect dependencies required via older-than-selected versions must exist in
9+
# the module graph, but do not need to be listed explicitly in the go.mod file
10+
# (since they are implied).
11+
go mod graph
12+
13+
14+
# The modules must also appear in the build list, not just the graph.
15+
go list -m all
16+
stdout '^i v0.1.0'
17+
18+
# The packages provided by those dependencies must resolve.
19+
go list all
20+
stdout '^i$'
21+
22+
-- go.mod --
23+
module main
24+
25+
go 1.13
26+
27+
require (
28+
a v0.0.0
29+
b v0.0.0
30+
c v0.0.0
31+
)
32+
33+
// Apply replacements so that the test can be self-contained.
34+
// (It's easier to see all of the modules here than to go
35+
// rooting around in testdata/mod.)
36+
replace (
37+
a => ./a
38+
b => ./b
39+
c => ./c
40+
x v0.1.0 => ./x1
41+
x v0.2.0 => ./x2
42+
i => ./i
43+
)
44+
-- main.go --
45+
package main
46+
47+
import (
48+
_ "a"
49+
_ "b"
50+
_ "c"
51+
)
52+
53+
func main() {}
54+
-- a/go.mod --
55+
module a
56+
go 1.13
57+
require x v0.1.0
58+
-- a/a.go --
59+
package a
60+
-- b/go.mod --
61+
module b
62+
go 1.13
63+
require x v0.2.0
64+
-- b/b.go --
65+
package b
66+
-- c/go.mod --
67+
module c
68+
go 1.13
69+
-- c/c.go --
70+
package c
71+
import _ "i"
72+
-- x1/go.mod --
73+
module x
74+
go1.13
75+
require i v0.1.0
76+
-- x2/go.mod --
77+
module x
78+
go1.13
79+
-- i/go.mod --
80+
-- i/i.go --
81+
package i
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
env GO111MODULE=on
2+
3+
# Regression test for golang.org/issue/29773: 'go list -m' was not following
4+
# dependencies through older versions of the main module.
5+
6+
go list -f '{{with .Module}}{{.Path}}{{with .Version}} {{.}}{{end}}{{end}}' all
7+
cmp stdout pkgmods.txt
8+
9+
go list -m all
10+
cmp stdout mods.txt
11+
12+
go mod graph
13+
cmp stdout graph.txt
14+
15+
-- go.mod --
16+
module golang.org/issue/root
17+
18+
go 1.12
19+
20+
replace (
21+
golang.org/issue/mirror v0.1.0 => ./mirror-v0.1.0
22+
golang.org/issue/pkg v0.1.0 => ./pkg-v0.1.0
23+
golang.org/issue/root v0.1.0 => ./root-v0.1.0
24+
)
25+
26+
require golang.org/issue/mirror v0.1.0
27+
28+
-- root.go --
29+
package root
30+
31+
import _ "golang.org/issue/mirror"
32+
33+
-- mirror-v0.1.0/go.mod --
34+
module golang.org/issue/mirror
35+
36+
require golang.org/issue/root v0.1.0
37+
38+
-- mirror-v0.1.0/mirror.go --
39+
package mirror
40+
41+
import _ "golang.org/issue/pkg"
42+
43+
-- pkg-v0.1.0/go.mod --
44+
module golang.org/issue/pkg
45+
46+
-- pkg-v0.1.0/pkg.go --
47+
package pkg
48+
49+
-- root-v0.1.0/go.mod --
50+
module golang.org/issue/root
51+
52+
require golang.org/issue/pkg v0.1.0
53+
54+
-- pkgmods.txt --
55+
golang.org/issue/mirror v0.1.0
56+
golang.org/issue/pkg v0.1.0
57+
golang.org/issue/root
58+
-- mods.txt --
59+
golang.org/issue/root
60+
golang.org/issue/mirror v0.1.0 => ./mirror-v0.1.0
61+
golang.org/issue/pkg v0.1.0 => ./pkg-v0.1.0
62+
-- graph.txt --
63+
golang.org/issue/root golang.org/issue/[email protected]
64+
golang.org/issue/[email protected] golang.org/issue/[email protected]
65+
golang.org/issue/[email protected] golang.org/issue/[email protected]

0 commit comments

Comments
 (0)