Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@ go:
go_import_path: google.golang.org/grpc

before_install:
- if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then go get -u github.com/golang/lint/golint honnef.co/go/tools/cmd/staticcheck; 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
- if [[ "$TRAVIS_GO_VERSION" = 1.8* ]]; then ./vet.sh -install || exit 1; fi

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'
- '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
- if [[ "$TRAVIS_GO_VERSION" = 1.8* ]]; then ./vet.sh || exit 1; fi
- 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
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ proto:
echo "error: protoc not installed" >&2; \
exit 1; \
fi
go get -u -v github.com/golang/protobuf/protoc-gen-go golang.org/x/tools/cmd/stringer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this?

Though this works on travis, someone trying to run make proto locally may fail because of these two missing packages...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with reverting this, but then we should change make proto in vet.sh to run go generate. Otherwise you end up with the latency of go get every time you run vet.sh, which is not really desirable.

Alternatively, we can check $GOPATH/..... for these two things and fail with a friendlier error if they are not found.

Thoughts?

go generate google.golang.org/grpc/...

test: testdeps
Expand All @@ -32,9 +31,6 @@ testrace: testdeps
clean:
go clean -i google.golang.org/grpc/...

coverage: testdeps
./coverage.sh --coveralls

.PHONY: \
all \
deps \
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func init() {
runMode[0] = true
runMode[1] = true
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, ", "))
}
switch compressorMode {
Expand Down
48 changes: 0 additions & 48 deletions coverage.sh

This file was deleted.

23 changes: 0 additions & 23 deletions install-protobuf.sh

This file was deleted.

74 changes: 74 additions & 0 deletions vet.sh
Original file line number Diff line number Diff line change
@@ -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 ./...