Browse Source

Iterating over go maps don't guarantee order, so sort before iterating
This makes the build predictable and comparable - can now compare build output.
Also remove timestamps from build step logging, again for ease of comparison.

Signed-off-by: Graham MacDonald <grahamamacdonald@gmail.com>

Graham MacDonald 5 years ago
parent
commit
d30baf4148
2 changed files with 40 additions and 4 deletions
  1. 29 3
      util/src/harvey/cmd/build/build.go
  2. 11 1
      util/src/harvey/cmd/build/codegen.go

+ 29 - 3
util/src/harvey/cmd/build/build.go

@@ -59,6 +59,7 @@ import (
 	"path"
 	"path/filepath"
 	"regexp"
+	"sort"
 	"strings"
 )
 
@@ -125,6 +126,8 @@ func globby(s []string) []string {
 	for n := range f {
 		all = append(all, n)
 	}
+	sort.Strings(all)
+
 	debug("Glob of '%v' is '%v'", s, all)
 	return all
 }
@@ -223,7 +226,15 @@ func include(f string, targ string, b *build) {
 	var builds buildfile
 	fail(json.Unmarshal(d, &builds))
 
-	for _, build := range builds {
+	// Sort keys so we can guaranteed order of iteration over builds
+	var buildkeys []string
+	for n := range builds {
+		buildkeys = append(buildkeys, n)
+	}
+	sort.Strings(buildkeys)
+
+	for _, n := range buildkeys {
+		build := builds[n]
 		t := target(&build)
 		if t != "" {
 			targ = t
@@ -231,7 +242,9 @@ func include(f string, targ string, b *build) {
 		}
 	}
 
-	for n, build := range builds {
+	for _, n := range buildkeys {
+		build := builds[n]
+
 		log.Printf("Merging %s", n)
 		b.Cflags = append(b.Cflags, build.Cflags...)
 		b.Oflags = append(b.Oflags, build.Oflags...)
@@ -311,7 +324,17 @@ func process(f string, r []*regexp.Regexp) []build {
 	d, err := ioutil.ReadFile(f)
 	fail(err)
 	fail(json.Unmarshal(d, &builds))
-	for n, build := range builds {
+
+	// Sort keys so we can guaranteed order of iteration over builds
+	var buildkeys []string
+	for n := range builds {
+		buildkeys = append(buildkeys, n)
+	}
+	sort.Strings(buildkeys)
+
+	for _, n := range buildkeys {
+		build := builds[n]
+
 		build.name = n
 		build.jsons = make(map[string]bool)
 		skip := true
@@ -637,6 +660,9 @@ func project(bf string, which []*regexp.Regexp) {
 }
 
 func main() {
+	// Disable logging timestamps - easier to compare build output
+	log.SetFlags(0)
+
 	// A small amount of setup is done in the paths*.go files. They are
 	// OS-specific path setup/manipulation. "harvey" is set there and $PATH is
 	// adjusted.

+ 11 - 1
util/src/harvey/cmd/build/codegen.go

@@ -37,6 +37,7 @@ import (
 	"io/ioutil"
 	"os"
 	"os/exec"
+	"sort"
 	"text/template"
 )
 
@@ -195,7 +196,16 @@ func data2c(name string, path string) string {
 func confcode(path string, kern *kernel) []byte {
 	var rootcodes []string
 	var rootnames []string
-	for name, path := range kern.Ramfiles {
+
+	// Sort keys so we can guaranteed order of iteration over ramfiles
+	var ramfilenames []string
+	for name := range kern.Ramfiles {
+		ramfilenames = append(ramfilenames, name)
+	}
+	sort.Strings(ramfilenames)
+
+	for _, name := range ramfilenames {
+		path := kern.Ramfiles[name]
 		code := data2c(name, fromRoot(path))
 		rootcodes = append(rootcodes, code)
 		rootnames = append(rootnames, name)