]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: skip over all workspace modules in go mod verify
authorMichael Matloob <matloob@golang.org>
Mon, 17 Apr 2023 20:42:18 +0000 (16:42 -0400)
committerMichael Matloob <matloob@golang.org>
Tue, 18 Apr 2023 19:49:40 +0000 (19:49 +0000)
This was a remaining place where we made the assumption that there is
only one workspace module. So we'd only skip the first workspace
module when running go mod verify. Instead skip over the first
MainModules.Len() modules of the buildlist, which are all the main
modules.

Fixes #54372

Change-Id: Ife687c907ae4326759c43cc35f78d429d5113b19
Reviewed-on: https://go-review.googlesource.com/c/go/+/485475
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/go/internal/modcmd/verify.go
src/cmd/go/internal/modload/buildlist.go
src/cmd/go/testdata/script/work_issue54372.txt [new file with mode: 0644]

index a5f7f2456358c526a15842d80eca1c7500a4b5b1..20fa9667924114ee73832227182675852a39caf1 100644 (file)
@@ -58,7 +58,7 @@ func runVerify(ctx context.Context, cmd *base.Command, args []string) {
 
        // Use a slice of result channels, so that the output is deterministic.
        const defaultGoVersion = ""
-       mods := modload.LoadModGraph(ctx, defaultGoVersion).BuildList()[1:]
+       mods := modload.LoadModGraph(ctx, defaultGoVersion).BuildList()[modload.MainModules.Len():]
        errsChans := make([]<-chan []error, len(mods))
 
        for i, mod := range mods {
index 005f306ff409664be44123843dfbb8976aa70618..046743b59e6e4de04e9dca62ab98ec42fd6128a2 100644 (file)
@@ -448,7 +448,7 @@ func (mg *ModuleGraph) WalkBreadthFirst(f func(m module.Version)) {
 }
 
 // BuildList returns the selected versions of all modules present in the graph,
-// beginning with Target.
+// beginning with the main modules.
 //
 // The order of the remaining elements in the list is deterministic
 // but arbitrary.
diff --git a/src/cmd/go/testdata/script/work_issue54372.txt b/src/cmd/go/testdata/script/work_issue54372.txt
new file mode 100644 (file)
index 0000000..bd3108a
--- /dev/null
@@ -0,0 +1,37 @@
+# go mod verify should not try to verify the workspace modules.
+# This is a test for #54372.
+
+go mod verify
+stdout 'all modules verified'
+! stderr .
+
+-- go.work --
+go 1.21
+
+use (
+    ./a
+    ./b
+    ./c
+    ./d
+)
+-- a/go.mod --
+module example.com/a
+
+go 1.21
+
+require rsc.io/quote v1.1.0
+-- a/a.go --
+package a
+import _ "rsc.io/quote"
+-- b/go.mod --
+module example.com/b
+
+go 1.21
+-- c/go.mod --
+module example.com/c
+
+go 1.21
+-- d/go.mod --
+module example.com/d
+
+go 1.21
\ No newline at end of file