vet.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. if [[ `uname -a` = *"Darwin"* ]]; then
  3. echo "It seems you are running on Mac. This script does not work on Mac. See https://github.com/grpc/grpc-go/issues/2047"
  4. exit 1
  5. fi
  6. set -ex # Exit on error; debugging enabled.
  7. set -o pipefail # Fail a pipe if any sub-command fails.
  8. die() {
  9. echo "$@" >&2
  10. exit 1
  11. }
  12. PATH="$GOPATH/bin:$GOROOT/bin:$PATH"
  13. # Check proto in manual runs or cron runs.
  14. if [[ "$TRAVIS" != "true" || "$TRAVIS_EVENT_TYPE" = "cron" ]]; then
  15. check_proto="true"
  16. fi
  17. if [ "$1" = "-install" ]; then
  18. go get -d \
  19. google.golang.org/grpc/...
  20. go get -u \
  21. github.com/golang/lint/golint \
  22. golang.org/x/tools/cmd/goimports \
  23. honnef.co/go/tools/cmd/staticcheck \
  24. github.com/client9/misspell/cmd/misspell \
  25. github.com/golang/protobuf/protoc-gen-go
  26. if [[ "$check_proto" = "true" ]]; then
  27. if [[ "$TRAVIS" = "true" ]]; then
  28. PROTOBUF_VERSION=3.3.0
  29. PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
  30. pushd /home/travis
  31. wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME}
  32. unzip ${PROTOC_FILENAME}
  33. bin/protoc --version
  34. popd
  35. elif ! which protoc > /dev/null; then
  36. die "Please install protoc into your path"
  37. fi
  38. fi
  39. exit 0
  40. elif [[ "$#" -ne 0 ]]; then
  41. die "Unknown argument(s): $*"
  42. fi
  43. # TODO: Remove this check and the mangling below once "context" is imported
  44. # directly.
  45. if git status --porcelain | read; then
  46. die "Uncommitted or untracked files found; commit changes first"
  47. fi
  48. git ls-files "*.go" | xargs grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)\|DO NOT EDIT" 2>&1 | tee /dev/stderr | (! read)
  49. git ls-files "*.go" | xargs grep -l '"unsafe"' 2>&1 | (! grep -v '_test.go') | tee /dev/stderr | (! read)
  50. git ls-files "*.go" | xargs grep -l '"math/rand"' 2>&1 | (! grep -v '^examples\|^stress\|grpcrand') | tee /dev/stderr | (! read)
  51. gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read)
  52. goimports -l . 2>&1 | tee /dev/stderr | (! read)
  53. golint ./... 2>&1 | (grep -vE "(_mock|\.pb)\.go:" || true) | tee /dev/stderr | (! read)
  54. # Undo any edits made by this script.
  55. cleanup() {
  56. git reset --hard HEAD
  57. }
  58. trap cleanup EXIT
  59. # Rewrite golang.org/x/net/context -> context imports (see grpc/grpc-go#1484).
  60. # TODO: Remove this mangling once "context" is imported directly (grpc/grpc-go#711).
  61. git ls-files "*.go" | xargs sed -i 's:"golang.org/x/net/context":"context":'
  62. set +o pipefail
  63. # TODO: Stop filtering pb.go files once golang/protobuf#214 is fixed.
  64. go tool vet -all . 2>&1 | grep -vE '(clientconn|transport\/transport_test).go:.*cancel (function|var)' | grep -vF '.pb.go:' | tee /dev/stderr | (! read)
  65. set -o pipefail
  66. git reset --hard HEAD
  67. if [[ "$check_proto" = "true" ]]; then
  68. PATH="/home/travis/bin:$PATH" make proto && \
  69. git status --porcelain 2>&1 | (! read) || \
  70. (git status; git --no-pager diff; exit 1)
  71. fi
  72. # TODO(menghanl): fix errors in transport_test.
  73. staticcheck -ignore '
  74. google.golang.org/grpc/transport/transport_test.go:SA2002
  75. google.golang.org/grpc/benchmark/benchmain/main.go:SA1019
  76. google.golang.org/grpc/stats/stats_test.go:SA1019
  77. google.golang.org/grpc/test/end2end_test.go:SA1019
  78. google.golang.org/grpc/balancer_test.go:SA1019
  79. google.golang.org/grpc/balancer.go:SA1019
  80. google.golang.org/grpc/clientconn_test.go:SA1019
  81. ' ./...
  82. misspell -error .