build: Let "go generate" create assets

This commit is contained in:
Jakob Borg 2018-06-26 09:14:21 +02:00
parent 406b394704
commit ef5ca0c218
5 changed files with 28 additions and 6 deletions

View File

@ -738,12 +738,11 @@ func listFiles(dir string) []string {
func rebuildAssets() { func rebuildAssets() {
os.Setenv("SOURCE_DATE_EPOCH", fmt.Sprint(buildStamp())) os.Setenv("SOURCE_DATE_EPOCH", fmt.Sprint(buildStamp()))
runPipe("lib/auto/gui.files.go", "go", "run", "script/genassets.go", "gui") runPrint("go", "generate", "github.com/syncthing/syncthing/lib/auto", "github.com/syncthing/syncthing/cmd/strelaypoolsrv/auto")
runPipe("cmd/strelaypoolsrv/auto/gui.go", "go", "run", "script/genassets.go", "cmd/strelaypoolsrv/gui")
} }
func lazyRebuildAssets() { func lazyRebuildAssets() {
if shouldRebuildAssets("lib/auto/gui.files.go", "gui") || shouldRebuildAssets("cmd/strelaypoolsrv/auto/gui.go", "cmd/strelaypoolsrv/auto/gui") { if shouldRebuildAssets("lib/auto/gui.files.go", "gui") || shouldRebuildAssets("cmd/strelaypoolsrv/auto/gui.files.go", "cmd/strelaypoolsrv/auto/gui") {
rebuildAssets() rebuildAssets()
} }
} }

View File

@ -1 +1 @@
gui.go gui.files.go

View File

@ -0,0 +1,10 @@
// Copyright (C) 2018 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
//go:generate go run ../../../script/genassets.go -o gui.files.go ../gui
// Package auto contains auto generated files for web assets.
package auto

View File

@ -4,5 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/. // You can obtain one at https://mozilla.org/MPL/2.0/.
//go:generate go run ../../script/genassets.go -o gui.files.go ../../gui
// Package auto contains auto generated files for web assets. // Package auto contains auto generated files for web assets.
package auto package auto

View File

@ -86,6 +86,7 @@ type templateVars struct {
} }
func main() { func main() {
outfile := flag.String("o", "", "Name of output file (default stdout)")
flag.Parse() flag.Parse()
filepath.Walk(flag.Arg(0), walkerFor(flag.Arg(0))) filepath.Walk(flag.Arg(0), walkerFor(flag.Arg(0)))
@ -104,7 +105,17 @@ func main() {
}) })
bs, err := format.Source(buf.Bytes()) bs, err := format.Source(buf.Bytes())
if err != nil { if err != nil {
panic(err) fmt.Fprintln(os.Stderr, err)
os.Exit(1)
} }
os.Stdout.Write(bs)
out := io.Writer(os.Stdout)
if *outfile != "" {
out, err = os.Create(*outfile)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
out.Write(bs)
} }