mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Internal change.
PiperOrigin-RevId: 333287864
This commit is contained in:
@@ -77,6 +77,7 @@ func main() {
|
||||
// Create a new declaration slice with all imports at the top, merging any
|
||||
// redundant imports.
|
||||
imports := make(map[string]*ast.ImportSpec)
|
||||
var importNames []string // Keep imports in the original order to get deterministic output.
|
||||
var anonImports []*ast.ImportSpec
|
||||
for _, d := range f.Decls {
|
||||
if g, ok := d.(*ast.GenDecl); ok && g.Tok == token.IMPORT {
|
||||
@@ -98,6 +99,7 @@ func main() {
|
||||
}
|
||||
} else {
|
||||
imports[n] = i
|
||||
importNames = append(importNames, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,8 +114,8 @@ func main() {
|
||||
Lparen: token.NoPos + 1,
|
||||
Specs: make([]ast.Spec, 0, l),
|
||||
}
|
||||
for _, i := range imports {
|
||||
d.Specs = append(d.Specs, i)
|
||||
for _, i := range importNames {
|
||||
d.Specs = append(d.Specs, imports[i])
|
||||
}
|
||||
for _, i := range anonImports {
|
||||
d.Specs = append(d.Specs, i)
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -20,6 +20,7 @@ package gomarshal
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -40,6 +41,8 @@ func (g *interfaceGenerator) areFieldsPackedExpression() (string, bool) {
|
||||
for accessor, _ := range g.as {
|
||||
cs = append(cs, fmt.Sprintf("%s.Packed()", accessor))
|
||||
}
|
||||
// Sort expressions for determinstic build outputs.
|
||||
sort.Strings(cs)
|
||||
return strings.Join(cs, " && "), true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user