-
Notifications
You must be signed in to change notification settings - Fork 219
/
Makefile
166 lines (133 loc) · 5.38 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
.DEFAULT_GOAL:=help
SHELL = /bin/sh
MOLC := moleculec
MOLC_VERSION := 0.3.1
VERBOSE := $(if ${CI},--verbose,)
CLIPPY_OPTS := -D warnings -D clippy::clone_on_ref_ptr -D clippy::enum_glob_use -D clippy::fallible_impl_from
##@ Testing
.PHONY: test
test: ## Run all tests.
cargo test ${VERBOSE} --all -- --nocapture
# Tarpaulin only supports x86_64 processors running Linux.
# https://github.com/xd009642/tarpaulin/issues/161
# https://github.com/xd009642/tarpaulin/issues/190#issuecomment-473564880
.PHONY: cov
cov: ## Run code coverage.
RUSTC="$$(pwd)/devtools/cov/rustc-proptest-fix" taskset -c 0 cargo tarpaulin --timeout 300 --exclude-files "*/generated/" "test/*" "*/tests/" --all -v --out Xml
.PHONY: setup-ckb-test
setup-ckb-test:
cp -f Cargo.lock test/Cargo.lock
rm -rf test/target && ln -snf ../target/ test/target
.PHONY: submodule-init
submodule-init:
git submodule update --init
.PHONY: integration
integration: submodule-init setup-ckb-test ## Run integration tests in "test" dir.
cargo build
cd test && RUST_BACKTRACE=1 cargo run -- --bin ../target/debug/ckb ${CKB_TEST_ARGS}
.PHONY: integration-windows
integration-windows: submodule-init
cp -f Cargo.lock test/Cargo.lock
cargo build
mv target test/
cd test && cargo run -- --bin target/debug/ckb ${CKB_TEST_ARGS}
.PHONY: integration-release
integration-release: submodule-init setup-ckb-test
cargo build --release
cd test && cargo run --release -- --bin ../target/release/ckb ${CKB_TEST_ARGS}
##@ Document
.PHONY: doc
doc: ## Build the documentation for the local package.
cargo doc --all --no-deps
.PHONY: doc-deps
doc-deps: ## Build the documentation for the local package and all dependencies.
cargo doc --all
.PHONY: gen-rpc-doc
gen-rpc-doc: ## Generate rpc documentation
./devtools/doc/jsonfmt.py rpc/json/rpc.json
./devtools/doc/rpc.py rpc/json/rpc.json > rpc/README.md
.PHONY: gen-hashes
gen-hashes: ## Generate docs/hashes.toml
cargo run cli hashes -b > docs/hashes.toml
##@ Building
.PHONY: check
check: setup-ckb-test ## Runs all of the compiler's checks.
cargo check ${VERBOSE} --all --all-targets --all-features
cd test && cargo check ${VERBOSE} --all --all-targets --all-features
.PHONY: build
build: ## Build binary with release profile.
cargo build ${VERBOSE} --release
.PHONY: prod
prod: ## Build binary for production release.
RUSTFLAGS="--cfg disable_faketime" cargo build ${VERBOSE} --release
.PHONY: prod-docker
prod-docker:
RUSTFLAGS="--cfg disable_faketime --cfg docker" cargo build --verbose --release
.PHONY: prod-test
prod-test:
RUSTFLAGS="--cfg disable_faketime" RUSTDOCFLAGS="--cfg disable_faketime" cargo test ${VERBOSE} --all -- --nocapture
.PHONY: docker
docker: ## Build docker image
docker build -f docker/hub/Dockerfile -t nervos/ckb:$$(git describe) .
docker run --rm -it nervos/ckb:$$(git describe) --version
.PHONY: docker-publish
docker-publish:
docker push nervos/ckb:$$(git describe)
docker tag nervos/ckb:$$(git describe) nervos/ckb:latest
docker push nervos/ckb:latest
##@ Code Quality
.PHONY: fmt
fmt: setup-ckb-test ## Check Rust source code format to keep to the same style.
cargo fmt ${VERBOSE} --all -- --check
cd test && cargo fmt ${VERBOSE} --all -- --check
.PHONY: clippy
clippy: setup-ckb-test ## Run linter to examine Rust source codes.
cargo clippy ${VERBOSE} --all --all-targets --all-features -- ${CLIPPY_OPTS}
cd test && cargo clippy ${VERBOSE} --all --all-targets --all-features -- ${CLIPPY_OPTS}
.PHONY: security-audit
security-audit: ## Use cargo-audit to audit Cargo.lock for crates with security vulnerabilities.
@cargo +nightly install cargo-audit -Z install-upgrade
cargo audit
# expecting to see "Success No vulnerable packages found"
.PHONY: bench-test
bench-test:
cd benches && cargo bench --features ci -- --test
##@ Continuous Integration
.PHONY: ci
ci: ## Run recipes for CI.
ci: fmt clippy test bench-test check-cargotoml check-whitespaces check-dirty-rpc-doc security-audit
git diff --exit-code Cargo.lock
.PHONY: check-cargotoml
check-cargotoml:
./devtools/ci/check-cargotoml.sh
.PHONY: check-whitespace
check-whitespaces:
git -c core.whitespace=-blank-at-eof diff-index --check --cached $$(git rev-parse --verify master 2>/dev/null || echo "4b825dc642cb6eb9a060e54bf8d69288fbee4904") --
.PHONY: check-dirty-rpc-doc
check-dirty-rpc-doc: gen-rpc-doc
git diff --exit-code rpc/README.md rpc/json/rpc.json
##@ Generates Files
.PHONY: gen
GEN_FILES := util/types/src/generated/types.rs
gen: ${GEN_FILES} # Generate Protocol Files
.PHONY: check-moleculec-version
check-moleculec-version:
test "$$(${MOLC} --version | awk '{ print $$2 }' | tr -d ' ')" = ${MOLC_VERSION}
util/types/src/generated/types.rs: check-moleculec-version util/types/schemas/ckb.mol
${MOLC} \
--language rust \
--schema-file util/types/schemas/ckb.mol \
| rustfmt \
> util/types/src/generated/types.rs
##@ Cleanup
.PHONY: clean-node-files
clean-node-files: ## Clean files generated by `ckb init`
rm -rf ckb.toml ckb-miner.toml specs/ data/
##@ Helpers
.PHONY: stats
stats: ## Counting lines of code.
@cargo count --version || cargo +nightly install --git https://github.com/kbknapp/cargo-count
@cargo count --separator , --unsafe-statistics
.PHONY: help
help: ## Display help message.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)