Debian Codegraph @

Makefile

raw
1 empty :=
2 space := $(empty) $(empty)
3 PACKAGE := github.com/envoyproxy/protoc-gen-validate
4
5 # protoc-gen-go parameters for properly generating the import path for PGV
6 VALIDATE_IMPORT := Mvalidate/validate.proto=${PACKAGE}/validate
7 GO_IMPORT_SPACES := ${VALIDATE_IMPORT},\
8 Mgoogle/protobuf/any.proto=google.golang.org/protobuf/types/known/anypb,\
9 Mgoogle/protobuf/duration.proto=google.golang.org/protobuf/types/known/durationpb,\
10 Mgoogle/protobuf/struct.proto=google.golang.org/protobuf/types/known/structpb,\
11 Mgoogle/protobuf/timestamp.proto=google.golang.org/protobuf/types/known/timestamppb,\
12 Mgoogle/protobuf/wrappers.proto=google.golang.org/protobuf/types/known/wrapperspb,\
13 Mgoogle/protobuf/descriptor.proto=google.golang.org/protobuf/types/descriptorpb
14 GO_IMPORT:=$(subst $(space),,$(GO_IMPORT_SPACES))
15
16 .DEFAULT_GOAL := help
17
18 .PHONY: help
19 help: Makefile
20 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
21
22 .PHONY: build
23 build: validate/validate.pb.go ## generates the PGV binary and installs it into $$GOPATH/bin
24 go install .
25
26 .PHONY: bazel
27 bazel: ## generate the PGV plugin with Bazel
28 bazel build //cmd/... //tests/...
29
30 .PHONY: build_generation_tests
31 build_generation_tests:
32 bazel build //tests/generation/...
33
34 .PHONY: gazelle
35 gazelle: ## runs gazelle against the codebase to generate Bazel BUILD files
36 bazel run //:gazelle -- update-repos -from_file=go.mod -prune -to_macro=dependencies.bzl%go_third_party
37 bazel run //:gazelle
38
39 .PHONY: lint
40 lint: bin/golint bin/shadow ## lints the package for common code smells
41 test -z "$(shell gofmt -d -s ./*.go)" || (gofmt -d -s ./*.go && exit 1)
42 # golint -set_exit_status
43 # check for variable shadowing
44 go vet -vettool=$(shell pwd)/bin/shadow ./...
45 # lints the python code for style enforcement
46 flake8 --config=python/setup.cfg python/protoc_gen_validate/validator.py
47 isort --check-only python/protoc_gen_validate/validator.py
48
49 bin/shadow:
50 GOBIN=$(shell pwd)/bin go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
51
52 bin/golint:
53 GOBIN=$(shell pwd)/bin go install golang.org/x/lint/golint
54
55 bin/protoc-gen-go:
56 GOBIN=$(shell pwd)/bin go install google.golang.org/protobuf/cmd/[email protected]
57
58 bin/harness:
59 cd tests && go build -o ../bin/harness ./harness/executor
60
61 .PHONY: harness
62 harness: testcases tests/harness/go/harness.pb.go tests/harness/go/main/go-harness tests/harness/cc/cc-harness bin/harness ## runs the test harness, validating a series of test cases in all supported languages
63 ./bin/harness -go -cc
64
65 .PHONY: bazel-tests
66 bazel-tests: ## runs all tests with Bazel
67 bazel test //tests/... --test_output=errors
68
69 .PHONY: example-workspace
70 example-workspace: ## run all tests in the example workspace
71 cd example-workspace && bazel test //... --test_output=errors
72
73 .PHONY: testcases
74 testcases: bin/protoc-gen-go ## generate the test harness case protos
75 rm -r tests/harness/cases/go || true
76 mkdir tests/harness/cases/go
77 rm -r tests/harness/cases/other_package/go || true
78 mkdir tests/harness/cases/other_package/go
79 rm -r tests/harness/cases/yet_another_package/go || true
80 mkdir tests/harness/cases/yet_another_package/go
81 rm -r tests/harness/cases/sort/go || true
82 mkdir tests/harness/cases/sort/go
83 # protoc-gen-go makes us go a package at a time
84 cd tests/harness/cases/other_package && \
85 protoc \
86 -I . \
87 -I ../../../.. \
88 --go_out="module=${PACKAGE}/tests/harness/cases/other_package/go,${GO_IMPORT}:./go" \
89 --plugin=protoc-gen-go=$(shell pwd)/bin/protoc-gen-go \
90 --validate_out="module=${PACKAGE}/tests/harness/cases/other_package/go,lang=go:./go" \
91 ./*.proto
92 cd tests/harness/cases/yet_another_package && \
93 protoc \
94 -I . \
95 -I ../../../.. \
96 --go_out="module=${PACKAGE}/tests/harness/cases/yet_another_package/go,${GO_IMPORT}:./go" \
97 --plugin=protoc-gen-go=$(shell pwd)/bin/protoc-gen-go \
98 --validate_out="module=${PACKAGE}/tests/harness/cases/yet_another_package/go,lang=go:./go" \
99 ./*.proto
100 cd tests/harness/cases/sort && \
101 protoc \
102 -I . \
103 -I ../../../.. \
104 --go_out="module=${PACKAGE}/tests/harness/cases/sort/go,${GO_IMPORT}:./go" \
105 --plugin=protoc-gen-go=$(shell pwd)/bin/protoc-gen-go \
106 --validate_out="module=${PACKAGE}/tests/harness/cases/sort/go,lang=go:./go" \
107 ./*.proto
108 cd tests/harness/cases && \
109 protoc \
110 -I . \
111 -I ../../.. \
112 --go_out="module=${PACKAGE}/tests/harness/cases/go,Mtests/harness/cases/other_package/embed.proto=${PACKAGE}/tests/harness/cases/other_package/go;other_package,Mtests/harness/cases/yet_another_package/embed.proto=${PACKAGE}/tests/harness/cases/yet_another_package/go,${GO_IMPORT}:./go" \
113 --plugin=protoc-gen-go=$(shell pwd)/bin/protoc-gen-go \
114 --validate_out="module=${PACKAGE}/tests/harness/cases/go,lang=go,Mtests/harness/cases/other_package/embed.proto=${PACKAGE}/tests/harness/cases/other_package/go,Mtests/harness/cases/yet_another_package/embed.proto=${PACKAGE}/tests/harness/cases/yet_another_package/go:./go" \
115 ./*.proto
116
117 validate/validate.pb.go: bin/protoc-gen-go validate/validate.proto
118 protoc -I . \
119 --plugin=protoc-gen-go=$(shell pwd)/bin/protoc-gen-go \
120 --go_opt=paths=source_relative \
121 --go_out="${GO_IMPORT}:." validate/validate.proto
122
123 tests/harness/go/harness.pb.go: bin/protoc-gen-go tests/harness/harness.proto
124 # generates the test harness protos
125 cd tests/harness && protoc -I . \
126 --plugin=protoc-gen-go=$(shell pwd)/bin/protoc-gen-go \
127 --go_out="module=${PACKAGE}/tests/harness/go,${GO_IMPORT}:./go" harness.proto
128
129 tests/harness/go/main/go-harness:
130 # generates the go-specific test harness
131 cd tests && go build -o ./harness/go/main/go-harness ./harness/go/main
132
133 tests/harness/cc/cc-harness: tests/harness/cc/harness.cc
134 # generates the C++-specific test harness
135 # use bazel which knows how to pull in the C++ common proto libraries
136 bazel build //tests/harness/cc:cc-harness
137 cp bazel-bin/tests/harness/cc/cc-harness $@
138 chmod 0755 $@
139
140 tests/harness/java/java-harness:
141 # generates the Java-specific test harness
142 mvn -q -f java/pom.xml clean package -DskipTests
143
144 .PHONY: prepare-python-release
145 prepare-python-release:
146 cp validate/validate.proto python/
147 cp LICENSE python/
148
149 .PHONY: python-release
150 python-release: prepare-python-release
151 rm -rf python/dist
152 python3.8 -m build --no-isolation --sdist python
153 # the below command should be identical to `python3.8 -m build --wheel`
154 # however that returns mysterious `error: could not create 'build': File exists`.
155 # setuptools copies source and data files to a temporary build directory,
156 # but why there's a collision or why setuptools stopped respecting the `build_lib` flag is unclear.
157 # As a workaround, we build a source distribution and then separately build a wheel from it.
158 python3.8 -m pip wheel --wheel-dir python/dist --no-deps python/dist/*
159 python3.8 -m twine upload --verbose --skip-existing --repository ${PYPI_REPO} --username "__token__" --password ${PGV_PYPI_TOKEN} python/dist/*
160
161 .PHONY: check-generated
162 check-generated: ## run during CI; this checks that the checked-in generated code matches the generated version.
163 for f in validate/validate.pb.go ; do \
164 mv $$f $$f.original ; \
165 make $$f ; \
166 mv $$f $$f.generated ; \
167 cp $$f.original $$f ; \
168 diff $$f.original $$f.generated ; \
169 done
170
171 .PHONY: ci
172 ci: lint bazel testcases bazel-tests build_generation_tests example-workspace check-generated
173
174 .PHONY: clean
175 clean: ## clean up generated files
176 (which bazel && bazel clean) || true
177 rm -f \
178 bin/protoc-gen-go \
179 bin/harness \
180 tests/harness/cc/cc-harness \
181 tests/harness/go/main/go-harness \
182 tests/harness/go/harness.pb.go
183 rm -rf \
184 tests/harness/cases/go \
185 tests/harness/cases/other_package/go \
186 tests/harness/cases/yet_another_package/go
187 rm -rf \
188 python/dist \
189 python/*.egg-info