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

Refactor code generation #65

Merged
merged 13 commits into from
Sep 8, 2023
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Ignore direnv files
/.envrc
46 changes: 44 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
Q=$(if $V,,@)
SRC=$(shell find . -type f -name '*.go')

# protoc-gen-go constraints
GEN_GO_BIN ?= protoc-gen-go
GEN_GO_MIN_VERSION ?= 1.31.0
GEN_GO_VERSION ?= $(shell $(GEN_GO_BIN) --version | awk -F ' v' '{print $$NF}')

# protoc-gen-go-grpc constraints
GEN_GRPC_BIN ?= protoc-gen-go-grpc
GEN_GRPC_MIN_VERSION ?= 1.3.0
GEN_GRPC_VERSION ?= $(shell $(GEN_GRPC_BIN) --version | awk -F ' ' '{print $$NF}')

all: lint generate test

ci: test
Expand Down Expand Up @@ -55,7 +65,39 @@ lint:
# Generate
#########################################

generate:
protoc --proto_path=. --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative provisioners.proto admin.proto config.proto eab.proto majordomo.proto policy.proto
generate: check-gen-go-version check-gen-grpc-version
@# remove any previously generated protobufs & gRPC files
@find . \
-type f \
-name "*.pb.go" \
-delete

@# generate the corresponding protobufs & gRPC code files
find spec -type f -name "*.proto" -print0 | xargs -0 protoc \
--proto_path=spec \
--go_opt=paths=source_relative \
--go_out=.. \
--go-grpc_opt=paths=source_relative \
--go-grpc_out=..

.PHONY: generate

#########################################
# Tool constraints
#########################################

check-gen-go-version:
@if ! printf "%s\n%s" "$(GEN_GO_MIN_VERSION)" "$(GEN_GO_VERSION)" | sort -V -C; then \
echo "Your $(GEN_GO_BIN) version (v$(GEN_GO_VERSION)) is older than the minimum required (v$(GEN_GO_MIN_VERSION))."; \
exit 1; \
fi

.PHONY: check-gen-go-version

check-gen-grpc-version:
@if ! printf "%s\n%s" "$(GEN_GRPC_MIN_VERSION)" "$(GEN_GRPC_VERSION)" | sort -V -C; then \
echo "Your $(GEN_GRPC_BIN) version (v$(GEN_GRPC_VERSION)) is older than the minimum required (v$(GEN_GRPC_MIN_VERSION))."; \
exit 1; \
fi

.PHONY: check-gen-grpc-version
135 changes: 68 additions & 67 deletions admin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading