Use a stable ordering for generated types.

Otherwise this pollutes the 'go' branch and doesn't conform to standards
for generate bazel files.

PiperOrigin-RevId: 349605037
This commit is contained in:
Adin Scannell 2020-12-30 14:51:23 -08:00 committed by gVisor bot
parent 1b66bad7c4
commit 0fb5de1154
1 changed files with 8 additions and 0 deletions

View File

@ -447,7 +447,15 @@ func (g *Generator) Run() error {
for i, a := range asts {
// Collect type declarations marked for code generation and generate
// Marshallable interfaces.
var sortedTypes []*marshallableType
for _, t := range g.collectMarshallableTypes(a, fsets[i]) {
sortedTypes = append(sortedTypes, t)
}
sort.Slice(sortedTypes, func(x, y int) bool {
// Sort by type name, which should be unique within a package.
return sortedTypes[x].spec.Name.String() < sortedTypes[y].spec.Name.String()
})
for _, t := range sortedTypes {
impl := g.generateOne(t, fsets[i])
// Collect Marshallable types referenced by the generated code.
for ref := range impl.ms {