summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2020-12-30 14:51:23 -0800
committergVisor bot <gvisor-bot@google.com>2020-12-30 14:53:03 -0800
commit0fb5de1154411bd207dadae31c37054db9941061 (patch)
tree25c11cba9efcb6d39ea378ee991a8e0beca8fb97
parent1b66bad7c47e914994e19f39119d91ab6805002a (diff)
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
-rw-r--r--tools/go_marshal/gomarshal/generator.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/go_marshal/gomarshal/generator.go b/tools/go_marshal/gomarshal/generator.go
index 6f41b1b79..28ae6c4ef 100644
--- a/tools/go_marshal/gomarshal/generator.go
+++ b/tools/go_marshal/gomarshal/generator.go
@@ -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 {