vet.sh 3.1 KB

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