-
Notifications
You must be signed in to change notification settings - Fork 0
/
Justfile
325 lines (275 loc) · 7.41 KB
/
Justfile
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# Check out Just at: https://just.systems/
alias b := build
alias t := test
alias v := vet
[private]
@default:
just --list
# Audit the project for known vulnerabilities
@audit:
cargo deny check advisories \
--config ./deny.toml
# Build the rm binary
@build:
cargo build \
{{BUILD_ARGS}} \
{{FEATURES}}
[private]
@build-each:
cargo build-all-features \
{{BUILD_ARGS}}
# Reset the repository to a clean state
@clean: _clean_cargo _clean_git
@_clean_cargo:
cargo clean
@_clean_git:
git clean -fx \
_reports/ \
mutants.out*/ \
profile_fs/ \
cobertura* \
lcov* \
loc.rs \
perf.data \
perf.data.old \
perf.svg \
tarpaulin*
# Check license compliance
@compliance:
cargo deny check licenses \
--config ./deny.toml
# Produce a coverage report for all tests
@coverage:
cargo tarpaulin \
{{COVERAGE_ARGS}} \
{{TEST_FEATURES}} \
{{FEATURES}}
mv _reports/coverage/tarpaulin-report.html _reports/coverage/coverage-all.html
# Produce a coverage report for integration tests
@coverage-integration:
cargo tarpaulin \
{{COVERAGE_ARGS}} \
{{TEST_INTEGRATION_ARGS}} \
{{TEST_FEATURES}} \
{{FEATURES}}
mv _reports/coverage/tarpaulin-report.html _reports/coverage/coverage-integration.html
# Produce a coverage report for unit tests
@coverage-unit:
cargo tarpaulin \
{{COVERAGE_ARGS}} \
{{TEST_UNIT_ARGS}} \
{{TEST_FEATURES}} \
{{FEATURES}}
mv _reports/coverage/tarpaulin-report.html _reports/coverage/coverage-unit.html
# Run an ephemeral development environment container
@dev-env engine="docker":
just dev-img {{engine}}
{{engine}} run -it \
--rm \
--workdir '/rust-rm' \
--mount "type=bind,source=$(pwd),target=/rust-rm" \
--name 'rust-rm-dev-env' \
'rust-rm-dev-img'
# Build a development environment container image
@dev-img engine="docker":
{{engine}} build \
--file 'Containerfile.dev' \
--tag 'rust-rm-dev-img' \
.
# Generate documentation for the project and dependencies
@docs:
cargo doc \
{{DOCS_ARGS}}
# Format the source code
@fmt:
cargo fmt
[private]
@fmt-check:
cargo fmt --check
# Get the (minimum) number of lines of source code
@loc:
perl \
-0777 -pe \
's/#\[cfg\(test\)\]\s+(?:#\[cfg\(feature\s*=\s*"[^"]+"\)\]\s+)?(?:pub\s+)?(?:mod [a-z_]+ (\{(?:(?>[^{}]+)|(?1))*\})|use [A-Za-z_\:;]+)//g' \
src/main.rs \
| sed \
-e '/^ *$/d' \
-e '/^ *\/\//d' \
-e '/^ *#\[allow(/d' \
-e '/^ *#\[cfg_attr(test,/d' \
-e '/^ *#\[cfg(not(tarpaulin_include))]/d' \
-e '/^ *#!\[deny/d' \
> loc.rs
wc -l loc.rs
# Run mutation tests
@mutation:
cargo mutants \
--output _reports/ \
--exclude-re cli::run \
--exclude-re logging \
--exclude-re 'main -> ExitCode' \
--exclude-re rm::dispose \
--exclude-re 'impl Display' \
-- \
{{TEST_UNIT_ARGS}} \
{{TEST_FEATURES}}
# Profile with visualization using <https://github.com/brendangregg/FlameGraph>
[private]
@profile: _profile_prepare
cargo build {{FEATURES}}
perf record -F99 --call-graph dwarf -- \
just run --dir --recursive --force profile_fs
perf script | ./stackcollapse-perf.pl | ./flamegraph.pl > perf.svg
_profile_prepare:
#!/usr/bin/env perl
`rm -rf profile_fs`;
`mkdir profile_fs`;
for(1..1000) { `touch profile_fs/file-$_`; }
`mkdir profile_fs/nested_dir`;
for(1..750) { `touch profile_fs/nested_dir/file-$_`; }
# Run rm with the given arguments
@run *ARGS:
cargo run \
{{FEATURES}} \
-- \
{{ARGS}}
# Run all tests
@test:
cargo test \
{{TEST_ARGS}} \
{{TEST_FEATURES}} \
{{FEATURES}}
# Run all integration tests
@test-integration:
cargo test \
{{TEST_ARGS}} \
{{TEST_INTEGRATION_ARGS}} \
{{TEST_FEATURES}} \
{{FEATURES}}
# Run all unit tests
@test-unit:
cargo test \
{{TEST_ARGS}} \
{{TEST_UNIT_ARGS}} \
{{TEST_FEATURES}} \
{{FEATURES}}
[private]
@test-each:
cargo test-all-features \
{{TEST_ARGS}} \
{{TEST_FEATURES}}
# Run all checks that should always succeed
@verify: build-each compliance docs fmt-check test-each vet
# Statically analyze the source code
@vet: _vet_check _vet_clippy _vet_verify_project
@_vet_check:
echo 'Running "cargo check"...'
cargo {{ if ci == TRUE { "check-all-features" } else { "check" } }} \
{{CI_ONLY_CARGO_ARGS}}
@_vet_clippy:
echo 'Running "cargo clippy"...'
cargo clippy \
--no-deps \
--tests \
-- \
--deny clippy::cargo \
--deny clippy::complexity \
--deny clippy::correctness \
--deny clippy::pedantic \
--deny clippy::perf \
--deny clippy::style \
--deny clippy::suspicious \
\
--deny clippy::absolute_paths \
--deny clippy::allow_attributes_without_reason \
--deny clippy::arithmetic_side_effects \
--deny clippy::cfg_not_test \
--deny clippy::dbg_macro \
--deny clippy::disallowed_script_idents \
--deny clippy::empty_enum_variants_with_brackets \
--deny clippy::expect_used \
--deny clippy::field_scoped_visibility_modifiers \
--deny clippy::let_underscore_untyped \
--deny clippy::if_then_some_else_none \
--deny clippy::infinite_loop \
--deny clippy::iter_over_hash_type \
--deny clippy::impl_trait_in_params \
--deny clippy::indexing_slicing \
--deny clippy::missing_asserts_for_indexing \
--deny clippy::missing_docs_in_private_items \
--deny clippy::missing_enforced_import_renames \
--deny clippy::pathbuf_init_then_push \
--deny clippy::print_stderr \
--deny clippy::print_stdout \
--deny clippy::rc_buffer \
--deny clippy::rc_mutex \
--deny clippy::ref_patterns \
--deny clippy::renamed_function_params \
--deny clippy::string_lit_chars_any \
--deny clippy::unused_result_ok \
--deny clippy::unwrap_used
@_vet_verify_project:
echo 'Running "cargo verify-project"...'
cargo verify-project \
--quiet \
{{CI_ONLY_CARGO_ARGS}}
# --------------------------------------------------------------------------------------------------
[private]
@ci-audit:
just ci={{TRUE}} audit
[private]
@ci-build:
just ci={{TRUE}} build-each
[private]
@ci-compliance:
just ci={{TRUE}} compliance
[private]
@ci-coverage:
just ci={{TRUE}} \
test_features={{ALL_TEST_FEATURES}} \
coverage
[private]
@ci-docs:
just ci={{TRUE}} docs
[private]
@ci-fmt:
just ci={{TRUE}} fmt-check
[private]
@ci-mutation:
just ci={{TRUE}} \
test_features={{ALL_TEST_FEATURES}} \
mutation
[private]
@ci-test:
just ci={{TRUE}} \
test_features={{ALL_TEST_FEATURES}} \
test-each
[private]
@ci-vet:
just ci={{TRUE}} vet
# --------------------------------------------------------------------------------------------------
TRUE := "1"
FALSE := "0"
ci := FALSE
STD_BUILD_ARGS := "--release"
STD_COVERAGE_ARGS := "--count --line --engine llvm --out html --output-dir _reports/coverage/"
STD_DOCS_ARGS := "--document-private-items"
STD_TEST_ARGS := ""
CI_ONLY_CARGO_ARGS := if ci == TRUE { "--locked" } else { "" }
CI_ONLY_COVERAGE_ARGS := if ci == TRUE { "--out lcov" } else { "" }
CI_ONLY_TEST_ARGS := if ci == TRUE { "--no-fail-fast" } else { "" }
ALL_TEST_FEATURES := "test-dangerous,test-symlink,test-trash"
BUILD_ARGS := STD_BUILD_ARGS + " " + CI_ONLY_CARGO_ARGS
COVERAGE_ARGS := STD_COVERAGE_ARGS + " " + CI_ONLY_CARGO_ARGS + " " + CI_ONLY_COVERAGE_ARGS
DOCS_ARGS := STD_DOCS_ARGS + " " + CI_ONLY_CARGO_ARGS
TEST_ARGS := STD_TEST_ARGS + " " + CI_ONLY_TEST_ARGS + " " + CI_ONLY_CARGO_ARGS
TEST_INTEGRATION_ARGS := "--test '*'"
TEST_UNIT_ARGS := "--bins"
features := FALSE
FEATURES := if features == FALSE {
""
} else {
"--no-default-features " + if features == "" { "" } else { "--features " + features }
}
test_features := ""
TEST_FEATURES := if test_features == "" { "" } else { "--features " + test_features }