build.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. IFS=$'\n\t'
  4. DOCKERIMGV=1.4-1
  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 linux -goarch amd64 tar
  41. go run build.go -goos linux -goarch 386 tar
  42. go run build.go -goos linux -goarch armv5 tar
  43. go run build.go -goos linux -goarch armv6 tar
  44. go run build.go -goos linux -goarch armv7 tar
  45. go run build.go -goos freebsd -goarch amd64 tar
  46. go run build.go -goos freebsd -goarch 386 tar
  47. go run build.go -goos openbsd -goarch amd64 tar
  48. go run build.go -goos openbsd -goarch 386 tar
  49. go run build.go -goos darwin -goarch amd64 tar
  50. go run build.go -goos windows -goarch amd64 zip
  51. go run build.go -goos windows -goarch 386 zip
  52. ;;
  53. setup)
  54. echo "Don't worry, just build."
  55. ;;
  56. test-cov)
  57. ulimit -t 600 &>/dev/null || true
  58. ulimit -d 512000 &>/dev/null || true
  59. ulimit -m 512000 &>/dev/null || true
  60. go get github.com/axw/gocov/gocov
  61. go get github.com/AlekSi/gocov-xml
  62. echo "mode: set" > coverage.out
  63. fail=0
  64. # For every package in the repo
  65. for dir in $(go list ./...) ; do
  66. # run the tests
  67. godep go test -coverprofile=profile.out $dir
  68. if [ -f profile.out ] ; then
  69. # and if there was test output, append it to coverage.out
  70. grep -v "mode: set" profile.out >> coverage.out
  71. rm profile.out
  72. fi
  73. done
  74. gocov convert coverage.out | gocov-xml > coverage.xml
  75. # This is usually run from within Jenkins. If it is, we need to
  76. # tweak the paths in coverage.xml so cobertura finds the
  77. # source.
  78. if [[ "${WORKSPACE:-default}" != "default" ]] ; then
  79. sed "s#$WORKSPACE##g" < coverage.xml > coverage.xml.new && mv coverage.xml.new coverage.xml
  80. fi
  81. ;;
  82. docker-init)
  83. docker build -q -t syncthing/build:$DOCKERIMGV docker >/dev/null
  84. ;;
  85. docker-all)
  86. docker run --rm -h syncthing-builder -u $(id -u) -t \
  87. -v $(pwd):/go/src/github.com/syncthing/syncthing \
  88. -w /go/src/github.com/syncthing/syncthing \
  89. syncthing/build:$DOCKERIMGV \
  90. sh -c './build.sh clean && ./build.sh all && STTRACE=all ./build.sh test-cov'
  91. ;;
  92. docker-test)
  93. docker run --rm -h syncthing-builder -u $(id -u) -t \
  94. -v $(pwd):/tmp/syncthing \
  95. syncthing/build:$DOCKERIMGV \
  96. sh -euxc 'mkdir -p /go/src/github.com/syncthing \
  97. && cd /go/src/github.com/syncthing \
  98. && cp -r /tmp/syncthing syncthing \
  99. && cd syncthing \
  100. && ./build.sh clean \
  101. && go run build.go -race \
  102. && export GOPATH=$(pwd)/Godeps/_workspace:$GOPATH \
  103. && cd test \
  104. && go test -tags integration -v -timeout 60m -short'
  105. ;;
  106. *)
  107. echo "Unknown build command $1"
  108. ;;
  109. esac