Commit 19912e1d authored by Robert Griesemer's avatar Robert Griesemer

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/22478Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent e607abbf
...@@ -7,6 +7,7 @@ package main ...@@ -7,6 +7,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"sort"
) )
/* /*
...@@ -48,6 +49,15 @@ func mkzdefaultcc(dir, file string) { ...@@ -48,6 +49,15 @@ func mkzdefaultcc(dir, file string) {
// //
// It is invoked to write go/build/zcgo.go. // It is invoked to write go/build/zcgo.go.
func mkzcgo(dir, file string) { 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 var buf bytes.Buffer
fmt.Fprintf(&buf, fmt.Fprintf(&buf,
...@@ -56,11 +66,9 @@ func mkzcgo(dir, file string) { ...@@ -56,11 +66,9 @@ func mkzcgo(dir, file string) {
"package build\n"+ "package build\n"+
"\n"+ "\n"+
"var cgoEnabled = map[string]bool{\n") "var cgoEnabled = map[string]bool{\n")
for plat, hasCgo := range cgoEnabled { for _, plat := range list {
if hasCgo {
fmt.Fprintf(&buf, "\t%q: true,\n", plat) fmt.Fprintf(&buf, "\t%q: true,\n", plat)
} }
}
fmt.Fprintf(&buf, "}") fmt.Fprintf(&buf, "}")
writefile(buf.String(), file, writeSkipSame) writefile(buf.String(), file, writeSkipSame)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment