go/packages: make visit order stable

Change-Id: Iee9b29364dd986e1f1676ff0aa989267c4149c30
Reviewed-on: https://go-review.googlesource.com/c/146357
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Ian Cottrell 2018-10-31 14:51:16 -04:00
parent 45ff765b48
commit d51e88b5ae
1 changed files with 2 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package packages
import ( import (
"fmt" "fmt"
"os" "os"
"sort"
) )
// Visit visits all the packages in the import graph whose roots are // Visit visits all the packages in the import graph whose roots are
@ -23,6 +24,7 @@ func Visit(pkgs []*Package, pre func(*Package) bool, post func(*Package)) {
for path := range pkg.Imports { for path := range pkg.Imports {
paths = append(paths, path) paths = append(paths, path)
} }
sort.Strings(paths) // Imports is a map, this makes visit stable
for _, path := range paths { for _, path := range paths {
visit(pkg.Imports[path]) visit(pkg.Imports[path])
} }