]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cmdgo] cmd/go: sort roots when joining multiple main module roots
authorMichael Matloob <matloob@golang.org>
Wed, 28 Jul 2021 16:32:08 +0000 (12:32 -0400)
committerMichael Matloob <matloob@golang.org>
Wed, 28 Jul 2021 18:15:59 +0000 (18:15 +0000)
When concatenating multiple main modules' roots we need to resort
the list of main module roots. This avoids a panic from unsorted main
module roots. This will get better when we have structured module
roots.

Change-Id: I68fed47b0f3b131ed3dadf45db3c442286a0ced0
Reviewed-on: https://go-review.googlesource.com/c/go/+/338111
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/modload/buildlist.go
src/cmd/go/testdata/script/work.txt

index d2957a34c42dd51c0b509cf097c52c36c371be10..4fbe563cb832c911bfff31dbb58162660eb5d302 100644 (file)
@@ -1083,6 +1083,9 @@ func updateEagerRoots(ctx context.Context, direct map[string]bool, rs *Requireme
                }
                roots = append(roots, min...)
        }
+       if MainModules.Len() > 1 {
+               module.Sort(roots)
+       }
        if rs.depth == eager && reflect.DeepEqual(roots, rs.rootModules) && reflect.DeepEqual(direct, rs.direct) {
                // The root set is unchanged and rs was already eager, so keep rs to
                // preserve its cached ModuleGraph (if any).
index 0d820fffc2db4d112929d3880550d063ec64822b..eeaf92eaec4215966d96b45adc785f42d2ce74a2 100644 (file)
@@ -36,6 +36,11 @@ cp go.work.backup go.work
 cp go.work.d go.work
 go run example.com/d
 
+# Test that we don't run into "newRequirements called with unsorted roots"
+# panic with unsorted main modules.
+cp go.work.backwards go.work
+go run example.com/d
+
 -- go.work.dup --
 go 1.17
 
@@ -109,3 +114,12 @@ import "example.com/b/lib"
 func main() {
        lib.Hello()
 }
+
+-- go.work.backwards --
+go 1.18
+
+directory (
+    d
+    b
+    a
+)
\ No newline at end of file