syncthing/build.sh

239 lines
4.0 KiB
Bash
Raw Normal View History

2014-03-17 18:15:59 +01:00
#!/usr/bin/env bash
2013-12-22 00:16:49 +01: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
# replace "...-12-g123abc" with "...+12-g123abc" to remain semver compatible-ish
version=$(git describe --always --dirty)
version=$(echo "$version" | sed 's/-\([0-9]\{1,3\}-g[0-9a-f]\{5,10\}\)/+\1/')
date=$(git show -s --format=%ct)
user=$(whoami)
2014-04-22 08:25:40 +02:00
host=$(hostname)
host=${host%%.*}
2014-06-13 20:44:00 +02: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-22 00:16:49 +01:00
2014-05-13 01:00:57 +02:00
check() {
if ! command -v godep >/dev/null ; then
echo "Error: no godep. Try \"$0 setup\"."
exit 1
fi
}
2014-03-02 23:55:08 +01:00
build() {
2014-05-13 01:00:57 +02:00
check
godep go build $* -ldflags "$ldflags" ./cmd/syncthing
2014-03-02 23:55:08 +01:00
}
assets() {
2014-05-13 01:00:57 +02:00
check
2014-07-23 08:31:13 +02:00
godep go run cmd/genassets/main.go gui > auto/gui.files.go
2014-03-02 23:55:08 +01:00
}
test-cov() {
2014-06-10 16:55:16 +02: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
2014-06-10 16:55:16 +02:00
fi
done
exit $fail
}
2014-03-02 23:55:08 +01:00
test() {
2014-05-13 01:00:57 +02:00
check
2014-07-12 19:33:38 +02:00
go vet ./...
godep go test -cpu=1,2,4 $* ./...
}
2014-03-02 23:55:08 +01:00
tarDist() {
name="$1"
rm -rf "$name"
2014-03-02 23:55:08 +01:00
mkdir -p "$name"
cp syncthing "${distFiles[@]}" "$name"
tar zcvf "$name.tar.gz" "$name"
rm -rf "$name"
}
zipDist() {
name="$1"
rm -rf "$name"
2014-03-02 23:55:08 +01:00
mkdir -p "$name"
for f in "${distFiles[@]}" ; do
2014-07-12 19:43:47 +02:00
GOARCH="" GOOS="" go run cmd/todos/main.go < "$f" > "$name/$f.txt"
done
cp syncthing.exe "$name"
2014-03-02 23:55:08 +01:00
zip -r "$name.zip" "$name"
rm -rf "$name"
}
2014-04-08 15:14:36 +02:00
deps() {
2014-05-13 01:00:57 +02:00
check
2014-07-23 07:59:45 +02:00
godep save ./cmd/...
2014-04-08 15:14:36 +02:00
}
2014-05-13 01:00:57 +02:00
setup() {
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-13 01:00:57 +02:00
}
xdr() {
2014-07-12 23:06:48 +02:00
for f in discover/packets files/leveldb protocol/message ; do
2014-08-01 13:12:54 +02:00
go run "$(godep path)/src/github.com/calmh/xdr/cmd/genxdr/main.go" -- "${f}.go" > "${f}_xdr.go"
done
}
2014-07-31 09:08:08 +02: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
}
transifex() {
pushd gui
go run ../cmd/transifexdl/main.go
popd
2014-07-30 11:52:16 +02:00
assets
}
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 09:42:21 +02:00
for os in darwin-amd64 freebsd-amd64 freebsd-386 linux-amd64 linux-386 windows-amd64 windows-386 ; do
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 23:55:08 +01:00
case "$1" in
"")
2014-04-09 23:00:23 +02:00
shift
export GOBIN=$(pwd)/bin
godep go install $* -ldflags "$ldflags" ./cmd/...
2014-03-02 23:55:08 +01:00
;;
2014-08-11 11:54:48 +02:00
clean)
rm -rf bin Godeps/_workspace/pkg $GOPATH/pkg/*/github.com/syncthing
;;
noupgrade)
export GOBIN=$(pwd)/bin
godep go install -tags noupgrade -ldflags "$ldflags" ./cmd/...
;;
race)
build -race
;;
2014-05-13 01:04:49 +02:00
guidev)
echo "Syncthing is already built for GUI developments. Try:"
echo " STGUIASSETS=~/someDir/gui syncthing"
2014-05-13 01:04:49 +02:00
;;
2014-03-22 21:33:18 +01:00
test)
test -short
2014-03-22 21:33:18 +01:00
;;
test-cov)
test-cov
;;
2014-03-02 23:55:08 +01:00
tar)
rm -f *.tar.gz *.zip
test -short || exit 1
assets
2014-03-02 23:55:08 +01:00
build
eval $(go env)
name="syncthing-${GOOS/darwin/macosx}-$GOARCH-$version"
2014-03-02 23:55:08 +01:00
tarDist "$name"
;;
all)
shift
build-all
;;
2014-05-06 13:13:56 +02:00
all-noupgrade)
shift
build-all -tags noupgrade
2014-03-02 23:55:08 +01:00
;;
2014-04-08 15:14:36 +02:00
deps)
deps
;;
assets)
assets
;;
2014-05-13 01:00:57 +02:00
setup)
setup
;;
xdr)
xdr
;;
2014-07-31 09:08:08 +02:00
translate)
translate
;;
transifex)
transifex
;;
2014-03-02 23:55:08 +01:00
*)
echo "Unknown build parameter $1"
;;
esac