Debian Codegraph @

Makefile

raw
1 # the name of this package
2 PKG := $(shell go list .)
3 PROTOC_VER := $(shell protoc --version | cut -d' ' -f2)
4
5 .PHONY: bootstrap
6 bootstrap: testdata # set up the project for development
7
8 .PHONY: quick
9 quick: testdata # runs all tests without the race detector or coverage
10 ifeq ($(PROTOC_VER), 3.17.0)
11 go test $(PKGS) --tags=proto3_presence
12 else
13 go test $(PKGS)
14 endif
15
16 .PHONY: tests
17 tests: testdata # runs all tests against the package with race detection and coverage percentage
18 ifeq ($(PROTOC_VER), 3.17.0)
19 go test -race -cover ./... --tags=proto3_presence
20 else
21 go test -race -cover ./...
22 endif
23
24 .PHONY: cover
25 cover: testdata # runs all tests against the package, generating a coverage report and opening it in the browser
26 ifeq ($(PROTOC_VER), 3.17.0)
27 go test -race -covermode=atomic -coverprofile=cover.out ./... --tags=proto3_presence || true
28 else
29 go test -race -covermode=atomic -coverprofile=cover.out ./... || true
30 endif
31 go tool cover -html cover.out -o cover.html
32 open cover.html
33
34 .PHONY: docs
35 docs: # starts a doc server and opens a browser window to this package
36 (sleep 2 && open http://localhost:6060/pkg/$(PKG)/) &
37 godoc -http=localhost:6060
38
39 .PHONY: testdata
40 testdata: testdata-graph testdata-go testdata/generated testdata/fdset.bin # generate all testdata
41
42 .PHONY: testdata-graph
43 testdata-graph: bin/protoc-gen-debug # parses the proto file sets in testdata/graph and renders binary CodeGeneratorRequest
44 set -e; for subdir in `find ./testdata/graph -mindepth 1 -maxdepth 1 -type d`; do \
45 protoc -I ./testdata/graph \
46 --plugin=protoc-gen-debug=./bin/protoc-gen-debug \
47 --debug_out="$$subdir:$$subdir" \
48 `find $$subdir -name "*.proto"`; \
49 done
50
51 testdata/generated: protoc-gen-go bin/protoc-gen-example
52 go install google.golang.org/protobuf/cmd/protoc-gen-go
53 rm -rf ./testdata/generated && mkdir -p ./testdata/generated
54 # generate the official go code, must be one directory at a time
55 set -e; for subdir in `find ./testdata/protos -mindepth 1 -type d`; do \
56 files=`find $$subdir -maxdepth 1 -name "*.proto"`; \
57 [ ! -z "$$files" ] && \
58 protoc -I ./testdata/protos \
59 --go_out="$$GOPATH/src" \
60 $$files; \
61 done
62 # generate using our demo plugin, don't need to go directory at a time
63 set -e; for subdir in `find ./testdata/protos -mindepth 1 -maxdepth 1 -type d`; do \
64 protoc -I ./testdata/protos \
65 --plugin=protoc-gen-example=./bin/protoc-gen-example \
66 --example_out="paths=source_relative:./testdata/generated" \
67 `find $$subdir -name "*.proto"`; \
68 done
69
70 testdata/fdset.bin:
71 @protoc -I ./testdata/protos \
72 -o ./testdata/fdset.bin \
73 --include_imports \
74 testdata/protos/**/*.proto
75
76 .PHONY: testdata-go
77 testdata-go: protoc-gen-go bin/protoc-gen-debug # generate go-specific testdata
78 cd lang/go && $(MAKE) \
79 testdata-names \
80 testdata-packages \
81 testdata-outputs
82 ifeq ($(PROTOC_VER), 3.17.0)
83 cd lang/go && $(MAKE) \
84 testdata-presence
85 endif
86
87 .PHONY: protoc-gen-go
88 protoc-gen-go:
89 go install google.golang.org/protobuf/cmd/protoc-gen-go
90
91 bin/protoc-gen-example: # creates the demo protoc plugin for demonstrating uses of PG*
92 go build -o ./bin/protoc-gen-example ./testdata/protoc-gen-example
93
94 bin/protoc-gen-debug: # creates the protoc-gen-debug protoc plugin for output ProtoGeneratorRequest messages
95 go build -o ./bin/protoc-gen-debug ./protoc-gen-debug
96
97 .PHONY: clean
98 clean:
99 rm -rf bin
100 rm -rf testdata/generated
101 set -e; for f in `find . -name *.pb.bin`; do \
102 rm $$f; \
103 done
104 set -e; for f in `find . -name *.pb.go`; do \
105 rm $$f; \
106 done