Skip to content

Commit 3f60da7

Browse files
committed
cmd/go/internal/modcmd: correctly filter out main modules in verify
This change fixes a bug where we incorrectly filtered out the main modules from the beginning of the build list before verifying them. We made the assumption that the first MainModules.Len() entries of the build list were the main modules, but now it can contain the go and toolchain version entries, so removing the first MainModules.Len() entries could leave main module names in the build list if any of their names sorted after the string 'go'. Fixes #62663 Change-Id: I35ab6857a556f58d306303322afe24c48fc8b38f Reviewed-on: https://go-review.googlesource.com/c/go/+/565378 Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 3580c21 commit 3f60da7

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/cmd/go/internal/modcmd/verify.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func runVerify(ctx context.Context, cmd *base.Command, args []string) {
6161
if err != nil {
6262
base.Fatal(err)
6363
}
64-
mods := mg.BuildList()[modload.MainModules.Len():]
64+
mods := mg.BuildList()
6565
// Use a slice of result channels, so that the output is deterministic.
6666
errsChans := make([]<-chan []error, len(mods))
6767

@@ -94,6 +94,9 @@ func verifyMod(ctx context.Context, mod module.Version) []error {
9494
// "go" and "toolchain" have no disk footprint; nothing to verify.
9595
return nil
9696
}
97+
if modload.MainModules.Contains(mod.Path) {
98+
return nil
99+
}
97100
var errs []error
98101
zip, zipErr := modfetch.CachePath(ctx, mod, "zip")
99102
if zipErr == nil {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Regression test for Issue #62663: we would filter out the toolchain and
2+
# main modules from the build list incorrectly, leading to the workspace
3+
# modules being checked for correct sums. Specifically this would happen when
4+
# the module name sorted after the virtual 'go' version module name because
5+
# it could not get chopped off when we removed the MainModules.Len() modules
6+
# at the beginning of the build list and we would remove the go module instead.
7+
8+
go mod verify
9+
10+
-- go.work --
11+
go 1.21
12+
13+
use (
14+
./a
15+
./b
16+
)
17+
-- a/go.mod --
18+
module hexample.com/a // important for test that module name sorts after 'go'
19+
20+
go 1.21
21+
-- b/go.mod --
22+
module hexample.com/b // important for test that module name sorts after 'go'
23+
24+
go 1.21

0 commit comments

Comments
 (0)