Skip to content

Commit

Permalink
Refactored code generation (#65)
Browse files Browse the repository at this point in the history
This commit refactored the codebase in order to address our internal build issue. It additionally added checks to the Makefile, that ensure that code is generated via suitable versions of protoc-gen-go and protoc-gen-go-grpc going forward.
  • Loading branch information
azazeal authored Sep 8, 2023
1 parent 295c0c0 commit b02f24e
Show file tree
Hide file tree
Showing 15 changed files with 1,731 additions and 1,671 deletions.
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

0 comments on commit b02f24e

Please sign in to comment.