2014-11-16 20:13:20 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 19:43:32 +00:00
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// 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,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-08-18 19:57:10 +00:00
|
|
|
|
2021-08-17 08:10:41 +00:00
|
|
|
//go:build ignore
|
2014-08-18 19:57:10 +00:00
|
|
|
// +build ignore
|
|
|
|
|
2014-08-18 19:38:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/tar"
|
|
|
|
"archive/zip"
|
|
|
|
"bytes"
|
2017-07-17 13:20:13 +00:00
|
|
|
"compress/flate"
|
2014-08-18 19:38:22 +00:00
|
|
|
"compress/gzip"
|
2022-11-05 14:40:53 +00:00
|
|
|
"encoding/base64"
|
2020-02-07 15:21:01 +00:00
|
|
|
"encoding/json"
|
2016-10-08 08:34:07 +00:00
|
|
|
"errors"
|
2014-08-18 19:38:22 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"os/user"
|
|
|
|
"path/filepath"
|
|
|
|
"regexp"
|
|
|
|
"runtime"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2021-04-11 18:04:15 +00:00
|
|
|
"text/template"
|
2014-10-13 18:13:42 +00:00
|
|
|
"time"
|
2022-07-28 17:36:39 +00:00
|
|
|
|
|
|
|
buildpkg "github.com/syncthing/syncthing/lib/build"
|
2014-08-18 19:38:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-02-10 13:29:17 +00:00
|
|
|
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
|
2022-01-13 08:57:23 +00:00
|
|
|
buildOut string
|
2021-02-10 13:29:17 +00:00
|
|
|
debugBinary bool
|
|
|
|
coverage bool
|
2021-05-28 20:20:18 +00:00
|
|
|
long bool
|
2021-02-10 13:29:17 +00:00
|
|
|
timeout = "120s"
|
2021-05-28 20:20:18 +00:00
|
|
|
longTimeout = "600s"
|
2021-02-10 13:29:17 +00:00
|
|
|
numVersions = 5
|
|
|
|
withNextGenGUI = os.Getenv("BUILD_NEXT_GEN_GUI") != ""
|
2014-08-18 19:38:22 +00:00
|
|
|
)
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
type target struct {
|
2016-09-12 12:21:07 +00:00
|
|
|
name string
|
2017-06-09 08:53:45 +00:00
|
|
|
debname string
|
|
|
|
debdeps []string
|
2019-08-08 16:04:52 +00:00
|
|
|
debpre string
|
2017-06-09 08:53:45 +00:00
|
|
|
description string
|
2019-10-07 11:30:25 +00:00
|
|
|
buildPkgs []string
|
2016-09-12 12:21:07 +00:00
|
|
|
binaryName string
|
|
|
|
archiveFiles []archiveFile
|
2021-04-11 18:04:15 +00:00
|
|
|
systemdService string
|
2016-09-12 12:21:07 +00:00
|
|
|
installationFiles []archiveFile
|
|
|
|
tags []string
|
2016-04-06 21:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type archiveFile struct {
|
|
|
|
src string
|
|
|
|
dst string
|
|
|
|
perm os.FileMode
|
|
|
|
}
|
|
|
|
|
|
|
|
var targets = map[string]target{
|
|
|
|
"all": {
|
|
|
|
// Only valid for the "build" and "install" commands as it lacks all
|
2019-10-07 11:30:25 +00:00
|
|
|
// the archive creation stuff. buildPkgs gets filled out in init()
|
|
|
|
tags: []string{"purego"},
|
2016-04-06 21:18:30 +00:00
|
|
|
},
|
|
|
|
"syncthing": {
|
|
|
|
// The default target for "build", "install", "tar", "zip", "deb", etc.
|
2017-06-09 08:53:45 +00:00
|
|
|
name: "syncthing",
|
|
|
|
debname: "syncthing",
|
|
|
|
debdeps: []string{"libc6", "procps"},
|
|
|
|
description: "Open Source Continuous File Synchronization",
|
2019-10-07 11:30:25 +00:00
|
|
|
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/syncthing"},
|
2017-06-09 08:53:45 +00:00
|
|
|
binaryName: "syncthing", // .exe will be added automatically for Windows builds
|
2016-04-06 21:18:30 +00:00
|
|
|
archiveFiles: []archiveFile{
|
|
|
|
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
|
|
|
|
{src: "README.md", dst: "README.txt", perm: 0644},
|
|
|
|
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
|
|
|
|
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
|
|
|
|
// All files from etc/ and extra/ added automatically in init().
|
|
|
|
},
|
2021-04-11 18:04:15 +00:00
|
|
|
systemdService: "syncthing@*.service",
|
2016-09-12 12:21:07 +00:00
|
|
|
installationFiles: []archiveFile{
|
2016-04-06 21:18:30 +00:00
|
|
|
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
|
|
|
|
{src: "README.md", dst: "deb/usr/share/doc/syncthing/README.txt", perm: 0644},
|
|
|
|
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing/LICENSE.txt", perm: 0644},
|
|
|
|
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing/AUTHORS.txt", perm: 0644},
|
|
|
|
{src: "man/syncthing.1", dst: "deb/usr/share/man/man1/syncthing.1", perm: 0644},
|
|
|
|
{src: "man/syncthing-config.5", dst: "deb/usr/share/man/man5/syncthing-config.5", perm: 0644},
|
|
|
|
{src: "man/syncthing-stignore.5", dst: "deb/usr/share/man/man5/syncthing-stignore.5", perm: 0644},
|
|
|
|
{src: "man/syncthing-device-ids.7", dst: "deb/usr/share/man/man7/syncthing-device-ids.7", perm: 0644},
|
|
|
|
{src: "man/syncthing-event-api.7", dst: "deb/usr/share/man/man7/syncthing-event-api.7", perm: 0644},
|
|
|
|
{src: "man/syncthing-faq.7", dst: "deb/usr/share/man/man7/syncthing-faq.7", perm: 0644},
|
|
|
|
{src: "man/syncthing-networking.7", dst: "deb/usr/share/man/man7/syncthing-networking.7", perm: 0644},
|
|
|
|
{src: "man/syncthing-rest-api.7", dst: "deb/usr/share/man/man7/syncthing-rest-api.7", perm: 0644},
|
|
|
|
{src: "man/syncthing-security.7", dst: "deb/usr/share/man/man7/syncthing-security.7", perm: 0644},
|
|
|
|
{src: "man/syncthing-versioning.7", dst: "deb/usr/share/man/man7/syncthing-versioning.7", perm: 0644},
|
|
|
|
{src: "etc/linux-systemd/system/syncthing@.service", dst: "deb/lib/systemd/system/syncthing@.service", perm: 0644},
|
|
|
|
{src: "etc/linux-systemd/system/syncthing-resume.service", dst: "deb/lib/systemd/system/syncthing-resume.service", perm: 0644},
|
|
|
|
{src: "etc/linux-systemd/user/syncthing.service", dst: "deb/usr/lib/systemd/user/syncthing.service", perm: 0644},
|
2021-03-05 07:08:29 +00:00
|
|
|
{src: "etc/linux-sysctl/30-syncthing.conf", dst: "deb/usr/lib/sysctl.d/30-syncthing.conf", perm: 0644},
|
2016-11-03 15:46:25 +00:00
|
|
|
{src: "etc/firewall-ufw/syncthing", dst: "deb/etc/ufw/applications.d/syncthing", perm: 0644},
|
2018-10-20 06:25:59 +00:00
|
|
|
{src: "etc/linux-desktop/syncthing-start.desktop", dst: "deb/usr/share/applications/syncthing-start.desktop", perm: 0644},
|
|
|
|
{src: "etc/linux-desktop/syncthing-ui.desktop", dst: "deb/usr/share/applications/syncthing-ui.desktop", perm: 0644},
|
|
|
|
{src: "assets/logo-32.png", dst: "deb/usr/share/icons/hicolor/32x32/apps/syncthing.png", perm: 0644},
|
|
|
|
{src: "assets/logo-64.png", dst: "deb/usr/share/icons/hicolor/64x64/apps/syncthing.png", perm: 0644},
|
|
|
|
{src: "assets/logo-128.png", dst: "deb/usr/share/icons/hicolor/128x128/apps/syncthing.png", perm: 0644},
|
|
|
|
{src: "assets/logo-256.png", dst: "deb/usr/share/icons/hicolor/256x256/apps/syncthing.png", perm: 0644},
|
|
|
|
{src: "assets/logo-512.png", dst: "deb/usr/share/icons/hicolor/512x512/apps/syncthing.png", perm: 0644},
|
|
|
|
{src: "assets/logo-only.svg", dst: "deb/usr/share/icons/hicolor/scalable/apps/syncthing.svg", perm: 0644},
|
2016-04-06 21:18:30 +00:00
|
|
|
},
|
|
|
|
},
|
2016-07-04 10:51:22 +00:00
|
|
|
"stdiscosrv": {
|
2017-06-09 08:53:45 +00:00
|
|
|
name: "stdiscosrv",
|
|
|
|
debname: "syncthing-discosrv",
|
|
|
|
debdeps: []string{"libc6"},
|
2019-08-08 16:04:52 +00:00
|
|
|
debpre: "cmd/stdiscosrv/scripts/preinst",
|
2017-06-09 08:53:45 +00:00
|
|
|
description: "Syncthing Discovery Server",
|
2019-10-07 11:30:25 +00:00
|
|
|
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/stdiscosrv"},
|
2017-06-09 08:53:45 +00:00
|
|
|
binaryName: "stdiscosrv", // .exe will be added automatically for Windows builds
|
2016-05-31 19:57:04 +00:00
|
|
|
archiveFiles: []archiveFile{
|
|
|
|
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
|
2016-07-04 10:51:22 +00:00
|
|
|
{src: "cmd/stdiscosrv/README.md", dst: "README.txt", perm: 0644},
|
2018-01-16 19:46:48 +00:00
|
|
|
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
|
2016-05-31 19:57:04 +00:00
|
|
|
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
|
|
|
|
},
|
2021-10-09 18:33:14 +00:00
|
|
|
systemdService: "stdiscosrv.service",
|
2016-09-12 12:21:07 +00:00
|
|
|
installationFiles: []archiveFile{
|
2016-05-31 19:57:04 +00:00
|
|
|
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
|
2017-06-09 08:53:45 +00:00
|
|
|
{src: "cmd/stdiscosrv/README.md", dst: "deb/usr/share/doc/syncthing-discosrv/README.txt", perm: 0644},
|
2018-08-11 20:45:31 +00:00
|
|
|
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing-discosrv/LICENSE.txt", perm: 0644},
|
2017-06-09 08:53:45 +00:00
|
|
|
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-discosrv/AUTHORS.txt", perm: 0644},
|
2016-07-27 15:00:10 +00:00
|
|
|
{src: "man/stdiscosrv.1", dst: "deb/usr/share/man/man1/stdiscosrv.1", perm: 0644},
|
2021-08-22 18:04:47 +00:00
|
|
|
{src: "cmd/stdiscosrv/etc/linux-systemd/stdiscosrv.service", dst: "deb/lib/systemd/system/stdiscosrv.service", perm: 0644},
|
2019-08-08 16:04:52 +00:00
|
|
|
{src: "cmd/stdiscosrv/etc/linux-systemd/default", dst: "deb/etc/default/syncthing-discosrv", perm: 0644},
|
|
|
|
{src: "cmd/stdiscosrv/etc/firewall-ufw/stdiscosrv", dst: "deb/etc/ufw/applications.d/stdiscosrv", perm: 0644},
|
2016-05-31 19:57:04 +00:00
|
|
|
},
|
2016-06-02 12:22:40 +00:00
|
|
|
tags: []string{"purego"},
|
2016-05-31 19:57:04 +00:00
|
|
|
},
|
2016-07-04 10:51:22 +00:00
|
|
|
"strelaysrv": {
|
2017-06-09 08:53:45 +00:00
|
|
|
name: "strelaysrv",
|
|
|
|
debname: "syncthing-relaysrv",
|
|
|
|
debdeps: []string{"libc6"},
|
2019-08-08 16:04:52 +00:00
|
|
|
debpre: "cmd/strelaysrv/scripts/preinst",
|
2017-06-09 08:53:45 +00:00
|
|
|
description: "Syncthing Relay Server",
|
2019-10-07 11:30:25 +00:00
|
|
|
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/strelaysrv"},
|
2017-06-09 08:53:45 +00:00
|
|
|
binaryName: "strelaysrv", // .exe will be added automatically for Windows builds
|
2016-06-02 12:07:29 +00:00
|
|
|
archiveFiles: []archiveFile{
|
|
|
|
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
|
2016-07-04 10:51:22 +00:00
|
|
|
{src: "cmd/strelaysrv/README.md", dst: "README.txt", perm: 0644},
|
|
|
|
{src: "cmd/strelaysrv/LICENSE", dst: "LICENSE.txt", perm: 0644},
|
2018-08-11 20:45:31 +00:00
|
|
|
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
|
2016-06-02 12:07:29 +00:00
|
|
|
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
|
|
|
|
},
|
2021-10-09 18:33:14 +00:00
|
|
|
systemdService: "strelaysrv.service",
|
2016-09-12 12:21:07 +00:00
|
|
|
installationFiles: []archiveFile{
|
2016-06-02 12:07:29 +00:00
|
|
|
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
|
2017-06-09 08:53:45 +00:00
|
|
|
{src: "cmd/strelaysrv/README.md", dst: "deb/usr/share/doc/syncthing-relaysrv/README.txt", perm: 0644},
|
|
|
|
{src: "cmd/strelaysrv/LICENSE", dst: "deb/usr/share/doc/syncthing-relaysrv/LICENSE.txt", perm: 0644},
|
2018-08-11 20:45:31 +00:00
|
|
|
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing-relaysrv/LICENSE.txt", perm: 0644},
|
2017-06-09 08:53:45 +00:00
|
|
|
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaysrv/AUTHORS.txt", perm: 0644},
|
2016-07-27 15:00:10 +00:00
|
|
|
{src: "man/strelaysrv.1", dst: "deb/usr/share/man/man1/strelaysrv.1", perm: 0644},
|
2021-08-22 18:04:47 +00:00
|
|
|
{src: "cmd/strelaysrv/etc/linux-systemd/strelaysrv.service", dst: "deb/lib/systemd/system/strelaysrv.service", perm: 0644},
|
2019-08-08 16:04:52 +00:00
|
|
|
{src: "cmd/strelaysrv/etc/linux-systemd/default", dst: "deb/etc/default/syncthing-relaysrv", perm: 0644},
|
|
|
|
{src: "cmd/strelaysrv/etc/firewall-ufw/strelaysrv", dst: "deb/etc/ufw/applications.d/strelaysrv", perm: 0644},
|
2016-06-02 12:07:29 +00:00
|
|
|
},
|
|
|
|
},
|
2016-07-04 09:08:11 +00:00
|
|
|
"strelaypoolsrv": {
|
2017-06-09 08:53:45 +00:00
|
|
|
name: "strelaypoolsrv",
|
|
|
|
debname: "syncthing-relaypoolsrv",
|
|
|
|
debdeps: []string{"libc6"},
|
|
|
|
description: "Syncthing Relay Pool Server",
|
2019-10-07 11:30:25 +00:00
|
|
|
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/strelaypoolsrv"},
|
2017-06-09 08:53:45 +00:00
|
|
|
binaryName: "strelaypoolsrv", // .exe will be added automatically for Windows builds
|
2016-07-04 09:08:11 +00:00
|
|
|
archiveFiles: []archiveFile{
|
|
|
|
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
|
|
|
|
{src: "cmd/strelaypoolsrv/README.md", dst: "README.txt", perm: 0644},
|
|
|
|
{src: "cmd/strelaypoolsrv/LICENSE", dst: "LICENSE.txt", perm: 0644},
|
|
|
|
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
|
|
|
|
},
|
2016-09-12 12:21:07 +00:00
|
|
|
installationFiles: []archiveFile{
|
2016-07-04 09:08:11 +00:00
|
|
|
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
|
2017-06-09 08:53:45 +00:00
|
|
|
{src: "cmd/strelaypoolsrv/README.md", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/README.txt", perm: 0644},
|
|
|
|
{src: "cmd/strelaypoolsrv/LICENSE", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/LICENSE.txt", perm: 0644},
|
|
|
|
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/AUTHORS.txt", perm: 0644},
|
2016-07-04 09:08:11 +00:00
|
|
|
},
|
|
|
|
},
|
2016-04-06 21:18:30 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 08:29:14 +00:00
|
|
|
func initTargets() {
|
2019-10-07 11:30:25 +00:00
|
|
|
all := targets["all"]
|
|
|
|
pkgs, _ := filepath.Glob("cmd/*")
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
pkg = filepath.Base(pkg)
|
|
|
|
if strings.HasPrefix(pkg, ".") {
|
|
|
|
// ignore dotfiles
|
|
|
|
continue
|
|
|
|
}
|
2021-02-25 08:29:14 +00:00
|
|
|
if noupgrade && pkg == "stupgrades" {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-07 11:30:25 +00:00
|
|
|
all.buildPkgs = append(all.buildPkgs, fmt.Sprintf("github.com/syncthing/syncthing/cmd/%s", pkg))
|
|
|
|
}
|
|
|
|
targets["all"] = all
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
// The "syncthing" target includes a few more files found in the "etc"
|
|
|
|
// and "extra" dirs.
|
|
|
|
syncthingPkg := targets["syncthing"]
|
|
|
|
for _, file := range listFiles("etc") {
|
|
|
|
syncthingPkg.archiveFiles = append(syncthingPkg.archiveFiles, archiveFile{src: file, dst: file, perm: 0644})
|
|
|
|
}
|
|
|
|
for _, file := range listFiles("extra") {
|
|
|
|
syncthingPkg.archiveFiles = append(syncthingPkg.archiveFiles, archiveFile{src: file, dst: file, perm: 0644})
|
|
|
|
}
|
|
|
|
for _, file := range listFiles("extra") {
|
2016-09-12 12:21:07 +00:00
|
|
|
syncthingPkg.installationFiles = append(syncthingPkg.installationFiles, archiveFile{src: file, dst: "deb/usr/share/doc/syncthing/" + filepath.Base(file), perm: 0644})
|
2016-04-06 21:18:30 +00:00
|
|
|
}
|
|
|
|
targets["syncthing"] = syncthingPkg
|
|
|
|
}
|
|
|
|
|
2014-08-18 19:38:22 +00:00
|
|
|
func main() {
|
|
|
|
log.SetFlags(0)
|
|
|
|
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
parseFlags()
|
|
|
|
|
2016-06-08 16:15:45 +00:00
|
|
|
if debug {
|
|
|
|
t0 := time.Now()
|
|
|
|
defer func() {
|
|
|
|
log.Println("... build completed in", time.Since(t0))
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2021-02-25 08:29:14 +00:00
|
|
|
initTargets()
|
|
|
|
|
2016-06-07 07:12:10 +00:00
|
|
|
// Invoking build.go with no parameters at all builds everything (incrementally),
|
2016-04-06 21:18:30 +00:00
|
|
|
// which is what you want for maximum error checking during development.
|
2014-08-18 19:38:22 +00:00
|
|
|
if flag.NArg() == 0 {
|
2016-06-07 07:12:10 +00:00
|
|
|
runCommand("install", targets["all"])
|
|
|
|
} else {
|
|
|
|
// with any command given but not a target, the target is
|
|
|
|
// "syncthing". So "go run build.go install" is "go run build.go install
|
|
|
|
// syncthing" etc.
|
|
|
|
targetName := "syncthing"
|
|
|
|
if flag.NArg() > 1 {
|
|
|
|
targetName = flag.Arg(1)
|
|
|
|
}
|
|
|
|
target, ok := targets[targetName]
|
|
|
|
if !ok {
|
|
|
|
log.Fatalln("Unknown target", target)
|
2014-11-17 15:02:41 +00:00
|
|
|
}
|
2015-04-28 20:32:10 +00:00
|
|
|
|
2016-06-07 07:12:10 +00:00
|
|
|
runCommand(flag.Arg(0), target)
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
2016-06-07 07:12:10 +00:00
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2016-06-07 07:12:10 +00:00
|
|
|
func runCommand(cmd string, target target) {
|
2020-11-20 16:43:59 +00:00
|
|
|
var tags []string
|
|
|
|
if noupgrade {
|
|
|
|
tags = []string{"noupgrade"}
|
|
|
|
}
|
|
|
|
tags = append(tags, strings.Fields(extraTags)...)
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
switch cmd {
|
|
|
|
case "install":
|
|
|
|
install(target, tags)
|
2017-07-07 20:43:26 +00:00
|
|
|
metalintShort()
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "build":
|
|
|
|
build(target, tags)
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "test":
|
2020-07-30 08:58:43 +00:00
|
|
|
test(strings.Fields(extraTags), "github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/...")
|
2015-05-23 13:08:17 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "bench":
|
2020-07-30 08:58:43 +00:00
|
|
|
bench(strings.Fields(extraTags), "github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/...")
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2020-06-16 12:33:17 +00:00
|
|
|
case "integration":
|
|
|
|
integration(false)
|
|
|
|
|
|
|
|
case "integrationbench":
|
|
|
|
integration(true)
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "assets":
|
|
|
|
rebuildAssets()
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2021-09-26 10:08:23 +00:00
|
|
|
case "update-deps":
|
|
|
|
updateDependencies()
|
|
|
|
|
2016-07-04 10:40:29 +00:00
|
|
|
case "proto":
|
|
|
|
proto()
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2021-03-03 07:53:50 +00:00
|
|
|
case "testmocks":
|
|
|
|
testmocks()
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "translate":
|
|
|
|
translate()
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "transifex":
|
|
|
|
transifex()
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "tar":
|
2020-11-20 16:43:59 +00:00
|
|
|
buildTar(target, tags)
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "zip":
|
2020-11-20 16:43:59 +00:00
|
|
|
buildZip(target, tags)
|
2015-05-11 16:39:53 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "deb":
|
|
|
|
buildDeb(target)
|
2014-08-18 19:38:22 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "vet":
|
2017-07-07 20:43:26 +00:00
|
|
|
metalintShort()
|
2015-04-28 20:32:10 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
case "lint":
|
2017-07-07 20:43:26 +00:00
|
|
|
metalintShort()
|
2016-06-08 16:15:45 +00:00
|
|
|
|
|
|
|
case "metalint":
|
2017-07-07 20:43:26 +00:00
|
|
|
metalint()
|
2016-04-06 21:18:30 +00:00
|
|
|
|
2016-09-06 10:54:40 +00:00
|
|
|
case "version":
|
|
|
|
fmt.Println(getVersion())
|
|
|
|
|
2020-06-02 09:40:45 +00:00
|
|
|
case "changelog":
|
|
|
|
vers, err := currentAndLatestVersions(numVersions)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, ver := range vers {
|
|
|
|
underline := strings.Repeat("=", len(ver))
|
|
|
|
msg, err := tagMessage(ver)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
fmt.Printf("%s\n%s\n\n%s\n\n", ver, underline, msg)
|
|
|
|
}
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
default:
|
|
|
|
log.Fatalf("Unknown command %q", cmd)
|
2014-09-28 11:07:13 +00:00
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 21:47:53 +00:00
|
|
|
func parseFlags() {
|
|
|
|
flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH")
|
|
|
|
flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS")
|
2018-12-20 14:24:35 +00:00
|
|
|
flag.StringVar(&goCmd, "gocmd", "go", "Specify `go` command")
|
2016-05-19 21:47:53 +00:00
|
|
|
flag.BoolVar(&noupgrade, "no-upgrade", noupgrade, "Disable upgrade functionality")
|
|
|
|
flag.StringVar(&version, "version", getVersion(), "Set compiled in version string")
|
|
|
|
flag.BoolVar(&race, "race", race, "Use race detector")
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
flag.StringVar(&extraTags, "tags", extraTags, "Extra tags, space separated")
|
2017-07-27 10:55:07 +00:00
|
|
|
flag.StringVar(&installSuffix, "installsuffix", installSuffix, "Install suffix, optional")
|
2017-10-13 09:24:38 +00:00
|
|
|
flag.StringVar(&pkgdir, "pkgdir", "", "Set -pkgdir parameter for `go build`")
|
2019-01-11 23:07:53 +00:00
|
|
|
flag.StringVar(&cc, "cc", os.Getenv("CC"), "Set CC environment variable for `go build`")
|
2018-01-03 08:07:15 +00:00
|
|
|
flag.BoolVar(&debugBinary, "debug-binary", debugBinary, "Create unoptimized binary to use with delve, set -gcflags='-N -l' and omit -ldflags")
|
2019-02-14 22:38:47 +00:00
|
|
|
flag.BoolVar(&coverage, "coverage", coverage, "Write coverage profile of tests to coverage.txt")
|
2021-05-28 20:20:18 +00:00
|
|
|
flag.BoolVar(&long, "long", long, "Run tests without the -short flag")
|
2020-06-02 09:40:45 +00:00
|
|
|
flag.IntVar(&numVersions, "num-versions", numVersions, "Number of versions for changelog command")
|
2020-06-16 12:33:17 +00:00
|
|
|
flag.StringVar(&run, "run", "", "Specify which tests to run")
|
|
|
|
flag.StringVar(&benchRun, "bench", "", "Specify which benchmarks to run")
|
2021-02-10 13:29:17 +00:00
|
|
|
flag.BoolVar(&withNextGenGUI, "with-next-gen-gui", withNextGenGUI, "Also build 'newgui'")
|
2022-01-13 08:57:23 +00:00
|
|
|
flag.StringVar(&buildOut, "build-out", "", "Set the '-o' value for 'go build'")
|
2016-05-19 21:47:53 +00:00
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
2020-07-30 08:58:43 +00:00
|
|
|
func test(tags []string, pkgs ...string) {
|
2016-03-28 10:03:13 +00:00
|
|
|
lazyRebuildAssets()
|
|
|
|
|
2020-07-30 08:58:43 +00:00
|
|
|
tags = append(tags, "purego")
|
2021-05-28 20:20:18 +00:00
|
|
|
args := []string{"test", "-tags", strings.Join(tags, " ")}
|
|
|
|
if long {
|
|
|
|
timeout = longTimeout
|
|
|
|
} else {
|
|
|
|
args = append(args, "-short")
|
|
|
|
}
|
|
|
|
args = append(args, "-timeout", timeout)
|
2019-02-14 22:38:47 +00:00
|
|
|
|
|
|
|
if runtime.GOARCH == "amd64" {
|
|
|
|
switch runtime.GOOS {
|
2022-07-28 17:36:39 +00:00
|
|
|
case buildpkg.Darwin, buildpkg.Linux, buildpkg.FreeBSD: // , "windows": # See https://github.com/golang/go/issues/27089
|
2019-02-14 22:38:47 +00:00
|
|
|
args = append(args, "-race")
|
|
|
|
}
|
2016-02-15 10:33:24 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 22:38:47 +00:00
|
|
|
if coverage {
|
2019-06-13 17:28:14 +00:00
|
|
|
args = append(args, "-covermode", "atomic", "-coverprofile", "coverage.txt", "-coverpkg", strings.Join(pkgs, ","))
|
2016-02-15 10:33:24 +00:00
|
|
|
}
|
2019-02-14 22:38:47 +00:00
|
|
|
|
2020-06-16 12:33:17 +00:00
|
|
|
args = append(args, runArgs()...)
|
|
|
|
|
2019-02-14 22:38:47 +00:00
|
|
|
runPrint(goCmd, append(args, pkgs...)...)
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 08:58:43 +00:00
|
|
|
func bench(tags []string, pkgs ...string) {
|
2016-03-28 10:03:13 +00:00
|
|
|
lazyRebuildAssets()
|
2020-07-30 08:58:43 +00:00
|
|
|
args := append([]string{"test", "-run", "NONE", "-tags", strings.Join(tags, " ")}, benchArgs()...)
|
2020-06-16 12:33:17 +00:00
|
|
|
runPrint(goCmd, append(args, pkgs...)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func integration(bench bool) {
|
|
|
|
lazyRebuildAssets()
|
|
|
|
args := []string{"test", "-v", "-timeout", "60m", "-tags"}
|
|
|
|
tags := "purego,integration"
|
|
|
|
if bench {
|
|
|
|
tags += ",benchmark"
|
|
|
|
}
|
|
|
|
args = append(args, tags)
|
|
|
|
args = append(args, runArgs()...)
|
|
|
|
if bench {
|
|
|
|
if run == "" {
|
|
|
|
args = append(args, "-run", "Benchmark")
|
|
|
|
}
|
|
|
|
args = append(args, benchArgs()...)
|
|
|
|
}
|
|
|
|
args = append(args, "./test")
|
|
|
|
fmt.Println(args)
|
|
|
|
runPrint(goCmd, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runArgs() []string {
|
|
|
|
if run == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return []string{"-run", run}
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchArgs() []string {
|
|
|
|
if benchRun == "" {
|
|
|
|
return []string{"-bench", "."}
|
|
|
|
}
|
|
|
|
return []string{"-bench", benchRun}
|
2015-05-23 13:08:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
func install(target target, tags []string) {
|
2021-02-10 13:29:17 +00:00
|
|
|
if (target.name == "syncthing" || target.name == "") && !withNextGenGUI {
|
|
|
|
log.Println("Notice: Next generation GUI will not be built; see --with-next-gen-gui.")
|
|
|
|
}
|
|
|
|
|
2016-03-28 10:03:13 +00:00
|
|
|
lazyRebuildAssets()
|
|
|
|
|
2016-06-02 12:22:40 +00:00
|
|
|
tags = append(target.tags, tags...)
|
|
|
|
|
2015-10-20 13:29:33 +00:00
|
|
|
cwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
os.Setenv("GOBIN", filepath.Join(cwd, "bin"))
|
2018-01-03 08:07:15 +00:00
|
|
|
|
2020-06-21 15:32:55 +00:00
|
|
|
setBuildEnvVars()
|
2018-03-26 18:44:44 +00:00
|
|
|
|
2018-05-02 06:30:23 +00:00
|
|
|
// On Windows generate a special file which the Go compiler will
|
|
|
|
// automatically use when generating Windows binaries to set things like
|
|
|
|
// the file icon, version, etc.
|
2018-03-26 18:44:44 +00:00
|
|
|
if goos == "windows" {
|
|
|
|
sysoPath, err := shouldBuildSyso(cwd)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Warning: Windows binaries will not have file information encoded: %v", err)
|
|
|
|
}
|
|
|
|
defer shouldCleanupSyso(sysoPath)
|
|
|
|
}
|
|
|
|
|
2021-04-22 09:14:25 +00:00
|
|
|
args := []string{"install", "-v"}
|
2020-04-16 08:09:33 +00:00
|
|
|
args = appendParameters(args, tags, target.buildPkgs...)
|
|
|
|
runPrint(goCmd, args...)
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
func build(target target, tags []string) {
|
2021-02-10 13:29:17 +00:00
|
|
|
if (target.name == "syncthing" || target.name == "") && !withNextGenGUI {
|
|
|
|
log.Println("Notice: Next generation GUI will not be built; see --with-next-gen-gui.")
|
|
|
|
}
|
|
|
|
|
2016-03-28 10:03:13 +00:00
|
|
|
lazyRebuildAssets()
|
2016-06-02 12:22:40 +00:00
|
|
|
tags = append(target.tags, tags...)
|
|
|
|
|
2017-07-17 13:20:13 +00:00
|
|
|
rmr(target.BinaryName())
|
2018-01-03 08:07:15 +00:00
|
|
|
|
2020-06-21 15:32:55 +00:00
|
|
|
setBuildEnvVars()
|
2018-05-02 06:30:23 +00:00
|
|
|
|
|
|
|
// On Windows generate a special file which the Go compiler will
|
|
|
|
// automatically use when generating Windows binaries to set things like
|
|
|
|
// the file icon, version, etc.
|
|
|
|
if goos == "windows" {
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
sysoPath, err := shouldBuildSyso(cwd)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Warning: Windows binaries will not have file information encoded: %v", err)
|
|
|
|
}
|
|
|
|
defer shouldCleanupSyso(sysoPath)
|
|
|
|
}
|
|
|
|
|
2021-04-22 09:14:25 +00:00
|
|
|
args := []string{"build", "-v"}
|
2022-01-13 08:57:23 +00:00
|
|
|
if buildOut != "" {
|
|
|
|
args = append(args, "-o", buildOut)
|
|
|
|
}
|
2020-04-16 08:09:33 +00:00
|
|
|
args = appendParameters(args, tags, target.buildPkgs...)
|
|
|
|
runPrint(goCmd, args...)
|
2018-01-03 08:07:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 15:32:55 +00:00
|
|
|
func setBuildEnvVars() {
|
|
|
|
os.Setenv("GOOS", goos)
|
|
|
|
os.Setenv("GOARCH", goarch)
|
|
|
|
os.Setenv("CC", cc)
|
|
|
|
if os.Getenv("CGO_ENABLED") == "" {
|
|
|
|
switch goos {
|
|
|
|
case "darwin", "solaris":
|
|
|
|
default:
|
|
|
|
os.Setenv("CGO_ENABLED", "0")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 08:09:33 +00:00
|
|
|
func appendParameters(args []string, tags []string, pkgs ...string) []string {
|
2017-10-13 09:24:38 +00:00
|
|
|
if pkgdir != "" {
|
|
|
|
args = append(args, "-pkgdir", pkgdir)
|
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
if len(tags) > 0 {
|
2016-06-06 11:39:08 +00:00
|
|
|
args = append(args, "-tags", strings.Join(tags, " "))
|
2017-07-27 10:55:07 +00:00
|
|
|
}
|
|
|
|
if installSuffix != "" {
|
|
|
|
args = append(args, "-installsuffix", installSuffix)
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
2014-11-29 21:17:54 +00:00
|
|
|
if race {
|
|
|
|
args = append(args, "-race")
|
|
|
|
}
|
2016-03-31 07:33:09 +00:00
|
|
|
|
2018-01-03 08:07:15 +00:00
|
|
|
if !debugBinary {
|
|
|
|
// Regular binaries get version tagged and skip some debug symbols
|
2021-04-22 09:14:25 +00:00
|
|
|
args = append(args, "-trimpath", "-ldflags", ldflags(tags))
|
2018-01-03 08:07:15 +00:00
|
|
|
} else {
|
|
|
|
// -gcflags to disable optimizations and inlining. Skip -ldflags
|
|
|
|
// because `Could not launch program: decoding dwarf section info at
|
|
|
|
// offset 0x0: too short` on 'dlv exec ...' see
|
2020-11-16 08:54:31 +00:00
|
|
|
// https://github.com/go-delve/delve/issues/79
|
2021-04-22 09:14:25 +00:00
|
|
|
args = append(args, "-gcflags", "all=-N -l")
|
2018-01-03 08:07:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 08:09:33 +00:00
|
|
|
return append(args, pkgs...)
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 16:43:59 +00:00
|
|
|
func buildTar(target target, tags []string) {
|
2016-04-06 21:18:30 +00:00
|
|
|
name := archiveName(target)
|
|
|
|
filename := name + ".tar.gz"
|
|
|
|
|
2020-11-20 16:43:59 +00:00
|
|
|
for _, tag := range tags {
|
|
|
|
if tag == "noupgrade" {
|
|
|
|
name += "-noupgrade"
|
|
|
|
break
|
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
2015-08-21 07:31:46 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
build(target, tags)
|
2019-12-03 07:37:39 +00:00
|
|
|
codesign(target)
|
2016-04-06 21:18:30 +00:00
|
|
|
|
|
|
|
for i := range target.archiveFiles {
|
2017-07-17 13:20:13 +00:00
|
|
|
target.archiveFiles[i].src = strings.Replace(target.archiveFiles[i].src, "{{binary}}", target.BinaryName(), 1)
|
|
|
|
target.archiveFiles[i].dst = strings.Replace(target.archiveFiles[i].dst, "{{binary}}", target.BinaryName(), 1)
|
2016-04-08 10:53:29 +00:00
|
|
|
target.archiveFiles[i].dst = name + "/" + target.archiveFiles[i].dst
|
2016-04-06 21:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tarGz(filename, target.archiveFiles)
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
fmt.Println(filename)
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 16:43:59 +00:00
|
|
|
func buildZip(target target, tags []string) {
|
2016-04-06 21:18:30 +00:00
|
|
|
name := archiveName(target)
|
|
|
|
filename := name + ".zip"
|
|
|
|
|
2020-11-20 16:43:59 +00:00
|
|
|
for _, tag := range tags {
|
|
|
|
if tag == "noupgrade" {
|
|
|
|
name += "-noupgrade"
|
|
|
|
break
|
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
2015-08-21 07:31:46 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
build(target, tags)
|
2019-12-03 07:37:39 +00:00
|
|
|
codesign(target)
|
2017-11-20 07:10:18 +00:00
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
for i := range target.archiveFiles {
|
2017-07-17 13:20:13 +00:00
|
|
|
target.archiveFiles[i].src = strings.Replace(target.archiveFiles[i].src, "{{binary}}", target.BinaryName(), 1)
|
|
|
|
target.archiveFiles[i].dst = strings.Replace(target.archiveFiles[i].dst, "{{binary}}", target.BinaryName(), 1)
|
2016-04-08 10:53:29 +00:00
|
|
|
target.archiveFiles[i].dst = name + "/" + target.archiveFiles[i].dst
|
2015-01-07 15:15:50 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
zipFile(filename, target.archiveFiles)
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
fmt.Println(filename)
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
func buildDeb(target target) {
|
2015-05-11 16:39:53 +00:00
|
|
|
os.RemoveAll("deb")
|
|
|
|
|
2015-05-23 11:05:47 +00:00
|
|
|
// "goarch" here is set to whatever the Debian packages expect. We correct
|
2016-10-20 09:16:30 +00:00
|
|
|
// it to what we actually know how to build and keep the Debian variant
|
|
|
|
// name in "debarch".
|
2015-05-23 11:05:47 +00:00
|
|
|
debarch := goarch
|
|
|
|
switch goarch {
|
|
|
|
case "i386":
|
|
|
|
goarch = "386"
|
|
|
|
case "armel", "armhf":
|
|
|
|
goarch = "arm"
|
|
|
|
}
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
build(target, []string{"noupgrade"})
|
2015-05-11 16:39:53 +00:00
|
|
|
|
2016-09-12 12:21:07 +00:00
|
|
|
for i := range target.installationFiles {
|
2017-07-17 13:20:13 +00:00
|
|
|
target.installationFiles[i].src = strings.Replace(target.installationFiles[i].src, "{{binary}}", target.BinaryName(), 1)
|
|
|
|
target.installationFiles[i].dst = strings.Replace(target.installationFiles[i].dst, "{{binary}}", target.BinaryName(), 1)
|
2015-05-11 16:39:53 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 12:21:07 +00:00
|
|
|
for _, af := range target.installationFiles {
|
2015-05-11 16:39:53 +00:00
|
|
|
if err := copyFile(af.src, af.dst, af.perm); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-12 12:21:07 +00:00
|
|
|
maintainer := "Syncthing Release Management <release@syncthing.net>"
|
|
|
|
debver := version
|
|
|
|
if strings.HasPrefix(debver, "v") {
|
|
|
|
debver = debver[1:]
|
2017-04-05 14:56:24 +00:00
|
|
|
// Debian interprets dashes as separator between main version and
|
|
|
|
// Debian package version, and thus thinks 0.14.26-rc.1 is better
|
|
|
|
// than just 0.14.26. This rectifies that.
|
2018-05-05 13:33:54 +00:00
|
|
|
debver = strings.Replace(debver, "-", "~", -1)
|
2016-01-19 17:49:41 +00:00
|
|
|
}
|
2017-06-09 08:53:45 +00:00
|
|
|
args := []string{
|
|
|
|
"-t", "deb",
|
|
|
|
"-s", "dir",
|
|
|
|
"-C", "deb",
|
|
|
|
"-n", target.debname,
|
|
|
|
"-v", debver,
|
|
|
|
"-a", debarch,
|
|
|
|
"-m", maintainer,
|
|
|
|
"--vendor", maintainer,
|
|
|
|
"--description", target.description,
|
2016-09-12 12:21:07 +00:00
|
|
|
"--url", "https://syncthing.net/",
|
2017-06-09 08:53:45 +00:00
|
|
|
"--license", "MPL-2",
|
|
|
|
}
|
|
|
|
for _, dep := range target.debdeps {
|
|
|
|
args = append(args, "-d", dep)
|
|
|
|
}
|
2021-04-11 18:04:15 +00:00
|
|
|
if target.systemdService != "" {
|
|
|
|
debpost, err := createPostInstScript(target)
|
|
|
|
defer os.Remove(debpost)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
args = append(args, "--after-upgrade", debpost)
|
2017-06-09 08:53:45 +00:00
|
|
|
}
|
2019-08-08 16:04:52 +00:00
|
|
|
if target.debpre != "" {
|
|
|
|
args = append(args, "--before-install", target.debpre)
|
|
|
|
}
|
2017-06-09 08:53:45 +00:00
|
|
|
runPrint("fpm", args...)
|
2015-05-11 16:39:53 +00:00
|
|
|
}
|
|
|
|
|
2021-04-11 18:04:15 +00:00
|
|
|
func createPostInstScript(target target) (string, error) {
|
|
|
|
scriptname := filepath.Join("script", "deb-post-inst.template")
|
|
|
|
t, err := template.ParseFiles(scriptname)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
scriptname = strings.TrimSuffix(scriptname, ".template")
|
|
|
|
w, err := os.Create(scriptname)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer w.Close()
|
|
|
|
if err = t.Execute(w, struct {
|
|
|
|
Service, Command string
|
|
|
|
}{
|
|
|
|
target.systemdService, target.binaryName,
|
|
|
|
}); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return scriptname, nil
|
|
|
|
}
|
|
|
|
|
2018-03-26 18:44:44 +00:00
|
|
|
func shouldBuildSyso(dir string) (string, error) {
|
2020-02-07 15:21:01 +00:00
|
|
|
type M map[string]interface{}
|
2020-03-29 14:51:50 +00:00
|
|
|
version := getVersion()
|
|
|
|
version = strings.TrimPrefix(version, "v")
|
|
|
|
major, minor, patch := semanticVersion()
|
2020-02-07 15:21:01 +00:00
|
|
|
bs, err := json.Marshal(M{
|
|
|
|
"FixedFileInfo": M{
|
|
|
|
"FileVersion": M{
|
|
|
|
"Major": major,
|
|
|
|
"Minor": minor,
|
|
|
|
"Patch": patch,
|
2020-03-29 14:51:50 +00:00
|
|
|
},
|
|
|
|
"ProductVersion": M{
|
|
|
|
"Major": major,
|
|
|
|
"Minor": minor,
|
|
|
|
"Patch": patch,
|
2020-02-07 15:21:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"StringFileInfo": M{
|
2021-02-08 14:48:05 +00:00
|
|
|
"CompanyName": "The Syncthing Authors",
|
|
|
|
"FileDescription": "Syncthing - Open Source Continuous File Synchronization",
|
|
|
|
"FileVersion": version,
|
|
|
|
"InternalName": "syncthing",
|
|
|
|
"LegalCopyright": "The Syncthing Authors",
|
|
|
|
"OriginalFilename": "syncthing",
|
|
|
|
"ProductName": "Syncthing",
|
|
|
|
"ProductVersion": version,
|
2020-02-07 15:21:01 +00:00
|
|
|
},
|
|
|
|
"IconPath": "assets/logo.ico",
|
|
|
|
})
|
2018-03-26 18:44:44 +00:00
|
|
|
if err != nil {
|
2020-02-07 15:21:01 +00:00
|
|
|
return "", err
|
2018-03-26 18:44:44 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 15:21:01 +00:00
|
|
|
jsonPath := filepath.Join(dir, "versioninfo.json")
|
2021-11-22 07:59:47 +00:00
|
|
|
err = os.WriteFile(jsonPath, bs, 0644)
|
2020-02-28 19:40:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", errors.New("failed to create " + jsonPath + ": " + err.Error())
|
|
|
|
}
|
|
|
|
|
2018-03-26 18:44:44 +00:00
|
|
|
defer func() {
|
|
|
|
if err := os.Remove(jsonPath); err != nil {
|
|
|
|
log.Printf("Warning: unable to remove generated %s: %v. Please remove it manually.", jsonPath, err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
sysoPath := filepath.Join(dir, "cmd", "syncthing", "resource.syso")
|
|
|
|
|
2021-09-17 15:07:32 +00:00
|
|
|
// See https://github.com/josephspurrier/goversioninfo#command-line-flags
|
|
|
|
armOption := ""
|
|
|
|
if strings.Contains(goarch, "arm") {
|
|
|
|
armOption = "-arm=true"
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := runError("goversioninfo", "-o", sysoPath, armOption); err != nil {
|
2018-03-26 18:44:44 +00:00
|
|
|
return "", errors.New("failed to create " + sysoPath + ": " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return sysoPath, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func shouldCleanupSyso(sysoFilePath string) {
|
|
|
|
if sysoFilePath == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := os.Remove(sysoFilePath); err != nil {
|
|
|
|
log.Printf("Warning: unable to remove generated %s: %v. Please remove it manually.", sysoFilePath, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
// copyFile copies a file from src to dst, ensuring the containing directory
|
|
|
|
// exists. The permission bits are copied as well. If dst already exists and
|
|
|
|
// the contents are identical to src the modification time is not updated.
|
2015-05-11 16:39:53 +00:00
|
|
|
func copyFile(src, dst string, perm os.FileMode) error {
|
2021-11-22 07:59:47 +00:00
|
|
|
in, err := os.ReadFile(src)
|
2015-05-11 16:39:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
|
2021-11-22 07:59:47 +00:00
|
|
|
out, err := os.ReadFile(dst)
|
2015-05-11 16:39:53 +00:00
|
|
|
if err != nil {
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
// The destination probably doesn't exist, we should create
|
|
|
|
// it.
|
|
|
|
goto copy
|
|
|
|
}
|
|
|
|
|
|
|
|
if bytes.Equal(in, out) {
|
|
|
|
// The permission bits may have changed without the contents
|
|
|
|
// changing so we always mirror them.
|
|
|
|
os.Chmod(dst, perm)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
copy:
|
|
|
|
os.MkdirAll(filepath.Dir(dst), 0777)
|
2021-11-22 07:59:47 +00:00
|
|
|
if err := os.WriteFile(dst, in, perm); err != nil {
|
2015-05-11 16:39:53 +00:00
|
|
|
return err
|
|
|
|
}
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
|
|
|
|
return nil
|
2015-05-11 16:39:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-24 12:48:52 +00:00
|
|
|
func listFiles(dir string) []string {
|
|
|
|
var res []string
|
|
|
|
filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-07 11:30:25 +00:00
|
|
|
|
2014-11-24 12:48:52 +00:00
|
|
|
if fi.Mode().IsRegular() {
|
|
|
|
res = append(res, path)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2016-03-28 10:03:13 +00:00
|
|
|
func rebuildAssets() {
|
2018-05-29 06:49:25 +00:00
|
|
|
os.Setenv("SOURCE_DATE_EPOCH", fmt.Sprint(buildStamp()))
|
2020-05-10 09:44:34 +00:00
|
|
|
runPrint(goCmd, "generate", "github.com/syncthing/syncthing/lib/api/auto", "github.com/syncthing/syncthing/cmd/strelaypoolsrv/auto")
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2016-03-28 10:03:13 +00:00
|
|
|
func lazyRebuildAssets() {
|
2021-02-10 13:29:17 +00:00
|
|
|
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 {
|
2016-03-28 10:03:13 +00:00
|
|
|
rebuildAssets()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 13:29:17 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-07-04 09:22:56 +00:00
|
|
|
func shouldRebuildAssets(target, srcdir string) bool {
|
|
|
|
info, err := os.Stat(target)
|
2016-03-28 10:03:13 +00:00
|
|
|
if err != nil {
|
|
|
|
// If the file doesn't exist, we must rebuild it
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if any of the files in gui/ are newer than the asset file. If
|
|
|
|
// so we should rebuild it.
|
|
|
|
currentBuild := info.ModTime()
|
|
|
|
assetsAreNewer := false
|
2016-10-08 08:34:07 +00:00
|
|
|
stop := errors.New("no need to iterate further")
|
2016-07-04 09:22:56 +00:00
|
|
|
filepath.Walk(srcdir, func(path string, info os.FileInfo, err error) error {
|
2016-03-28 10:03:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-10-08 08:34:07 +00:00
|
|
|
if info.ModTime().After(currentBuild) {
|
|
|
|
assetsAreNewer = true
|
|
|
|
return stop
|
2016-03-28 10:03:13 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
return assetsAreNewer
|
|
|
|
}
|
|
|
|
|
2021-09-26 10:08:23 +00:00
|
|
|
func updateDependencies() {
|
2022-09-14 08:29:44 +00:00
|
|
|
// Figure out desired Go version
|
|
|
|
bs, err := os.ReadFile("go.mod")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
re := regexp.MustCompile(`(?m)^go\s+([0-9.]+)`)
|
|
|
|
matches := re.FindSubmatch(bs)
|
|
|
|
if len(matches) != 2 {
|
|
|
|
log.Fatal("failed to parse go.mod")
|
|
|
|
}
|
|
|
|
goVersion := string(matches[1])
|
|
|
|
|
|
|
|
runPrint(goCmd, "get", "-u", "all")
|
|
|
|
runPrint(goCmd, "mod", "tidy", "-go="+goVersion, "-compat="+goVersion)
|
2021-09-26 10:08:23 +00:00
|
|
|
|
|
|
|
// We might have updated the protobuf package and should regenerate to match.
|
|
|
|
proto()
|
|
|
|
}
|
|
|
|
|
2016-07-04 10:40:29 +00:00
|
|
|
func proto() {
|
2019-09-04 06:33:29 +00:00
|
|
|
pv := protobufVersion()
|
2021-05-08 10:52:06 +00:00
|
|
|
repo := "https://github.com/gogo/protobuf.git"
|
|
|
|
path := filepath.Join("repos", "protobuf")
|
2019-09-04 06:33:29 +00:00
|
|
|
|
2021-09-26 10:08:23 +00:00
|
|
|
runPrint(goCmd, "install", fmt.Sprintf("github.com/gogo/protobuf/protoc-gen-gogofast@%v", pv))
|
2018-12-18 11:36:38 +00:00
|
|
|
os.MkdirAll("repos", 0755)
|
2021-05-08 10:52:06 +00:00
|
|
|
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
runPrint("git", "clone", repo, path)
|
|
|
|
} else {
|
|
|
|
runPrintInDir(path, "git", "fetch")
|
2018-12-18 11:36:38 +00:00
|
|
|
}
|
2021-05-08 10:52:06 +00:00
|
|
|
runPrintInDir(path, "git", "checkout", pv)
|
|
|
|
|
2021-03-03 07:53:50 +00:00
|
|
|
runPrint(goCmd, "generate", "github.com/syncthing/syncthing/cmd/stdiscosrv")
|
2020-08-25 06:11:14 +00:00
|
|
|
runPrint(goCmd, "generate", "proto/generate.go")
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 07:53:50 +00:00
|
|
|
func testmocks() {
|
|
|
|
args := []string{
|
|
|
|
"generate",
|
|
|
|
"github.com/syncthing/syncthing/lib/config",
|
|
|
|
"github.com/syncthing/syncthing/lib/connections",
|
|
|
|
"github.com/syncthing/syncthing/lib/discover",
|
|
|
|
"github.com/syncthing/syncthing/lib/events",
|
|
|
|
"github.com/syncthing/syncthing/lib/logger",
|
|
|
|
"github.com/syncthing/syncthing/lib/model",
|
|
|
|
"github.com/syncthing/syncthing/lib/protocol",
|
|
|
|
}
|
|
|
|
runPrint(goCmd, args...)
|
|
|
|
}
|
|
|
|
|
2014-08-18 19:38:22 +00:00
|
|
|
func translate() {
|
2016-01-10 15:37:31 +00:00
|
|
|
os.Chdir("gui/default/assets/lang")
|
2018-12-20 14:24:35 +00:00
|
|
|
runPipe("lang-en-new.json", goCmd, "run", "../../../../script/translate.go", "lang-en.json", "../../../")
|
2014-08-18 19:38:22 +00:00
|
|
|
os.Remove("lang-en.json")
|
|
|
|
err := os.Rename("lang-en-new.json", "lang-en.json")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-01-13 09:56:42 +00:00
|
|
|
os.Chdir("../../../..")
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func transifex() {
|
2016-01-10 15:37:31 +00:00
|
|
|
os.Chdir("gui/default/assets/lang")
|
2018-12-20 14:24:35 +00:00
|
|
|
runPrint(goCmd, "run", "../../../../script/transifexdl.go")
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 08:58:43 +00:00
|
|
|
func ldflags(tags []string) string {
|
2020-02-07 15:21:01 +00:00
|
|
|
b := new(strings.Builder)
|
2014-08-18 19:38:22 +00:00
|
|
|
b.WriteString("-w")
|
2020-02-07 15:21:01 +00:00
|
|
|
fmt.Fprintf(b, " -X github.com/syncthing/syncthing/lib/build.Version=%s", version)
|
|
|
|
fmt.Fprintf(b, " -X github.com/syncthing/syncthing/lib/build.Stamp=%d", buildStamp())
|
|
|
|
fmt.Fprintf(b, " -X github.com/syncthing/syncthing/lib/build.User=%s", buildUser())
|
|
|
|
fmt.Fprintf(b, " -X github.com/syncthing/syncthing/lib/build.Host=%s", buildHost())
|
2020-07-30 08:58:43 +00:00
|
|
|
fmt.Fprintf(b, " -X github.com/syncthing/syncthing/lib/build.Tags=%s", strings.Join(tags, ","))
|
2019-09-07 18:21:09 +00:00
|
|
|
if v := os.Getenv("EXTRA_LDFLAGS"); v != "" {
|
2019-10-07 11:30:25 +00:00
|
|
|
fmt.Fprintf(b, " %s", v)
|
2019-09-07 18:21:09 +00:00
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
return b.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func rmr(paths ...string) {
|
|
|
|
for _, path := range paths {
|
2016-08-14 20:48:11 +00:00
|
|
|
if debug {
|
|
|
|
log.Println("rm -r", path)
|
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
os.RemoveAll(path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:18 +00:00
|
|
|
func getReleaseVersion() (string, error) {
|
2021-11-22 07:59:47 +00:00
|
|
|
bs, err := os.ReadFile("RELEASE")
|
2015-03-12 10:17:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(bytes.TrimSpace(bs)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getGitVersion() (string, error) {
|
2020-06-20 06:42:06 +00:00
|
|
|
// The current version as Git sees it
|
2020-06-26 07:02:35 +00:00
|
|
|
bs, err := runError("git", "describe", "--always", "--dirty", "--abbrev=8")
|
2014-10-13 18:13:42 +00:00
|
|
|
if err != nil {
|
2015-03-12 10:17:18 +00:00
|
|
|
return "", err
|
2014-10-13 18:13:42 +00:00
|
|
|
}
|
2020-06-20 06:42:06 +00:00
|
|
|
vcur := string(bs)
|
|
|
|
|
|
|
|
// The closest current tag name
|
|
|
|
bs, err = runError("git", "describe", "--always", "--abbrev=0")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
v0 := string(bs)
|
|
|
|
|
2020-07-28 08:58:01 +00:00
|
|
|
// To be more semantic-versionish and ensure proper ordering in our
|
2022-04-10 20:24:57 +00:00
|
|
|
// upgrade process, we make sure there's only one hyphen in the version.
|
2020-07-28 08:58:01 +00:00
|
|
|
|
|
|
|
versionRe := regexp.MustCompile(`-([0-9]{1,3}-g[0-9a-f]{5,10}(-dirty)?)`)
|
2020-06-20 06:42:06 +00:00
|
|
|
if m := versionRe.FindStringSubmatch(vcur); len(m) > 0 {
|
|
|
|
suffix := strings.ReplaceAll(m[1], "-", ".")
|
|
|
|
|
|
|
|
if strings.Contains(v0, "-") {
|
|
|
|
// We're based of a tag with a prerelease string. We can just
|
|
|
|
// add our dev stuff directly.
|
|
|
|
return fmt.Sprintf("%s.dev.%s", v0, suffix), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're based on a release version. We need to bump the patch
|
|
|
|
// version and then add a -dev prerelease string.
|
|
|
|
next := nextPatchVersion(v0)
|
|
|
|
return fmt.Sprintf("%s-dev.%s", next, suffix), nil
|
|
|
|
}
|
|
|
|
return vcur, nil
|
2015-03-12 10:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getVersion() string {
|
|
|
|
// First try for a RELEASE file,
|
|
|
|
if ver, err := getReleaseVersion(); err == nil {
|
|
|
|
return ver
|
|
|
|
}
|
2015-03-13 09:10:13 +00:00
|
|
|
// ... then see if we have a Git tag.
|
2015-03-12 10:17:18 +00:00
|
|
|
if ver, err := getGitVersion(); err == nil {
|
2016-03-10 09:24:11 +00:00
|
|
|
if strings.Contains(ver, "-") {
|
|
|
|
// The version already contains a hash and stuff. See if we can
|
|
|
|
// find a current branch name to tack onto it as well.
|
|
|
|
return ver + getBranchSuffix()
|
|
|
|
}
|
2015-03-12 10:17:18 +00:00
|
|
|
return ver
|
|
|
|
}
|
|
|
|
// This seems to be a dev build.
|
|
|
|
return "unknown-dev"
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 14:51:50 +00:00
|
|
|
func semanticVersion() (major, minor, patch int) {
|
|
|
|
r := regexp.MustCompile(`v(\d+)\.(\d+).(\d+)`)
|
2018-03-26 18:44:44 +00:00
|
|
|
matches := r.FindStringSubmatch(getVersion())
|
2020-03-29 14:51:50 +00:00
|
|
|
if len(matches) != 4 {
|
|
|
|
return 0, 0, 0
|
2020-02-28 19:40:14 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 14:51:50 +00:00
|
|
|
var ints [3]int
|
|
|
|
for i, s := range matches[1:] {
|
|
|
|
ints[i], _ = strconv.Atoi(s)
|
2018-03-26 18:44:44 +00:00
|
|
|
}
|
2020-03-29 14:51:50 +00:00
|
|
|
return ints[0], ints[1], ints[2]
|
2018-03-26 18:44:44 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 09:24:11 +00:00
|
|
|
func getBranchSuffix() string {
|
|
|
|
bs, err := runError("git", "branch", "-a", "--contains")
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-10 09:37:13 +00:00
|
|
|
branches := strings.Split(string(bs), "\n")
|
2016-03-10 09:24:11 +00:00
|
|
|
if len(branches) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-10 09:37:13 +00:00
|
|
|
branch := ""
|
|
|
|
for i, candidate := range branches {
|
|
|
|
if strings.HasPrefix(candidate, "*") {
|
|
|
|
// This is the current branch. Select it!
|
|
|
|
branch = strings.TrimLeft(candidate, " \t*")
|
|
|
|
break
|
|
|
|
} else if i == 0 {
|
|
|
|
// Otherwise the first branch in the list will do.
|
|
|
|
branch = strings.TrimSpace(branch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if branch == "" {
|
|
|
|
return ""
|
|
|
|
}
|
2016-03-10 09:24:11 +00:00
|
|
|
|
|
|
|
// The branch name may be on the form "remotes/origin/foo" from which we
|
|
|
|
// just want "foo".
|
2016-03-10 09:37:13 +00:00
|
|
|
parts := strings.Split(branch, "/")
|
2016-03-10 09:24:11 +00:00
|
|
|
if len(parts) == 0 || len(parts[len(parts)-1]) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
2016-03-10 09:37:13 +00:00
|
|
|
|
2016-03-10 09:47:15 +00:00
|
|
|
branch = parts[len(parts)-1]
|
2017-06-30 12:02:16 +00:00
|
|
|
switch branch {
|
2020-06-16 05:01:55 +00:00
|
|
|
case "master", "release", "main":
|
2017-06-30 12:02:16 +00:00
|
|
|
// these are not special
|
2016-03-10 09:37:13 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-10 09:49:11 +00:00
|
|
|
validBranchRe := regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)
|
2016-03-10 09:47:15 +00:00
|
|
|
if !validBranchRe.MatchString(branch) {
|
|
|
|
// There's some odd stuff in the branch name. Better skip it.
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-10 09:37:13 +00:00
|
|
|
return "-" + branch
|
2016-03-10 09:24:11 +00:00
|
|
|
}
|
|
|
|
|
2014-08-18 19:38:22 +00:00
|
|
|
func buildStamp() int64 {
|
2016-06-29 18:52:49 +00:00
|
|
|
// If SOURCE_DATE_EPOCH is set, use that.
|
|
|
|
if s, _ := strconv.ParseInt(os.Getenv("SOURCE_DATE_EPOCH"), 10, 64); s > 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to get the timestamp of the latest commit.
|
2014-10-15 16:15:21 +00:00
|
|
|
bs, err := runError("git", "show", "-s", "--format=%ct")
|
2014-10-13 18:13:42 +00:00
|
|
|
if err != nil {
|
2016-06-29 18:52:49 +00:00
|
|
|
// Fall back to "now".
|
2014-10-13 18:13:42 +00:00
|
|
|
return time.Now().Unix()
|
|
|
|
}
|
2016-06-29 18:52:49 +00:00
|
|
|
|
2022-11-25 12:14:06 +00:00
|
|
|
s, err := strconv.ParseInt(string(bs), 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
// Fall back to "now".
|
|
|
|
log.Printf("Failed to parse git output: %q: %v", string(bs), err)
|
|
|
|
return time.Now().Unix()
|
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildUser() string {
|
2016-07-27 21:27:45 +00:00
|
|
|
if v := os.Getenv("BUILD_USER"); v != "" {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2014-08-18 19:38:22 +00:00
|
|
|
u, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
return "unknown-user"
|
|
|
|
}
|
|
|
|
return strings.Replace(u.Username, " ", "-", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildHost() string {
|
2016-07-27 21:27:45 +00:00
|
|
|
if v := os.Getenv("BUILD_HOST"); v != "" {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2014-08-18 19:38:22 +00:00
|
|
|
h, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
return "unknown-host"
|
|
|
|
}
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildArch() string {
|
|
|
|
os := goos
|
|
|
|
if os == "darwin" {
|
2018-06-13 21:20:52 +00:00
|
|
|
os = "macos"
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s-%s", os, goarch)
|
|
|
|
}
|
|
|
|
|
2016-04-06 21:18:30 +00:00
|
|
|
func archiveName(target target) string {
|
|
|
|
return fmt.Sprintf("%s-%s-%s", target.name, buildArch(), version)
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
2014-10-15 16:15:21 +00:00
|
|
|
func runError(cmd string, args ...string) ([]byte, error) {
|
2016-06-08 16:15:45 +00:00
|
|
|
if debug {
|
|
|
|
t0 := time.Now()
|
|
|
|
log.Println("runError:", cmd, strings.Join(args, " "))
|
|
|
|
defer func() {
|
|
|
|
log.Println("... in", time.Since(t0))
|
|
|
|
}()
|
|
|
|
}
|
2014-10-15 16:15:21 +00:00
|
|
|
ecmd := exec.Command(cmd, args...)
|
|
|
|
bs, err := ecmd.CombinedOutput()
|
2015-04-28 20:32:10 +00:00
|
|
|
return bytes.TrimSpace(bs), err
|
2014-10-15 16:15:21 +00:00
|
|
|
}
|
|
|
|
|
2014-08-18 19:38:22 +00:00
|
|
|
func runPrint(cmd string, args ...string) {
|
2018-12-18 11:36:38 +00:00
|
|
|
runPrintInDir(".", cmd, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runPrintInDir(dir string, cmd string, args ...string) {
|
2016-06-08 16:15:45 +00:00
|
|
|
if debug {
|
|
|
|
t0 := time.Now()
|
|
|
|
log.Println("runPrint:", cmd, strings.Join(args, " "))
|
|
|
|
defer func() {
|
|
|
|
log.Println("... in", time.Since(t0))
|
|
|
|
}()
|
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
ecmd := exec.Command(cmd, args...)
|
|
|
|
ecmd.Stdout = os.Stdout
|
|
|
|
ecmd.Stderr = os.Stderr
|
2018-12-18 11:36:38 +00:00
|
|
|
ecmd.Dir = dir
|
2014-08-18 19:38:22 +00:00
|
|
|
err := ecmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runPipe(file, cmd string, args ...string) {
|
2016-06-08 16:15:45 +00:00
|
|
|
if debug {
|
|
|
|
t0 := time.Now()
|
|
|
|
log.Println("runPipe:", cmd, strings.Join(args, " "))
|
|
|
|
defer func() {
|
|
|
|
log.Println("... in", time.Since(t0))
|
|
|
|
}()
|
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
fd, err := os.Create(file)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
ecmd := exec.Command(cmd, args...)
|
|
|
|
ecmd.Stdout = fd
|
|
|
|
ecmd.Stderr = os.Stderr
|
|
|
|
err = ecmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-08-23 20:19:29 +00:00
|
|
|
fd.Close()
|
2014-08-18 19:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func tarGz(out string, files []archiveFile) {
|
|
|
|
fd, err := os.Create(out)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-07-17 13:20:13 +00:00
|
|
|
gw, err := gzip.NewWriterLevel(fd, gzip.BestCompression)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-08-18 19:38:22 +00:00
|
|
|
tw := tar.NewWriter(gw)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
sf, err := os.Open(f.src)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
info, err := sf.Stat()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
h := &tar.Header{
|
|
|
|
Name: f.dst,
|
|
|
|
Size: info.Size(),
|
|
|
|
Mode: int64(info.Mode()),
|
|
|
|
ModTime: info.ModTime(),
|
|
|
|
}
|
|
|
|
|
|
|
|
err = tw.WriteHeader(h)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
_, err = io.Copy(tw, sf)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
sf.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
err = tw.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
err = gw.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
err = fd.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func zipFile(out string, files []archiveFile) {
|
|
|
|
fd, err := os.Create(out)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
zw := zip.NewWriter(fd)
|
|
|
|
|
2017-07-17 13:20:13 +00:00
|
|
|
var fw *flate.Writer
|
|
|
|
|
|
|
|
// Register the deflator.
|
|
|
|
zw.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
|
|
|
|
var err error
|
|
|
|
if fw == nil {
|
|
|
|
// Creating a flate compressor for every file is
|
|
|
|
// expensive, create one and reuse it.
|
|
|
|
fw, err = flate.NewWriter(out, flate.BestCompression)
|
|
|
|
} else {
|
|
|
|
fw.Reset(out)
|
|
|
|
}
|
|
|
|
return fw, err
|
|
|
|
})
|
|
|
|
|
2014-08-18 19:38:22 +00:00
|
|
|
for _, f := range files {
|
|
|
|
sf, err := os.Open(f.src)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
info, err := sf.Stat()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fh, err := zip.FileInfoHeader(info)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-06-20 09:49:19 +00:00
|
|
|
fh.Name = filepath.ToSlash(f.dst)
|
2014-08-18 19:38:22 +00:00
|
|
|
fh.Method = zip.Deflate
|
|
|
|
|
|
|
|
if strings.HasSuffix(f.dst, ".txt") {
|
|
|
|
// Text file. Read it and convert line endings.
|
2021-11-22 07:59:47 +00:00
|
|
|
bs, err := io.ReadAll(sf)
|
2014-08-18 19:38:22 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-11-22 08:38:24 +00:00
|
|
|
bs = bytes.Replace(bs, []byte{'\n'}, []byte{'\r', '\n'}, -1)
|
2014-08-18 19:38:22 +00:00
|
|
|
fh.UncompressedSize = uint32(len(bs))
|
|
|
|
fh.UncompressedSize64 = uint64(len(bs))
|
|
|
|
|
|
|
|
of, err := zw.CreateHeader(fh)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
of.Write(bs)
|
|
|
|
} else {
|
|
|
|
// Binary file. Copy verbatim.
|
|
|
|
of, err := zw.CreateHeader(fh)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
_, err = io.Copy(of, sf)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = zw.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
err = fd.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2014-12-22 09:52:09 +00:00
|
|
|
|
2019-12-03 07:37:39 +00:00
|
|
|
func codesign(target target) {
|
|
|
|
switch goos {
|
|
|
|
case "windows":
|
|
|
|
windowsCodesign(target.BinaryName())
|
|
|
|
case "darwin":
|
|
|
|
macosCodesign(target.BinaryName())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 18:43:50 +00:00
|
|
|
func macosCodesign(file string) {
|
|
|
|
if pass := os.Getenv("CODESIGN_KEYCHAIN_PASS"); pass != "" {
|
|
|
|
bs, err := runError("security", "unlock-keychain", "-p", pass)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Codesign: unlocking keychain failed:", string(bs))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if id := os.Getenv("CODESIGN_IDENTITY"); id != "" {
|
2020-05-11 16:16:44 +00:00
|
|
|
bs, err := runError("codesign", "--options=runtime", "-s", id, file)
|
2016-01-16 18:43:50 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println("Codesign: signing failed:", string(bs))
|
|
|
|
return
|
|
|
|
}
|
2016-01-16 18:59:01 +00:00
|
|
|
log.Println("Codesign: successfully signed", file)
|
2016-01-16 18:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-15 07:26:25 +00:00
|
|
|
|
2017-11-20 07:10:18 +00:00
|
|
|
func windowsCodesign(file string) {
|
|
|
|
st := "signtool.exe"
|
2017-11-20 13:54:52 +00:00
|
|
|
|
2017-11-20 07:10:18 +00:00
|
|
|
if path := os.Getenv("CODESIGN_SIGNTOOL"); path != "" {
|
|
|
|
st = path
|
|
|
|
}
|
|
|
|
|
2017-11-20 13:54:52 +00:00
|
|
|
for i, algo := range []string{"sha1", "sha256"} {
|
|
|
|
args := []string{"sign", "/fd", algo}
|
|
|
|
if f := os.Getenv("CODESIGN_CERTIFICATE_FILE"); f != "" {
|
|
|
|
args = append(args, "/f", f)
|
2022-11-05 14:40:53 +00:00
|
|
|
} else if b := os.Getenv("CODESIGN_CERTIFICATE_BASE64"); b != "" {
|
|
|
|
// Decode the PFX certificate from base64.
|
|
|
|
bs, err := base64.RawStdEncoding.DecodeString(b)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Codesign: signing failed: decoding base64:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write it to a temporary file
|
|
|
|
f, err := os.CreateTemp("", "codesign-*.pfx")
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Codesign: signing failed: creating temp file:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_ = f.Chmod(0600) // best effort remove other users' access
|
|
|
|
defer os.Remove(f.Name())
|
|
|
|
if _, err := f.Write(bs); err != nil {
|
|
|
|
log.Println("Codesign: signing failed: writing temp file:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
log.Println("Codesign: signing failed: closing temp file:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use that when signing
|
|
|
|
args = append(args, "/f", f.Name())
|
2017-11-20 13:54:52 +00:00
|
|
|
}
|
|
|
|
if p := os.Getenv("CODESIGN_CERTIFICATE_PASSWORD"); p != "" {
|
|
|
|
args = append(args, "/p", p)
|
|
|
|
}
|
|
|
|
if tr := os.Getenv("CODESIGN_TIMESTAMP_SERVER"); tr != "" {
|
|
|
|
switch algo {
|
|
|
|
case "sha256":
|
|
|
|
args = append(args, "/tr", tr, "/td", algo)
|
|
|
|
default:
|
|
|
|
args = append(args, "/t", tr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if i > 0 {
|
|
|
|
args = append(args, "/as")
|
|
|
|
}
|
|
|
|
args = append(args, file)
|
|
|
|
|
|
|
|
bs, err := runError(st, args...)
|
|
|
|
if err != nil {
|
2022-11-05 14:40:53 +00:00
|
|
|
log.Printf("Codesign: signing failed: %v: %s", err, string(bs))
|
2017-11-20 13:54:52 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Println("Codesign: successfully signed", file, "using", algo)
|
2017-11-20 07:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-07 20:43:26 +00:00
|
|
|
func metalint() {
|
|
|
|
lazyRebuildAssets()
|
2018-12-20 14:24:35 +00:00
|
|
|
runPrint(goCmd, "test", "-run", "Metalint", "./meta")
|
2016-05-23 21:19:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 20:43:26 +00:00
|
|
|
func metalintShort() {
|
|
|
|
lazyRebuildAssets()
|
2018-12-20 14:24:35 +00:00
|
|
|
runPrint(goCmd, "test", "-short", "-run", "Metalint", "./meta")
|
2016-05-23 21:19:08 +00:00
|
|
|
}
|
build: Support builds outside of GOPATH
This adds support for building with the source placed anywhere and no
GOPATH set. The build script handles this by creating a temporary GOPATH
in the system temp dir (or another specified location) and mirroring the
source there before building. The resulting binaries etc still end up in
the same place as usual, meaning at least the "build", "install", "tar",
"zip", "deb", "snap", "test", "vet", "lint", "metalint" and "clean"
commands work without a GOPATH. To this end these commands internally
use fully qualified package paths like
"github.com/syncthing/syncthing/cmd/..." instead of "./cmd/..." like
before.
There is a new command "gopath" that prepares and echoes the directory
of the temporary GOPATH. This can be used to run other non-build go
commands:
export GOPATH=$(go run build.go gopath) // GOPATH is now set
go test -v -race github.com/syncthing/syncthing/cmd/...
There is a new option "-no-build-gopath" that prevents the
check-and-copy step, instead assuming the temporary GOPATH is already
created and up to date. This is a performance optimization for build
servers running multiple builds commands in sequence:
go run build.go gopath // creates a temporary GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
go run build.go -no-build-gopath -goos=... tar // reuses GOPATH
The temporary GOPATH is placed in the system temporary directory
(os.TempDir()) unless overridden by the STTMPDIR variable. It is named
after the hash of the current directory where build.go is run. The
reason for this is that the name should be unique to a source checkout
without risk for conflict, but still persistent between runs of
build.go.
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4253
LGTM: AudriusButkevicius, imsodin
2017-07-11 07:57:58 +00:00
|
|
|
|
2017-07-17 13:20:13 +00:00
|
|
|
func (t target) BinaryName() string {
|
|
|
|
if goos == "windows" {
|
|
|
|
return t.binaryName + ".exe"
|
|
|
|
}
|
|
|
|
return t.binaryName
|
|
|
|
}
|
2019-09-04 06:33:29 +00:00
|
|
|
|
|
|
|
func protobufVersion() string {
|
|
|
|
bs, err := runError(goCmd, "list", "-f", "{{.Version}}", "-m", "github.com/gogo/protobuf")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Getting protobuf version:", err)
|
|
|
|
}
|
|
|
|
return string(bs)
|
|
|
|
}
|
2020-06-02 09:40:45 +00:00
|
|
|
|
|
|
|
func currentAndLatestVersions(n int) ([]string, error) {
|
|
|
|
bs, err := runError("git", "tag", "--sort", "taggerdate")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
lines := strings.Split(string(bs), "\n")
|
|
|
|
reverseStrings(lines)
|
|
|
|
|
|
|
|
// The one at the head is the latest version. We always keep that one.
|
|
|
|
// Then we filter out remaining ones with dashes (pre-releases etc).
|
|
|
|
|
|
|
|
latest := lines[:1]
|
|
|
|
nonPres := filterStrings(lines[1:], func(s string) bool { return !strings.Contains(s, "-") })
|
|
|
|
vers := append(latest, nonPres...)
|
|
|
|
return vers[:n], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func reverseStrings(ss []string) {
|
|
|
|
for i := 0; i < len(ss)/2; i++ {
|
|
|
|
ss[i], ss[len(ss)-1-i] = ss[len(ss)-1-i], ss[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func filterStrings(ss []string, op func(string) bool) []string {
|
|
|
|
n := ss[:0]
|
|
|
|
for _, s := range ss {
|
|
|
|
if op(s) {
|
|
|
|
n = append(n, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func tagMessage(tag string) (string, error) {
|
|
|
|
hash, err := runError("git", "rev-parse", tag)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
obj, err := runError("git", "cat-file", "-p", string(hash))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return trimTagMessage(string(obj), tag), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func trimTagMessage(msg, tag string) string {
|
|
|
|
firstBlank := strings.Index(msg, "\n\n")
|
|
|
|
if firstBlank > 0 {
|
|
|
|
msg = msg[firstBlank+2:]
|
|
|
|
}
|
|
|
|
msg = strings.TrimPrefix(msg, tag)
|
|
|
|
beginSig := strings.Index(msg, "-----BEGIN PGP")
|
|
|
|
if beginSig > 0 {
|
|
|
|
msg = msg[:beginSig]
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(msg)
|
|
|
|
}
|
2020-06-20 06:42:06 +00:00
|
|
|
|
|
|
|
func nextPatchVersion(ver string) string {
|
|
|
|
parts := strings.SplitN(ver, "-", 2)
|
|
|
|
digits := strings.Split(parts[0], ".")
|
|
|
|
n, _ := strconv.Atoi(digits[len(digits)-1])
|
|
|
|
digits[len(digits)-1] = strconv.Itoa(n + 1)
|
|
|
|
return strings.Join(digits, ".")
|
|
|
|
}
|