diff --git a/.travis.yml b/.travis.yml index d3620c5..0af8c00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,14 @@ language: go -go: "1.11" +go: 1.13.x go_import_path: github.com/lyft/protoc-gen-star env: - global: - - GLIDE_VER="v0.13.1" matrix: - PROTOC_VER="3.5.1" - PROTOC_VER="3.6.1" before_install: - mkdir -p $GOPATH/bin - - wget "https://github.com/Masterminds/glide/releases/download/${GLIDE_VER}/glide-${GLIDE_VER}-linux-amd64.tar.gz" -O /tmp/glide.tar.gz - - tar -xvf /tmp/glide.tar.gz --strip-components 1 -C ${GOPATH}/bin - wget "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/protoc-${PROTOC_VER}-linux-x86_64.zip" -O /tmp/protoc.zip - unzip /tmp/protoc.zip -d /tmp - sudo mv /tmp/bin/protoc /usr/local/bin/protoc diff --git a/Makefile b/Makefile index e49719a..3f24e6b 100644 --- a/Makefile +++ b/Makefile @@ -2,29 +2,30 @@ PKG := $(shell go list .) PKGS := $(shell go list ./...) +export GO111MODULE = on + .PHONY: bootstrap -bootstrap: vendor testdata # set up the project for development +bootstrap: testdata # set up the project for development .PHONY: lint -lint: # lints the package for common code smells +lint: bin/shadow # lints the package for common code smells set -e; for f in `find . -name "*.go" -not -name "*.pb.go" | grep -v vendor`; do \ out=`gofmt -s -d $$f`; \ test -z "$$out" || (echo $$out && exit 1); \ done - which golint || go get -u golang.org/x/lint/golint - golint -set_exit_status $(PKGS) - go vet -all -shadow -shadowstrict $(PKGS) + go run golang.org/x/lint/golint -set_exit_status $(PKGS) + go vet -all -vettool=bin/shadow $(PKGS) .PHONY: quick -quick: vendor testdata # runs all tests without the race detector or coverage +quick: testdata # runs all tests without the race detector or coverage go test $(PKGS) .PHONY: tests -tests: vendor testdata # runs all tests against the package with race detection and coverage percentage +tests: testdata # runs all tests against the package with race detection and coverage percentage go test -race -cover $(PKGS) .PHONY: cover -cover: vendor testdata # runs all tests against the package, generating a coverage report and opening it in the browser +cover: testdata # runs all tests against the package, generating a coverage report and opening it in the browser go test -race -covermode=atomic -coverprofile=cover.out $(PKGS) || true go tool cover -html cover.out -o cover.html open cover.html @@ -46,14 +47,14 @@ testdata-graph: bin/protoc-gen-debug # parses the proto file sets in testdata/gr `find $$subdir -name "*.proto"`; \ done -testdata/generated: protoc-gen-go bin/protoc-gen-example - which protoc-gen-go || (go install github.com/golang/protobuf/protoc-gen-go) +testdata/generated: bin/protoc-gen-go bin/protoc-gen-example rm -rf ./testdata/generated && mkdir -p ./testdata/generated # generate the official go code, must be one directory at a time set -e; for subdir in `find ./testdata/protos -type d -mindepth 1`; do \ files=`find $$subdir -name "*.proto" -maxdepth 1`; \ [ ! -z "$$files" ] && \ protoc -I ./testdata/protos \ + --plugin=protoc-gen-go=./bin/protoc-gen-go \ --go_out="$$GOPATH/src" \ $$files; \ done @@ -72,25 +73,23 @@ testdata/fdset.bin: testdata/protos/**/*.proto .PHONY: testdata-go -testdata-go: protoc-gen-go bin/protoc-gen-debug # generate go-specific testdata +testdata-go: bin/protoc-gen-go bin/protoc-gen-debug # generate go-specific testdata cd lang/go && $(MAKE) \ testdata-names \ testdata-packages \ testdata-outputs -vendor: # install project dependencies - which glide || (curl https://glide.sh/get | sh) - glide install +bin/protoc-gen-go: # creates the protoc-gen-go plugin using the vendored version + go build -o $@ github.com/golang/protobuf/protoc-gen-go -.PHONY: protoc-gen-go -protoc-gen-go: - which protoc-gen-go || (go get -u github.com/golang/protobuf/protoc-gen-go) +bin/protoc-gen-example: # creates the demo protoc plugin for demonstrating uses of PG* + go build -o $@ ./testdata/protoc-gen-example -bin/protoc-gen-example: vendor # creates the demo protoc plugin for demonstrating uses of PG* - go build -o ./bin/protoc-gen-example ./testdata/protoc-gen-example +bin/protoc-gen-debug: # creates the protoc-gen-debug protoc plugin for output ProtoGeneratorRequest messages + go build -o $@ ./protoc-gen-debug -bin/protoc-gen-debug: vendor # creates the protoc-gen-debug protoc plugin for output ProtoGeneratorRequest messages - go build -o ./bin/protoc-gen-debug ./protoc-gen-debug +bin/shadow: # creates the linter used for variable shadowing analysis. + go build -o $@ golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow .PHONY: clean clean: diff --git a/README.md b/README.md index c33c2ac..20848ac 100644 --- a/README.md +++ b/README.md @@ -300,16 +300,13 @@ PG* seeks to provide all the tools necessary to rapidly and ergonomically extend ### Setup -For developing on PG*, you should install the package within the `GOPATH`. PG* uses [glide][glide] for dependency management. +For developing on PG*, you should install the package within the `GOPATH`. ```sh go get -u github.com/lyft/protoc-gen-star cd $GOPATH/src/github.com/lyft/protoc-gen-star -make vendor ``` -To upgrade dependencies, please make the necessary modifications in `glide.yaml` and run `glide update`. - ### Linting & Static Analysis To avoid style nits and also to enforce some best practices for Go packages, PG* requires passing `golint`, `go vet`, and `go fmt -s` for all code changes. @@ -364,7 +361,6 @@ make testdata/generated PG* uses [TravisCI][travis] to validate all code changes. Please view the [configuration][travis.yml] for what tests are involved in the validation. -[glide]: http://glide.sh [pgg]: https://github.com/golang/protobuf/tree/master/protoc-gen-go [pge]: https://github.com/lyft/protoc-gen-star/tree/master/testdata/protoc-gen-example [travis]: https://travis-ci.com/lyft/protoc-gen-star diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8230112 --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module github.com/lyft/protoc-gen-star + +go 1.13 + +require ( + github.com/golang/protobuf v1.3.2 + github.com/spf13/afero v1.2.2 + github.com/stretchr/testify v1.4.0 + golang.org/x/lint v0.0.0-20190930215403-16217165b5de + golang.org/x/text v0.3.2 // indirect + golang.org/x/tools v0.0.0-20191114200427-caa0b0f7d508 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..cbe907e --- /dev/null +++ b/go.sum @@ -0,0 +1,31 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= +github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20191114200427-caa0b0f7d508 h1:0FYNp0PF9kFm/ZUrvcJiQ12IUJJG7iAc6Cu01wbKrbU= +golang.org/x/tools v0.0.0-20191114200427-caa0b0f7d508/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/lang/go/Makefile b/lang/go/Makefile index a4dac5c..e8a4c46 100644 --- a/lang/go/Makefile +++ b/lang/go/Makefile @@ -1,5 +1,5 @@ .PHONY: testdata-go-names -testdata-names: ../../bin/protoc-gen-debug # parse the proto file sets in testdata/names and renders binary CodeGeneratorRequest + official go codegen +testdata-names: ../../bin/protoc-gen-debug ../../bin/protoc-gen-go # parse the proto file sets in testdata/names and renders binary CodeGeneratorRequest + official go codegen cd testdata/names && \ set -e; for subdir in `find . -type d -mindepth 1 -maxdepth 1`; do \ cd $$subdir; \ @@ -7,12 +7,13 @@ testdata-names: ../../bin/protoc-gen-debug # parse the proto file sets in testda protoc -I . \ --plugin=protoc-gen-debug=../../../../../bin/protoc-gen-debug \ --debug_out=".:." \ + --plugin=protoc-gen-go=../../../../../bin/protoc-gen-go \ --go_out="plugins,paths=source_relative,$$params:." \ `find . -name "*.proto"`; \ cd -; \ done -testdata-packages: ../../bin/protoc-gen-debug +testdata-packages: ../../bin/protoc-gen-debug ../../bin/protoc-gen-go cd testdata/packages && \ set -e; for subdir in `find . -type d -mindepth 1 -maxdepth 1 | grep -v targets`; do \ cd $$subdir; \ @@ -20,12 +21,13 @@ testdata-packages: ../../bin/protoc-gen-debug protoc -I . -I .. \ --plugin=protoc-gen-debug=../../../../../bin/protoc-gen-debug \ --debug_out=".:." \ + --plugin=protoc-gen-go=../../../../../bin/protoc-gen-go \ --go_out="paths=source_relative,$$params:." \ `find . -name "*.proto"`; \ cd -; \ done -testdata-outputs: ../../bin/protoc-gen-debug +testdata-outputs: ../../bin/protoc-gen-debug ../../bin/protoc-gen-go cd testdata/outputs && \ set -e; for subdir in `find . -type d -mindepth 1 -maxdepth 1`; do \ cd $$subdir; \ @@ -33,6 +35,7 @@ testdata-outputs: ../../bin/protoc-gen-debug protoc -I . -I .. \ --plugin=protoc-gen-debug=../../../../../bin/protoc-gen-debug \ --debug_out=".:." \ + --plugin=protoc-gen-go=../../../../../bin/protoc-gen-go \ --go_out="$$params:." \ `find . -name "*.proto"`; \ cd -; \ @@ -40,3 +43,6 @@ testdata-outputs: ../../bin/protoc-gen-debug ../../bin/protoc-gen-debug: cd ../.. && $(MAKE) bin/protoc-gen-debug + +../../bin/protoc-gen-go: + cd ../.. && $(MAKE) bin/protoc-gen-go diff --git a/tools.go b/tools.go new file mode 100644 index 0000000..c3da897 --- /dev/null +++ b/tools.go @@ -0,0 +1,9 @@ +// +build tools + +package tools + +import ( + _ "github.com/golang/protobuf/protoc-gen-go" + _ "golang.org/x/lint/golint" + _ "golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow" +)