-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
168 lines (130 loc) · 4.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
# Heavily inspired by Reth: https://github.com/paradigmxyz/reth/blob/d599393771f9d7d137ea4abf271e1bd118184c73/Makefile
.DEFAULT_GOAL := help
GIT_TAG ?= $(shell git describe --tags --abbrev=0)
BUILD_PATH = "target"
# Cargo profile for builds. Default is for local builds, CI uses an override.
PROFILE ?= release
# Extra flags for Cargo
CARGO_INSTALL_EXTRA_FLAGS ?=
# List of features to use for building
FEATURES ?=
# The docker image name
DOCKER_IMAGE_NAME ?=
##@ Help
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build
.PHONY: build
build: ## Build the workspace into the `target` directory.
cargo build --workspace --features "$(FEATURES)" --profile "$(PROFILE)"
##@ Test
UNIT_TEST_ARGS := --locked --workspace -E 'kind(lib)' -E 'kind(bin)' -E 'kind(proc-macro)'
COV_FILE := lcov.info
.PHONY: test-unit
test-unit: ## Run unit tests.
-cargo install cargo-nextest --locked
cargo nextest run $(UNIT_TEST_ARGS)
.PHONY: cov-unit
cov-unit: ## Run unit tests with coverage.
rm -f $(COV_FILE)
cargo llvm-cov nextest --lcov --output-path $(COV_FILE) $(UNIT_TEST_ARGS)
.PHONY: cov-report-html
cov-report-html: ## Generate an HTML coverage report and open it in the browser.
cargo llvm-cov --open --workspace --locked nextest
.PHONY: sec
sec: ## Check for security advisories on any dependencies.
cargo audit # HACK: not denying warnings as we depend on `yaml-rust` via `format-serde-error` which is unmaintained
.PHONY: clean-cargo
clean-cargo: ## cargo clean
cargo clean 2>/dev/null
.PHONY: clean-docker-data
clean-docker-data: ## Remove docker data files inside /docker/.data
rm -rf $(DOCKER_DIR)/$(DOCKER_DATADIR) 2>/dev/null
.PHONY: clean-poetry
clean-poetry: ## Remove poetry virtual environment
cd $(FUNCTIONAL_TESTS_DIR) && rm -rf .venv 2>/dev/null
##@ Code Quality
.PHONY: fmt-check-ws
fmt-check-ws: ## Check formatting issues but do not fix automatically.
cargo fmt --check
.PHONY: fmt-ws
fmt-ws: ## Format source code in the workspace.
cargo fmt --all
.PHONY: ensure-taplo
ensure-taplo:
@if ! command -v taplo &> /dev/null; then \
echo "taplo not found. Please install it by following the instructions from: https://taplo.tamasfe.dev/cli/installation/binary.html" \
exit 1; \
fi
.PHONY: fmt-check-toml
fmt-check-toml: ensure-taplo ## Runs `taplo` to check that TOML files are properly formatted
taplo fmt --check
.PHONY: fmt-toml
fmt-toml: ensure-taplo ## Runs `taplo` to format TOML files
taplo fmt
.PHONY: lint-check-ws
lint-check-ws: ## Checks for lint issues in the workspace.
cargo clippy \
--workspace \
--lib \
--examples \
--tests \
--benches \
--all-features \
--no-deps \
-- -D warnings
.PHONY: lint-fix-ws
lint-fix-ws: ## Lints the workspace and applies fixes where possible.
cargo clippy \
--workspace \
--lib \
--examples \
--tests \
--benches \
--all-features \
--fix \
--no-deps \
-- -D warnings
ensure-codespell:
@if ! command -v codespell &> /dev/null; then \
echo "codespell not found. Please install it by running the command 'pip install codespell' or refer to the following link for more information: https://github.com/codespell-project/codespell" \
exit 1; \
fi
.PHONY: lint-codespell
lint-check-codespell: ensure-codespell ## Runs `codespell` to check for spelling errors.
codespell
.PHONY: lint-fix-codespell
lint-fix-codespell: ensure-codespell ## Runs `codespell` to fix spelling errors if possible.
codespell -w
.PHONY: lint-toml
lint-check-toml: ensure-taplo ## Lints TOML files
taplo lint
.PHONY: lint
lint: fmt-check-ws fmt-check-toml lint-check-ws lint-check-codespell ## Runs all lints and checks for issues without trying to fix them.
@echo "\n\033[36m======== OK: Lints and Formatting ========\033[0m\n"
.PHONY: lint-fix
lint-fix: fmt-toml fmt-ws lint-fix-ws lint-fix-codespell ## Runs all lints and applies fixes where possible.
@echo "\n\033[36m======== OK: Lints and Formatting Fixes ========\033[0m\n"
.PHONY: rustdocs
rustdocs: ## Runs `cargo docs` to generate the Rust documents in the `target/doc` directory.
RUSTDOCFLAGS="\
--show-type-layout \
--enable-index-page -Z unstable-options \
-A rustdoc::private-doc-tests \
-D warnings" \
cargo doc \
--workspace \
--no-deps
.PHONY: test-doc
test-doc: ## Runs doctests on the workspace.
cargo test --doc --workspace
.PHONY: test
test: ## Runs all tests in the workspace including unit and docs tests.
make test-unit && \
make test-doc
.PHONY: pr
pr: lint sec rustdocs test-doc test-unit ## Runs lints (without fixing), audit, docs, and tests (run this before creating a PR).
@echo "\n\033[36m======== CHECKS_COMPLETE ========\033[0m\n"
@test -z "$$(git status --porcelain)" || echo "WARNNG: You have uncommitted changes"
@echo "All good to create a PR!"