You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

125 rivejä
4.2 KiB

  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. fail_on_output() {
  13. tee /dev/stderr | (! read)
  14. }
  15. # Check to make sure it's safe to modify the user's git repo.
  16. git status --porcelain | fail_on_output
  17. # Undo any edits made by this script.
  18. cleanup() {
  19. git reset --hard HEAD
  20. }
  21. trap cleanup EXIT
  22. PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"
  23. if [[ "$1" = "-install" ]]; then
  24. # Check for module support
  25. if go help mod >& /dev/null; then
  26. go install \
  27. golang.org/x/lint/golint \
  28. golang.org/x/tools/cmd/goimports \
  29. honnef.co/go/tools/cmd/staticcheck \
  30. github.com/client9/misspell/cmd/misspell \
  31. github.com/golang/protobuf/protoc-gen-go
  32. else
  33. # Ye olde `go get` incantation.
  34. # Note: this gets the latest version of all tools (vs. the pinned versions
  35. # with Go modules).
  36. go get -u \
  37. golang.org/x/lint/golint \
  38. golang.org/x/tools/cmd/goimports \
  39. honnef.co/go/tools/cmd/staticcheck \
  40. github.com/client9/misspell/cmd/misspell \
  41. github.com/golang/protobuf/protoc-gen-go
  42. fi
  43. if [[ -z "${VET_SKIP_PROTO}" ]]; then
  44. if [[ "${TRAVIS}" = "true" ]]; then
  45. PROTOBUF_VERSION=3.3.0
  46. PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
  47. pushd /home/travis
  48. wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME}
  49. unzip ${PROTOC_FILENAME}
  50. bin/protoc --version
  51. popd
  52. elif ! which protoc > /dev/null; then
  53. die "Please install protoc into your path"
  54. fi
  55. fi
  56. exit 0
  57. elif [[ "$#" -ne 0 ]]; then
  58. die "Unknown argument(s): $*"
  59. fi
  60. # - Ensure all source files contain a copyright message.
  61. git ls-files "*.go" | xargs grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)\|DO NOT EDIT" 2>&1 | fail_on_output
  62. # - Make sure all tests in grpc and grpc/test use leakcheck via Teardown.
  63. (! grep 'func Test[^(]' *_test.go)
  64. (! grep 'func Test[^(]' test/*.go)
  65. # - Do not import math/rand for real library code. Use internal/grpcrand for
  66. # thread safety.
  67. git ls-files "*.go" | xargs grep -l '"math/rand"' 2>&1 | (! grep -v '^examples\|^stress\|grpcrand')
  68. # - Ensure all ptypes proto packages are renamed when importing.
  69. git ls-files "*.go" | (! xargs grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/")
  70. # - Check imports that are illegal in appengine (until Go 1.11).
  71. # TODO: Remove when we drop Go 1.10 support
  72. go list -f {{.Dir}} ./... | xargs go run test/go_vet/vet.go
  73. # - gofmt, goimports, golint (with exceptions for generated code), go vet.
  74. gofmt -s -d -l . 2>&1 | fail_on_output
  75. goimports -l . 2>&1 | fail_on_output
  76. golint ./... 2>&1 | (! grep -vE "(_mock|\.pb)\.go:")
  77. go tool vet -all .
  78. # - Check that generated proto files are up to date.
  79. if [[ -z "${VET_SKIP_PROTO}" ]]; then
  80. PATH="/home/travis/bin:${PATH}" make proto && \
  81. git status --porcelain 2>&1 | fail_on_output || \
  82. (git status; git --no-pager diff; exit 1)
  83. fi
  84. # - Check that our module is tidy.
  85. if go help mod >& /dev/null; then
  86. go mod tidy && \
  87. git status --porcelain 2>&1 | fail_on_output || \
  88. (git status; git --no-pager diff; exit 1)
  89. fi
  90. # - Collection of static analysis checks
  91. # TODO(menghanl): fix errors in transport_test.
  92. staticcheck -go 1.9 -checks 'inherit,-ST1015' -ignore '
  93. google.golang.org/grpc/balancer.go:SA1019
  94. google.golang.org/grpc/balancer_test.go:SA1019
  95. google.golang.org/grpc/clientconn_test.go:SA1019
  96. google.golang.org/grpc/balancer/roundrobin/roundrobin_test.go:SA1019
  97. google.golang.org/grpc/benchmark/benchmain/main.go:SA1019
  98. google.golang.org/grpc/benchmark/worker/benchmark_client.go:SA1019
  99. google.golang.org/grpc/internal/transport/handler_server.go:SA1019
  100. google.golang.org/grpc/internal/transport/handler_server_test.go:SA1019
  101. google.golang.org/grpc/stats/stats_test.go:SA1019
  102. google.golang.org/grpc/test/channelz_test.go:SA1019
  103. google.golang.org/grpc/test/end2end_test.go:SA1019
  104. google.golang.org/grpc/test/healthcheck_test.go:SA1019
  105. google.golang.org/grpc/clientconn.go:S1024
  106. ' ./...
  107. misspell -error .