From c240b05369ba74d6add3fc6cfce748ad78e7f783 Mon Sep 17 00:00:00 2001 From: Nathan Chan Date: Fri, 8 Dec 2017 11:37:28 -0800 Subject: [PATCH 1/2] Sort controllers so that builds are reproducible. Ordering of controllers in routes.go and main.go is unstable in successive runs of revel build. This change will assure that the ordering is stable. --- harness/build.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/harness/build.go b/harness/build.go index d2b92d7..9edd2ca 100755 --- a/harness/build.go +++ b/harness/build.go @@ -42,6 +42,10 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) { sourceInfo.InitImportPaths = append(sourceInfo.InitImportPaths, strings.Split(dbImportPath,",")...) } + // Sort controllers so that file generation is reproducible + controllers := sourceInfo.ControllerSpecs() + sort.SliceStable(controllers, func(i, j int) bool { return controllers[i].String() < controllers[j].String() }) + // Generate two source files. templateArgs := map[string]interface{}{ "Controllers": sourceInfo.ControllerSpecs(), From fc904827cd8a757cd414f144b87201eaee9924f3 Mon Sep 17 00:00:00 2001 From: Nathan Chan Date: Mon, 11 Dec 2017 09:54:55 -0800 Subject: [PATCH 2/2] Make sorting compatible with go >= 1.6 --- harness/build.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) mode change 100755 => 100644 harness/build.go diff --git a/harness/build.go b/harness/build.go old mode 100755 new mode 100644 index 9edd2ca..eb5f413 --- a/harness/build.go +++ b/harness/build.go @@ -23,6 +23,12 @@ import ( var importErrorPattern = regexp.MustCompile("cannot find package \"([^\"]+)\"") +type ByString []*TypeInfo + +func (c ByString) Len() int { return len(c) } +func (c ByString) Swap(i, j int) { c[i], c[j] = c[j], c[i] } +func (c ByString) Less(i, j int) bool { return c[i].String() < c[j].String() } + // Build the app: // 1. Generate the the main.go file. // 2. Run the appropriate "go build" command. @@ -39,16 +45,16 @@ func Build(buildFlags ...string) (app *App, compileError *revel.Error) { // Add the db.import to the import paths. if dbImportPath, found := revel.Config.String("db.import"); found { - sourceInfo.InitImportPaths = append(sourceInfo.InitImportPaths, strings.Split(dbImportPath,",")...) + sourceInfo.InitImportPaths = append(sourceInfo.InitImportPaths, strings.Split(dbImportPath, ",")...) } // Sort controllers so that file generation is reproducible controllers := sourceInfo.ControllerSpecs() - sort.SliceStable(controllers, func(i, j int) bool { return controllers[i].String() < controllers[j].String() }) + sort.Stable(ByString(controllers)) // Generate two source files. templateArgs := map[string]interface{}{ - "Controllers": sourceInfo.ControllerSpecs(), + "Controllers": controllers, "ValidationKeys": sourceInfo.ValidationKeys, "ImportPaths": calcImportAliases(sourceInfo), "TestSuites": sourceInfo.TestSuites(),