forked from sei-protocol/sei-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
220 lines (174 loc) · 6.79 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
#!/usr/bin/make -f
VERSION := $(shell echo $(shell git describe --tags))
COMMIT := $(shell git log -1 --format='%H')
BUILDDIR ?= $(CURDIR)/build
INVARIANT_CHECK_INTERVAL ?= $(INVARIANT_CHECK_INTERVAL:-0)
export PROJECT_HOME=$(shell git rev-parse --show-toplevel)
export GO_PKG_PATH=$(HOME)/go/pkg
export GO111MODULE = on
# process build tags
LEDGER_ENABLED ?= true
build_tags = netgo
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
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
# process linker flags
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sei \
-X github.com/cosmos/cosmos-sdk/version.ServerName=seid \
-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)"
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
# BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' -race
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
#### Command List ####
all: lint install
install: go.sum
go install $(BUILD_FLAGS) ./cmd/seid
install-with-race-detector: go.sum
go install -race $(BUILD_FLAGS) ./cmd/seid
install-price-feeder: go.sum
go install $(BUILD_FLAGS) ./oracle/price-feeder
loadtest: go.sum
go build $(BUILD_FLAGS) -o ./build/loadtest ./loadtest/
price-feeder: go.sum
go build $(BUILD_FLAGS) -o ./build/price-feeder ./oracle/price-feeder
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify
lint:
golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify
build:
go build $(BUILD_FLAGS) -o ./build/seid ./cmd/seid
build-price-feeder:
go build $(BUILD_FLAGS) -o ./build/price-feeder ./oracle/price-feeder
clean:
rm -rf ./build
###############################################################################
### Local testing using docker container ###
###############################################################################
# To start a 4-node cluster from scratch:
# make clean && make docker-cluster-start
# To stop the 4-node cluster:
# make docker-cluster-stop
# If you have already built the binary, you can skip the build:
# make docker-cluster-start-skipbuild
###############################################################################
# Build linux binary on other platforms
build-linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-gnu-gcc make build
.PHONY: build-linux
build-price-feeder-linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-gnu-gcc make build-price-feeder
.PHONY: build-price-feeder-linux
# Build docker image
build-docker-node:
@cd docker && docker build --tag sei-chain/localnode localnode --platform linux/x86_64
.PHONY: build-docker-node
build-rpc-node:
@cd docker && docker build --tag sei-chain/rpcnode rpcnode --platform linux/x86_64
.PHONY: build-rpc-node
# Run a single node docker container
run-local-node: kill-sei-node build-docker-node
@rm -rf $(PROJECT_HOME)/build/generated
docker run --rm \
--name sei-node \
--network host \
-v $(PROJECT_HOME):/sei-protocol/sei-chain:Z \
-v $(GO_PKG_PATH)/mod:/root/go/pkg/mod:Z \
--platform linux/x86_64 \
sei-chain/localnode
.PHONY: run-local-node
# Run a single rpc state sync node docker container
run-rpc-node: build-rpc-node
docker run --rm \
--name sei-rpc-node \
--network docker_localnet \
-v $(PROJECT_HOME):/sei-protocol/sei-chain:Z \
-v $(PROJECT_HOME)/../sei-tendermint:/sei-protocol/sei-tendermint:Z \
-v $(PROJECT_HOME)/../sei-cosmos:/sei-protocol/sei-cosmos:Z \
-v $(PROJECT_HOME)/../sei-db:/sei-protocol/sei-db:Z \
-v $(GO_PKG_PATH)/mod:/root/go/pkg/mod:Z \
-p 26668-26670:26656-26658 \
--platform linux/x86_64 \
sei-chain/rpcnode
.PHONY: run-rpc-node
run-rpc-node-skipbuild: build-rpc-node
docker run --rm \
--name sei-rpc-node \
--network docker_localnet \
-v $(PROJECT_HOME):/sei-protocol/sei-chain:Z \
-v $(PROJECT_HOME)/../sei-tendermint:/sei-protocol/sei-tendermint:Z \
-v $(PROJECT_HOME)/../sei-cosmos:/sei-protocol/sei-cosmos:Z \
-v $(PROJECT_HOME)/../sei-db:/sei-protocol/sei-db:Z \
-v $(GO_PKG_PATH)/mod:/root/go/pkg/mod:Z \
-p 26668-26670:26656-26658 \
--platform linux/x86_64 \
--env SKIP_BUILD=true \
sei-chain/rpcnode
.PHONY: run-rpc-node
kill-sei-node:
docker ps --filter name=sei-node --filter status=running -aq | xargs docker kill
kill-rpc-node:
docker ps --filter name=sei-rpc-node --filter status=running -aq | xargs docker kill
# Run a 4-node docker containers
docker-cluster-start: docker-cluster-stop build-docker-node
@rm -rf $(PROJECT_HOME)/build/generated
@cd docker && NUM_ACCOUNTS=10 INVARIANT_CHECK_INTERVAL=${INVARIANT_CHECK_INTERVAL} UPGRADE_VERSION_LIST=${UPGRADE_VERSION_LIST} docker-compose up
.PHONY: localnet-start
# Use this to skip the seid build process
docker-cluster-start-skipbuild: docker-cluster-stop build-docker-node
@rm -rf $(PROJECT_HOME)/build/generated
@cd docker && NUM_ACCOUNTS=10 SKIP_BUILD=true docker-compose up
.PHONY: localnet-start
# Stop 4-node docker containers
docker-cluster-stop:
@cd docker && docker-compose down
.PHONY: localnet-stop
# 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 ?= 4
$(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 -d -n l/$(NUM_SPLIT) $< $<.
test-group-%:split-test-packages
cat $(BUILDDIR)/packages.txt.$* | xargs go test -parallel 4 -mod=readonly -timeout=10m -race -coverprofile=$*.profile.out -covermode=atomic