cmd/dist: sort entries in zcgo.go generated file for deterministic build

This simplifies comparison of object files across different builds
by ensuring that the strings in the zcgo.go always appear in the
same order.

Change-Id: I3639ea4fd10e0d645b838d1bbb03cd33deca340e
Reviewed-on: https://go-review.googlesource.com/22478
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2016-04-26 15:18:48 -07:00
parent e607abbfd6
commit 19912e1d0a
1 changed files with 12 additions and 4 deletions

View File

@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
"sort"
)
/*
@ -48,6 +49,15 @@ func mkzdefaultcc(dir, file string) {
//
// It is invoked to write go/build/zcgo.go.
func mkzcgo(dir, file string) {
// sort for deterministic zcgo.go file
var list []string
for plat, hasCgo := range cgoEnabled {
if hasCgo {
list = append(list, plat)
}
}
sort.Strings(list)
var buf bytes.Buffer
fmt.Fprintf(&buf,
@ -56,10 +66,8 @@ func mkzcgo(dir, file string) {
"package build\n"+
"\n"+
"var cgoEnabled = map[string]bool{\n")
for plat, hasCgo := range cgoEnabled {
if hasCgo {
fmt.Fprintf(&buf, "\t%q: true,\n", plat)
}
for _, plat := range list {
fmt.Fprintf(&buf, "\t%q: true,\n", plat)
}
fmt.Fprintf(&buf, "}")