forked from ltcsuite/neutrino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
125 lines (96 loc) · 2.56 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
PKG := github.com/dcrlabs/neutrino-ltc
LTCD_PKG := github.com/ltcsuite/ltcd
GOACC_PKG := github.com/ory/go-acc
GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports
GO_BIN := ${GOPATH}/bin
LINT_BIN := $(GO_BIN)/golangci-lint
GOACC_BIN := $(GO_BIN)/go-acc
# NOTE: Install linter locally with
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.48.0
GOACC_COMMIT := v0.2.6
GOBUILD := go build -v
GOINSTALL := go install -v
GOTEST := go test
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'
GOLIST_COVER := $$(go list -deps $(PKG)/... | grep '$(PKG)')
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
LTCD_COMMIT := $(shell cat go.mod | \
grep $(LTCD_PKG) | \
head -n1 | \
awk -F " " '{ print $$2 }' | \
awk -F "/" '{ print $$1 }')
RM := rm -f
CP := cp
MAKE := make
XARGS := xargs -L 1
# Linting uses a lot of memory, so keep it under control by limiting the number
# of workers if requested.
ifneq ($(workers),)
LINT_WORKERS = --concurrency=$(workers)
endif
LINT = $(LINT_BIN) run -v $(LINT_WORKERS)
GREEN := "\\033[0;32m"
NC := "\\033[0m"
define print
echo $(GREEN)$1$(NC)
endef
default: build
all: build check
# ============
# DEPENDENCIES
# ============
# Cannot work with Go 1.18+ which disallows replaces in release installs:
ltcd:
@$(call print, "Installing ltcd.")
(cd /tmp && git clone -b $(LTCD_COMMIT) https://$(LTCD_PKG) ltcd && \
cd ltcd && $(GOINSTALL))
$(GOACC_BIN):
@$(call print, "Fetching go-acc")
$(GOINSTALL) $(GOACC_PKG)@$(GOACC_COMMIT)
goimports:
@$(call print, "Installing goimports.")
$(GOINSTALL) $(GOIMPORTS_PKG)@latest
# ============
# INSTALLATION
# ============
build:
@$(call print, "Compiling neutrino.")
$(GOBUILD) $(PKG)/...
# =======
# TESTING
# =======
check: unit
unit: ltcd
@$(call print, "Running unit tests.")
$(GOLIST) | $(XARGS) env $(GOTEST)
unit-cover: ltcd $(GOACC_BIN)
@$(call print, "Running unit coverage tests.")
$(GOACC_BIN) $(GOLIST_COVER)
unit-race: ltcd
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOLIST) | $(XARGS) env $(GOTEST) -race
# =========
# UTILITIES
# =========
fmt: goimports
@$(call print, "Fixing imports.")
goimports -w $(GOFILES_NOVENDOR)
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)
lint:
@$(call print, "Linting source.")
$(LINT)
clean:
@$(call print, "Cleaning source.$(NC)")
$(RM) coverage.txt
.PHONY: all \
ltcd \
default \
build \
check \
unit \
unit-cover \
unit-race \
fmt \
lint \
clean