forked from settlus/chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
225 lines (179 loc) · 7.95 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
#!/usr/bin/make -f
# Git information
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%h')
VERSION ?= $(shell echo $(shell git describe --tags --always) | sed 's/^v//')
# Path and directory variables
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_DIR := $(notdir $(patsubst %/,%,$(dir $(MKFILE_PATH))))
# Docker configuration
DOCKER := $(shell which docker)
# Binary configuration
SETTLUS_BINARY := settlusd
.PHONY: all
all: build
###############################################################################
### Build ###
###############################################################################
# Build tags processing
build_tags := netgo
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
# Linker flags setup
ldflags := -X github.com/cosmos/cosmos-sdk/version.Name=settlus \
-X github.com/cosmos/cosmos-sdk/version.AppName=$(SETTLUS_BINARY) \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/settlus/chain/tools/interop-node/version.Name=interop-node \
-X github.com/settlus/chain/tools/interop-node/version.Version=$(VERSION) \
-X github.com/settlus/chain/tools/interop-node/version.Commit=$(COMMIT)
# Build tags to linker flags
build_tags_comma_sep := $(subst $(subst ,, ),,,$(build_tags))
ldflags += -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"
# Additional linker flags
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
# Final build flags setup
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif
ifneq (,$(findstring nooptimization,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
endif
# Build targets
BUILD_TARGETS := build install
BUILDDIR ?= $(CURDIR)/build
build: BUILD_ARGS=-o $(BUILDDIR)/
$(BUILD_TARGETS): go.sum $(BUILDDIR)/
@echo "Building..."
@go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... || (echo "Build failed"; exit 1)
$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/
test:
@echo "Running tests..."
@go test -mod=readonly $(shell go list ./... | grep -v tests/e2e)|| (echo "Tests failed"; exit 1)
e2e-test:
@echo "Running e2e tests..."
@go test ./tests/e2e -v || (echo "Tests failed"; exit 1)
clean:
@echo "Cleaning up..."
@rm -rf $(BUILDDIR)
.PHONY: build test clean
###############################################################################
### Linting ###
###############################################################################
lint:
@golangci-lint run ./...
.PHONY: lint
###############################################################################
### Protobuf ###
###############################################################################
protoVer=v0.7
protoImageName=tendermintdev/sdk-proto-gen:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace --user 0 $(protoImageName)
SWAGGER_DIR=./swagger-proto
THIRD_PARTY_DIR=$(SWAGGER_DIR)/third_party
DEPS_COSMOS_SDK_VERSION := $(shell cat go.sum | grep 'github.com/settlus/cosmos-sdk' | grep -v -e 'go.mod' | tail -n 1 | awk '{ print $$2; }')
DEPS_IBC_GO_VERSION := $(shell cat go.sum | grep 'github.com/cosmos/ibc-go' | grep -v -e 'go.mod' | tail -n 1 | awk '{ print $$2; }')
DEPS_COSMOS_PROTO := $(shell cat go.sum | grep 'github.com/cosmos/cosmos-proto' | grep -v -e 'go.mod' | tail -n 1 | awk '{ print $$2; }')
DEPS_COSMOS_GOGOPROTO := $(shell cat go.sum | grep 'github.com/cosmos/gogoproto' | grep -v -e 'go.mod' | tail -n 1 | awk '{ print $$2; }')
DEPS_COSMOS_ICS23 := go/$(shell cat go.sum | grep 'github.com/cosmos/ics23/go' | grep -v -e 'go.mod' | tail -n 1 | awk '{ print $$2; }')
proto-all: proto-format proto-lint proto-gen proto-swagger-gen
proto-gen:
@echo "Generating Protobuf files"
@$(protoImage) sh ./scripts/protocgen.sh
proto-format:
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;
proto-lint:
@$(protoImage) buf lint --error-format=json
proto-swagger-gen:
@echo "Downloading Protobuf dependencies"
@go get github.com/cosmos/gogoproto
@make proto-download-deps
@echo "Generating Protobuf Swagger"
$(protoImage) sh ./scripts/protoc-swagger-gen.sh
@go mod tidy
proto-download-deps:
mkdir -p "$(THIRD_PARTY_DIR)/cosmos_tmp" && \
cd "$(THIRD_PARTY_DIR)/cosmos_tmp" && \
git init && \
git remote add origin "https://github.com/settlus/cosmos-sdk.git" && \
git config core.sparseCheckout true && \
printf "proto\nthird_party\n" > .git/info/sparse-checkout && \
git pull origin "$(DEPS_COSMOS_SDK_VERSION)" && \
rm -f ./proto/buf.* && \
mv ./proto/* ..
rm -rf "$(THIRD_PARTY_DIR)/cosmos_tmp"
mkdir -p "$(THIRD_PARTY_DIR)/cosmos_proto_tmp" && \
cd "$(THIRD_PARTY_DIR)/cosmos_proto_tmp" && \
git init && \
git remote add origin "https://github.com/cosmos/cosmos-proto.git" && \
git config core.sparseCheckout true && \
printf "proto\n" > .git/info/sparse-checkout && \
git pull origin "$(DEPS_COSMOS_PROTO_VERSION)" && \
rm -f ./proto/buf.* && \
mv ./proto/* ..
rm -rf "$(THIRD_PARTY_DIR)/cosmos_proto_tmp"
mkdir -p "$(THIRD_PARTY_DIR)/gogoproto" && \
curl -SSL "https://raw.githubusercontent.com/cosmos/gogoproto/$(DEPS_COSMOS_GOGOPROTO)/gogoproto/gogo.proto" > "$(THIRD_PARTY_DIR)/gogoproto/gogo.proto"
mkdir -p "$(THIRD_PARTY_DIR)/google/api" && \
curl -sSL https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/annotations.proto > "$(THIRD_PARTY_DIR)/google/api/annotations.proto"
curl -sSL https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/http.proto > "$(THIRD_PARTY_DIR)/google/api/http.proto"
proto-clean:
rm -rf $(SWAGGER_DIR) tmp-swagger-gen
.PHONY: proto-all proto-gen proto-format proto-lint proto-swagger-gen proto-download-deps proto-clean
###############################################################################
### Localnet ###
###############################################################################
LOCALNET_SETUP_FILE=docker-compose.yml
LOCALNET_DOCKER_TAG=settlus/localnet
localnet-build:
docker build --tag $(LOCALNET_DOCKER_TAG) $(CURDIR)/.
localnet-stop:
docker-compose -f $(LOCALNET_SETUP_FILE) down -v
rm -rf $(CURDIR)/.testnets
localnet-start: localnet-stop
make build
$(BUILDDIR)/settlusd testnet init-files --keyring-backend test --starting-ip-address 192.168.11.2
docker-compose -f $(LOCALNET_SETUP_FILE) up -d
.PHONY: localnet-build localnet-start localnet-stop
###############################################################################
### Releasing ###
###############################################################################
PACKAGE_NAME:=github.com/settlus/chain
GOLANG_CROSS_VERSION = v1.21
GOPATH ?= '$(HOME)/go'
release-dry-run:
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v ${GOPATH}/pkg:/go/pkg \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--clean --skip-validate --skip-publish --snapshot
release:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean --skip-validate
.PHONY: release-dry-run release