summaryrefslogtreecommitdiffhomepage
path: root/tools/go_generics/imports.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-09-23 07:27:30 -0700
committergVisor bot <gvisor-bot@google.com>2020-09-23 07:29:31 -0700
commitd00207ff482fd5cfa607d37979b5455f41a86e3b (patch)
tree618b977ecaa896174e32c445cda99efac23e1f1f /tools/go_generics/imports.go
parent99decaadd6da0df2d8ec70ddea9d754c9d71a584 (diff)
Internal change.
PiperOrigin-RevId: 333287864
Diffstat (limited to 'tools/go_generics/imports.go')
-rw-r--r--tools/go_generics/imports.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/tools/go_generics/imports.go b/tools/go_generics/imports.go
index 148dc7216..90d3aa1e0 100644
--- a/tools/go_generics/imports.go
+++ b/tools/go_generics/imports.go
@@ -21,6 +21,7 @@ import (
"go/format"
"go/parser"
"go/token"
+ "sort"
"strconv"
"gvisor.dev/gvisor/tools/go_generics/globals"
@@ -132,10 +133,17 @@ func updateImports(maps []mapValue, imports mapValue) (ast.Decl, error) {
if len(importsUsed) == 0 {
return nil, nil
}
+ var names []string
+ for n := range importsUsed {
+ names = append(names, n)
+ }
+ // Sort the new imports for deterministic build outputs.
+ sort.Strings(names)
// Create spec array for each new import.
specs := make([]ast.Spec, 0, len(importsUsed))
- for _, i := range importsUsed {
+ for _, n := range names {
+ i := importsUsed[n]
specs = append(specs, &ast.ImportSpec{
Name: &ast.Ident{Name: i.newName},
Path: &ast.BasicLit{Value: i.path},