Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Remove protoc-gen-go dependency (lyft#30)
Browse files Browse the repository at this point in the history
* Removal of Plugins

* protoc-gen-debug + a bunch of testdata

* - Gatherer + AST graph parser

* Move some isolated Go-specific stuff

* SourceCodeInfo

* WKTs

* Imports

* Move go specific stuff into subpackage

* Mock Debugger

* Bye PGGo

* Buncha tests…

* Generator to use new AST + workflows

* Update module interface

* Update persister

* proto related helpers

* update example plugin

* Readme + Travis
  • Loading branch information
rodaine authored Sep 4, 2018
1 parent f3b83fc commit b870fc9
Show file tree
Hide file tree
Showing 156 changed files with 4,610 additions and 4,950 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# vendored code
vendor/
testdata/generated/

# binaries
bin/

# coverage reports
cover.*


testdata/generated/
**/*.pb.go
**/code_generator_request.pb.bin
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
language: go
go: "1.10"
go: "1.11"

env:
global:
- GLIDE_VER="v0.13.1"
- GLIDE_ARCH="linux-amd64"
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}-${GLIDE_ARCH}.tar.gz" -O /tmp/glide.tar.gz
- 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
- sudo mv /tmp/include/google /usr/local/include/google

install: make install
install: make testdata
script: make lint tests
100 changes: 77 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
# the name of this package
PKG := $(shell go list .)

.PHONY: install
install: # downloads dependencies (including test deps) for the package
which glide || (curl https://glide.sh/get | sh)
glide install
# the name of this package & all subpackages
PKG := $(shell go list .)
PKGS := $(shell go list ./...)

.PHONY: lint
lint: # 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
test -z "$(gofmt -d -s ./*.go)" || (gofmt -d -s ./*.go && exit 1)
golint -set_exit_status
go tool vet -all -shadow -shadowstrict *.go
golint -set_exit_status $(PKGS)
go vet -all -shadow -shadowstrict $(PKGS)

.PHONY: quick
quick: # runs all tests without the race detector or coverage percentage
go test
quick: vendor # runs all tests without the race detector or coverage
go test $(PKGS)

.PHONY: tests
tests: # runs all tests against the package with race detection and coverage percentage
go test -race -cover
tests: vendor # runs all tests against the package with race detection and coverage percentage
go test -race -cover $(PKGS)

.PHONY: cover
cover: # runs all tests against the package, generating a coverage report and opening it in the browser
go test -race -covermode=atomic -coverprofile=cover.out
cover: vendor # 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

Expand All @@ -32,11 +31,66 @@ docs: # starts a doc server and opens a browser window to this package
(sleep 2 && open http://localhost:6060/pkg/$(PKG)/) &
godoc -http=localhost:6060

.PHONY: demo
demo: # compiles, installs, and runs the demo protoc-plugin
go install $(PKG)/testdata/protoc-gen-example
rm -r ./testdata/generated || true
mkdir -p ./testdata/generated
set -e; cd ./testdata/protos; for subdir in `find . -type d -mindepth 1 -maxdepth 1`; do \
protoc -I . --example_out="plugins:../generated" `find $$subdir -name "*.proto"`; \
.PHONY: testdata
testdata: testdata-graph testdata-go testdata/generated # generate all testdata

.PHONY: testdata-graph
testdata-graph: bin/protoc-gen-debug # parses the proto file sets in testdata/graph and renders binary CodeGeneratorRequest
set -e; for subdir in `find ./testdata/graph -type d -mindepth 1 -maxdepth 1`; do \
protoc -I ./testdata/graph \
--plugin=protoc-gen-debug=./bin/protoc-gen-debug \
--debug_out="$$subdir:$$subdir" \
`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)
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 \
--go_out="$$GOPATH/src" \
$$files; \
done
# generate using our demo plugin, don't need to go directory at a time
set -e; for subdir in `find ./testdata/protos -type d -mindepth 1 -maxdepth 1`; do \
protoc -I ./testdata/protos \
--plugin=protoc-gen-example=./bin/protoc-gen-example \
--example_out="paths=source_relative:./testdata/generated" \
`find $$subdir -name "*.proto"`; \
done

.PHONY: testdata-go
testdata-go: 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

.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: 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: vendor # creates the protoc-gen-debug protoc plugin for output ProtoGeneratorRequest messages
go build -o ./bin/protoc-gen-debug ./protoc-gen-debug

.PHONY: clean
clean:
rm -rf vendor
rm -rf bin
rm -rf testdata/generated
set -e; for f in `find . -name *.pb.bin`; do \
rm $$f; \
done
set -e; for f in `find . -name *.pb.go`; do \
rm $$f; \
done
Loading

0 comments on commit b870fc9

Please sign in to comment.