OSDN Git Service

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