build.sh 3.1 KB

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