Skip to content

Commit

Permalink
Makefile: make target proto-gen part of every build
Browse files Browse the repository at this point in the history
Also, adjust the target so it only runs if *.proto files changed.
Also, change it so docker uses ephemeral containers (not permanent).
  • Loading branch information
orenl-lava committed Aug 10, 2023
1 parent cafc50e commit 45dbc8a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# build-image-amd64 - docker build (output: `$(BUILD_DIR)/*-linux-amd64`) with docker image
# build-image-arm64 - docker build (output: `$(BUILD_DIR)/*-linux-arm64`) with docker image
#
# proto-gen - (re)generate protobuf file
# test - run unit-tests
# lint - run the linter
#
Expand Down Expand Up @@ -332,20 +333,26 @@ lint:
@echo "--> Running linter"
golangci-lint run --config .golangci.yml

PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)
# protobuf generation

define rwildcard
$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
endef

protoVer=0.13.5
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
containerProtoGen=$(PROJECT_NAME)-proto-gen-$(protoVer)
containerProtoFmt=$(PROJECT_NAME)-proto-fmt-$(protoVer)
containerProtoGen=lava-proto-gen-$(protoVer)
containerProtoFmt=lava-proto-fmt-$(protoVer)

proto-gen: $(BUILDDIR)/proto-gen

proto-gen:
@echo "Generating Protobuf files"
if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); \
else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
sh ./scripts/protocgen.sh; fi
$(BUILDDIR)/proto-gen: $(call rwildcard,proto/,*.proto)
@echo "Generating protobuf files"
docker run --rm -v $(CURDIR):/workspace --workdir /workspace \
$(protoImageName) sh ./scripts/protocgen.sh
@touch $@

.PHONY: all docker-build lint test \
.PHONY: all docker-build lint test proto-gen \
build build-all install install-all \
go-mod-cache go.sum draw-deps \
build-docker-helper build-docker-copier \
Expand Down

0 comments on commit 45dbc8a

Please sign in to comment.