build.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. deps)
  24. build "$@"
  25. ;;
  26. assets)
  27. build "$@"
  28. ;;
  29. xdr)
  30. build "$@"
  31. ;;
  32. translate)
  33. build "$@"
  34. ;;
  35. deb)
  36. build "$@"
  37. ;;
  38. setup)
  39. build "$@"
  40. ;;
  41. test)
  42. ulimit -t 600 &>/dev/null || true
  43. ulimit -d 512000 &>/dev/null || true
  44. ulimit -m 512000 &>/dev/null || true
  45. LOGGER_DISCARD=1 build test
  46. ;;
  47. bench)
  48. LOGGER_DISCARD=1 build bench | script benchfilter
  49. ;;
  50. prerelease)
  51. build transifex
  52. git add -A gui/assets/ lib/auto/
  53. pushd man ; ./refresh.sh ; popd
  54. git add -A man
  55. ;;
  56. noupgrade)
  57. build -no-upgrade tar
  58. ;;
  59. all)
  60. build -goos darwin -goarch amd64 tar
  61. build -goos dragonfly -goarch amd64 tar
  62. build -goos freebsd -goarch 386 tar
  63. build -goos freebsd -goarch amd64 tar
  64. build -goos linux -goarch 386 tar
  65. build -goos linux -goarch amd64 tar
  66. build -goos linux -goarch arm tar
  67. build -goos netbsd -goarch 386 tar
  68. build -goos netbsd -goarch amd64 tar
  69. build -goos openbsd -goarch 386 tar
  70. build -goos openbsd -goarch amd64 tar
  71. build -goos solaris -goarch amd64 tar
  72. build -goos windows -goarch 386 zip
  73. build -goos windows -goarch amd64 zip
  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 ./...) ; do
  83. # run the tests
  84. godep go test -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: set" 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. docker-all)
  100. img=${DOCKERIMG:-syncthing/build:latest}
  101. docker run --rm -h syncthing-builder -u $(id -u) -t \
  102. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  103. -w /go/src/github.com/syncthing/syncthing \
  104. -e "STTRACE=$STTRACE" \
  105. "$img" \
  106. sh -c './build.sh clean \
  107. && ./build.sh test-cov \
  108. && ./build.sh bench \
  109. && ./build.sh all'
  110. ;;
  111. docker-test)
  112. img=${DOCKERIMG:-syncthing/build:latest}
  113. docker run --rm -h syncthing-builder -u $(id -u) -t \
  114. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  115. -w /go/src/github.com/syncthing/syncthing \
  116. -e "STTRACE=$STTRACE" \
  117. "$img" \
  118. sh -euxc './build.sh clean \
  119. && go run build.go -race \
  120. && export GOPATH=$(pwd)/Godeps/_workspace:$GOPATH \
  121. && cd test \
  122. && go test -tags integration -v -timeout 90m -short \
  123. && git clean -fxd .'
  124. ;;
  125. docker-lint)
  126. img=${DOCKERIMG:-syncthing/build:latest}
  127. docker run --rm -h syncthing-builder -u $(id -u) -t \
  128. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  129. -w /go/src/github.com/syncthing/syncthing \
  130. -e "STTRACE=$STTRACE" \
  131. "$img" \
  132. sh -euxc 'go run build.go lint'
  133. ;;
  134. docker-vet)
  135. img=${DOCKERIMG:-syncthing/build:latest}
  136. docker run --rm -h syncthing-builder -u $(id -u) -t \
  137. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  138. -w /go/src/github.com/syncthing/syncthing \
  139. -e "STTRACE=$STTRACE" \
  140. "$img" \
  141. sh -euxc 'go run build.go vet'
  142. ;;
  143. *)
  144. echo "Unknown build command $1"
  145. ;;
  146. esac