forked from kakao/varlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
137 lines (110 loc) · 4.01 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
MAKEFLAGS += --warn-undefined-variables
SHELL := /bin/bash
GO := go
GCFLAGS := -gcflags=all='-N -l'
GOPATH := $(shell $(GO) env GOPATH)
PKGS := $(shell $(GO) list ./... | \
egrep -v "github.com/kakao/varlog/vendor" | \
egrep -v "github.com/kakao/varlog/tools" | \
sed -e "s;github.com/kakao/varlog/;;")
ifneq ($(shell echo $$OSTYPE | egrep "darwin"),)
export CGO_CFLAGS=-Wno-undef-prefix
endif
PYTHON := python3
.DEFAULT_GOAL := all
.PHONY: all
all: generate precommit build
# precommit
.PHONY: precommit precommit_lint
precommit: fmt tidy vet test test_py
precommit_lint: fmt tidy vet lint test test_py
# build
BIN_DIR := $(CURDIR)/bin
VMR := $(BIN_DIR)/vmr
VARLOGADM := $(BIN_DIR)/varlogadm
VARLOGSN := $(BIN_DIR)/varlogsn
VARLOGCTL := $(BIN_DIR)/varlogctl
VARLOGCLI := $(BIN_DIR)/varlogcli
MRTOOL := $(BIN_DIR)/mrtool
BENCHMARK := $(BIN_DIR)/benchmark
.PHONY: build vmr varlogadm varlogsn varlogctl varlogcli mrtool benchmark
build: vmr varlogadm varlogsn varlogctl varlogcli mrtool benchmark
vmr:
$(GO) build $(GCFLAGS) -o $(VMR) $(CURDIR)/cmd/varlogmr
varlogadm:
$(GO) build $(GCFLAGS) -o $(VARLOGADM) $(CURDIR)/cmd/varlogadm
varlogsn:
$(GO) build $(GCFLAGS) -o $(VARLOGSN) $(CURDIR)/cmd/varlogsn
varlogctl:
$(GO) build $(GCFLAGS) -o $(VARLOGCTL) $(CURDIR)/cmd/varlogctl
varlogcli:
$(GO) build $(GCFLAGS) -o $(VARLOGCLI) $(CURDIR)/cmd/varlogcli
mrtool:
$(GO) build $(GCFLAGS) -o $(MRTOOL) $(CURDIR)/cmd/mrtool
benchmark:
$(GO) build $(GCFLAGS) -o $(BENCHMARK) $(CURDIR)/cmd/benchmark
# testing
TEST_FLAGS := -race -failfast -count=1
GO_COVERAGE_OUTPUT := coverage.out
GO_COVERAGE_OUTPUT_TMP := $(GO_COVERAGE_OUTPUT).tmp
PYTEST := pytest
PYTHON_COVERAGE_OUTPUT := coverage.xml
.PHONY: test test_coverage test_ci test_report coverage_report test_py
test:
$(GO) test $(TEST_FLAGS) ./...
$(PYTEST)
test_coverage:
$(GO) test $(TEST_FLAGS) -coverprofile=$(GO_COVERAGE_OUTPUT_TMP) -covermode=atomic ./...
cat $(GO_COVERAGE_OUTPUT_TMP) | grep -v "_mock.go" | grep -v ".pb.go" > $(GO_COVERAGE_OUTPUT)
$(RM) $(GO_COVERAGE_OUTPUT_TMP)
$(PYTEST) --cov=./ --cov-report=xml:$(PYTHON_COVERAGE_OUTPUT)
# If you want to specify a directory for grpc_health_probe, enter following:
# make test_e2e_local TEST_ARGS="-args -grpc-health-probe-executable=<path>"
#
# If you have installed the grpc_health_probe and can look it up by PATH, it is
# unnecessary to enter TEST_ARGS.
TEST_ARGS :=
test_e2e_local: build
$(GO) test $(TEST_FLAGS) ./tests/ee/... -tags=e2e $(TEST_ARGS)
test_e2e_k8s: build
$(GO) test $(TEST_FLAGS) ./tests/ee/... -tags=e2e,k8s
# proto
DOCKER_PROTOBUF = ghcr.io/kakao/varlog-protobuf:0.1.0
PROTOC := docker run --rm -u $(shell id -u) -v$(PWD):$(PWD) -w$(PWD) $(DOCKER_PROTOBUF) --proto_path=$(PWD)
PROTO_SRCS := $(shell find . -name "*.proto" -not -path "./vendor/*")
PROTO_PBS := $(PROTO_SRCS:.proto=.pb.go)
PROTO_INCS := -I$(GOPATH)/src -I$(CURDIR)/proto -I$(CURDIR)/vendor
.PHONY: proto
proto: $(PROTO_PBS)
$(PROTO_PBS): $(PROTO_SRCS)
@echo $(PROTOC)
for src in $^ ; do \
$(PROTOC) $(PROTO_INCS) \
--gogo_out=plugins=grpc,Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,paths=source_relative:. $$src ; \
done
# go:generate
.PHONY: generate
generate:
$(GO) generate ./...
# tools: lint, fmt, vet
.PHONY: fmt lint vet
fmt:
@echo goimports
@$(foreach path,$(PKGS),goimports -w -local $(shell $(GO) list -m) ./$(path);)
@echo gofmt
@$(foreach path,$(PKGS),gofmt -w -s ./$(path);)
lint:
docker run --rm -v $$(pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run
vet:
@echo govet
@$(foreach path,$(PKGS),$(GO) vet ./$(path);)
tidy:
$(GO) mod tidy
# cleanup
.PHONY: clean clean_mock
clean:
$(GO) clean
$(RM) $(GO_COVERAGE_OUTPUT) $(PYTHON_COVERAGE_OUTPUT)
$(RM) $(VMR) $(VARLOGADM) $(VARLOGSN) $(VARLOGCTL) $(VARLOGCLI) $(MRTOOL) $(BENCHMARK)
clean_mock:
@$(foreach path,$(shell $(GO) list ./... | grep -v vendor | sed -e s#github.com/kakao/varlog/##),$(RM) -f $(path)/*_mock.go;)