forked from nervosnetwork/ckb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
139 lines (105 loc) · 5.03 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
.DEFAULT_GOAL:=help
SHELL = /bin/sh
MOLC := moleculec
MOLC_VERSION := 0.2.5
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
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
cov: ## Run code coverage.
RUSTC="$$(pwd)/devtools/cov/rustc-proptest-fix" taskset -c 0 cargo tarpaulin --timeout 300 --exclude-files protocol/src/protocol_generated* test/* */tests/ --all -v --out Xml
setup-ckb-test:
cp -f Cargo.lock test/Cargo.lock
rm -rf test/target && ln -snf ../target/ test/target
integration: setup-ckb-test ## Run integration tests in "test" dir.
cargo build
cd test && cargo run -- --bin ../target/debug/ckb ${CKB_TEST_ARGS}
integration-windows:
cp -f Cargo.lock test/Cargo.lock
cargo build
mv target test/
cd test && cargo run -- --bin target/debug/ckb ${CKB_TEST_ARGS}
integration-release: setup-ckb-test
cargo build --release
cd test && cargo run --release -- --bin ../target/release/ckb ${CKB_TEST_ARGS}
##@ Document
doc: ## Build the documentation for the local package.
cargo doc --all --no-deps
doc-deps: ## Build the documentation for the local package and all dependencies.
cargo doc --all
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
gen-hashes: ## Generate docs/hashes.toml
cargo run cli hashes -b > docs/hashes.toml
##@ Building
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
build: ## Build binary with release profile.
cargo build ${VERBOSE} --release
prod: ## Build binary for production release.
RUSTFLAGS="--cfg disable_faketime" cargo build ${VERBOSE} --release
prod-docker:
RUSTFLAGS="--cfg disable_faketime --cfg docker" cargo build --verbose --release
prod-test:
RUSTFLAGS="--cfg disable_faketime" RUSTDOCFLAGS="--cfg disable_faketime" cargo test ${VERBOSE} --all -- --nocapture
docker: ## Build docker image
docker build -f docker/hub/Dockerfile -t nervos/ckb:$$(git describe) .
docker run --rm -it nervos/ckb:$$(git describe) --version
docker-publish:
docker push nervos/ckb:$$(git describe)
docker tag nervos/ckb:$$(git describe) nervos/ckb:latest
docker push nervos/ckb:latest
##@ Code Quality
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
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}
security-audit: ## Use cargo-audit to audit Cargo.lock for crates with security vulnerabilities.
@cargo audit --version || cargo install cargo-audit
@cargo audit
# expecting to see "Success No vulnerable packages found"
bench-test:
cd benches && cargo bench --features ci -- --test
##@ Continuous Integration
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
check-cargotoml:
./devtools/ci/check-cargotoml.sh
check-whitespaces:
git -c core.whitespace=-blank-at-eof diff-index --check --cached $$(git rev-parse --verify master 2>/dev/null || echo "4b825dc642cb6eb9a060e54bf8d69288fbee4904") --
check-dirty-rpc-doc: gen-rpc-doc
git diff --exit-code rpc/README.md rpc/json/rpc.json
##@ Generates Files
GEN_FILES := util/types/src/generated/types.rs
gen: ${GEN_FILES} # Generate Protocol Files
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
clean-node-files: ## Clean files generated by `ckb init`
rm -rf ckb.toml ckb-miner.toml specs/ data/
##@ Helpers
stats: ## Counting lines of code.
@cargo count --version || cargo +nightly install --git https://github.com/kbknapp/cargo-count
@cargo count --separator , --unsafe-statistics
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)
.PHONY: build prod prod-test prod-docker docker docker-publish
.PHONY: gen clean-node-files check-moleculec-version
.PHONY: fmt test clippy doc doc-deps gen-rpc-doc gen-hashes check stats check-dirty-rpc-doc cov
.PHONY: ci security-audit check-cargotoml check-whitespaces
.PHONY: integration integration-release setup-ckb-test