2014-03-17 17:15:59 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-12-21 23:16:49 +00:00
|
|
|
|
2014-02-01 19:23:02 +00:00
|
|
|
export COPYFILE_DISABLE=true
|
2014-05-25 19:36:38 +00:00
|
|
|
export GO386=387 # Don't use SSE on 32 bit builds
|
2014-02-01 19:23:02 +00:00
|
|
|
|
2014-05-28 17:09:27 +00:00
|
|
|
distFiles=(README.md LICENSE CONTRIBUTORS) # apart from the binary itself
|
2014-08-05 17:38:31 +00:00
|
|
|
|
|
|
|
# replace "...-12-g123abc" with "...+12-g123abc" to remain semver compatible-ish
|
2014-03-28 13:36:57 +00:00
|
|
|
version=$(git describe --always --dirty)
|
2014-08-05 17:38:31 +00:00
|
|
|
version=$(echo "$version" | sed 's/-\([0-9]\{1,3\}-g[0-9a-f]\{5,10\}\)/+\1/')
|
|
|
|
|
2014-05-11 20:26:48 +00:00
|
|
|
date=$(git show -s --format=%ct)
|
2014-04-19 14:44:28 +00:00
|
|
|
user=$(whoami)
|
2014-04-22 06:25:40 +00:00
|
|
|
host=$(hostname)
|
|
|
|
host=${host%%.*}
|
2014-06-13 18:44:00 +00:00
|
|
|
bldenv=${ENVIRONMENT:-default}
|
|
|
|
ldflags="-w -X main.Version $version -X main.BuildStamp $date -X main.BuildUser $user -X main.BuildHost $host -X main.BuildEnv $bldenv"
|
2013-12-21 23:16:49 +00:00
|
|
|
|
2014-05-12 23:00:57 +00:00
|
|
|
check() {
|
|
|
|
if ! command -v godep >/dev/null ; then
|
|
|
|
echo "Error: no godep. Try \"$0 setup\"."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-03-02 22:55:08 +00:00
|
|
|
build() {
|
2014-05-12 23:00:57 +00:00
|
|
|
check
|
|
|
|
godep go build $* -ldflags "$ldflags" ./cmd/syncthing
|
2014-03-02 22:55:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-08 13:16:07 +00:00
|
|
|
assets() {
|
2014-05-12 23:00:57 +00:00
|
|
|
check
|
2014-07-23 06:31:13 +00:00
|
|
|
godep go run cmd/genassets/main.go gui > auto/gui.files.go
|
2014-03-02 22:55:08 +00:00
|
|
|
}
|
|
|
|
|
2014-06-08 22:55:34 +00:00
|
|
|
test-cov() {
|
2014-06-10 14:55:16 +00:00
|
|
|
echo "mode: set" > coverage.out
|
|
|
|
fail=0
|
|
|
|
|
|
|
|
for dir in $(go list ./...) ; do
|
|
|
|
godep go test -coverprofile=profile.out $dir || fail=1
|
|
|
|
if [ -f profile.out ] ; then
|
|
|
|
grep -v "mode: set" profile.out >> coverage.out
|
2014-07-31 10:51:50 +00:00
|
|
|
rm profile.out
|
2014-06-10 14:55:16 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-06-08 22:55:34 +00:00
|
|
|
|
|
|
|
exit $fail
|
|
|
|
}
|
|
|
|
|
2014-03-02 22:55:08 +00:00
|
|
|
test() {
|
2014-05-12 23:00:57 +00:00
|
|
|
check
|
2014-07-12 17:33:38 +00:00
|
|
|
go vet ./...
|
2014-08-01 14:30:13 +00:00
|
|
|
godep go test -cpu=1,2,4 $* ./...
|
2014-03-21 06:40:48 +00:00
|
|
|
}
|
2014-03-02 22:55:08 +00:00
|
|
|
|
2014-03-22 20:38:01 +00:00
|
|
|
sign() {
|
2014-03-28 13:36:57 +00:00
|
|
|
if git describe --exact-match 2>/dev/null >/dev/null ; then
|
|
|
|
# HEAD is a tag
|
|
|
|
id=BCE524C7
|
|
|
|
if gpg --list-keys "$id" >/dev/null 2>&1 ; then
|
|
|
|
gpg -ab -u "$id" "$1"
|
|
|
|
fi
|
2014-03-22 20:38:01 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-03-02 22:55:08 +00:00
|
|
|
tarDist() {
|
|
|
|
name="$1"
|
2014-03-21 06:40:48 +00:00
|
|
|
rm -rf "$name"
|
2014-03-02 22:55:08 +00:00
|
|
|
mkdir -p "$name"
|
|
|
|
cp syncthing "${distFiles[@]}" "$name"
|
2014-03-22 20:38:01 +00:00
|
|
|
sign "$name/syncthing"
|
2014-03-02 22:55:08 +00:00
|
|
|
tar zcvf "$name.tar.gz" "$name"
|
|
|
|
rm -rf "$name"
|
|
|
|
}
|
|
|
|
|
|
|
|
zipDist() {
|
|
|
|
name="$1"
|
2014-03-21 06:40:48 +00:00
|
|
|
rm -rf "$name"
|
2014-03-02 22:55:08 +00:00
|
|
|
mkdir -p "$name"
|
2014-05-28 17:28:17 +00:00
|
|
|
for f in "${distFiles[@]}" ; do
|
2014-07-12 17:43:47 +00:00
|
|
|
GOARCH="" GOOS="" go run cmd/todos/main.go < "$f" > "$name/$f.txt"
|
2014-05-28 17:28:17 +00:00
|
|
|
done
|
|
|
|
cp syncthing.exe "$name"
|
2014-03-22 20:38:01 +00:00
|
|
|
sign "$name/syncthing.exe"
|
2014-03-02 22:55:08 +00:00
|
|
|
zip -r "$name.zip" "$name"
|
|
|
|
rm -rf "$name"
|
|
|
|
}
|
|
|
|
|
2014-04-08 13:14:36 +00:00
|
|
|
deps() {
|
2014-05-12 23:00:57 +00:00
|
|
|
check
|
2014-07-23 05:59:45 +00:00
|
|
|
godep save ./cmd/...
|
2014-04-08 13:14:36 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 23:00:57 +00:00
|
|
|
setup() {
|
2014-07-31 13:37:34 +00:00
|
|
|
go get -v code.google.com/p/go.tools/cmd/cover
|
|
|
|
go get -v code.google.com/p/go.tools/cmd/vet
|
|
|
|
go get -v github.com/mattn/goveralls
|
|
|
|
go get -v github.com/tools/godep
|
2014-05-12 23:00:57 +00:00
|
|
|
}
|
|
|
|
|
2014-07-06 17:21:37 +00:00
|
|
|
xdr() {
|
2014-07-12 21:06:48 +00:00
|
|
|
for f in discover/packets files/leveldb protocol/message ; do
|
2014-08-01 11:12:54 +00:00
|
|
|
go run "$(godep path)/src/github.com/calmh/xdr/cmd/genxdr/main.go" -- "${f}.go" > "${f}_xdr.go"
|
2014-07-06 17:21:37 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-07-31 07:08:08 +00:00
|
|
|
translate() {
|
|
|
|
pushd gui
|
|
|
|
go run ../cmd/translate/main.go lang-en.json < index.html > lang-en-new.json
|
|
|
|
mv lang-en-new.json lang-en.json
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
2014-07-28 13:14:02 +00:00
|
|
|
transifex() {
|
|
|
|
pushd gui
|
2014-08-06 12:56:32 +00:00
|
|
|
go run ../cmd/transifexdl/main.go
|
2014-07-28 13:14:02 +00:00
|
|
|
popd
|
2014-07-30 09:52:16 +00:00
|
|
|
assets
|
2014-07-28 13:14:02 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 09:59:33 +00:00
|
|
|
build-all() {
|
|
|
|
rm -f *.tar.gz *.zip
|
|
|
|
test -short || exit 1
|
|
|
|
assets
|
|
|
|
|
|
|
|
rm -rf bin Godeps/_workspace/pkg $GOPATH/pkg/*/github.com/syncthing
|
2014-08-13 07:42:21 +00:00
|
|
|
for os in darwin-amd64 freebsd-amd64 freebsd-386 linux-amd64 linux-386 windows-amd64 windows-386 ; do
|
2014-08-11 09:59:33 +00:00
|
|
|
export GOOS=${os%-*}
|
|
|
|
export GOARCH=${os#*-}
|
|
|
|
|
|
|
|
build $*
|
|
|
|
|
|
|
|
name="syncthing-${os/darwin/macosx}-$version"
|
|
|
|
case $GOOS in
|
|
|
|
windows)
|
|
|
|
zipDist "$name"
|
|
|
|
rm -f syncthing.exe
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
tarDist "$name"
|
|
|
|
rm -f syncthing
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
export GOOS=linux
|
|
|
|
export GOARCH=arm
|
|
|
|
|
|
|
|
origldflags="$ldflags"
|
|
|
|
|
|
|
|
export GOARM=7
|
|
|
|
ldflags="$origldflags -X main.GoArchExtra v7"
|
|
|
|
build $*
|
|
|
|
tarDist "syncthing-linux-armv7-$version"
|
|
|
|
|
|
|
|
export GOARM=6
|
|
|
|
ldflags="$origldflags -X main.GoArchExtra v6"
|
|
|
|
build $*
|
|
|
|
tarDist "syncthing-linux-armv6-$version"
|
|
|
|
|
|
|
|
export GOARM=5
|
|
|
|
ldflags="$origldflags -X main.GoArchExtra v5"
|
|
|
|
build $*
|
|
|
|
tarDist "syncthing-linux-armv5-$version"
|
|
|
|
}
|
|
|
|
|
2014-03-02 22:55:08 +00:00
|
|
|
case "$1" in
|
|
|
|
"")
|
2014-04-09 21:00:23 +00:00
|
|
|
shift
|
2014-07-24 07:56:00 +00:00
|
|
|
export GOBIN=$(pwd)/bin
|
|
|
|
godep go install $* -ldflags "$ldflags" ./cmd/...
|
2014-03-02 22:55:08 +00:00
|
|
|
;;
|
|
|
|
|
2014-08-11 09:54:48 +00:00
|
|
|
clean)
|
|
|
|
rm -rf bin Godeps/_workspace/pkg $GOPATH/pkg/*/github.com/syncthing
|
|
|
|
;;
|
|
|
|
|
2014-08-11 09:59:33 +00:00
|
|
|
noupgrade)
|
|
|
|
export GOBIN=$(pwd)/bin
|
|
|
|
godep go install -tags noupgrade -ldflags "$ldflags" ./cmd/...
|
|
|
|
;;
|
|
|
|
|
2014-03-29 17:53:48 +00:00
|
|
|
race)
|
|
|
|
build -race
|
|
|
|
;;
|
|
|
|
|
2014-05-12 23:04:49 +00:00
|
|
|
guidev)
|
2014-05-22 14:12:19 +00:00
|
|
|
echo "Syncthing is already built for GUI developments. Try:"
|
|
|
|
echo " STGUIASSETS=~/someDir/gui syncthing"
|
2014-05-12 23:04:49 +00:00
|
|
|
;;
|
|
|
|
|
2014-03-22 20:33:18 +00:00
|
|
|
test)
|
2014-08-01 14:30:13 +00:00
|
|
|
test -short
|
2014-03-22 20:33:18 +00:00
|
|
|
;;
|
|
|
|
|
2014-06-08 22:55:34 +00:00
|
|
|
test-cov)
|
|
|
|
test-cov
|
|
|
|
;;
|
|
|
|
|
2014-03-02 22:55:08 +00:00
|
|
|
tar)
|
2014-03-21 06:40:48 +00:00
|
|
|
rm -f *.tar.gz *.zip
|
2014-08-01 14:30:13 +00:00
|
|
|
test -short || exit 1
|
2014-04-08 13:16:07 +00:00
|
|
|
assets
|
2014-03-02 22:55:08 +00:00
|
|
|
build
|
|
|
|
|
|
|
|
eval $(go env)
|
2014-08-01 14:30:28 +00:00
|
|
|
name="syncthing-${GOOS/darwin/macosx}-$GOARCH-$version"
|
2014-03-02 22:55:08 +00:00
|
|
|
|
|
|
|
tarDist "$name"
|
|
|
|
;;
|
|
|
|
|
|
|
|
all)
|
2014-08-11 09:59:33 +00:00
|
|
|
shift
|
|
|
|
build-all
|
|
|
|
;;
|
2014-05-06 11:13:56 +00:00
|
|
|
|
2014-08-11 09:59:33 +00:00
|
|
|
all-noupgrade)
|
|
|
|
shift
|
|
|
|
build-all -tags noupgrade
|
2014-03-02 22:55:08 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
upload)
|
|
|
|
tag=$(git describe)
|
|
|
|
shopt -s nullglob
|
2014-03-20 16:55:16 +00:00
|
|
|
for f in *.tar.gz *.zip *.asc ; do
|
2014-08-01 14:35:37 +00:00
|
|
|
relup syncthing/syncthing "$tag" "$f"
|
2014-03-02 22:55:08 +00:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
|
2014-04-08 13:14:36 +00:00
|
|
|
deps)
|
|
|
|
deps
|
|
|
|
;;
|
|
|
|
|
2014-04-08 13:16:07 +00:00
|
|
|
assets)
|
|
|
|
assets
|
|
|
|
;;
|
|
|
|
|
2014-05-12 23:00:57 +00:00
|
|
|
setup)
|
|
|
|
setup
|
|
|
|
;;
|
|
|
|
|
2014-07-06 17:21:37 +00:00
|
|
|
xdr)
|
|
|
|
xdr
|
|
|
|
;;
|
|
|
|
|
2014-07-31 07:08:08 +00:00
|
|
|
translate)
|
|
|
|
translate
|
|
|
|
;;
|
|
|
|
|
2014-07-28 13:14:02 +00:00
|
|
|
transifex)
|
|
|
|
transifex
|
|
|
|
;;
|
|
|
|
|
2014-03-02 22:55:08 +00:00
|
|
|
*)
|
|
|
|
echo "Unknown build parameter $1"
|
|
|
|
;;
|
|
|
|
esac
|