build.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. STTRACE=${STTRACE:-}
  5. case "${1:-default}" in
  6. default)
  7. go run build.go
  8. ;;
  9. clean)
  10. go run build.go "$1"
  11. ;;
  12. test)
  13. ulimit -t 60 &>/dev/null || true
  14. ulimit -d 512000 &>/dev/null || true
  15. ulimit -m 512000 &>/dev/null || true
  16. go run build.go "$1"
  17. ;;
  18. tar)
  19. go run build.go "$1"
  20. ;;
  21. deps)
  22. go run build.go "$1"
  23. ;;
  24. assets)
  25. go run build.go "$1"
  26. ;;
  27. xdr)
  28. go run build.go "$1"
  29. ;;
  30. translate)
  31. go run build.go "$1"
  32. ;;
  33. transifex)
  34. go run build.go "$1"
  35. ;;
  36. noupgrade)
  37. go run build.go -no-upgrade tar
  38. ;;
  39. all)
  40. go run build.go -goos darwin -goarch amd64 tar
  41. go run build.go -goos darwin -goarch 386 tar
  42. go run build.go -goos dragonfly -goarch 386 tar
  43. go run build.go -goos dragonfly -goarch amd64 tar
  44. go run build.go -goos freebsd -goarch 386 tar
  45. go run build.go -goos freebsd -goarch amd64 tar
  46. go run build.go -goos linux -goarch 386 tar
  47. go run build.go -goos linux -goarch amd64 tar
  48. go run build.go -goos linux -goarch arm tar
  49. go run build.go -goos netbsd -goarch 386 tar
  50. go run build.go -goos netbsd -goarch amd64 tar
  51. go run build.go -goos openbsd -goarch 386 tar
  52. go run build.go -goos openbsd -goarch amd64 tar
  53. go run build.go -goos solaris -goarch amd64 tar
  54. go run build.go -goos windows -goarch 386 zip
  55. go run build.go -goos windows -goarch amd64 zip
  56. ;;
  57. setup)
  58. echo "Don't worry, just build."
  59. ;;
  60. test-cov)
  61. ulimit -t 600 &>/dev/null || true
  62. ulimit -d 512000 &>/dev/null || true
  63. ulimit -m 512000 &>/dev/null || true
  64. go get github.com/axw/gocov/gocov
  65. go get github.com/AlekSi/gocov-xml
  66. echo "mode: set" > coverage.out
  67. fail=0
  68. # For every package in the repo
  69. for dir in $(go list ./...) ; do
  70. # run the tests
  71. godep go test -coverprofile=profile.out $dir
  72. if [ -f profile.out ] ; then
  73. # and if there was test output, append it to coverage.out
  74. grep -v "mode: set" profile.out >> coverage.out
  75. rm profile.out
  76. fi
  77. done
  78. gocov convert coverage.out | gocov-xml > coverage.xml
  79. # This is usually run from within Jenkins. If it is, we need to
  80. # tweak the paths in coverage.xml so cobertura finds the
  81. # source.
  82. if [[ "${WORKSPACE:-default}" != "default" ]] ; then
  83. sed "s#$WORKSPACE##g" < coverage.xml > coverage.xml.new && mv coverage.xml.new coverage.xml
  84. fi
  85. ;;
  86. docker-all)
  87. docker run --rm -h syncthing-builder -u $(id -u) -t \
  88. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  89. -w /go/src/github.com/syncthing/syncthing \
  90. -e "STTRACE=$STTRACE" \
  91. syncthing/build:latest \
  92. sh -c './build.sh clean \
  93. && go vet ./cmd/... ./internal/... \
  94. && ( golint ./cmd/... ; golint ./internal/... ) | egrep -v "comment on exported|should have comment" \
  95. && ./build.sh all \
  96. && STTRACE=all ./build.sh test-cov'
  97. ;;
  98. docker-test)
  99. docker run --rm -h syncthing-builder -u $(id -u) -t \
  100. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  101. -w /go/src/github.com/syncthing/syncthing \
  102. -e "STTRACE=$STTRACE" \
  103. syncthing/build:latest \
  104. sh -euxc './build.sh clean \
  105. && go run build.go -race \
  106. && export GOPATH=$(pwd)/Godeps/_workspace:$GOPATH \
  107. && cd test \
  108. && go test -tags integration -v -timeout 60m -short \
  109. && git clean -fxd .'
  110. ;;
  111. *)
  112. echo "Unknown build command $1"
  113. ;;
  114. esac