forked from meshplus/bitxhub
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
158 lines (128 loc) · 6.3 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
SHELL := /bin/bash
CURRENT_PATH = $(shell pwd)
APP_NAME = axiom-ledger
AXM_GEN = axmgen
export GODEBUG=x509ignoreCN=0
GO_BIN = go
ifneq (${GO},)
GO_BIN = ${GO}
endif
# build with verison infos
BUILD_CONST_DIR = github.com/axiomesh/${APP_NAME}/pkg/repo
BUILD_DATE = $(shell date +%FT%T)
GIT_COMMIT = $(shell git log --pretty=format:'%h' -n 1)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(version),)
# not specify version: make install
APP_VERSION = $(shell git describe --abbrev=0 --tag)
ifeq ($(APP_VERSION),)
APP_VERSION = dev
endif
else
# specify version: make install version=v0.6.1-dev
APP_VERSION = $(version)
endif
GOLDFLAGS += -X "${BUILD_CONST_DIR}.BuildDate=${BUILD_DATE}"
GOLDFLAGS += -X "${BUILD_CONST_DIR}.BuildCommit=${GIT_COMMIT}"
GOLDFLAGS += -X "${BUILD_CONST_DIR}.BuildBranch=${GIT_BRANCH}"
GOLDFLAGS += -X "${BUILD_CONST_DIR}.BuildVersion=${APP_VERSION}"
ifneq ($(secret),)
# specify version: add a flag
GOLDFLAGS += -X "${BUILD_CONST_DIR}.BuildVersionSecret=$(secret)"
endif
ifneq ($(net),)
# specify version: add a flag
GOLDFLAGS += -X "${BUILD_CONST_DIR}.BuildNet=$(net)"
endif
COVERAGE_TEST_PKGS := $(shell ${GO_BIN} list ./... | grep -v 'syncer' | grep -v 'vm' | grep -v 'proof' | grep -v 'repo' | grep -v 'mock_*' | grep -v 'tester' | grep -v 'proto' | grep -v 'cmd' | grep -v 'api' | grep -v 'solidity')
INTEGRATION_COVERAGE_TEST_PKGS :=$(shell ${GO_BIN} list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' -deps ./... |grep -E 'github.com/axiomesh/axiom-ledger|github.com/axiomesh/axiom-bft|github.com/axiomesh/axiom-kit|github.com/axiomesh/axiom-p2p|github.com/axiomesh/eth-kit' | grep -v 'syncer' | grep -v 'vm' | grep -v 'proof' | grep -v 'repo' | grep -v 'mock_*' | grep -v 'tester' | grep -v 'proto' | grep -v 'cmd'| paste -sd ",")
INTEGRATION_COVERAGE_DIR = $(CURRENT_PATH)/integration
RED=\033[0;31m
GREEN=\033[0;32m
BLUE=\033[0;34m
NC=\033[0m
GOARCH := $(or $(GOARCH),$(shell go env GOARCH))
GOOS := $(or $(GOOS),$(shell go env GOOS))
help: Makefile
@printf "${BLUE}Choose a command run:${NC}\n"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
## make prepare: Preparation before development
prepare:
${GO_BIN} install go.uber.org/mock/mockgen@main
${GO_BIN} install github.com/golangci/golangci-lint/cmd/[email protected]
${GO_BIN} install github.com/fsgo/go_fmt/cmd/gorgeous@latest
${GO_BIN} install github.com/ethereum/go-ethereum/cmd/[email protected]
@type "solc" 2> /dev/null || echo 'Please install solc'
## make generate-mock: Run go generate
generate-mock:
${GO_BIN} generate ./...
## make linter: Run golanci-lint
linter:
golangci-lint run --timeout=5m --new-from-rev=HEAD~1 -v
## make fmt: Formats go source code
fmt:
gorgeous -local github.com/axiomesh -mi
## make test: Run go unittest
test:
@time ${GO_BIN} test -timeout 300s ./... -count=1
## make test-coverage: Test project with cover
test-coverage:
${GO_BIN} test -timeout 300s -short -coverprofile cover.out -covermode=atomic ${COVERAGE_TEST_PKGS}
cat cover.out | grep -v "pb.go" >> coverage.txt
## make smoke-test: Run smoke test
smoke-test:
@mkdir -p ${INTEGRATION_COVERAGE_DIR}
cd scripts && bash smoke_test.sh -b ${BRANCH} -i ${INTEGRATION_COVERAGE_DIR}
${GO_BIN} tool covdata textfmt -i=${INTEGRATION_COVERAGE_DIR} -pkg=${INTEGRATION_COVERAGE_TEST_PKGS} -o=profile.txt
${GO_BIN} tool cover -func=profile.txt
## make build-coverage: Go build the project for integration test
build-coverage:
@mkdir -p bin
${GO_BIN} build -cover -ldflags '${GOLDFLAGS}' ./cmd/${APP_NAME}
@cp -f ./${APP_NAME} bin
@printf "${GREEN}Build ${APP_NAME} successfully!${NC}\n"
## make build: Go build the project
build:
@mkdir -p ./bin
@rm -f bin/${APP_NAME}
${GO_BIN} build -ldflags '${GOLDFLAGS}' ./cmd/${APP_NAME}
@cp -f ./${APP_NAME} ./bin
@printf "${GREEN}Build ${APP_NAME} successfully!${NC}\n"
## make install: Go install the project
install:
${GO_BIN} install -ldflags '${GOLDFLAGS}' ./cmd/${APP_NAME}
@printf "${GREEN}Install ${APP_NAME} successfully!${NC}\n"
axmgen:
${GO_BIN} install -ldflags '${GOLDFLAGS}' ./cmd/${AXM_GEN}
@printf "${GREEN}Install ${AXM_GEN} successfully!${NC}\n"
## make cluster: Run cluster including 4 nodes
cluster:build
cd scripts && bash cluster.sh
## make solo: Run one node in solo mode
solo:build
cd scripts && bash solo.sh
package:build
cp -f ${APP_NAME} ./scripts/package/tools/bin/${APP_NAME}
tar czvf ./${APP_NAME}-${APP_VERSION}-${GOARCH}-${GOOS}.tar.gz -C ./scripts/package/ .
## make precommit: Check code like CI
precommit: fmt test-coverage linter
SYSTEM_CONTRACTS_PATH = $(CURRENT_PATH)/internal/executor/system
SYSTEM_CONTRACTS_DIRS = $(shell find $(SYSTEM_CONTRACTS_PATH) -maxdepth 10 -type d)
SYSTEM_CONTRACTS = $(foreach d, $(SYSTEM_CONTRACTS_DIRS), $(wildcard $(d)/*.sys.sol))
define generate-abi
echo "Generating abi for $(subst $(SYSTEM_CONTRACTS_PATH),,$(1))";
solc --abi --bin $(1) --pretty-json -o $(shell dirname $(1)) --overwrite;
echo "Generated abi for $(subst $(SYSTEM_CONTRACTS_PATH),.,$(1))";
echo "Generating binding for $(subst $(SYSTEM_CONTRACTS_PATH),.,$(1))";
mkdir -p $(shell echo "$(basename $(basename $(1)))" | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]')_client
abigen --abi $(patsubst %.sys.sol,%.abi,$(1)) --bin $(patsubst %.sys.sol,%.bin,$(1)) --pkg $(shell basename $(1) .sys.sol | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]')_client --type BindingContract --out $(shell echo "$(basename $(basename $(1)))" | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]')_client/binding.go;
mkdir -p $(shell echo "$(basename $(basename $(1)))" | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]')
axmgen --abi $(patsubst %.sys.sol,%.abi,$(1)) --pkg $(shell basename $(1) .sys.sol | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]') --out $(shell echo "$(basename $(basename $(1)))" | sed 's/\([a-z0-9]\)\([A-Z]\)/\1_\2/g' | tr '[:upper:]' '[:lower:]')/binding.go;
echo "Generated binding for $(subst $(SYSTEM_CONTRACTS_PATH),.,$(1))";
echo "";
endef
axmgen-check:
@type "axmgen" 2> /dev/null || (echo 'axmgen is not installed, installing axmgen' && make axmgen)
## make generate-system-contracts-binding: Generate system contracts abi binding
generate-system-contracts-binding: axmgen-check
@$(foreach contract, $(SYSTEM_CONTRACTS),$(call generate-abi, $(contract)))