forked from lightninglabs/pool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
162 lines (123 loc) · 3.97 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
PKG := github.com/lightninglabs/pool
ESCPKG := github.com\/lightninglabs\/pool
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
GOACC_PKG := github.com/ory/go-acc
GO_BIN := ${GOPATH}/bin
LINT_BIN := $(GO_BIN)/golangci-lint
GOACC_BIN := $(GO_BIN)/go-acc
LINT_COMMIT := v1.18.0
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
DEPGET := cd /tmp && go get -v
GOBUILD := go build -v
GOINSTALL := go install -v
GOTEST := go test -v
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
GOLISTCOVER := $(shell go list -deps -f '{{.ImportPath}}' ./... | grep '$(PKG)' | sed -e 's/^$(ESCPKG)/./')
COMMIT := $(shell git describe --abbrev=40 --dirty)
LDFLAGS := -X $(PKG).Commit=$(COMMIT)
RM := rm -f
CP := cp
MAKE := make
XARGS := xargs -L 1
include make/testing_flags.mk
include make/release_flags.mk
# For the release, we want to remove the symbol table and debug information (-s)
# and omit the DWARF symbol table (-w). Also we clear the build ID.
RELEASE_LDFLAGS := -s -w -buildid= $(LDFLAGS)
# 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: scratch
all: scratch check install
# ============
# DEPENDENCIES
# ============
$(LINT_BIN):
@$(call print, "Fetching linter")
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
$(GOACC_BIN):
@$(call print, "Fetching go-acc")
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
# ============
# INSTALLATION
# ============
build:
@$(call print, "Building Pool.")
$(GOBUILD) -ldflags="$(LDFLAGS)" $(PKG)/cmd/pool
$(GOBUILD) -ldflags="$(LDFLAGS)" $(PKG)/cmd/poold
install:
@$(call print, "Installing Pool.")
$(GOINSTALL) -ldflags="$(LDFLAGS)" $(PKG)/cmd/pool
$(GOINSTALL) -ldflags="$(LDFLAGS)" $(PKG)/cmd/poold
release:
@$(call print, "Releasing pool and poold binaries.")
$(VERSION_CHECK)
./scripts/release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "" "$(RELEASE_LDFLAGS)"
scratch: build
# =======
# TESTING
# =======
check: unit
unit:
@$(call print, "Running unit tests.")
$(UNIT)
unit-cover: $(GOACC_BIN)
@$(call print, "Running unit coverage tests.")
$(GOACC_BIN) $(COVER_PKG)
unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE)
# =============
# FLAKE HUNTING
# =============
flake-unit:
@$(call print, "Flake hunting unit tests.")
while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done
flake-race:
@$(call print, "Flake hunting race tests.")
while [ $$? -eq 0 ]; do GOTRACEBACK=all CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(UNIT_RACE) -count=1; done
# =========
# UTILITIES
# =========
fmt:
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)
lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(LINT)
list:
@$(call print, "Listing commands.")
@$(MAKE) -qp | \
awk -F':' '/^[a-zA-Z0-9][^$$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | \
grep -v Makefile | \
sort
gen: rpc mock
mock:
@$(call print, "Generating mock packages.")
cd ./gen; ./gen_mock_docker.sh
mock-check: mock
@$(call print, "Verifying mocks.")
if test -n "$$(git status --porcelain '*.go')"; then echo "Mocks not properly generated!"; git status --porcelain '*.go'; exit 1; fi
rpc:
@$(call print, "Compiling protos.")
cd ./poolrpc; ./gen_protos_docker.sh
rpc-check: rpc
@$(call print, "Verifying protos.")
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with correct version!"; git status; git diff; exit 1; fi
rpc-js-compile:
@$(call print, "Compiling JSON/WASM stubs.")
GOOS=js GOARCH=wasm $(GOBUILD) $(PKG)/poolrpc
clean:
@$(call print, "Cleaning source.$(NC)")
$(RM) ./pool
$(RM) ./poold
$(RM) coverage.txt