-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
93 lines (76 loc) · 1.84 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
ifeq ($(V),1)
Q =
else
Q = @
endif
PROTODIR := proto
WPDIR := white-paper
TEST_OPTS := -count=1
TARGETS := degitx degitx-gitaly
SRC_DIR := $(abspath $(dir $(lastword ${MAKEFILE_LIST})))
BUILD_DIR := ${SRC_DIR}/target
PKG := cqfn.org/degitx
ifeq ($(V),1)
GOFLAGS :=
else
GOFLAGS := -v
endif
# find all commands binary names
find_cmd = $(notdir $(shell find ${SRC_DIR}/cmd -mindepth 1 -maxdepth 1 -type d -print))
# run_tests_dir - run all tests in provided directory
define _run_tests_dir
go test ${FLAGS} ${TEST_OPTS} "./$(1)/..."
endef
unexport GOROOT
export GOBIN=${BUILD_DIR}/bin
export GOCACHE=${BUILD_DIR}/cache
export PATH := ${BUILD_DIR}/bin:${PATH}
.PHONY: all
all: build
# build binaries
.PHONY: build
build: proto gen
${Q}go install ${GOFLAGS} $(addprefix ${PKG}/cmd/, $(call find_cmd))
.PHONY: gen
gen:
${Q}go generate ./...
# tests
.PHONY: test
test: proto
$(call _run_tests_dir,internal)
$(call _run_tests_dir,pkg)
# race detector
.PHONY: test-race
test-race: TEST_OPTS := ${TEST_OPTS} -race
test-race: test
# benchmarks
.PHONY: bench
bench: TEST_OPTS := ${TEST_OPTS} -bench=. -run=^$
bench: test
# generate protobuf sources
.PHONY: proto
proto:
$(MAKE) -C $(PROTODIR)
# clean all
.PHONY: clean
clean:
$(MAKE) -C $(PROTODIR) clean
${Q}mkdir -pv ${BUILD_DIR}
${Q}chmod -R +w ${BUILD_DIR}
${Q}rm -fr ${BUILD_DIR}
# install required dependencies
install-deps:
$(MAKE) -C $(PROTODIR) install-deps
# run golangci-lint
lint:
${Q}golangci-lint ${FLAGS} run
.PHONY: check-mod-tidy
check-mod-tidy:
${Q}git diff --exit-code go.mod go.sum || (echo "error: uncommitted changes in go.mod or go.sum" && exit 1)
${Q}go mod tidy
${Q}git diff --exit-code go.mod go.sum || (echo "error: uncommitted changes in go.mod or go.sum" && exit 1)
# verify build before commit
.PHONY: verify
verify: build test lint check-mod-tidy
$(WPDIR):
$(MAKE) -C $(WPDIR)