-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
160 lines (110 loc) · 4 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
ALL_SOURCES = $(shell git ls-files .)
RS_SOURCES = $(filter %.rs, $(ALL_SOURCES))
TOML_SOURCES = $(filter %.toml, $(ALL_SOURCES))
CARGO_SOURCES = $(RS_SOURCES) $(TOML_SOURCES)
TEST_FLAGS = RUST_BACKTRACE=1
TEST_EXTRA_FLAGS = -- --nocapture
ifneq ($(wildcard .single-thread-tests),)
TEST_EXTRA_FLAGS += --test-threads 1
endif
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help.replace(' # ALLOW TODOX', '')))
endef
export PRINT_HELP_PYSCRIPT
help: ## print this error message
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
ifeq ($(wildcard .no-todo-x),)
todo-x: .make.todo-x ## check for leftover TODOX # ALLOW TODOX
else
todo-x:
endif
TODO = todo$()x
.make.todo-x: $(ALL_SOURCES)
cargo $(TODO)
touch $@
formatted: .make.formatted ## check code is properly formatted
.make.formatted: .cargo/config.toml $(CARGO_SOURCES)
cargo fmt --all -- --check
touch $@
reformat: .make.reformat ## reformat the code
.make.reformat: .cargo/config.toml $(CARGO_SOURCES)
cargo fmt --all
touch $@
check: .make.check ## check the sources
.make.check: .cargo/config.toml $(CARGO_SOURCES)
cargo check --tests
touch $@
smells: .make.smells ## check for code smells with clippy
.make.smells: .cargo/config.toml .make.check
cargo clippy -- --no-deps
touch $@
build: .make.build ## build everything
.make.build: .cargo/config.toml $(CARGO_SOURCES)
cargo build
cargo test --no-run
touch $@
test: .make.test ## run tests
.make.test: .cargo/config.toml .make.build
$(TEST_FLAGS) cargo test $(TEST_EXTRA_FLAGS)
touch $@
retest: .cargo/config.toml ## force re-run tests with nocapture
$(TEST_FLAGS) cargo test $(TEST_EXTRA_FLAGS)
coverage: .make.coverage ## generate coverage report
.make.coverage: .make.test
rm -f tarpaulin*
$(TEST_FLAGS) cargo tarpaulin --skip-clean --out xml $(TEST_EXTRA_FLAGS)
touch $@
ifeq ($(wildcard .no-coverage-annotations),)
coverage-annotations: .make.coverage-annotations ## check coverage annotations in code
else
coverage-annotations:
endif
.make.coverage-annotations: .cargo/config.toml .make.coverage
cargo coverage-annotations
touch $@
doc: .make.doc ## generate documentation
.make.doc: .cargo/config.toml $(CARGO_SOURCES) README.md
cargo doc --no-deps # --workspace
touch $@
udeps: .make.udeps ## check for unused dependencies
.make.udeps: .cargo/config.toml $(CARGO_SOURCES)
cargo +nightly udeps --workspace --all-targets
touch $@
outdated: .make.outdated ## check all dependencies are up-to-date
.make.outdated: .cargo/config.toml $(TOML_SOURCES)
cargo outdated --root-deps-only --exit-code 1
touch $@
audit: .make.audit ## audit dependencies for bugs or security issues
.make.audit: .cargo/config.toml $(TOML_SOURCES)
cargo audit
touch $@
common: todo-x formatted smells udeps coverage-annotations doc
dev: reformat tags common outdated audit ## verify during development
staged: ## check everything is staged for git commit
@if git status . | grep -q 'Changes not staged\|Untracked files'; then git status; false; else true; fi
pre-commit: tags common staged outdated audit ## verify everything before commit
pre-publish: .make.pre-publish ## publish dry run (post-commit, pre-push)
.make.pre-publish: $(ALL_SOURCES)
cargo publish --dry-run
touch $@
on-push: common pre-publish ## verify a pushed commit in a CI action
monthly: outdated audit ## verify dependencies in a monthly CI action
publish: on-push monthly ## actually publish
cargo publish
tags: $(RS_SOURCES) ## tags file for vim or Emacs.
ctags --recurse src tests
clobber: ## remove all generated files
rm -f .make.* tags cobertura.xml
rm -rf .cargo target
clean: ## remove generated files except for dependencies
rm -f .make.* tags tarpaulin cobertura.xml
rm -rf .cargo `find target -name '*cargo-todo*'`
.cargo/config.toml:
mkdir -p .cargo
echo '[build]' > $@
cargo tarpaulin --print-rust-flags | tail -1 | sed 's/RUSTFLAGS/rustflags/' >> $@