2014-11-16 13:13:20 -07:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 12:43:32 -07:00
|
|
|
//
|
2015-03-07 13:36:35 -07: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-08 23:52:18 -07:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-08-18 12:57:10 -07:00
|
|
|
|
|
|
|
// +build ignore
|
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/tar"
|
|
|
|
"archive/zip"
|
|
|
|
"bytes"
|
2017-07-17 06:20:13 -07:00
|
|
|
"compress/flate"
|
2014-08-18 12:38:22 -07:00
|
|
|
"compress/gzip"
|
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 00:57:58 -07:00
|
|
|
"crypto/sha256"
|
2016-10-08 01:34:07 -07:00
|
|
|
"errors"
|
2014-08-18 12:38:22 -07:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"os/user"
|
|
|
|
"path/filepath"
|
|
|
|
"regexp"
|
|
|
|
"runtime"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2016-10-20 02:16:30 -07:00
|
|
|
"text/template"
|
2014-10-13 11:13:42 -07:00
|
|
|
"time"
|
2014-08-18 12:38:22 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
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 00:57:58 -07:00
|
|
|
versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`)
|
|
|
|
goarch string
|
|
|
|
goos string
|
|
|
|
noupgrade bool
|
|
|
|
version string
|
|
|
|
goVersion float64
|
|
|
|
race bool
|
|
|
|
debug = os.Getenv("BUILDDEBUG") != ""
|
|
|
|
extraTags string
|
2017-07-27 03:55:07 -07:00
|
|
|
installSuffix string
|
2017-10-20 16:10:55 -07:00
|
|
|
pkgdir string
|
2018-01-03 01:07:15 -07:00
|
|
|
debugBinary bool
|
2018-05-10 12:38:49 -07:00
|
|
|
timeout = "120s"
|
2014-08-18 12:38:22 -07:00
|
|
|
)
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
type target struct {
|
2016-09-12 05:21:07 -07:00
|
|
|
name string
|
2017-06-09 01:53:45 -07:00
|
|
|
debname string
|
|
|
|
debdeps []string
|
|
|
|
debpost string
|
|
|
|
description string
|
2016-09-12 05:21:07 -07:00
|
|
|
buildPkg string
|
|
|
|
binaryName string
|
|
|
|
archiveFiles []archiveFile
|
|
|
|
installationFiles []archiveFile
|
|
|
|
tags []string
|
2016-04-06 14:18:30 -07: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
|
|
|
|
// the archive creation stuff.
|
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 00:57:58 -07:00
|
|
|
buildPkg: "github.com/syncthing/syncthing/cmd/...",
|
2016-06-02 07:32:23 -07:00
|
|
|
tags: []string{"purego"},
|
2016-04-06 14:18:30 -07:00
|
|
|
},
|
|
|
|
"syncthing": {
|
|
|
|
// The default target for "build", "install", "tar", "zip", "deb", etc.
|
2017-06-09 01:53:45 -07:00
|
|
|
name: "syncthing",
|
|
|
|
debname: "syncthing",
|
|
|
|
debdeps: []string{"libc6", "procps"},
|
|
|
|
debpost: "script/post-upgrade",
|
|
|
|
description: "Open Source Continuous File Synchronization",
|
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 00:57:58 -07:00
|
|
|
buildPkg: "github.com/syncthing/syncthing/cmd/syncthing",
|
2017-06-09 01:53:45 -07:00
|
|
|
binaryName: "syncthing", // .exe will be added automatically for Windows builds
|
2016-04-06 14:18:30 -07: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().
|
|
|
|
},
|
2016-09-12 05:21:07 -07:00
|
|
|
installationFiles: []archiveFile{
|
2016-04-06 14:18:30 -07: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},
|
2016-11-03 08:46:25 -07:00
|
|
|
{src: "etc/firewall-ufw/syncthing", dst: "deb/etc/ufw/applications.d/syncthing", perm: 0644},
|
2018-10-19 23:25:59 -07: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 14:18:30 -07:00
|
|
|
},
|
|
|
|
},
|
2016-07-04 03:51:22 -07:00
|
|
|
"stdiscosrv": {
|
2017-06-09 01:53:45 -07:00
|
|
|
name: "stdiscosrv",
|
|
|
|
debname: "syncthing-discosrv",
|
|
|
|
debdeps: []string{"libc6"},
|
|
|
|
description: "Syncthing Discovery Server",
|
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 00:57:58 -07:00
|
|
|
buildPkg: "github.com/syncthing/syncthing/cmd/stdiscosrv",
|
2017-06-09 01:53:45 -07:00
|
|
|
binaryName: "stdiscosrv", // .exe will be added automatically for Windows builds
|
2016-05-31 12:57:04 -07:00
|
|
|
archiveFiles: []archiveFile{
|
|
|
|
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
|
2016-07-04 03:51:22 -07:00
|
|
|
{src: "cmd/stdiscosrv/README.md", dst: "README.txt", perm: 0644},
|
2018-01-16 12:46:48 -07:00
|
|
|
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
|
2016-05-31 12:57:04 -07:00
|
|
|
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
|
|
|
|
},
|
2016-09-12 05:21:07 -07:00
|
|
|
installationFiles: []archiveFile{
|
2016-05-31 12:57:04 -07:00
|
|
|
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
|
2017-06-09 01:53:45 -07:00
|
|
|
{src: "cmd/stdiscosrv/README.md", dst: "deb/usr/share/doc/syncthing-discosrv/README.txt", perm: 0644},
|
2018-08-11 13:45:31 -07:00
|
|
|
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing-discosrv/LICENSE.txt", perm: 0644},
|
2017-06-09 01:53:45 -07:00
|
|
|
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-discosrv/AUTHORS.txt", perm: 0644},
|
2016-07-27 08:00:10 -07:00
|
|
|
{src: "man/stdiscosrv.1", dst: "deb/usr/share/man/man1/stdiscosrv.1", perm: 0644},
|
2016-05-31 12:57:04 -07:00
|
|
|
},
|
2016-06-02 05:22:40 -07:00
|
|
|
tags: []string{"purego"},
|
2016-05-31 12:57:04 -07:00
|
|
|
},
|
2016-07-04 03:51:22 -07:00
|
|
|
"strelaysrv": {
|
2017-06-09 01:53:45 -07:00
|
|
|
name: "strelaysrv",
|
|
|
|
debname: "syncthing-relaysrv",
|
|
|
|
debdeps: []string{"libc6"},
|
|
|
|
description: "Syncthing Relay Server",
|
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 00:57:58 -07:00
|
|
|
buildPkg: "github.com/syncthing/syncthing/cmd/strelaysrv",
|
2017-06-09 01:53:45 -07:00
|
|
|
binaryName: "strelaysrv", // .exe will be added automatically for Windows builds
|
2016-06-02 05:07:29 -07:00
|
|
|
archiveFiles: []archiveFile{
|
|
|
|
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
|
2016-07-04 03:51:22 -07:00
|
|
|
{src: "cmd/strelaysrv/README.md", dst: "README.txt", perm: 0644},
|
|
|
|
{src: "cmd/strelaysrv/LICENSE", dst: "LICENSE.txt", perm: 0644},
|
2018-08-11 13:45:31 -07:00
|
|
|
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
|
2016-06-02 05:07:29 -07:00
|
|
|
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
|
|
|
|
},
|
2016-09-12 05:21:07 -07:00
|
|
|
installationFiles: []archiveFile{
|
2016-06-02 05:07:29 -07:00
|
|
|
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
|
2017-06-09 01:53:45 -07: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 13:45:31 -07:00
|
|
|
{src: "LICENSE", dst: "deb/usr/share/doc/syncthing-relaysrv/LICENSE.txt", perm: 0644},
|
2017-06-09 01:53:45 -07:00
|
|
|
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaysrv/AUTHORS.txt", perm: 0644},
|
2016-07-27 08:00:10 -07:00
|
|
|
{src: "man/strelaysrv.1", dst: "deb/usr/share/man/man1/strelaysrv.1", perm: 0644},
|
2016-06-02 05:07:29 -07:00
|
|
|
},
|
|
|
|
},
|
2016-07-04 02:08:11 -07:00
|
|
|
"strelaypoolsrv": {
|
2017-06-09 01:53:45 -07:00
|
|
|
name: "strelaypoolsrv",
|
|
|
|
debname: "syncthing-relaypoolsrv",
|
|
|
|
debdeps: []string{"libc6"},
|
|
|
|
description: "Syncthing Relay Pool Server",
|
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 00:57:58 -07:00
|
|
|
buildPkg: "github.com/syncthing/syncthing/cmd/strelaypoolsrv",
|
2017-06-09 01:53:45 -07:00
|
|
|
binaryName: "strelaypoolsrv", // .exe will be added automatically for Windows builds
|
2016-07-04 02:08:11 -07: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 05:21:07 -07:00
|
|
|
installationFiles: []archiveFile{
|
2016-07-04 02:08:11 -07:00
|
|
|
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
|
2017-06-09 01:53:45 -07: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 02:08:11 -07:00
|
|
|
},
|
|
|
|
},
|
2016-04-06 14:18:30 -07:00
|
|
|
}
|
|
|
|
|
2018-12-18 04:36:38 -07:00
|
|
|
// These are repos we need to clone to run "go generate"
|
|
|
|
|
|
|
|
type dependencyRepo struct {
|
|
|
|
path string
|
|
|
|
repo string
|
|
|
|
commit string
|
|
|
|
}
|
|
|
|
|
|
|
|
var dependencyRepos = []dependencyRepo{
|
|
|
|
{path: "protobuf", repo: "https://github.com/gogo/protobuf.git", commit: "v1.0.0"},
|
|
|
|
{path: "xdr", repo: "https://github.com/calmh/xdr.git", commit: "08e072f9cb16"},
|
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
func init() {
|
|
|
|
// 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 05:21:07 -07:00
|
|
|
syncthingPkg.installationFiles = append(syncthingPkg.installationFiles, archiveFile{src: file, dst: "deb/usr/share/doc/syncthing/" + filepath.Base(file), perm: 0644})
|
2016-04-06 14:18:30 -07:00
|
|
|
}
|
|
|
|
targets["syncthing"] = syncthingPkg
|
|
|
|
}
|
|
|
|
|
2014-08-18 12:38:22 -07: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 00:57:58 -07:00
|
|
|
parseFlags()
|
|
|
|
|
2016-06-08 09:15:45 -07:00
|
|
|
if debug {
|
|
|
|
t0 := time.Now()
|
|
|
|
defer func() {
|
|
|
|
log.Println("... build completed in", time.Since(t0))
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:12:10 -07:00
|
|
|
// Invoking build.go with no parameters at all builds everything (incrementally),
|
2016-04-06 14:18:30 -07:00
|
|
|
// which is what you want for maximum error checking during development.
|
2014-08-18 12:38:22 -07:00
|
|
|
if flag.NArg() == 0 {
|
2016-06-07 00:12:10 -07: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 08:02:41 -07:00
|
|
|
}
|
2015-04-28 13:32:10 -07:00
|
|
|
|
2016-06-07 00:12:10 -07:00
|
|
|
runCommand(flag.Arg(0), target)
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
2016-06-07 00:12:10 -07:00
|
|
|
}
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-06-07 00:12:10 -07:00
|
|
|
func runCommand(cmd string, target target) {
|
2016-04-06 14:18:30 -07:00
|
|
|
switch cmd {
|
|
|
|
case "setup":
|
|
|
|
setup()
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "install":
|
|
|
|
var tags []string
|
|
|
|
if noupgrade {
|
|
|
|
tags = []string{"noupgrade"}
|
|
|
|
}
|
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 00:57:58 -07:00
|
|
|
tags = append(tags, strings.Fields(extraTags)...)
|
2016-04-06 14:18:30 -07:00
|
|
|
install(target, tags)
|
2017-07-07 13:43:26 -07:00
|
|
|
metalintShort()
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "build":
|
|
|
|
var tags []string
|
|
|
|
if noupgrade {
|
|
|
|
tags = []string{"noupgrade"}
|
|
|
|
}
|
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 00:57:58 -07:00
|
|
|
tags = append(tags, strings.Fields(extraTags)...)
|
2016-04-06 14:18:30 -07:00
|
|
|
build(target, tags)
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "test":
|
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 00:57:58 -07:00
|
|
|
test("github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/...")
|
2015-05-23 06:08:17 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "bench":
|
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 00:57:58 -07:00
|
|
|
bench("github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/...")
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "assets":
|
|
|
|
rebuildAssets()
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
case "proto":
|
|
|
|
proto()
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "translate":
|
|
|
|
translate()
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "transifex":
|
|
|
|
transifex()
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "tar":
|
|
|
|
buildTar(target)
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "zip":
|
|
|
|
buildZip(target)
|
2015-05-11 09:39:53 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "deb":
|
|
|
|
buildDeb(target)
|
2014-08-18 12:38:22 -07:00
|
|
|
|
2016-10-20 02:16:30 -07:00
|
|
|
case "snap":
|
|
|
|
buildSnap(target)
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "vet":
|
2017-07-07 13:43:26 -07:00
|
|
|
metalintShort()
|
2015-04-28 13:32:10 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
case "lint":
|
2017-07-07 13:43:26 -07:00
|
|
|
metalintShort()
|
2016-06-08 09:15:45 -07:00
|
|
|
|
|
|
|
case "metalint":
|
2017-07-07 13:43:26 -07:00
|
|
|
metalint()
|
2016-04-06 14:18:30 -07:00
|
|
|
|
2016-09-06 03:54:40 -07:00
|
|
|
case "version":
|
|
|
|
fmt.Println(getVersion())
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
default:
|
|
|
|
log.Fatalf("Unknown command %q", cmd)
|
2014-09-28 04:07:13 -07:00
|
|
|
}
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2016-05-19 14:47:53 -07:00
|
|
|
func parseFlags() {
|
|
|
|
flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH")
|
|
|
|
flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS")
|
|
|
|
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 00:57:58 -07:00
|
|
|
flag.StringVar(&extraTags, "tags", extraTags, "Extra tags, space separated")
|
2017-07-27 03:55:07 -07:00
|
|
|
flag.StringVar(&installSuffix, "installsuffix", installSuffix, "Install suffix, optional")
|
2017-10-13 02:24:38 -07:00
|
|
|
flag.StringVar(&pkgdir, "pkgdir", "", "Set -pkgdir parameter for `go build`")
|
2018-01-03 01:07:15 -07:00
|
|
|
flag.BoolVar(&debugBinary, "debug-binary", debugBinary, "Create unoptimized binary to use with delve, set -gcflags='-N -l' and omit -ldflags")
|
2016-05-19 14:47:53 -07:00
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
func setup() {
|
2016-11-24 03:33:43 -07:00
|
|
|
packages := []string{
|
|
|
|
"github.com/alecthomas/gometalinter",
|
|
|
|
"github.com/AlekSi/gocov-xml",
|
|
|
|
"github.com/axw/gocov/gocov",
|
|
|
|
"github.com/FiloSottile/gvt",
|
2018-10-16 11:53:03 -07:00
|
|
|
"golang.org/x/lint/golint",
|
2016-11-24 03:33:43 -07:00
|
|
|
"github.com/gordonklaus/ineffassign",
|
2016-12-17 07:37:11 -07:00
|
|
|
"github.com/mdempsky/unconvert",
|
2016-11-24 03:33:43 -07:00
|
|
|
"github.com/mitchellh/go-wordwrap",
|
|
|
|
"github.com/opennota/check/cmd/...",
|
2016-11-24 04:05:04 -07:00
|
|
|
"github.com/tsenart/deadcode",
|
2016-11-24 03:33:43 -07:00
|
|
|
"golang.org/x/net/html",
|
|
|
|
"golang.org/x/tools/cmd/cover",
|
2017-10-15 03:39:50 -07:00
|
|
|
"honnef.co/go/tools/cmd/gosimple",
|
|
|
|
"honnef.co/go/tools/cmd/staticcheck",
|
|
|
|
"honnef.co/go/tools/cmd/unused",
|
2018-03-26 11:44:44 -07:00
|
|
|
"github.com/josephspurrier/goversioninfo",
|
2016-11-24 03:33:43 -07:00
|
|
|
}
|
|
|
|
for _, pkg := range packages {
|
|
|
|
fmt.Println(pkg)
|
|
|
|
runPrint("go", "get", "-u", pkg)
|
|
|
|
}
|
2017-01-02 17:16:21 -07: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 00:57:58 -07:00
|
|
|
runPrint("go", "install", "-v", "github.com/syncthing/syncthing/vendor/github.com/gogo/protobuf/protoc-gen-gogofast")
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2016-03-05 13:01:58 -07:00
|
|
|
func test(pkgs ...string) {
|
2016-03-28 03:03:13 -07:00
|
|
|
lazyRebuildAssets()
|
|
|
|
|
2016-02-15 03:33:24 -07:00
|
|
|
useRace := runtime.GOARCH == "amd64"
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "darwin", "linux", "freebsd", "windows":
|
|
|
|
default:
|
|
|
|
useRace = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if useRace {
|
2018-05-10 12:38:49 -07:00
|
|
|
runPrint("go", append([]string{"test", "-short", "-race", "-timeout", timeout, "-tags", "purego"}, pkgs...)...)
|
2016-02-15 03:33:24 -07:00
|
|
|
} else {
|
2018-05-10 12:38:49 -07:00
|
|
|
runPrint("go", append([]string{"test", "-short", "-timeout", timeout, "-tags", "purego"}, pkgs...)...)
|
2016-02-15 03:33:24 -07:00
|
|
|
}
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2016-03-05 13:01:58 -07:00
|
|
|
func bench(pkgs ...string) {
|
2016-03-28 03:03:13 -07:00
|
|
|
lazyRebuildAssets()
|
2016-03-05 13:01:58 -07:00
|
|
|
runPrint("go", append([]string{"test", "-run", "NONE", "-bench", "."}, pkgs...)...)
|
2015-05-23 06:08:17 -07:00
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
func install(target target, tags []string) {
|
2016-03-28 03:03:13 -07:00
|
|
|
lazyRebuildAssets()
|
|
|
|
|
2016-06-02 05:22:40 -07:00
|
|
|
tags = append(target.tags, tags...)
|
|
|
|
|
2015-10-20 06:29:33 -07:00
|
|
|
cwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
os.Setenv("GOBIN", filepath.Join(cwd, "bin"))
|
2018-01-03 01:07:15 -07:00
|
|
|
|
|
|
|
args := []string{"install", "-v"}
|
|
|
|
args = appendParameters(args, tags, target)
|
2016-03-31 00:33:09 -07:00
|
|
|
|
|
|
|
os.Setenv("GOOS", goos)
|
|
|
|
os.Setenv("GOARCH", goarch)
|
2018-03-26 11:44:44 -07:00
|
|
|
|
2018-05-01 23:30:23 -07: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 11:44:44 -07: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)
|
|
|
|
}
|
|
|
|
|
2014-11-17 08:01:16 -07:00
|
|
|
runPrint("go", args...)
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
func build(target target, tags []string) {
|
2016-03-28 03:03:13 -07:00
|
|
|
lazyRebuildAssets()
|
|
|
|
|
2016-06-02 05:22:40 -07:00
|
|
|
tags = append(target.tags, tags...)
|
|
|
|
|
2017-07-17 06:20:13 -07:00
|
|
|
rmr(target.BinaryName())
|
2018-01-03 01:07:15 -07:00
|
|
|
|
2018-12-11 05:37:47 -07:00
|
|
|
args := []string{"build", "-v"}
|
2018-01-03 01:07:15 -07:00
|
|
|
args = appendParameters(args, tags, target)
|
|
|
|
|
|
|
|
os.Setenv("GOOS", goos)
|
|
|
|
os.Setenv("GOARCH", goarch)
|
2018-05-01 23:30:23 -07: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)
|
|
|
|
}
|
|
|
|
|
2018-01-03 01:07:15 -07:00
|
|
|
runPrint("go", args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func appendParameters(args []string, tags []string, target target) []string {
|
2017-10-13 02:24:38 -07:00
|
|
|
if pkgdir != "" {
|
|
|
|
args = append(args, "-pkgdir", pkgdir)
|
|
|
|
}
|
2014-08-18 12:38:22 -07:00
|
|
|
if len(tags) > 0 {
|
2016-06-06 04:39:08 -07:00
|
|
|
args = append(args, "-tags", strings.Join(tags, " "))
|
2017-07-27 03:55:07 -07:00
|
|
|
}
|
|
|
|
if installSuffix != "" {
|
|
|
|
args = append(args, "-installsuffix", installSuffix)
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
2014-11-29 14:17:54 -07:00
|
|
|
if race {
|
|
|
|
args = append(args, "-race")
|
|
|
|
}
|
2016-03-31 00:33:09 -07:00
|
|
|
|
2018-01-03 01:07:15 -07:00
|
|
|
if !debugBinary {
|
|
|
|
// Regular binaries get version tagged and skip some debug symbols
|
|
|
|
args = append(args, "-ldflags", ldflags())
|
|
|
|
} 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
|
|
|
|
// https://github.com/derekparker/delve/issues/79
|
|
|
|
args = append(args, "-gcflags", "-N -l")
|
|
|
|
}
|
|
|
|
|
|
|
|
return append(args, target.buildPkg)
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
func buildTar(target target) {
|
|
|
|
name := archiveName(target)
|
|
|
|
filename := name + ".tar.gz"
|
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
var tags []string
|
|
|
|
if noupgrade {
|
|
|
|
tags = []string{"noupgrade"}
|
|
|
|
name += "-noupgrade"
|
|
|
|
}
|
2015-08-21 00:31:46 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
build(target, tags)
|
2015-01-07 08:15:50 -07:00
|
|
|
|
2016-01-16 11:43:50 -07:00
|
|
|
if goos == "darwin" {
|
2017-07-17 06:20:13 -07:00
|
|
|
macosCodesign(target.BinaryName())
|
2016-01-16 11:43:50 -07:00
|
|
|
}
|
2016-04-06 14:18:30 -07:00
|
|
|
|
|
|
|
for i := range target.archiveFiles {
|
2017-07-17 06:20:13 -07: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 03:53:29 -07:00
|
|
|
target.archiveFiles[i].dst = name + "/" + target.archiveFiles[i].dst
|
2016-04-06 14:18:30 -07: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 00:57:58 -07:00
|
|
|
fmt.Println(filename)
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
func buildZip(target target) {
|
|
|
|
name := archiveName(target)
|
|
|
|
filename := name + ".zip"
|
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
var tags []string
|
|
|
|
if noupgrade {
|
|
|
|
tags = []string{"noupgrade"}
|
|
|
|
name += "-noupgrade"
|
|
|
|
}
|
2015-08-21 00:31:46 -07:00
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
build(target, tags)
|
|
|
|
|
2017-11-20 00:10:18 -07:00
|
|
|
if goos == "windows" {
|
|
|
|
windowsCodesign(target.BinaryName())
|
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
for i := range target.archiveFiles {
|
2017-07-17 06:20:13 -07: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 03:53:29 -07:00
|
|
|
target.archiveFiles[i].dst = name + "/" + target.archiveFiles[i].dst
|
2015-01-07 08:15:50 -07:00
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07: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 00:57:58 -07:00
|
|
|
fmt.Println(filename)
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
func buildDeb(target target) {
|
2015-05-11 09:39:53 -07:00
|
|
|
os.RemoveAll("deb")
|
|
|
|
|
2015-05-23 04:05:47 -07:00
|
|
|
// "goarch" here is set to whatever the Debian packages expect. We correct
|
2016-10-20 02:16:30 -07:00
|
|
|
// it to what we actually know how to build and keep the Debian variant
|
|
|
|
// name in "debarch".
|
2015-05-23 04:05:47 -07:00
|
|
|
debarch := goarch
|
|
|
|
switch goarch {
|
|
|
|
case "i386":
|
|
|
|
goarch = "386"
|
|
|
|
case "armel", "armhf":
|
|
|
|
goarch = "arm"
|
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
build(target, []string{"noupgrade"})
|
2015-05-11 09:39:53 -07:00
|
|
|
|
2016-09-12 05:21:07 -07:00
|
|
|
for i := range target.installationFiles {
|
2017-07-17 06:20:13 -07: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 09:39:53 -07:00
|
|
|
}
|
|
|
|
|
2016-09-12 05:21:07 -07:00
|
|
|
for _, af := range target.installationFiles {
|
2015-05-11 09:39:53 -07:00
|
|
|
if err := copyFile(af.src, af.dst, af.perm); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-12 05:21:07 -07:00
|
|
|
maintainer := "Syncthing Release Management <release@syncthing.net>"
|
|
|
|
debver := version
|
|
|
|
if strings.HasPrefix(debver, "v") {
|
|
|
|
debver = debver[1:]
|
2017-04-05 07:56:24 -07: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 06:33:54 -07:00
|
|
|
debver = strings.Replace(debver, "-", "~", -1)
|
2016-01-19 10:49:41 -07:00
|
|
|
}
|
2017-06-09 01:53:45 -07: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 05:21:07 -07:00
|
|
|
"--url", "https://syncthing.net/",
|
2017-06-09 01:53:45 -07:00
|
|
|
"--license", "MPL-2",
|
|
|
|
}
|
|
|
|
for _, dep := range target.debdeps {
|
|
|
|
args = append(args, "-d", dep)
|
|
|
|
}
|
|
|
|
if target.debpost != "" {
|
|
|
|
args = append(args, "--after-upgrade", target.debpost)
|
|
|
|
}
|
|
|
|
runPrint("fpm", args...)
|
2015-05-11 09:39:53 -07:00
|
|
|
}
|
|
|
|
|
2016-10-20 02:16:30 -07:00
|
|
|
func buildSnap(target target) {
|
2016-11-08 17:52:33 -07:00
|
|
|
os.RemoveAll("snap")
|
2016-11-12 01:36:19 -07:00
|
|
|
|
2016-10-20 02:16:30 -07:00
|
|
|
tmpl, err := template.ParseFiles("snapcraft.yaml.template")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
f, err := os.Create("snapcraft.yaml")
|
|
|
|
defer f.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-11-08 17:52:33 -07:00
|
|
|
|
|
|
|
snaparch := goarch
|
|
|
|
if snaparch == "armhf" {
|
|
|
|
goarch = "arm"
|
2018-06-26 23:08:57 -07:00
|
|
|
} else if snaparch == "i386" {
|
|
|
|
goarch = "386"
|
2016-11-12 01:36:19 -07:00
|
|
|
}
|
|
|
|
snapver := version
|
|
|
|
if strings.HasPrefix(snapver, "v") {
|
|
|
|
snapver = snapver[1:]
|
|
|
|
}
|
2016-11-12 01:43:12 -07:00
|
|
|
snapgrade := "devel"
|
2017-02-05 06:42:29 -07:00
|
|
|
if matched, _ := regexp.MatchString(`^\d+\.\d+\.\d+(-rc.\d+)?$`, snapver); matched {
|
2016-11-12 01:43:12 -07:00
|
|
|
snapgrade = "stable"
|
|
|
|
}
|
2016-11-08 17:52:33 -07:00
|
|
|
err = tmpl.Execute(f, map[string]string{
|
2018-06-26 23:08:57 -07:00
|
|
|
"Version": snapver,
|
|
|
|
"HostArchitecture": runtime.GOARCH,
|
|
|
|
"TargetArchitecture": snaparch,
|
|
|
|
"Grade": snapgrade,
|
2016-11-12 01:43:12 -07:00
|
|
|
})
|
2016-11-08 17:52:33 -07:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-10-20 02:16:30 -07:00
|
|
|
runPrint("snapcraft", "clean")
|
|
|
|
build(target, []string{"noupgrade"})
|
|
|
|
runPrint("snapcraft")
|
|
|
|
}
|
|
|
|
|
2018-03-26 11:44:44 -07:00
|
|
|
func shouldBuildSyso(dir string) (string, error) {
|
|
|
|
jsonPath := filepath.Join(dir, "versioninfo.json")
|
|
|
|
file, err := os.Create(filepath.Join(dir, "versioninfo.json"))
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.New("failed to create " + jsonPath + ": " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
major, minor, patch, build := semanticVersion()
|
|
|
|
fmt.Fprintf(file, `{
|
|
|
|
"FixedFileInfo": {
|
|
|
|
"FileVersion": {
|
|
|
|
"Major": %s,
|
|
|
|
"Minor": %s,
|
|
|
|
"Patch": %s,
|
|
|
|
"Build": %s
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"StringFileInfo": {
|
|
|
|
"FileDescription": "Open Source Continuous File Synchronization",
|
|
|
|
"LegalCopyright": "The Syncthing Authors",
|
|
|
|
"ProductVersion": "%s",
|
|
|
|
"ProductName": "Syncthing"
|
|
|
|
},
|
|
|
|
"IconPath": "assets/logo.ico"
|
|
|
|
}`, major, minor, patch, build, getVersion())
|
|
|
|
file.Close()
|
|
|
|
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")
|
|
|
|
|
|
|
|
if _, err := runError("goversioninfo", "-o", sysoPath); err != nil {
|
|
|
|
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 00:57:58 -07: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 09:39:53 -07:00
|
|
|
func copyFile(src, dst string, perm os.FileMode) error {
|
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 00:57:58 -07:00
|
|
|
in, err := ioutil.ReadFile(src)
|
2015-05-11 09:39:53 -07: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 00:57:58 -07:00
|
|
|
|
|
|
|
out, err := ioutil.ReadFile(dst)
|
2015-05-11 09:39:53 -07: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 00:57:58 -07: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)
|
|
|
|
if err := ioutil.WriteFile(dst, in, perm); err != nil {
|
2015-05-11 09:39:53 -07: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 00:57:58 -07:00
|
|
|
|
|
|
|
return nil
|
2015-05-11 09:39:53 -07:00
|
|
|
}
|
|
|
|
|
2014-11-24 05:48:52 -07: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
|
|
|
|
}
|
|
|
|
if fi.Mode().IsRegular() {
|
|
|
|
res = append(res, path)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2016-03-28 03:03:13 -07:00
|
|
|
func rebuildAssets() {
|
2018-05-28 23:49:25 -07:00
|
|
|
os.Setenv("SOURCE_DATE_EPOCH", fmt.Sprint(buildStamp()))
|
2018-06-26 00:14:21 -07:00
|
|
|
runPrint("go", "generate", "github.com/syncthing/syncthing/lib/auto", "github.com/syncthing/syncthing/cmd/strelaypoolsrv/auto")
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2016-03-28 03:03:13 -07:00
|
|
|
func lazyRebuildAssets() {
|
2018-06-26 00:14:21 -07:00
|
|
|
if shouldRebuildAssets("lib/auto/gui.files.go", "gui") || shouldRebuildAssets("cmd/strelaypoolsrv/auto/gui.files.go", "cmd/strelaypoolsrv/auto/gui") {
|
2016-03-28 03:03:13 -07:00
|
|
|
rebuildAssets()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 02:22:56 -07:00
|
|
|
func shouldRebuildAssets(target, srcdir string) bool {
|
|
|
|
info, err := os.Stat(target)
|
2016-03-28 03:03:13 -07: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 01:34:07 -07:00
|
|
|
stop := errors.New("no need to iterate further")
|
2016-07-04 02:22:56 -07:00
|
|
|
filepath.Walk(srcdir, func(path string, info os.FileInfo, err error) error {
|
2016-03-28 03:03:13 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-10-08 01:34:07 -07:00
|
|
|
if info.ModTime().After(currentBuild) {
|
|
|
|
assetsAreNewer = true
|
|
|
|
return stop
|
2016-03-28 03:03:13 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
return assetsAreNewer
|
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func proto() {
|
2018-12-18 04:36:38 -07:00
|
|
|
os.MkdirAll("repos", 0755)
|
|
|
|
for _, dep := range dependencyRepos {
|
|
|
|
path := filepath.Join("repos", dep.path)
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
runPrintInDir("repos", "git", "clone", dep.repo, dep.path)
|
|
|
|
runPrintInDir(path, "git", "checkout", dep.commit)
|
|
|
|
}
|
|
|
|
}
|
cmd/stdiscosrv: New discovery server (fixes #4618)
This is a new revision of the discovery server. Relevant changes and
non-changes:
- Protocol towards clients is unchanged.
- Recommended large scale design is still to be deployed nehind nginx (I
tested, and it's still a lot faster at terminating TLS).
- Database backend is leveldb again, only. It scales enough, is easy to
setup, and we don't need any backend to take care of.
- Server supports replication. This is a simple TCP channel - protect it
with a firewall when deploying over the internet. (We deploy this within
the same datacenter, and with firewall.) Any incoming client announces
are sent over the replication channel(s) to other peer discosrvs.
Incoming replication changes are applied to the database as if they came
from clients, but without the TLS/certificate overhead.
- Metrics are exposed using the prometheus library, when enabled.
- The database values and replication protocol is protobuf, because JSON
was quite CPU intensive when I tried that and benchmarked it.
- The "Retry-After" value for failed lookups gets slowly increased from
a default of 120 seconds, by 5 seconds for each failed lookup,
independently by each discosrv. This lowers the query load over time for
clients that are never seen. The Retry-After maxes out at 3600 after a
couple of weeks of this increase. The number of failed lookups is
stored in the database, now and then (avoiding making each lookup a
database put).
All in all this means clients can be pointed towards a cluster using
just multiple A / AAAA records to gain both load sharing and redundancy
(if one is down, clients will talk to the remaining ones).
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4648
2018-01-14 01:52:31 -07:00
|
|
|
runPrint("go", "generate", "github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/stdiscosrv")
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func translate() {
|
2016-01-10 08:37:31 -07:00
|
|
|
os.Chdir("gui/default/assets/lang")
|
2016-01-13 02:56:42 -07:00
|
|
|
runPipe("lang-en-new.json", "go", "run", "../../../../script/translate.go", "lang-en.json", "../../../")
|
2014-08-18 12:38:22 -07: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 02:56:42 -07:00
|
|
|
os.Chdir("../../../..")
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func transifex() {
|
2016-01-10 08:37:31 -07:00
|
|
|
os.Chdir("gui/default/assets/lang")
|
2016-01-13 02:56:42 -07:00
|
|
|
runPrint("go", "run", "../../../../script/transifexdl.go")
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func ldflags() string {
|
2016-03-05 14:25:28 -07:00
|
|
|
sep := '='
|
|
|
|
if goVersion > 0 && goVersion < 1.5 {
|
|
|
|
sep = ' '
|
2015-08-06 00:02:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
b := new(bytes.Buffer)
|
2014-08-18 12:38:22 -07:00
|
|
|
b.WriteString("-w")
|
2015-08-06 00:02:24 -07:00
|
|
|
fmt.Fprintf(b, " -X main.Version%c%s", sep, version)
|
|
|
|
fmt.Fprintf(b, " -X main.BuildStamp%c%d", sep, buildStamp())
|
|
|
|
fmt.Fprintf(b, " -X main.BuildUser%c%s", sep, buildUser())
|
|
|
|
fmt.Fprintf(b, " -X main.BuildHost%c%s", sep, buildHost())
|
2014-08-18 12:38:22 -07:00
|
|
|
return b.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func rmr(paths ...string) {
|
|
|
|
for _, path := range paths {
|
2016-08-14 13:48:11 -07:00
|
|
|
if debug {
|
|
|
|
log.Println("rm -r", path)
|
|
|
|
}
|
2014-08-18 12:38:22 -07:00
|
|
|
os.RemoveAll(path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 03:17:18 -07:00
|
|
|
func getReleaseVersion() (string, error) {
|
|
|
|
fd, err := os.Open("RELEASE")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer fd.Close()
|
|
|
|
|
|
|
|
bs, err := ioutil.ReadAll(fd)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(bytes.TrimSpace(bs)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getGitVersion() (string, error) {
|
2014-10-15 09:15:21 -07:00
|
|
|
v, err := runError("git", "describe", "--always", "--dirty")
|
2014-10-13 11:13:42 -07:00
|
|
|
if err != nil {
|
2015-03-12 03:17:18 -07:00
|
|
|
return "", err
|
2014-10-13 11:13:42 -07:00
|
|
|
}
|
2014-08-18 12:38:22 -07:00
|
|
|
v = versionRe.ReplaceAllFunc(v, func(s []byte) []byte {
|
|
|
|
s[0] = '+'
|
|
|
|
return s
|
|
|
|
})
|
2015-03-12 03:17:18 -07:00
|
|
|
return string(v), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getVersion() string {
|
|
|
|
// First try for a RELEASE file,
|
|
|
|
if ver, err := getReleaseVersion(); err == nil {
|
|
|
|
return ver
|
|
|
|
}
|
2015-03-13 02:10:13 -07:00
|
|
|
// ... then see if we have a Git tag.
|
2015-03-12 03:17:18 -07:00
|
|
|
if ver, err := getGitVersion(); err == nil {
|
2016-03-10 02:24:11 -07: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 03:17:18 -07:00
|
|
|
return ver
|
|
|
|
}
|
|
|
|
// This seems to be a dev build.
|
|
|
|
return "unknown-dev"
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2018-03-26 11:44:44 -07:00
|
|
|
func semanticVersion() (major, minor, patch, build string) {
|
|
|
|
r := regexp.MustCompile(`v(?P<Major>\d+)\.(?P<Minor>\d+).(?P<Patch>\d+).*\+(?P<CommitsAhead>\d+)`)
|
|
|
|
matches := r.FindStringSubmatch(getVersion())
|
|
|
|
if len(matches) != 5 {
|
|
|
|
return "0", "0", "0", "0"
|
|
|
|
}
|
|
|
|
return matches[1], matches[2], matches[3], matches[4]
|
|
|
|
}
|
|
|
|
|
2016-03-10 02:24:11 -07:00
|
|
|
func getBranchSuffix() string {
|
|
|
|
bs, err := runError("git", "branch", "-a", "--contains")
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-10 02:37:13 -07:00
|
|
|
branches := strings.Split(string(bs), "\n")
|
2016-03-10 02:24:11 -07:00
|
|
|
if len(branches) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-10 02:37:13 -07: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 02:24:11 -07:00
|
|
|
|
|
|
|
// The branch name may be on the form "remotes/origin/foo" from which we
|
|
|
|
// just want "foo".
|
2016-03-10 02:37:13 -07:00
|
|
|
parts := strings.Split(branch, "/")
|
2016-03-10 02:24:11 -07:00
|
|
|
if len(parts) == 0 || len(parts[len(parts)-1]) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
2016-03-10 02:37:13 -07:00
|
|
|
|
2016-03-10 02:47:15 -07:00
|
|
|
branch = parts[len(parts)-1]
|
2017-06-30 05:02:16 -07:00
|
|
|
switch branch {
|
|
|
|
case "master", "release":
|
|
|
|
// these are not special
|
2016-03-10 02:37:13 -07:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-10 02:49:11 -07:00
|
|
|
validBranchRe := regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)
|
2016-03-10 02:47:15 -07:00
|
|
|
if !validBranchRe.MatchString(branch) {
|
|
|
|
// There's some odd stuff in the branch name. Better skip it.
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-03-10 02:37:13 -07:00
|
|
|
return "-" + branch
|
2016-03-10 02:24:11 -07:00
|
|
|
}
|
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
func buildStamp() int64 {
|
2016-06-29 11:52:49 -07: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 09:15:21 -07:00
|
|
|
bs, err := runError("git", "show", "-s", "--format=%ct")
|
2014-10-13 11:13:42 -07:00
|
|
|
if err != nil {
|
2016-06-29 11:52:49 -07:00
|
|
|
// Fall back to "now".
|
2014-10-13 11:13:42 -07:00
|
|
|
return time.Now().Unix()
|
|
|
|
}
|
2016-06-29 11:52:49 -07:00
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
s, _ := strconv.ParseInt(string(bs), 10, 64)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildUser() string {
|
2016-07-27 14:27:45 -07:00
|
|
|
if v := os.Getenv("BUILD_USER"); v != "" {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
u, err := user.Current()
|
|
|
|
if err != nil {
|
|
|
|
return "unknown-user"
|
|
|
|
}
|
|
|
|
return strings.Replace(u.Username, " ", "-", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildHost() string {
|
2016-07-27 14:27:45 -07:00
|
|
|
if v := os.Getenv("BUILD_HOST"); v != "" {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
h, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
return "unknown-host"
|
|
|
|
}
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildArch() string {
|
|
|
|
os := goos
|
|
|
|
if os == "darwin" {
|
2018-06-13 14:20:52 -07:00
|
|
|
os = "macos"
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s-%s", os, goarch)
|
|
|
|
}
|
|
|
|
|
2016-04-06 14:18:30 -07:00
|
|
|
func archiveName(target target) string {
|
|
|
|
return fmt.Sprintf("%s-%s-%s", target.name, buildArch(), version)
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
2014-10-15 09:15:21 -07:00
|
|
|
func runError(cmd string, args ...string) ([]byte, error) {
|
2016-06-08 09:15:45 -07:00
|
|
|
if debug {
|
|
|
|
t0 := time.Now()
|
|
|
|
log.Println("runError:", cmd, strings.Join(args, " "))
|
|
|
|
defer func() {
|
|
|
|
log.Println("... in", time.Since(t0))
|
|
|
|
}()
|
|
|
|
}
|
2014-10-15 09:15:21 -07:00
|
|
|
ecmd := exec.Command(cmd, args...)
|
|
|
|
bs, err := ecmd.CombinedOutput()
|
2015-04-28 13:32:10 -07:00
|
|
|
return bytes.TrimSpace(bs), err
|
2014-10-15 09:15:21 -07:00
|
|
|
}
|
|
|
|
|
2014-08-18 12:38:22 -07:00
|
|
|
func runPrint(cmd string, args ...string) {
|
2018-12-18 04:36:38 -07:00
|
|
|
runPrintInDir(".", cmd, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runPrintInDir(dir string, cmd string, args ...string) {
|
2016-06-08 09:15:45 -07:00
|
|
|
if debug {
|
|
|
|
t0 := time.Now()
|
|
|
|
log.Println("runPrint:", cmd, strings.Join(args, " "))
|
|
|
|
defer func() {
|
|
|
|
log.Println("... in", time.Since(t0))
|
|
|
|
}()
|
|
|
|
}
|
2014-08-18 12:38:22 -07:00
|
|
|
ecmd := exec.Command(cmd, args...)
|
|
|
|
ecmd.Stdout = os.Stdout
|
|
|
|
ecmd.Stderr = os.Stderr
|
2018-12-18 04:36:38 -07:00
|
|
|
ecmd.Dir = dir
|
2014-08-18 12:38:22 -07:00
|
|
|
err := ecmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runPipe(file, cmd string, args ...string) {
|
2016-06-08 09:15:45 -07:00
|
|
|
if debug {
|
|
|
|
t0 := time.Now()
|
|
|
|
log.Println("runPipe:", cmd, strings.Join(args, " "))
|
|
|
|
defer func() {
|
|
|
|
log.Println("... in", time.Since(t0))
|
|
|
|
}()
|
|
|
|
}
|
2014-08-18 12:38:22 -07: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 13:19:29 -07:00
|
|
|
fd.Close()
|
2014-08-18 12:38:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func tarGz(out string, files []archiveFile) {
|
|
|
|
fd, err := os.Create(out)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-07-17 06:20:13 -07:00
|
|
|
gw, err := gzip.NewWriterLevel(fd, gzip.BestCompression)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-08-18 12:38:22 -07: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 06:20:13 -07: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 12:38:22 -07: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 02:49:19 -07:00
|
|
|
fh.Name = filepath.ToSlash(f.dst)
|
2014-08-18 12:38:22 -07:00
|
|
|
fh.Method = zip.Deflate
|
|
|
|
|
|
|
|
if strings.HasSuffix(f.dst, ".txt") {
|
|
|
|
// Text file. Read it and convert line endings.
|
|
|
|
bs, err := ioutil.ReadAll(sf)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
bs = bytes.Replace(bs, []byte{'\n'}, []byte{'\n', '\r'}, -1)
|
|
|
|
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 02:52:09 -07:00
|
|
|
|
2016-01-16 11:43:50 -07: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 != "" {
|
|
|
|
bs, err := runError("codesign", "-s", id, file)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Codesign: signing failed:", string(bs))
|
|
|
|
return
|
|
|
|
}
|
2016-01-16 11:59:01 -07:00
|
|
|
log.Println("Codesign: successfully signed", file)
|
2016-01-16 11:43:50 -07:00
|
|
|
}
|
|
|
|
}
|
2016-04-15 00:26:25 -07:00
|
|
|
|
2017-11-20 00:10:18 -07:00
|
|
|
func windowsCodesign(file string) {
|
|
|
|
st := "signtool.exe"
|
2017-11-20 06:54:52 -07:00
|
|
|
|
2017-11-20 00:10:18 -07:00
|
|
|
if path := os.Getenv("CODESIGN_SIGNTOOL"); path != "" {
|
|
|
|
st = path
|
|
|
|
}
|
|
|
|
|
2017-11-20 06:54:52 -07: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)
|
|
|
|
}
|
|
|
|
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 {
|
|
|
|
log.Println("Codesign: signing failed:", string(bs))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Println("Codesign: successfully signed", file, "using", algo)
|
2017-11-20 00:10:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-07 13:43:26 -07:00
|
|
|
func metalint() {
|
|
|
|
lazyRebuildAssets()
|
|
|
|
runPrint("go", "test", "-run", "Metalint", "./meta")
|
2016-05-23 14:19:08 -07:00
|
|
|
}
|
|
|
|
|
2017-07-07 13:43:26 -07:00
|
|
|
func metalintShort() {
|
|
|
|
lazyRebuildAssets()
|
|
|
|
runPrint("go", "test", "-short", "-run", "Metalint", "./meta")
|
2016-05-23 14:19:08 -07: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 00:57:58 -07:00
|
|
|
|
|
|
|
func temporaryBuildDir() (string, error) {
|
|
|
|
// The base of our temp dir is "syncthing-xxxxxxxx" where the x:es
|
|
|
|
// are eight bytes from the sha256 of our working directory. We do
|
|
|
|
// this because we want a name in the global temp dir that doesn't
|
|
|
|
// conflict with someone else building syncthing on the same
|
|
|
|
// machine, yet is persistent between runs from the same source
|
|
|
|
// directory.
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
hash := sha256.Sum256([]byte(wd))
|
|
|
|
base := fmt.Sprintf("syncthing-%x", hash[:4])
|
|
|
|
|
|
|
|
// The temp dir is taken from $STTMPDIR if set, otherwise the system
|
|
|
|
// default (potentially infrluenced by $TMPDIR on unixes).
|
|
|
|
var tmpDir string
|
|
|
|
if t := os.Getenv("STTMPDIR"); t != "" {
|
|
|
|
tmpDir = t
|
|
|
|
} else {
|
|
|
|
tmpDir = os.TempDir()
|
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Join(tmpDir, base), nil
|
|
|
|
}
|
|
|
|
|
2017-07-17 06:20:13 -07:00
|
|
|
func (t target) BinaryName() string {
|
|
|
|
if goos == "windows" {
|
|
|
|
return t.binaryName + ".exe"
|
|
|
|
}
|
|
|
|
return t.binaryName
|
|
|
|
}
|