-
Notifications
You must be signed in to change notification settings - Fork 323
/
Makefile
279 lines (239 loc) · 8.87 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
########################################################################################################################
# Copyright (c) 2019 IoTeX Foundation
# This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
# or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
# This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
########################################################################################################################
# Go parameters
GOCMD=go
GOVET=$(GOCMD) vet
GOBUILD=$(GOCMD) build
GOINSTALL=$(GOCMD) install
GOCLEAN=$(GOCMD) clean
GOTEST=GOARCH=amd64 CGO_ENABLED=1 $(GOCMD) test
GOGET=$(GOCMD) get
GOPATH=$(shell go env GOPATH)
BUILD_TARGET_SERVER=server
BUILD_TARGET_ACTINJV2=actioninjectorv2
BUILD_TARGET_ADDRGEN=addrgen
BUILD_TARGET_IOCTL=ioctl
BUILD_TARGET_NEWIOCTL=newioctl
BUILD_TARGET_XCTL=xctl
BUILD_TARGET_NEWXCTL=newxctl
BUILD_TARGET_MINICLUSTER=minicluster
BUILD_TARGET_RECOVER=recover
BUILD_TARGET_READTIP=readtip
BUILD_TARGET_IOMIGRATER=iomigrater
BUILD_TARGET_OS=$(shell go env GOOS)
BUILD_TARGET_ARCH=$(shell go env GOARCH)
# Pkgs
ALL_PKGS := $(shell go list ./... )
PKGS := $(shell go list ./... | grep -v /test/ )
ROOT_PKG := "github.com/iotexproject/iotex-core"
TEST_PKGS := $(shell go list ./... | grep -E -v 'pb$|testdata|mock')
# Docker parameters
DOCKERCMD=docker
# Package Info
ifndef PACKAGE_VERSION
PACKAGE_VERSION := $(shell git describe --tags)
endif
ifndef PACKAGE_COMMIT_ID
PACKAGE_COMMIT_ID := $(shell git rev-parse HEAD)
endif
ifndef GIT_STATUS
GIT_STATUS := $(shell git status --porcelain)
ifdef GIT_STATUS
GIT_STATUS := "dirty"
else
GIT_STATUS := "clean"
endif
endif
GO_VERSION := $(shell go version)
BUILD_TIME=$(shell date +%F-%Z/%T)
VersionImportPath := github.com/iotexproject/iotex-core/v2/pkg/version
PackageFlags += -X '$(VersionImportPath).PackageVersion=$(PACKAGE_VERSION)'
PackageFlags += -X '$(VersionImportPath).PackageCommitID=$(PACKAGE_COMMIT_ID)'
PackageFlags += -X '$(VersionImportPath).GitStatus=$(GIT_STATUS)'
PackageFlags += -X '$(VersionImportPath).GoVersion=$(GO_VERSION)'
PackageFlags += -X '$(VersionImportPath).BuildTime=$(BUILD_TIME)'
PackageFlags += -s -w
TEST_IGNORE= ".git,vendor"
COV_OUT := profile.coverprofile
COV_REPORT := overalls.coverprofile
COV_HTML := coverage.html
LINT_LOG := lint.log
V ?= 0
ifeq ($(V),0)
ECHO_V = @
else
VERBOSITY_FLAG = -v
DEBUG_FLAG = -debug
endif
default: clean build test
all: clean build-all test
.PHONY: build
build: ioctl
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_SERVER) -v ./$(BUILD_TARGET_SERVER)
.PHONY: build-all
build-all: build build-actioninjector build-addrgen build-minicluster build-staterecoverer build-readtip
.PHONY: build-actioninjector
build-actioninjector:
$(GOBUILD) -o ./bin/$(BUILD_TARGET_ACTINJV2) -v ./tools/actioninjector.v2
.PHONY: build-addrgen
build-addrgen:
$(GOBUILD) -o ./bin/$(BUILD_TARGET_ADDRGEN) -v ./tools/addrgen
.PHONY: build-minicluster
build-minicluster:
$(GOBUILD) -o ./bin/$(BUILD_TARGET_MINICLUSTER) -v ./tools/minicluster
.PHONY: build-staterecoverer
build-staterecoverer:
$(GOBUILD) -o ./bin/$(BUILD_TARGET_RECOVER) -v ./tools/staterecoverer
.PHONY: build-readtip
build-readtip:
$(GOBUILD) -o ./bin/$(BUILD_TARGET_READTIP) -v ./tools/readtip
.PHONY: fmt
fmt:
$(GOCMD) fmt ./...
$(GOCMD) mod tidy
.PHONY: lint
lint:
go list ./... | xargs $(GOVET)
.PHONY: lint-rich
lint-rich:
$(ECHO_V)rm -rf $(LINT_LOG)
@echo "Running golangcli lint..."
$(ECHO_V)golangci-lint run $(VERBOSITY_FLAG)--enable-all -D gochecknoglobals -D prealloc -D lll -D interfacer -D scopelint -D maligned -D dupl| tee -a $(LINT_LOG)
.PHONY: test
test: fmt
@$(GOTEST) -gcflags="all=-N -l" -short -race ${TEST_PKGS}
.PHONY: test-rich
test-rich:
@echo "Running test cases..."
$(ECHO_V)rm -f $(COV_REPORT)
$(ECHO_V)touch $(COV_OUT)
$(ECHO_V)RICHGO_FORCE_COLOR=1 overalls \
-project=$(ROOT_PKG) \
-go-binary=richgo \
-ignore $(TEST_IGNORE) \
$(DEBUG_FLAG) -- \
$(VERBOSITY_FLAG) -short | \
grep -v -e "Test args" -e "Processing"
.PHONY: test-html
test-html: test-rich
@echo "Generating test report html..."
$(ECHO_V)gocov convert $(COV_REPORT) | gocov-html > $(COV_HTML)
$(ECHO_V)open $(COV_HTML)
.PHONY: mockgen
mockgen:
@./misc/scripts/mockgen.sh
.PHONY: stringer
stringer:
sh ./misc/scripts/stringer.sh
.PHONY: license
license:
@./misc/scripts/licenseheader.sh
.PHONY: dev-deps
dev-deps:
@echo "Installing dev dependencies..."
$(ECHO_V)go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
$(ECHO_V)go get -u github.com/kyoh86/richgo
$(ECHO_V)go get -u github.com/axw/gocov/gocov
$(ECHO_V)go get -u gopkg.in/matm/v1/gocov-html
$(ECHO_V)go get -u github.com/go-playground/overalls
.PHONY: clean
clean:
@echo "Cleaning..."
$(ECHO_V)rm -rf ./bin/$(BUILD_TARGET_SERVER)
$(ECHO_V)rm -rf ./bin/$(BUILD_TARGET_ADDRGEN)
$(ECHO_V)rm -rf ./bin/$(BUILD_TARGET_IOTC)
$(ECHO_V)rm -rf ./e2etest/*chain*.db
$(ECHO_V)rm -rf *chain*.db
$(ECHO_V)rm -rf *trie*.db
$(ECHO_V)rm -rf *index*.db
$(ECHO_V)rm -rf *systemlog*.db
$(ECHO_V)rm -rf *candidate.index*.db
$(ECHO_V)rm -rf $(COV_REPORT) $(COV_HTML) $(LINT_LOG)
$(ECHO_V)find . -name $(COV_OUT) -delete
$(ECHO_V)find . -name $(TESTBED_COV_OUT) -delete
$(ECHO_V)$(GOCLEAN) -i $(PKGS)
.PHONY: reboot
reboot:
$(ECHO_V)rm -rf *chain*.db
$(ECHO_V)rm -rf *trie*.db
$(ECHO_V)rm -rf *index*.db
$(ECHO_V)rm -rf *candidate.index*.db
$(ECHO_V)rm -rf ./e2etest/*chain*.db
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_SERVER) -v ./$(BUILD_TARGET_SERVER)
./bin/$(BUILD_TARGET_SERVER) -plugin=gateway -config-path=./config/standalone-config.yaml -genesis-path=./config/standalone-genesis.yaml
.PHONY: run
run:
$(ECHO_V)rm -rf ./e2etest/*chain*.db
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_SERVER) -v ./$(BUILD_TARGET_SERVER)
sudo mkdir -p /var/data /var/log
sudo chown ${USER} /var/data /var/log
./bin/$(BUILD_TARGET_SERVER) -plugin=gateway -config-path=./config/standalone-config.yaml -genesis-path=./config/standalone-genesis.yaml
.PHONY: docker
docker:
DOCKER_BUILDKIT=1 $(DOCKERCMD) build -t $(USER)/iotex-core:latest .
.PHONY: docker-scan
docker-scan: docker
DOCKER_BUILDKIT=1 $(DOCKERCMD) login
DOCKER_BUILDKIT=1 $(DOCKERCMD) scan $(USER)/iotex-core:latest .
.PHONY: minicluster
minicluster:
$(ECHO_V)rm -rf *chain*.db
$(ECHO_V)rm -rf *trie*.db
$(ECHO_V)rm -rf *index*.db
$(ECHO_V)rm -rf *candidate.index*.db
$(ECHO_V)rm -rf *blob*.db
$(ECHO_V)rm -rf *bloomfilter.index*.db
$(ECHO_V)rm -rf *consensus*.db
$(ECHO_V)rm -rf *contractstaking.index*.db
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_MINICLUSTER) -v ./tools/minicluster
./bin/$(BUILD_TARGET_MINICLUSTER)
.PHONY: nightlybuild
nightlybuild:
$(ECHO_V)rm -rf *chain*.db
$(ECHO_V)rm -rf *trie*.db
$(ECHO_V)rm -rf *index*.db
$(ECHO_V)rm -rf *candidate.index*.db
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_MINICLUSTER) -v ./tools/minicluster
./bin/$(BUILD_TARGET_MINICLUSTER) -timeout=14400 -fp-token=true
.PHONY: recover
recover:
$(ECHO_V)rm -rf ./e2etest/*chain*.db
$(GOBUILD) -o ./bin/$(BUILD_TARGET_RECOVER) -v ./tools/staterecoverer
./bin/$(BUILD_TARGET_RECOVER) -plugin=gateway
.PHONY: ioctl
ioctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_IOCTL) -v ./tools/ioctl
.PHONY: newioctl
newioctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_NEWIOCTL) -v ./tools/newioctl
.PHONY: ioctl-cross
ioctl-cross:
$(DOCKERCMD) pull techknowlogick/xgo:latest
$(GOCMD) get src.techknowlogick.com/xgo
mkdir -p $(GOPATH)/src
sudo cp ./tools/ioctl/ioctl.go $(GOPATH)/src
cd $(GOPATH)/src && sudo rm -f go.mod && $(GOCMD) mod init main && $(GOCMD) mod tidy
cd $(GOPATH)/src && $(GOPATH)/bin/xgo --targets=$(BUILD_TARGET_OS)/$(BUILD_TARGET_ARCH) .
mkdir -p ./bin/$(BUILD_TARGET_IOCTL) && sudo mv $(GOPATH)/src/main-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH) ./bin/$(BUILD_TARGET_IOCTL)/ioctl-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH)
.PHONY: newioctl-cross
newioctl-cross:
$(DOCKERCMD) pull techknowlogick/xgo:latest
$(GOCMD) get src.techknowlogick.com/xgo
mkdir -p $(GOPATH)/src
sudo cp ./tools/newioctl/ioctl.go $(GOPATH)/src
cd $(GOPATH)/src && sudo rm -f go.mod && $(GOCMD) mod init main && $(GOCMD) mod tidy
cd $(GOPATH)/src && $(GOPATH)/bin/xgo --targets=$(BUILD_TARGET_OS)/$(BUILD_TARGET_ARCH) .
mkdir -p ./bin/$(BUILD_TARGET_NEWIOCTL) && sudo mv $(GOPATH)/src/main-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH) ./bin/$(BUILD_TARGET_NEWIOCTL)/ioctl-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH)
.PHONY: xctl
xctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_XCTL) -v ./tools/xctl
.PHONY: newxctl
newxctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_NEWXCTL) -v ./tools/newxctl
.PHONY: iomigrater
iomigrater:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_IOMIGRATER) -v ./tools/iomigrater