build.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 -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. notCovered=$(egrep -c '\s0$' coverage.out)
  92. total=$(wc -l coverage.out | awk '{print $1}')
  93. coverPct=$(awk "BEGIN{print (1 - $notCovered / $total) * 100}")
  94. echo "Total coverage is $coverPct%"
  95. gocov convert coverage.out | gocov-xml > coverage.xml
  96. # This is usually run from within Jenkins. If it is, we need to
  97. # tweak the paths in coverage.xml so cobertura finds the
  98. # source.
  99. if [[ "${WORKSPACE:-default}" != "default" ]] ; then
  100. sed "s#$WORKSPACE##g" < coverage.xml > coverage.xml.new && mv coverage.xml.new coverage.xml
  101. fi
  102. ;;
  103. test-xunit)
  104. ulimit -t 600 &>/dev/null || true
  105. ulimit -d 512000 &>/dev/null || true
  106. ulimit -m 512000 &>/dev/null || true
  107. (GOPATH="$(pwd)/Godeps/_workspace:$GOPATH" go test -v -race ./lib/... ./cmd/... || true) > tests.out
  108. go2xunit -output tests.xml -fail < tests.out
  109. ;;
  110. *)
  111. echo "Unknown build command $1"
  112. ;;
  113. esac