syncthing/build.sh

216 lines
3.6 KiB
Bash
Raw Normal View History

2014-03-17 10:15:59 -07:00
#!/usr/bin/env bash
2013-12-21 16:16:49 -07:00
export COPYFILE_DISABLE=true
export GO386=387 # Don't use SSE on 32 bit builds
distFiles=(README.md LICENSE CONTRIBUTORS) # apart from the binary itself
version=$(git describe --always --dirty)
date=$(git show -s --format=%ct)
user=$(whoami)
2014-04-21 23:25:40 -07:00
host=$(hostname)
host=${host%%.*}
2014-06-13 11:44:00 -07: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 16:16:49 -07:00
2014-05-12 16:00:57 -07:00
check() {
if ! command -v godep >/dev/null ; then
echo "Error: no godep. Try \"$0 setup\"."
exit 1
fi
}
2014-03-02 15:55:08 -07:00
build() {
2014-05-12 16:00:57 -07:00
check
godep go build $* -ldflags "$ldflags" ./cmd/syncthing
2014-03-02 15:55:08 -07:00
}
assets() {
2014-05-12 16:00:57 -07:00
check
godep go run cmd/assets/assets.go gui > auto/gui.files.go
2014-03-02 15:55:08 -07:00
}
test-cov() {
2014-06-10 07:55:16 -07: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
rm profile.out
fi
done
exit $fail
}
2014-03-02 15:55:08 -07:00
test() {
2014-05-12 16:00:57 -07:00
check
2014-07-12 10:33:38 -07:00
go vet ./...
godep go test -cpu=1,2,4 ./...
}
2014-03-02 15:55:08 -07:00
2014-03-22 13:38:01 -07:00
sign() {
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 13:38:01 -07:00
fi
}
2014-03-02 15:55:08 -07:00
tarDist() {
name="$1"
rm -rf "$name"
2014-03-02 15:55:08 -07:00
mkdir -p "$name"
cp syncthing "${distFiles[@]}" "$name"
2014-03-22 13:38:01 -07:00
sign "$name/syncthing"
2014-03-02 15:55:08 -07:00
tar zcvf "$name.tar.gz" "$name"
rm -rf "$name"
}
zipDist() {
name="$1"
rm -rf "$name"
2014-03-02 15:55:08 -07:00
mkdir -p "$name"
for f in "${distFiles[@]}" ; do
2014-07-12 10:43:47 -07:00
GOARCH="" GOOS="" go run cmd/todos/main.go < "$f" > "$name/$f.txt"
done
cp syncthing.exe "$name"
2014-03-22 13:38:01 -07:00
sign "$name/syncthing.exe"
2014-03-02 15:55:08 -07:00
zip -r "$name.zip" "$name"
rm -rf "$name"
}
2014-04-08 06:14:36 -07:00
deps() {
2014-05-12 16:00:57 -07:00
check
2014-05-11 11:40:14 -07:00
godep save ./cmd/syncthing ./cmd/assets ./discover/cmd/discosrv
2014-04-08 06:14:36 -07:00
}
2014-05-12 16:00:57 -07:00
setup() {
echo Installing godep...
go get -u github.com/tools/godep
echo Installing go vet...
go get -u code.google.com/p/go.tools/cmd/vet
}
xdr() {
go install ./xdr/cmd/genxdr
for f in discover/packets files/leveldb protocol/message scanner/blocks scanner/file ; do
genxdr "${f}.go" > "${f}_xdr.go"
done
}
2014-03-02 15:55:08 -07:00
case "$1" in
"")
2014-04-09 14:00:23 -07:00
shift
build $*
2014-03-02 15:55:08 -07:00
;;
race)
build -race
;;
2014-05-12 16:04:49 -07:00
guidev)
echo "Syncthing is already built for GUI developments. Try:"
echo " STGUIASSETS=~/someDir/gui syncthing"
2014-05-12 16:04:49 -07:00
;;
2014-03-22 13:33:18 -07:00
test)
test
;;
test-cov)
test-cov
;;
2014-03-02 15:55:08 -07:00
tar)
rm -f *.tar.gz *.zip
2014-03-02 15:55:08 -07:00
test || exit 1
assets
2014-03-02 15:55:08 -07:00
build
eval $(go env)
name="syncthing-$GOOS-$GOARCH-$version"
tarDist "$name"
;;
all)
rm -f *.tar.gz *.zip
2014-03-02 15:55:08 -07:00
test || exit 1
assets
2014-03-02 15:55:08 -07:00
godep go build ./discover/cmd/discosrv
2014-07-12 10:33:52 -07:00
for os in darwin-amd64 linux-386 linux-amd64 freebsd-amd64 windows-amd64 windows-386 ; do
2014-03-02 15:55:08 -07:00
export GOOS=${os%-*}
export GOARCH=${os#*-}
build
2014-03-02 15:55:08 -07:00
name="syncthing-$os-$version"
case $GOOS in
windows)
zipDist "$name"
rm -f syncthing.exe
;;
*)
tarDist "$name"
rm -f syncthing
;;
esac
done
2014-03-30 20:59:40 -07:00
export GOOS=linux
export GOARCH=arm
origldflags="$ldflags"
2014-03-30 20:59:40 -07:00
export GOARM=7
ldflags="$origldflags -X main.GoArchExtra v7"
2014-03-30 20:59:40 -07:00
build
tarDist "syncthing-linux-armv7-$version"
export GOARM=6
ldflags="$origldflags -X main.GoArchExtra v6"
2014-03-30 20:59:40 -07:00
build
tarDist "syncthing-linux-armv6-$version"
2014-05-06 04:13:56 -07:00
export GOARM=5
ldflags="$origldflags -X main.GoArchExtra v5"
2014-05-06 04:13:56 -07:00
build
tarDist "syncthing-linux-armv5-$version"
2014-03-02 15:55:08 -07:00
;;
upload)
tag=$(git describe)
shopt -s nullglob
for f in *.tar.gz *.zip *.asc ; do
2014-03-02 15:55:08 -07:00
relup calmh/syncthing "$tag" "$f"
done
;;
2014-04-08 06:14:36 -07:00
deps)
deps
;;
assets)
assets
;;
2014-05-12 16:00:57 -07:00
setup)
setup
;;
xdr)
xdr
;;
2014-03-02 15:55:08 -07:00
*)
echo "Unknown build parameter $1"
;;
esac