forked from lightningnetwork/lightning-onion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (146 loc) · 6.52 KB
/
Copy pathMakefile
File metadata and controls
197 lines (146 loc) · 6.52 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
VERSION := v0.0.1
COMMIT := $(shell git log -1 --format='%H')
ldflags = -X github.com/lightningnetwork/lightning-onion/version.Name=onion \
-X github.com/lightningnetwork/lightning-onion/version.ServerName=oniond \
-X github.com/lightningnetwork/lightning-onion/version.Version=$(VERSION) \
-X github.com/lightningnetwork/lightning-onion/version.Commit=$(COMMIT)
BUILD_FLAGS := -ldflags '$(ldflags)'
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)
UNAME_S := $(shell uname)
INSTALL_PATH = $(if $(filter $(UNAME_S), Linux), /usr/bin, $(if $(filter $(UNAME_S), Darwin), /usr/local/bin,))
all: install
install: go.sum
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/oniond
build: go.sum clean
go build -mod=mod $(BUILD_FLAGS) -o build/oniond ./cmd/oniond
build-ci-cd:
go build -mod=mod $(BUILD_FLAGS) -a -installsuffix cgo -o ./bin/oniond ./cmd/oniond
build-darwin-arm64:
GOOS=darwin GOARCH=arm64 go build -mod=mod ${BUILD_FLAGS} -o build/oniond ./cmd/oniond
codesign -s - build/oniond
build-linux:
GOOS=linux go build -mod=mod ${BUILD_FLAGS} -o build/oniond ./cmd/oniond
build-linux-amd64:
GOOS=linux GOARCH=amd64 go build -mod=mod ${BUILD_FLAGS} -o build/oniond ./cmd/oniond
build-linux-arm64:
GOOS=linux GOARCH=arm64 go build -mod=mod ${BUILD_FLAGS} -o build/oniond ./cmd/oniond
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
.PHONY: check-mockery
check-mockery:
@which mockery > /dev/null; if [ $$? -eq 1 ]; then \
echo "mockery is not installed, installing..."; \
go install github.com/vektra/mockery/v2@v2.32.0; \
else \
EXPECTED_VERSION="2.32.0"; \
CURRENT_VERSION=$$(mockery --version | grep -Eo "[0-9].[0-9]{2}.[0-9]"); \
if [ "$$EXPECTED_VERSION" != "$$CURRENT_VERSION" ]; then \
echo "Updating mockery to the required version"; \
go install github.com/vektra/mockery/v2@v2.32.0; \
else \
echo "mockery is already installed with the expected version"; \
fi \
fi
mocks: check-mockery
@echo "--> Generating mocks"
mockery
test mockery:
go test --cover -short -p 1 ./...
.PHONY: all install build build-linux test
###############################################################################
### Linting ###
###############################################################################
golangci_lint_cmd=$$(go env GOPATH)/bin/golangci-lint
golangci_version=v1.49.0
# look into .golangci.yml for enabling / disabling linters
lint:
@echo "--> Running linter"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
@$(golangci_lint_cmd) run --timeout=20m
lint-fix:
@echo "--> Running linter"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
@$(golangci_lint_cmd) run --fix --out-format=tab --issues-exit-code=0
.PHONY: lint lint-fix
# Clean up the build directory
clean:
rm -rf build/
.PHONY: clean
###############################################################################
### Protobuf ###
###############################################################################
protoVer=v0.3
protoImageName=tendermintdev/sdk-proto-gen:$(protoVer)
containerProtoGen=$(PROJECT_NAME)-proto-gen-$(protoVer)
containerProtoGenAny=$(PROJECT_NAME)-proto-gen-any-$(protoVer)
containerProtoGenSwagger=$(PROJECT_NAME)-proto-gen-swagger-$(protoVer)
containerProtoFmt=$(PROJECT_NAME)-proto-fmt-$(protoVer)
proto-all: proto-format proto-lint proto-tss
proto-format:
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;
proto-lint:
@$(protoImage) buf lint --error-format=json
proto-tss:
@echo "--> Building Protocol Buffers"
@for protocol in message ecdsa; do \
echo "Generating $$protocol.pb.go" ; \
protoc --go_out=./x/kima/types ./proto/KimaFinance/kima/$$protocol.proto ; \
done
.PHONY: proto-all proto-format proto-lint
# Create log files
log-files:
sudo mkdir -p /var/log/kimad && sudo touch /var/log/kimad/kimad.log && sudo touch /var/log/kimad/kimad_error.log
sudo mkdir -p /var/log/ecdsad && sudo touch /var/log/ecdsad/ecdsad.log && sudo touch /var/log/ecdsad/ecdsad_error.log
sudo mkdir -p /var/log/eddsad && sudo touch /var/log/eddsad/eddsad.log && sudo touch /var/log/eddsad/eddsad_error.log
.PHONY: log-files
###############################################################################
### Tests ###
###############################################################################
test: test-unit
test-all: test-unit test-race
PACKAGES_UNIT=$(shell go list ./... | grep -Ev 'vendor|importer')
TEST_PACKAGES=./...
TEST_TARGETS := test-unit test-unit-cover test-race
# Test runs-specific rules. To add a new test target, just add
# a new rule, customise ARGS or TEST_PACKAGES ad libitum, and
# append the new rule to the TEST_TARGETS list.
test-unit: ARGS=-timeout=20m -race
test-unit: TEST_PACKAGES=$(PACKAGES_UNIT)
test-race: ARGS=-race
test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION)
$(TEST_TARGETS): run-tests
test-unit-cover: ARGS=-timeout=20m -race -coverprofile=coverage.txt -covermode=atomic
test-unit-cover: TEST_PACKAGES=$(PACKAGES_UNIT)
run-tests:
ifneq (,$(shell which tparse 2>/dev/null))
go test -mod=readonly -json $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES) | tparse
else
go test -mod=readonly $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES)
endif
.PHONY: run-tests test test-all $(TEST_TARGETS)
# Implements test splitting and running. This is pulled directly from
# the github action workflows for better local reproducibility.
GO_TEST_FILES != find $(CURDIR) -name "*_test.go"
# default to four splits by default
NUM_SPLIT ?= 3
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin) # macOS
SPLIT_CMD = gsplit
else
SPLIT_CMD = split
endif
BUILDDIR ?= $(CURDIR)/build
$(BUILDDIR):
mkdir -p $@
# The format statement filters out all packages that don't have tests.
# Note we need to check for both in-package tests (.TestGoFiles) and
# out-of-package tests (.XTestGoFiles).
$(BUILDDIR)/packages.txt:$(GO_TEST_FILES) $(BUILDDIR)
go list -f "{{ if (or .TestGoFiles .XTestGoFiles) }}{{ .ImportPath }}{{ end }}" ./... | sort > $@
split-test-packages:$(BUILDDIR)/packages.txt
$(SPLIT_CMD) -d -n l/$(NUM_SPLIT) $< $<.
test-group-%:split-test-packages
cat $(BUILDDIR)/packages.txt.$* | xargs go test -mod=readonly -timeout=30m -race -coverprofile=$(BUILDDIR)/$*.profile.out