From fdf84cd1bd2c0c0b9229b7e79e0be79d6285d1d1 Mon Sep 17 00:00:00 2001 From: Gonzalo Serrano Date: Fri, 14 Oct 2022 18:47:05 +0200 Subject: [PATCH] Make registry load packages deterministically --- internal/descriptor/registry.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/descriptor/registry.go b/internal/descriptor/registry.go index 8a7142f1393..9080c2f312b 100644 --- a/internal/descriptor/registry.go +++ b/internal/descriptor/registry.go @@ -2,6 +2,7 @@ package descriptor import ( "fmt" + "sort" "strings" "github.com/golang/glog" @@ -187,12 +188,18 @@ func (r *Registry) LoadFromPlugin(gen *protogen.Plugin) error { } func (r *Registry) load(gen *protogen.Plugin) error { - for filePath, f := range gen.FilesByPath { - r.loadFile(filePath, f) + filePaths := make([]string, 0, len(gen.FilesByPath)) + for filePath := range gen.FilesByPath { + filePaths = append(filePaths, filePath) } + sort.Strings(filePaths) - for filePath, f := range gen.FilesByPath { - if !f.Generate { + for _, filePath := range filePaths { + r.loadFile(filePath, gen.FilesByPath[filePath]) + } + + for _, filePath := range filePaths { + if !gen.FilesByPath[filePath].Generate { continue } file := r.files[filePath]