Skip to content

Commit be7c681

Browse files
Bryan C. Millscherrymui
Bryan C. Mills
authored andcommitted
[release-branch.go1.18] cmd/go: avoid re-enqueuing workspace dependencies with errors
Fixes #53875. Updates #53874. Change-Id: I41ab15cb9b86b807a9d9ad21fe21fb7aa5fbb46f Reviewed-on: https://go-review.googlesource.com/c/go/+/417594 Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit a906d3d) Reviewed-on: https://go-review.googlesource.com/c/go/+/417656
1 parent 6ff8801 commit be7c681

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

src/cmd/go/internal/modload/buildlist.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ func readModGraph(ctx context.Context, pruning modPruning, roots []module.Versio
397397
seen := map[module.Version]bool{}
398398
for _, m := range roots {
399399
hasDepsInAll[m.Path] = true
400-
seen[m] = true
401400
}
402401
// This loop will terminate because it will call enqueue on each version of
403402
// each dependency of the modules in hasDepsInAll at most once (and only
@@ -406,11 +405,11 @@ func readModGraph(ctx context.Context, pruning modPruning, roots []module.Versio
406405
needsEnqueueing := map[module.Version]bool{}
407406
for p := range hasDepsInAll {
408407
m := module.Version{Path: p, Version: mg.g.Selected(p)}
409-
reqs, ok := mg.g.RequiredBy(m)
410-
if !ok {
408+
if !seen[m] {
411409
needsEnqueueing[m] = true
412410
continue
413411
}
412+
reqs, _ := mg.g.RequiredBy(m)
414413
for _, r := range reqs {
415414
s := module.Version{Path: r.Path, Version: mg.g.Selected(r.Path)}
416415
if cmpVersion(s.Version, r.Version) > 0 && !seen[s] {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
go work init
2+
go work use . ./sub
3+
4+
# Verify that the go.mod files for both modules in the workspace are tidy,
5+
# and add missing go.sum entries as needed.
6+
7+
cp go.mod go.mod.orig
8+
go mod tidy
9+
cmp go.mod go.mod.orig
10+
11+
cd sub
12+
cp go.mod go.mod.orig
13+
go mod tidy
14+
cmp go.mod go.mod.orig
15+
cd ..
16+
17+
go list -m all
18+
stdout '^rsc\.io/quote v1\.5\.1$'
19+
stdout '^rsc\.io/sampler v1\.3\.1$'
20+
21+
# Now remove the module dependencies from the module cache.
22+
# Because one module upgrades a transitive dependency needed by another,
23+
# listing the modules in the workspace should error out.
24+
25+
go clean -modcache
26+
env GOPROXY=off
27+
! go list -m all
28+
stderr '^go: rsc.io/[email protected]: module lookup disabled by GOPROXY=off$'
29+
30+
-- example.go --
31+
package example
32+
33+
import _ "rsc.io/sampler"
34+
-- go.mod --
35+
module example
36+
37+
go 1.18
38+
39+
require rsc.io/sampler v1.3.0
40+
41+
require (
42+
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
43+
rsc.io/testonly v1.0.0 // indirect
44+
)
45+
-- sub/go.mod --
46+
module example/sub
47+
48+
go 1.18
49+
50+
require rsc.io/quote v1.5.1
51+
52+
require (
53+
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
54+
rsc.io/sampler v1.3.1 // indirect
55+
)
56+
-- sub/sub.go --
57+
package example
58+
59+
import _ "rsc.io/quote"

0 commit comments

Comments
 (0)