Check "x/net/context" with go vet like "context" (#1490)

* Check "x/net/context" with `go vet` like "context"

Includes a signficant revamp of .travis.yml to execute a separate script for
all of the things we check before allowing a merge.

* fix bug in benchmain
This commit is contained in:
dfawley
2017-08-29 15:40:57 -07:00
committed by GitHub
parent 85a1e381f1
commit d6870035ab
6 changed files with 77 additions and 86 deletions

View File

@ -8,16 +8,8 @@ go:
go_import_path: google.golang.org/grpc go_import_path: google.golang.org/grpc
before_install: before_install:
- if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then go get -u github.com/golang/lint/golint honnef.co/go/tools/cmd/staticcheck; fi - if [[ "$TRAVIS_GO_VERSION" = 1.8* ]]; then ./vet.sh -install || exit 1; fi
- go get -u golang.org/x/tools/cmd/goimports github.com/axw/gocov/gocov github.com/mattn/goveralls golang.org/x/tools/cmd/cover
- if [[ "$TRAVIS_EVENT_TYPE" = "cron" && $TRAVIS_GO_VERSION = 1.8* ]]; then PROTOBUF_VERSION=3.3.0 ./install-protobuf.sh; fi
script: script:
- 'if [[ "$TRAVIS_EVENT_TYPE" = "cron" && $TRAVIS_GO_VERSION = 1.8* ]]; then PATH=/home/travis/bin:$PATH make proto && ! git status --porcelain | tee /dev/stderr | read || (git status; git diff; exit 1); fi' - if [[ "$TRAVIS_GO_VERSION" = 1.8* ]]; then ./vet.sh || exit 1; fi
- 'set -o pipefail && git ls-files "*.go" | xargs grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)\|DO NOT EDIT" 2>&1 | tee /dev/stderr | (! read)'
- 'set -o pipefail && gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read)'
- 'set -o pipefail && goimports -l . 2>&1 | tee /dev/stderr | (! read)'
- 'if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then ! golint ./... | grep -vE "(_mock|_string|\.pb)\.go:"; fi'
- 'if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then ! go tool vet -all . 2>&1 | grep -vF .pb.go:; fi' # https://github.com/golang/protobuf/issues/214
- make test testrace - make test testrace
- 'if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then staticcheck -ignore google.golang.org/grpc/transport/transport_test.go:SA2002 ./...; fi' # TODO(menghanl): fix these

View File

@ -20,7 +20,6 @@ proto:
echo "error: protoc not installed" >&2; \ echo "error: protoc not installed" >&2; \
exit 1; \ exit 1; \
fi fi
go get -u -v github.com/golang/protobuf/protoc-gen-go golang.org/x/tools/cmd/stringer
go generate google.golang.org/grpc/... go generate google.golang.org/grpc/...
test: testdeps test: testdeps
@ -32,9 +31,6 @@ testrace: testdeps
clean: clean:
go clean -i google.golang.org/grpc/... go clean -i google.golang.org/grpc/...
coverage: testdeps
./coverage.sh --coveralls
.PHONY: \ .PHONY: \
all \ all \
deps \ deps \

View File

@ -259,7 +259,7 @@ func init() {
runMode[0] = true runMode[0] = true
runMode[1] = true runMode[1] = true
default: default:
log.Fatalf("Unknown workloads setting: %v (want %v, %v, or %v)", log.Fatalf("Unknown workloads setting: %v (want one of: %v)",
workloads, strings.Join(allWorkloads, ", ")) workloads, strings.Join(allWorkloads, ", "))
} }
switch compressorMode { switch compressorMode {

View File

@ -1,48 +0,0 @@
#!/usr/bin/env bash
set -e
workdir=.cover
profile="$workdir/cover.out"
mode=set
end2endtest="google.golang.org/grpc/test"
generate_cover_data() {
rm -rf "$workdir"
mkdir "$workdir"
for pkg in "$@"; do
if [ $pkg == "google.golang.org/grpc" -o $pkg == "google.golang.org/grpc/transport" -o $pkg == "google.golang.org/grpc/metadata" -o $pkg == "google.golang.org/grpc/credentials" ]
then
f="$workdir/$(echo $pkg | tr / -)"
go test -covermode="$mode" -coverprofile="$f.cover" "$pkg"
go test -covermode="$mode" -coverpkg "$pkg" -coverprofile="$f.e2e.cover" "$end2endtest"
fi
done
echo "mode: $mode" >"$profile"
grep -h -v "^mode:" "$workdir"/*.cover >>"$profile"
}
show_cover_report() {
go tool cover -${1}="$profile"
}
push_to_coveralls() {
goveralls -coverprofile="$profile"
}
generate_cover_data $(go list ./...)
show_cover_report func
case "$1" in
"")
;;
--html)
show_cover_report html ;;
--coveralls)
push_to_coveralls ;;
*)
echo >&2 "error: invalid option: $1" ;;
esac
rm -rf "$workdir"

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
set -ex
die() {
echo "$@" >&2
exit 1
}
case "$PROTOBUF_VERSION" in
3*)
basename=protoc-$PROTOBUF_VERSION
;;
*)
die "unknown protobuf version: $PROTOBUF_VERSION"
;;
esac
cd /home/travis
wget https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename-linux-x86_64.zip
unzip $basename-linux-x86_64.zip
bin/protoc --version

74
vet.sh Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
set -ex # Exit on error; debugging enabled.
set -o pipefail # Fail a pipe if any sub-command fails.
die() {
echo "$@" >&2
exit 1
}
# TODO: Remove this check and the mangling below once "context" is imported
# directly.
if git status --porcelain | read; then
die "Uncommitted or untracked files found; commit changes first"
fi
# Undo any edits made by this script.
cleanup() {
git reset --hard HEAD
}
trap cleanup EXIT
# Check proto in manual runs or cron runs.
if [[ "$TRAVIS" != "true" || "$TRAVIS_EVENT_TYPE" = "cron" ]]; then
check_proto="true"
fi
if [ "$1" = "-install" ]; then
go get -d \
google.golang.org/grpc/...
go get -u \
github.com/golang/lint/golint \
golang.org/x/tools/cmd/goimports \
honnef.co/go/tools/cmd/staticcheck \
github.com/golang/protobuf/protoc-gen-go \
golang.org/x/tools/cmd/stringer
if [[ "$check_proto" = "true" ]]; then
if [[ "$TRAVIS" = "true" ]]; then
PROTOBUF_VERSION=3.3.0
cd /home/travis
wget https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename-linux-x86_64.zip
unzip $basename-linux-x86_64.zip
bin/protoc --version
elif ! which protoc > /dev/null; then
die "Please install protoc into your path"
fi
fi
exit 0
elif [[ "$#" -ne 0 ]]; then
die "Unknown argument(s): $*"
fi
git ls-files "*.go" | xargs grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)\|DO NOT EDIT" 2>&1 | tee /dev/stderr | (! read)
gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read)
goimports -l . 2>&1 | tee /dev/stderr | (! read)
golint ./... 2>&1 | (grep -vE "(_mock|_string|\.pb)\.go:" || true) | tee /dev/stderr | (! read)
# Rewrite golang.org/x/net/context -> context imports (see grpc/grpc-go#1484).
# TODO: Remove this mangling once "context" is imported directly (grpc/grpc-go#711).
git ls-files "*.go" | xargs sed -i 's:"golang.org/x/net/context":"context":'
set +o pipefail
# TODO: Stop filtering pb.go files once golang/protobuf#214 is fixed.
# TODO: Remove clientconn exception once go1.6 support is removed.
go tool vet -all . 2>&1 | grep -vE 'clientconn.go:.*cancel' | grep -vF '.pb.go:' | tee /dev/stderr | (! read)
set -o pipefail
git reset --hard HEAD
if [[ "$check_proto" = "true" ]]; then
PATH=/home/travis/bin:$PATH make proto && \
git status --porcelain 2>&1 | (! read) || \
(git status; git --no-pager diff; exit 1)
fi
# TODO(menghanl): fix errors in transport_test.
staticcheck -ignore google.golang.org/grpc/transport/transport_test.go:SA2002 ./...