forked from sedaprotocol/seda-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
363 lines (291 loc) · 11.8 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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/usr/bin/env make -f
###############################################################################
## Set Env Vars ##
###############################################################################
export CGO_ENABLED=1
export VERSION := $(shell echo $(shell git describe --tags --always --match "v*"))
export COMMIT := $(shell git log -1 --format='%H')
###############################################################################
## Set Local Vars ##
###############################################################################
LEDGER_ENABLED ?= true
BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
build_tags = netgo
# If we are building ledger support
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif
ifeq (secp,$(findstring secp,$(COSMOS_BUILD_OPTIONS)))
build_tags += libsecp256k1_sdk
endif
whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=seda-chain \
-X github.com/cosmos/cosmos-sdk/version.AppName=seda-chaind \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TMVERSION)
# DB Selection
ifeq ($(ENABLE_ROCKSDB),true)
BUILD_TAGS += rocksdb
test_tags += rocksdb
endif
# DB backend selection
ifeq (rocksdb,$(findstring rocksdb,$(COSMOS_BUILD_OPTIONS)))
ifneq ($(ENABLE_ROCKSDB),true)
$(error Cannot use RocksDB backend unless ENABLE_ROCKSDB=true)
endif
endif
# For building statically linked binaries
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif
# Check for debug option
ifeq (debug,$(findstring debug,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
endif
# default make command
all: clean go.sum fmt lint build
###############################################################################
## Build ##
###############################################################################
BUILD_TARGETS := build install
build: BUILD_ARGS=-o $(BUILDDIR)/
$(BUILD_TARGETS): go.sum $(BUILDDIR)/
@go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
$(BUILDDIR)/:
@mkdir -p $(BUILDDIR)/
clean:
@echo "--> Cleaning..."
@rm -rf $(BUILDDIR)/**
.PHONY: build clean
###############################################################################
### Tools & Dependencies ###
###############################################################################
go.sum: go.mod
@echo "Ensure dependencies have not been modified ..." >&2
@go mod verify
@go mod tidy
fmt:
@echo "--> Running go fmt"
$(shell go fmt ./...)
###############################################################################
### Linting ###
###############################################################################
golangci_version=v1.53.3
lint-install:
@echo "--> Installing golangci-lint $(golangci_version)"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
lint:
@echo "--> Running linter"
@./scripts/go-lint-all.bash --timeout=15m
.PHONY: lint lint-install
###############################################################################
### Protobuf ###
###############################################################################
proto-all: proto-gen proto-fmt proto-lint
proto-dep-install:
@go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@latest
@go install github.com/cosmos/gogoproto/protoc-gen-gocosmos@latest
@go install github.com/cosmos/gogoproto/protoc-gen-gogo@latest
proto-gen:
@echo "Generating Protobuf files"
@./scripts/proto_gen.sh
proto-fmt:
@echo "Formatting Protobuf files"
@find ./ -name "*.proto" -exec clang-format -i {} \;
proto-lint:
@echo "Linting Protobuf files"
@buf lint --error-format=json ./proto
proto-update-deps:
@echo "Updating Protobuf dependencies"
@buf mod update ./proto
.PHONY: proto-gen proto-fmt proto-lint proto-update-deps
###############################################################################
## Tests ##
###############################################################################
PACKAGES_UNIT=$(shell go list ./... | grep -v /e2e)
PACKAGES_E2E=$(shell go list ./... | grep /e2e)
TEST_PACKAGES=./...
TEST_TARGETS := test-unit test-unit-cover test-unit-race test-e2e
TEST_COVERAGE_PROFILE=coverage.txt
UNIT_TEST_TAGS = norace
TEST_RACE_TAGS = ""
test-unit: ARGS=-timeout=10m -tags='$(UNIT_TEST_TAGS)'
test-unit: TEST_PACKAGES=$(PACKAGES_UNIT)
test-unit-cover: ARGS=-timeout=10m -tags='$(UNIT_TEST_TAGS)' -coverprofile=$(TEST_COVERAGE_PROFILE) -covermode=atomic
test-unit-cover: TEST_PACKAGES=$(PACKAGES_UNIT)
test-unit-race: ARGS=-timeout=10m -race -tags='$(TEST_RACE_TAGS)'
test-unit-race: TEST_PACKAGES=$(PACKAGES_UNIT)
test-e2e: docker-build-e2e
test-e2e: ARGS=-timeout=10m -v
test-e2e: TEST_PACKAGES=$(PACKAGES_E2E)
$(TEST_TARGETS): run-tests
run-tests:
ifneq (,$(shell which tparse 2>/dev/null))
@echo "--> Running tests"
@go test -mod=readonly -json $(ARGS) $(TEST_PACKAGES) | tparse
else
@echo "--> Running tests"
@go test -mod=readonly $(ARGS) $(TEST_PACKAGES)
endif
cover-html: test-unit-cover
@echo "--> Opening in the browser"
@go tool cover -html=$(TEST_COVERAGE_PROFILE)
ifdef GITHUB_TOKEN
docker-build-e2e:
@docker build \
--build-arg GITHUB_TOKEN=$(GITHUB_TOKEN) \
-t sedaprotocol/seda-chaind-e2e \
-f dockerfiles/Dockerfile.e2e .
else
docker-build-e2e:
@echo "Error: GITHUB_TOKEN variable required to build e2e image"
endif
.PHONY: cover-html run-tests $(TEST_TARGETS) test test-race docker-build-e2e
###############################################################################
### Simulation Tests ###
###############################################################################
CURRENT_DIR = $(shell pwd)
test-sim-determinism:
@echo "Running determinism test..."
@cd ${CURRENT_DIR}/simulation && go test -mod=readonly -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h
test-sim-export-import:
@echo "Running export-import test..."
@cd ${CURRENT_DIR}/simulation && go test -mod=readonly -run TestAppExportImport -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h
test-sim-after-import:
@echo "Running simulation-after-import test..."
@cd ${CURRENT_DIR}/simulation && go test -mod=readonly -run TestAppSimulationAfterImport -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h
.PHONY: test-sim-determinism test-sim-export-import test-sim-after-import
SIM_NUM_BLOCKS ?= 500
SIM_BLOCK_SIZE ?= 200
SIM_COMMIT ?= true
test-sim-benchmark:
@echo "Running application benchmark for numBlocks=$(SIM_NUM_BLOCKS), blockSize=$(SIM_BLOCK_SIZE). This may take awhile!"
@cd ${CURRENT_DIR}/simulation && go test -mod=readonly -run=^$$ $(.) -bench ^BenchmarkSimulation$$ \
-Enabled=true -NumBlocks=$(SIM_NUM_BLOCKS) -BlockSize=$(SIM_BLOCK_SIZE) -Commit=$(SIM_COMMIT) -timeout 24h
.PHONY: test-sim-benchmark
###############################################################################
### interchaintest ###
###############################################################################
ictest-sdk-commands: rm-testcache
cd interchaintest && go test -race -v -run TestCoreSDKCommands .
ictest-sdk-boundaries: rm-testcache
cd interchaintest && go test -race -v -run TestSDKBoundaries .
ictest-chain-start: rm-testcache
cd interchaintest && go test -race -v -run TestChainStart .
ictest-state-sync: rm-testcache
cd interchaintest && go test -race -v -run TestStateSync .
ictest-ibc-xfer: rm-testcache
cd interchaintest && go test -race -v -run TestIBCTransfer .
ictest-packet-forward-middleware: rm-testcache
cd interchaintest && go test -race -v -run TestPacketForwardMiddleware .
rm-testcache:
go clean -testcache
###############################################################################
### Release ###
###############################################################################
GO_VERSION=1.21
GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GO_VERSION)
COSMWASM_VERSION := $(shell go list -m github.com/CosmWasm/wasmvm | sed 's/.* //')
ifdef GITHUB_TOKEN
release:
docker run \
--rm \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-e COSMWASM_VERSION=$(COSMWASM_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/seda-chaind \
-w /go/src/seda-chaind \
$(GORELEASER_IMAGE) \
release \
--clean
else
release:
@echo "Error: GITHUB_TOKEN variable required to 'make release'."
endif
release-dry-run:
@docker run \
--rm \
-e COSMWASM_VERSION=$(COSMWASM_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/seda-chaind \
-w /go/src/seda-chaind \
$(GORELEASER_IMAGE) \
release \
--clean \
--skip=publish
release-snapshot:
@docker run \
--rm \
-e COSMWASM_VERSION=$(COSMWASM_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/seda-chaind \
-w /go/src/seda-chaind \
$(GORELEASER_IMAGE) \
release \
--clean \
--snapshot \
--skip-validate\
--skip-publish
.PHONY: release release-dry-run release-snapshot
###############################################################################
### Docker ###
###############################################################################
RUNNER_BASE_IMAGE_DISTROLESS := gcr.io/distroless/static-debian11
RUNNER_BASE_IMAGE_ALPINE := alpine:3.17
docker-static-build:
@DOCKER_BUILDKIT=1 docker build \
-t seda-chain/seda-chaind-static-distroless \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
-f $(CURDIR)/dockerfiles/Dockerfile.static .
docker-static-build-alpine:
@DOCKER_BUILDKIT=1 docker build \
-t seda-chain/seda-chaind-static-alpine \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_ALPINE) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
-f $(CURDIR)/dockerfiles/Dockerfile.static .
.PHONY: docker-static-build docker-static-build-alpine