1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:34:41 -07:00

go/packages: sort root list in Load

The builders are currently flaky failing because of a root order being
wrong.
This causes all root lists to be sorted before being returned, so the
order is always stable no matter which underlying driver is running.

Fixes golang/go#27594

Change-Id: I09db45c67ad00f23dfaec8e271acbd13fc338888
Reviewed-on: https://go-review.googlesource.com/c/143737
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Ian Cottrell 2018-10-22 13:05:19 -04:00
parent 9aea6da185
commit 2d2de62981
4 changed files with 5 additions and 8 deletions

View File

@ -131,7 +131,6 @@ extractQueries:
return nil, err return nil, err
} }
response.Roots = append(response.Roots, namedResults...) response.Roots = append(response.Roots, namedResults...)
return response, nil return response, nil
} }

View File

@ -246,11 +246,6 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error)
createTestVariants(&response, v.pkg, v.xtestPkg) createTestVariants(&response, v.pkg, v.xtestPkg)
} }
// TODO(matloob): Is this the right ordering?
sort.SliceStable(response.Packages, func(i, j int) bool {
return response.Packages[i].PkgPath < response.Packages[j].PkgPath
})
return &response, nil return &response, nil
} }

View File

@ -20,6 +20,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort"
"strings" "strings"
"sync" "sync"
@ -173,6 +174,7 @@ func Load(cfg *Config, patterns ...string) ([]*Package, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
sort.Strings(response.Roots) // make all driver responses deterministic
return l.refine(response.Roots, response.Packages...) return l.refine(response.Roots, response.Packages...)
} }

View File

@ -298,8 +298,9 @@ func TestLoadAbsolutePath(t *testing.T) {
for _, p := range initial { for _, p := range initial {
got = append(got, p.ID) got = append(got, p.ID)
} }
if !reflect.DeepEqual(got, []string{"golang.org/gopatha/a", "golang.org/gopathb/b"}) { want := []string{"golang.org/gopatha/a", "golang.org/gopathb/b"}
t.Fatalf("initial packages loaded: got [%s], want [a b]", got) if !reflect.DeepEqual(got, want) {
t.Fatalf("initial packages loaded: got [%s], want [%s]", got, want)
} }
} }