build.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. STTRACE=${STTRACE:-}
  5. script() {
  6. name="$1"
  7. shift
  8. go run "script/$name.go" "$@"
  9. }
  10. build() {
  11. go run build.go "$@"
  12. }
  13. case "${1:-default}" in
  14. default)
  15. build
  16. ;;
  17. clean)
  18. build "$@"
  19. ;;
  20. tar)
  21. build "$@"
  22. ;;
  23. assets)
  24. build "$@"
  25. ;;
  26. xdr)
  27. build "$@"
  28. ;;
  29. translate)
  30. build "$@"
  31. ;;
  32. deb)
  33. build "$@"
  34. ;;
  35. setup)
  36. build "$@"
  37. ;;
  38. test)
  39. ulimit -t 600 &>/dev/null || true
  40. ulimit -d 512000 &>/dev/null || true
  41. ulimit -m 512000 &>/dev/null || true
  42. LOGGER_DISCARD=1 build test
  43. ;;
  44. bench)
  45. LOGGER_DISCARD=1 build bench | script benchfilter
  46. ;;
  47. prerelease)
  48. go run script/authors.go
  49. build transifex
  50. git add -A gui/default/assets/ lib/auto/
  51. pushd man ; ./refresh.sh ; popd
  52. git add -A man
  53. ;;
  54. noupgrade)
  55. build -no-upgrade tar
  56. ;;
  57. all)
  58. platforms=(
  59. darwin-amd64 dragonfly-amd64 freebsd-amd64 linux-amd64 netbsd-amd64 openbsd-amd64 solaris-amd64 windows-amd64
  60. freebsd-386 linux-386 netbsd-386 openbsd-386 windows-386
  61. linux-arm linux-arm64 linux-ppc64 linux-ppc64le
  62. )
  63. for plat in "${platforms[@]}"; do
  64. echo Building "$plat"
  65. goos="${plat%-*}"
  66. goarch="${plat#*-}"
  67. dist="tar"
  68. if [[ $goos == "windows" ]]; then
  69. dist="zip"
  70. fi
  71. build -goos "$goos" -goarch "$goarch" "$dist"
  72. echo
  73. done
  74. ;;
  75. test-cov)
  76. ulimit -t 600 &>/dev/null || true
  77. ulimit -d 512000 &>/dev/null || true
  78. ulimit -m 512000 &>/dev/null || true
  79. echo "mode: set" > coverage.out
  80. fail=0
  81. # For every package in the repo
  82. for dir in $(go list ./lib/... ./cmd/...) ; do
  83. # run the tests
  84. GOPATH="$(pwd)/Godeps/_workspace:$GOPATH" go test -race -coverprofile=profile.out $dir
  85. if [ -f profile.out ] ; then
  86. # and if there was test output, append it to coverage.out
  87. grep -v "mode: " profile.out >> coverage.out
  88. rm profile.out
  89. fi
  90. done
  91. gocov convert coverage.out | gocov-xml > coverage.xml
  92. # This is usually run from within Jenkins. If it is, we need to
  93. # tweak the paths in coverage.xml so cobertura finds the
  94. # source.
  95. if [[ "${WORKSPACE:-default}" != "default" ]] ; then
  96. sed "s#$WORKSPACE##g" < coverage.xml > coverage.xml.new && mv coverage.xml.new coverage.xml
  97. fi
  98. ;;
  99. test-xunit)
  100. ulimit -t 600 &>/dev/null || true
  101. ulimit -d 512000 &>/dev/null || true
  102. ulimit -m 512000 &>/dev/null || true
  103. (GOPATH="$(pwd)/Godeps/_workspace:$GOPATH" go test -v -race ./lib/... ./cmd/... || true) > tests.out
  104. go2xunit -output tests.xml -fail < tests.out
  105. ;;
  106. docker-all)
  107. img=${DOCKERIMG:-syncthing/build:latest}
  108. docker run --rm -h syncthing-builder -u $(id -u) -t \
  109. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  110. -w /go/src/github.com/syncthing/syncthing \
  111. -e "STTRACE=$STTRACE" \
  112. "$img" \
  113. sh -c './build.sh clean \
  114. && ./build.sh test-cov \
  115. && ./build.sh bench \
  116. && ./build.sh all'
  117. ;;
  118. docker-test)
  119. img=${DOCKERIMG:-syncthing/build:latest}
  120. docker run --rm -h syncthing-builder -u $(id -u) -t \
  121. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  122. -w /go/src/github.com/syncthing/syncthing \
  123. -e "STTRACE=$STTRACE" \
  124. "$img" \
  125. sh -euxc './build.sh clean \
  126. && go run build.go -race \
  127. && export GOPATH=$(pwd)/Godeps/_workspace:$GOPATH \
  128. && cd test \
  129. && go test -tags integration -v -timeout 90m -short \
  130. && git clean -fxd .'
  131. ;;
  132. docker-lint)
  133. img=${DOCKERIMG:-syncthing/build:latest}
  134. docker run --rm -h syncthing-builder -u $(id -u) -t \
  135. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  136. -w /go/src/github.com/syncthing/syncthing \
  137. -e "STTRACE=$STTRACE" \
  138. "$img" \
  139. sh -euxc 'go run build.go lint'
  140. ;;
  141. docker-vet)
  142. img=${DOCKERIMG:-syncthing/build:latest}
  143. docker run --rm -h syncthing-builder -u $(id -u) -t \
  144. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  145. -w /go/src/github.com/syncthing/syncthing \
  146. -e "STTRACE=$STTRACE" \
  147. "$img" \
  148. sh -euxc 'go run build.go vet'
  149. ;;
  150. *)
  151. echo "Unknown build command $1"
  152. ;;
  153. esac