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