Skip to content

Commit 1dac1ac

Browse files
Make registry load packages deterministically (#2945)
1 parent ab516bc commit 1dac1ac

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

internal/descriptor/registry.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package descriptor
22

33
import (
44
"fmt"
5+
"sort"
56
"strings"
67

78
"github.com/golang/glog"
@@ -187,12 +188,18 @@ func (r *Registry) LoadFromPlugin(gen *protogen.Plugin) error {
187188
}
188189

189190
func (r *Registry) load(gen *protogen.Plugin) error {
190-
for filePath, f := range gen.FilesByPath {
191-
r.loadFile(filePath, f)
191+
filePaths := make([]string, 0, len(gen.FilesByPath))
192+
for filePath := range gen.FilesByPath {
193+
filePaths = append(filePaths, filePath)
192194
}
195+
sort.Strings(filePaths)
193196

194-
for filePath, f := range gen.FilesByPath {
195-
if !f.Generate {
197+
for _, filePath := range filePaths {
198+
r.loadFile(filePath, gen.FilesByPath[filePath])
199+
}
200+
201+
for _, filePath := range filePaths {
202+
if !gen.FilesByPath[filePath].Generate {
196203
continue
197204
}
198205
file := r.files[filePath]

0 commit comments

Comments
 (0)