-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (100 loc) · 3.18 KB
/
Copy pathMakefile
File metadata and controls
124 lines (100 loc) · 3.18 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
# Copyright (c) 2024-2026 Hemi Labs, Inc.
# Use of this source code is governed by the MIT License,
# which can be found in the LICENSE file.
# PROJECTPATH is the project root directory.
# This Makefile is stored in the project root directory, so the directory is
# retrieved by getting the directory of this Makefile.
PROJECTPATH := $(abspath $(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
GO_LDFLAGS ?=
export GOCACHE ?= $(PROJECTPATH)/.gocache
export GOBIN ?= $(shell go env GOPATH)/bin
PROJECT_BIN := $(PROJECTPATH)/bin
# renovate: datasource=github-releases depName=golangci/golangci-lint versioning=semver
GOLANGCI_LINT_VERSION := v2.12.2
# renovate: datasource=github-releases depName=joshuasing/golicenser versioning=semver
GOLICENSER_VERSION := v0.3.1
# renovate: datasource=github-releases depName=mvdan/gofumpt versioning=semver
GOFUMPT_VERSION := v0.10.0
# renovate: datasource=go depName=golang.org/x/vuln versioning=semver
GOVULNCHECK_VERSION := v1.6.0
cmds := \
bfgd \
btctool \
hemictl \
hproxyd \
keygen \
popmd \
tbcd \
transfunctionerd
.PHONY: all
all: tidy build lint test install
.PHONY: clean
clean: clean-test
go clean -cache
rm -rf $(PROJECT_BIN)
# TODO: This should not be necessary, all test files should be in a tempdir.
.PHONY: clean-test
clean-test:
rm -rf $(PROJECTPATH)/service/tbc/.testleveldb/
.PHONY: deps
deps: lint-deps vulncheck-deps go-deps
.PHONY: go-deps
go-deps:
go mod download
go mod verify
.PHONY: tidy
tidy:
go mod tidy
.PHONY: build
build:
go build -trimpath -ldflags "$(GO_LDFLAGS)" ./...
.PHONY: install
install: $(cmds)
.PHONY: $(cmds)
$(cmds):
go build -trimpath -ldflags "$(GO_LDFLAGS)" -o $(PROJECT_BIN)/$@ ./cmd/$@
.PHONY: test
test:
go test -timeout=20m -coverprofile=$(PROJECTPATH)/coverage.out \
-covermode=atomic -ldflags "$(GO_LDFLAGS)" ./...
.PHONY: race
race:
go test -race -timeout=20m -coverprofile=$(PROJECTPATH)/coverage.out \
-covermode=atomic -ldflags "$(GO_LDFLAGS)" ./...
.PHONY: cover
cover: test
go tool cover -html=$(PROJECTPATH)/coverage.out
.PHONY: synctest
synctest:
go -C $(PROJECTPATH)/synctest test -v -timeout=1m ./...
define LICENSE_HEADER
Copyright (c) {{.year}} {{.author}}
Use of this source code is governed by the MIT License,
which can be found in the LICENSE file.
endef
export LICENSE_HEADER
LICENSE_AUTHOR := Hemi Labs, Inc.
.PHONY: fmt
fmt:
$(GOBIN)/golangci-lint fmt ./...
$(GOBIN)/golicenser -tmpl="$$LICENSE_HEADER" -author="$(LICENSE_AUTHOR)" -year-mode=git-range -fix ./...
.PHONY: lint
lint: fmt
$(GOBIN)/golangci-lint run --fix ./...
.PHONY: lint-check
lint-check:
$(GOBIN)/golangci-lint fmt --diff ./...
$(GOBIN)/golangci-lint run ./...
$(GOBIN)/golicenser -tmpl="$$LICENSE_HEADER" -author="$(LICENSE_AUTHOR)" -year-mode=git-range ./...
.PHONY: lint-deps
lint-deps:
@echo "Installing with $(shell go version)"
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
go install github.com/joshuasing/golicenser/cmd/golicenser@$(GOLICENSER_VERSION)
go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
.PHONY: vulncheck
vulncheck:
$(GOBIN)/govulncheck ./...
.PHONY: vulncheck-deps
vulncheck-deps:
go install golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION)