11COVERAGE ?= coverage.txt
2-
3- .PHONY : all build test clean
2+ GO ?= go
3+ GOBIN ?= $(shell $(GO ) env GOBIN)
4+ ifeq ($(strip $(GOBIN ) ) ,)
5+ GOBIN := $(shell $(GO ) env GOPATH) /bin
6+ endif
7+ BUF_VERSION ?= v1.41.0
8+ BUF_BIN ?= $(GOBIN ) /buf
9+ PROTO_DIR ?= proto
10+ BUF_BREAKING_AGAINST ?= origin/main
11+
12+ BUF := $(shell command -v buf 2>/dev/null)
13+ ifeq ($(strip $(BUF ) ) ,)
14+ BUF := $(BUF_BIN )
15+ endif
16+
17+ .PHONY : all build test clean fmt vet \
18+ proto-lint proto-gen proto-gen-ci proto-check-breaking buf-install
419
520all : build
621
722build : build-memiavl build-store build-versiondb
823
924build-memiavl :
10- @cd memiavl && go build -mod=readonly -tags=objstore ./...
25+ @cd memiavl && $( GO ) build -mod=readonly -tags=objstore ./...
1126
1227build-store :
13- @cd store && go build -mod=readonly -tags=objstore ./...
28+ @cd store && $( GO ) build -mod=readonly -tags=objstore ./...
1429
1530build-versiondb :
16- @cd versiondb && go build -mod=readonly -tags=objstore ./...
31+ @cd versiondb && $( GO ) build -mod=readonly -tags=objstore ./...
1732
1833
1934test : test-memiavl test-store test-versiondb
2035
2136test-memiavl :
22- @cd memiavl && go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE ) -covermode=atomic;
37+ @cd memiavl && $( GO ) test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE ) -covermode=atomic;
2338
2439test-store :
25- @cd store && go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE ) -covermode=atomic;
40+ @cd store && $( GO ) test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE ) -covermode=atomic;
2641
2742test-versiondb :
28- @cd versiondb && go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE ) -covermode=atomic;
43+ @cd versiondb && $( GO ) test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE ) -covermode=atomic;
2944
3045clean : clean-memiavl clean-store clean-versiondb
3146
@@ -36,10 +51,27 @@ clean-store:
3651 @cd store && go clean
3752
3853clean-versiondb :
39- @cd versiondb && go clean
54+ @cd versiondb && $( GO ) clean
4055
4156fmt :
42- go fmt ./memiavl/... ./store/... ./versiondb/...
57+ $( GO ) fmt ./memiavl/... ./store/... ./versiondb/...
4358
4459vet :
45- go vet ./memiavl/... ./store/... ./versiondb/...
60+ $(GO ) vet ./memiavl/... ./store/... ./versiondb/...
61+
62+ buf-install :
63+ @if ! command -v buf > /dev/null 2>&1 && [ ! -x " $( BUF_BIN) " ]; then \
64+ echo " Installing buf $( BUF_VERSION) " ; \
65+ GOBIN=$(GOBIN ) $(GO ) install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION ) ; \
66+ fi
67+
68+ proto-lint : buf-install
69+ $(BUF ) lint $(PROTO_DIR ) --config $(PROTO_DIR ) /buf.yaml
70+
71+ proto-gen : buf-install
72+ $(BUF ) generate $(PROTO_DIR ) --template $(PROTO_DIR ) /buf.gen.yaml
73+
74+ proto-gen-ci : proto-gen
75+
76+ proto-check-breaking : buf-install
77+ $(BUF ) breaking $(PROTO_DIR ) --against " .git#branch=$( BUF_BREAKING_AGAINST) ,subdir=$( PROTO_DIR) " --config $(PROTO_DIR ) /buf.yaml
0 commit comments