Repository: incubator-mynewt-newt Updated Branches: refs/heads/master 98b9a71dc -> da27d98ee
MYNEWT-753 newt - sysinit file inconsistent In the generated sysinit C file, calls to initialization functions are sorted by stage number. Within a stage number, the ordering is random, and varies from one build to the next. The randomness comes from Golang's random iteration of maps. This is bad because it prevents repeatable builds, and causes unnecessary rebuilds. The fix is to sort alphabetically by package name within a stage number. So, * First sort by stage number * Then sort by package name. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/8ac28b9b Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/8ac28b9b Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/8ac28b9b Branch: refs/heads/master Commit: 8ac28b9bda2ddcd14094e6fc9bcec3f6618d5370 Parents: ca783a7 Author: Christopher Collins <ccoll...@apache.org> Authored: Thu May 11 15:53:25 2017 -0700 Committer: Christopher Collins <ccoll...@apache.org> Committed: Thu May 11 15:53:25 2017 -0700 ---------------------------------------------------------------------- newt/sysinit/sysinit.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/8ac28b9b/newt/sysinit/sysinit.go ---------------------------------------------------------------------- diff --git a/newt/sysinit/sysinit.go b/newt/sysinit/sysinit.go index 29dc082..47233a0 100644 --- a/newt/sysinit/sysinit.go +++ b/newt/sysinit/sysinit.go @@ -69,9 +69,20 @@ func writePrototypes(pkgs []*pkg.LocalPackage, w io.Writer) { } func writeStage(stage int, initFuncs []*initFunc, w io.Writer) { - fmt.Fprintf(w, " /*** Stage %d */\n", stage) + // Sort stage alphabetically by package name. + pkgNames := make([]string, len(initFuncs)) + funcMap := make(map[string]*initFunc, len(initFuncs)) for i, initFunc := range initFuncs { - fmt.Fprintf(w, " /* %d.%d: %s */\n", stage, i, initFunc.pkg.Name()) + name := initFunc.pkg.Name() + pkgNames[i] = name + funcMap[name] = initFunc + } + sort.Strings(pkgNames) + + fmt.Fprintf(w, " /*** Stage %d */\n", stage) + for i, pkgName := range pkgNames { + initFunc := funcMap[pkgName] + fmt.Fprintf(w, " /* %d.%d: %s */\n", stage, i, pkgName) fmt.Fprintf(w, " %s();\n", initFunc.name) } }