diff options
author | Jakob Borg <jakob@kastelo.net> | 2021-02-10 14:29:17 +0100 |
---|---|---|
committer | Jakob Borg <jakob@kastelo.net> | 2021-02-15 14:52:28 +0100 |
commit | b2c9e7b07b92c1f6cd23b932511b3329fe7dd96d (patch) | |
tree | 6e1fc7ccd1e1411496097d9abfb2c76ca28241dd /build.go | |
parent | d117b4b570c0cdb54746e50af0e9a7e10d4ec2cf (diff) | |
download | syncthing-b2c9e7b07b92c1f6cd23b932511b3329fe7dd96d.tar.gz syncthing-b2c9e7b07b92c1f6cd23b932511b3329fe7dd96d.zip |
build: Add build process for newgui (#7351)
Diffstat (limited to 'build.go')
-rw-r--r-- | build.go | 81 |
1 files changed, 63 insertions, 18 deletions
@@ -34,23 +34,24 @@ import ( ) var ( - goarch string - goos string - noupgrade bool - version string - goCmd string - race bool - debug = os.Getenv("BUILDDEBUG") != "" - extraTags string - installSuffix string - pkgdir string - cc string - run string - benchRun string - debugBinary bool - coverage bool - timeout = "120s" - numVersions = 5 + goarch string + goos string + noupgrade bool + version string + goCmd string + race bool + debug = os.Getenv("BUILDDEBUG") != "" + extraTags string + installSuffix string + pkgdir string + cc string + run string + benchRun string + debugBinary bool + coverage bool + timeout = "120s" + numVersions = 5 + withNextGenGUI = os.Getenv("BUILD_NEXT_GEN_GUI") != "" ) type target struct { @@ -372,6 +373,7 @@ func parseFlags() { flag.IntVar(&numVersions, "num-versions", numVersions, "Number of versions for changelog command") flag.StringVar(&run, "run", "", "Specify which tests to run") flag.StringVar(&benchRun, "bench", "", "Specify which benchmarks to run") + flag.BoolVar(&withNextGenGUI, "with-next-gen-gui", withNextGenGUI, "Also build 'newgui'") flag.Parse() } @@ -438,6 +440,10 @@ func benchArgs() []string { } func install(target target, tags []string) { + if (target.name == "syncthing" || target.name == "") && !withNextGenGUI { + log.Println("Notice: Next generation GUI will not be built; see --with-next-gen-gui.") + } + lazyRebuildAssets() tags = append(target.tags, tags...) @@ -467,6 +473,10 @@ func install(target target, tags []string) { } func build(target target, tags []string) { + if (target.name == "syncthing" || target.name == "") && !withNextGenGUI { + log.Println("Notice: Next generation GUI will not be built; see --with-next-gen-gui.") + } + lazyRebuildAssets() tags = append(target.tags, tags...) @@ -764,11 +774,46 @@ func rebuildAssets() { } func lazyRebuildAssets() { - if shouldRebuildAssets("lib/api/auto/gui.files.go", "gui") || shouldRebuildAssets("cmd/strelaypoolsrv/auto/gui.files.go", "cmd/strelaypoolsrv/gui") { + shouldRebuild := shouldRebuildAssets("lib/api/auto/gui.files.go", "gui") || + shouldRebuildAssets("cmd/strelaypoolsrv/auto/gui.files.go", "cmd/strelaypoolsrv/gui") + + if withNextGenGUI { + shouldRebuild = buildNextGenGUI() || shouldRebuild + } + + if shouldRebuild { rebuildAssets() } } +func buildNextGenGUI() bool { + // Check if we need to run the npm process, and if so also set the flag + // to rebuild Go assets afterwards. The index.html is regenerated every + // time by the build process. This assumes the new GUI ends up in + // next-gen-gui/dist/next-gen-gui. + + if !shouldRebuildAssets("gui/next-gen-gui/index.html", "next-gen-gui") { + // The GUI is up to date. + return false + } + + runPrintInDir("next-gen-gui", "npm", "install") + runPrintInDir("next-gen-gui", "npm", "run", "build", "--", "--prod", "--subresource-integrity") + + rmr("gui/tech-ui") + + for _, src := range listFiles("next-gen-gui/dist") { + rel, _ := filepath.Rel("next-gen-gui/dist", src) + dst := filepath.Join("gui", rel) + if err := copyFile(src, dst, 0644); err != nil { + fmt.Println("copy:", err) + os.Exit(1) + } + } + + return true +} + func shouldRebuildAssets(target, srcdir string) bool { info, err := os.Stat(target) if err != nil { |