mirror of
https://github.com/golang/go
synced 2024-11-02 11:50:30 +00:00
[dev.cmdgo] cmd/go: sort roots when joining multiple main module roots
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>
This commit is contained in:
parent
288a83dcff
commit
176baafd5b
2 changed files with 17 additions and 0 deletions
|
@ -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).
|
||||
|
|
14
src/cmd/go/testdata/script/work.txt
vendored
14
src/cmd/go/testdata/script/work.txt
vendored
|
@ -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
|
||||
)
|
Loading…
Reference in a new issue