-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
200 lines (163 loc) · 5.48 KB
/
Copy pathMakefile
File metadata and controls
200 lines (163 loc) · 5.48 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
PKG := github.com/blinklabs-io/handshake-node
LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint
GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports
VULNCHECK_PKG := golang.org/x/vuln/cmd/govulncheck
GO_BIN := ${shell go env GOBIN}
# If GOBIN is not set, default to GOPATH/bin.
ifeq ($(GO_BIN),)
GO_BIN := $(shell go env GOPATH)/bin
endif
# Some targets change directories before invoking installed tools.
GO_BIN := $(abspath $(GO_BIN))
LINT_BIN := $(GO_BIN)/golangci-lint
GOIMPORTS_BIN := $(GO_BIN)/goimports
VULNCHECK_BIN := $(GO_BIN)/govulncheck
LINT_COMMIT := v2.1.6
GOIMPORTS_COMMIT := a24facf9e5586c95743d2f4ad15d148c7a8cf00b
VULNCHECK_COMMIT := v1.6.0
GOBUILD := go build -v
GOINSTALL := env GOBIN=$(GO_BIN) go install -v
DEV_TAGS := rpctest
GOTEST_DEV = go test -p 1 -v -tags=$(DEV_TAGS)
GOTEST := go test -v
COVER_FLAGS = -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(PKG)/...
# 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_TIMEOUT := 5m
LINT = $(LINT_BIN) run -v $(LINT_WORKERS) --timeout=$(LINT_TIMEOUT)
GREEN := "\\033[0;32m"
NC := "\\033[0m"
define print
echo $(GREEN)$1$(NC)
endef
#? default: Run `make build`
default: build
#? all: Run `make build` and `make check`
all: build check
# ============
# DEPENDENCIES
# ============
$(LINT_BIN):
@$(call print, "Fetching linter")
$(GOINSTALL) $(LINT_PKG)@$(LINT_COMMIT)
$(VULNCHECK_BIN):
@$(call print, "Fetching vulnerability scanner")
$(GOINSTALL) $(VULNCHECK_PKG)@$(VULNCHECK_COMMIT)
#? goimports: Install goimports
goimports:
@$(call print, "Installing goimports.")
$(GOINSTALL) $(GOIMPORTS_PKG)@$(GOIMPORTS_COMMIT)
# ============
# INSTALLATION
# ============
#? build: Build all binaries, place them in project directory
build:
@$(call print, "Building all binaries")
$(GOBUILD) $(PKG)
$(GOBUILD) $(PKG)/cmd/hnsctl
$(GOBUILD) $(PKG)/cmd/gencerts
$(GOBUILD) $(PKG)/cmd/findcheckpoint
$(GOBUILD) $(PKG)/cmd/addblock
$(GOBUILD) $(PKG)/cmd/hsdinterop
$(GOBUILD) $(PKG)/cmd/hnsparity
#? install: Install all binaries, place them in $GOPATH/bin
install:
@$(call print, "Installing all binaries")
$(GOINSTALL) $(PKG)
$(GOINSTALL) $(PKG)/cmd/hnsctl
$(GOINSTALL) $(PKG)/cmd/gencerts
$(GOINSTALL) $(PKG)/cmd/findcheckpoint
$(GOINSTALL) $(PKG)/cmd/addblock
$(GOINSTALL) $(PKG)/cmd/hsdinterop
$(GOINSTALL) $(PKG)/cmd/hnsparity
#? release-install: Install handshake-node and hnsctl release binaries, place them in $GOBIN
release-install:
@$(call print, "Installing handshake-node and hnsctl release binaries")
# Build both commands in one Go invocation so an in-tree GOBIN cannot make
# the second binary appear to come from a dirty worktree.
env CGO_ENABLED=0 $(GOINSTALL) -trimpath -ldflags="-s -w -buildid=" $(PKG) $(PKG)/cmd/hnsctl
# =======
# TESTING
# =======
#? check: Run `make unit`
check: unit
#? unit: Run unit tests
unit:
@$(call print, "Running unit tests.")
$(GOTEST_DEV) ./... -test.timeout=20m
cd hnsutil && $(GOTEST_DEV) ./... -test.timeout=20m
cd hnsutil/psbt && $(GOTEST_DEV) ./... -test.timeout=20m
#? unit-cover: Run unit coverage tests
unit-cover:
@$(call print, "Running unit coverage tests.")
$(GOTEST) $(COVER_FLAGS) ./...
cd hnsutil && $(GOTEST) $(COVER_FLAGS) ./...
cd hnsutil/psbt && $(GOTEST) $(COVER_FLAGS) ./...
#? unit-race: Run unit race tests
unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
cd hnsutil && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
cd hnsutil/psbt && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
#? integration: Run the bounded tagged RPC integration suite
integration:
@$(call print, "Running tagged RPC integration tests.")
$(GOTEST_DEV) ./integration -count=1 -test.timeout=20m
#? vuln: Check all modules for reachable known vulnerabilities
vuln: $(VULNCHECK_BIN)
@$(call print, "Checking for reachable known vulnerabilities.")
$(VULNCHECK_BIN) ./...
cd hnsutil && $(VULNCHECK_BIN) ./...
cd hnsutil/psbt && $(VULNCHECK_BIN) ./...
#? hsd-interop: Run live protocol tests against pinned hsd (requires HSD_DIR)
hsd-interop:
@$(call print, "Running live hsd interoperability protocol tests.")
env HSD_DIR="$(HSD_DIR)" $(GOTEST) -tags=hsdinterop ./cmd/hsdinterop -count=1 -test.timeout=2m
#? hnsparity: Build the manual mainnet parity runner
hnsparity:
@$(call print, "Building manual mainnet parity runner.")
$(GOBUILD) $(PKG)/cmd/hnsparity
# =========
# UTILITIES
# =========
#? fmt: Fix imports and formatting source
fmt: goimports
@$(call print, "Fixing imports.")
$(GOIMPORTS_BIN) -w .
@$(call print, "Formatting source.")
gofmt -l -w -s .
#? lint: Lint source
lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(LINT)
#? clean: Clean source
clean:
@$(call print, "Cleaning source.$(NC)")
rm -f coverage.txt hnsutil/coverage.txt hnsutil/psbt/coverage.txt
#? tidy-module: Run 'go mod tidy' for all modules
tidy-module:
echo "Running 'go mod tidy' for all modules"
scripts/tidy_modules.sh
.PHONY: all \
default \
build \
check \
unit \
unit-cover \
unit-race \
integration \
vuln \
hsd-interop \
hnsparity \
fmt \
lint \
clean \
tidy-module
#? help: Get more info on make commands
help: Makefile
@echo " Choose a command run in handshake-node:"
@sed -n 's/^#?//p' $< | column -t -s ':' | sort | sed -e 's/^/ /'
.PHONY: help