-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
342 lines (272 loc) · 8.34 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
##
# Development Recipes
#
# This justfile is intended to be run from inside a Docker sandbox:
# https://github.com/Blobfolio/righteous-sandbox
#
# docker run \
# --rm \
# -v "{{ invocation_directory() }}":/share \
# -it \
# --name "righteous_sandbox" \
# "righteous/sandbox:debian"
#
# Alternatively, you can just run cargo commands the usual way and ignore these
# recipes.
##
pkg_id := "fyi"
pkg_name := "FYI"
pkg_dir1 := justfile_directory() + "/fyi"
pkg_dir2 := justfile_directory() + "/fyi_msg"
cargo_dir := "/tmp/" + pkg_id + "-cargo"
cargo_bin := cargo_dir + "/release/" + pkg_id
doc_dir := justfile_directory() + "/doc"
release_dir := justfile_directory() + "/release"
export RUSTFLAGS := "-C target-cpu=x86-64-v3"
# Bench it!
bench BENCH="":
#!/usr/bin/env bash
clear
if [ -z "{{ BENCH }}" ]; then
cargo bench \
--benches \
--workspace \
--all-features \
--target-dir "{{ cargo_dir }}"
else
cargo bench \
--bench "{{ BENCH }}" \
--workspace \
--all-features \
--target-dir "{{ cargo_dir }}"
fi
exit 0
# Bin Test!
@bin-test:
[ -f "{{ cargo_bin }}" ] || just build
"{{ cargo_bin }}" print "This message has no prefix."
"{{ cargo_bin }}" blank
"{{ cargo_bin }}" print -p "Pink" -c 199 "This message has a custom pink prefix."
"{{ cargo_bin }}" print -p "Blue" -c 4 "This message has a custom blue prefix."
"{{ cargo_bin }}" blank
"{{ cargo_bin }}" notice "So official!"
"{{ cargo_bin }}" success "Hurray! You did it!"
"{{ cargo_bin }}" warning "Hold it there, Sparky!"
"{{ cargo_bin }}" error "Oopsie."
"{{ cargo_bin }}" blank
"{{ cargo_bin }}" review "The total was such-and-such."
"{{ cargo_bin }}" debug "The devil is in the details."
"{{ cargo_bin }}" info "Details without the word 'bug'."
"{{ cargo_bin }}" skipped "Wasn't worth doing."
"{{ cargo_bin }}" task "Let's get to work!"
"{{ cargo_bin }}" blank
"{{ cargo_bin }}" crunched "Some hard work just happened."
"{{ cargo_bin }}" done "As the French say, «FIN»."
"{{ cargo_bin }}" blank
"{{ cargo_bin }}" info -t "Messages can be timestamped."
"{{ cargo_bin }}" blank
"{{ cargo_bin }}" info "Messages can be indented."
"{{ cargo_bin }}" info -i "Messages can be indented."
"{{ cargo_bin }}" blank
"{{ cargo_bin }}" confirm "Does this default no?" || "{{ cargo_bin }}" error "Well that sucks."
"{{ cargo_bin }}" confirm -y "Did this work for you?" || "{{ cargo_bin }}" error "Well that sucks."
"{{ cargo_bin }}" blank
# Build Release!
@build:
# First let's build the Rust bit.
cargo build \
--bin "{{ pkg_id }}" \
--release \
--target-dir "{{ cargo_dir }}"
# Fix ownership, etc.
just _fix-chmod "{{ pkg_dir1 }}"
just _fix-chown "{{ pkg_dir1 }}"
# Build Debian package!
@build-deb: clean credits build
# cargo-deb doesn't support target_dir flags yet.
[ ! -d "{{ justfile_directory() }}/target" ] || rm -rf "{{ justfile_directory() }}/target"
mv "{{ cargo_dir }}" "{{ justfile_directory() }}/target"
# Build the deb.
cargo-deb \
--no-build \
--quiet \
-p {{ pkg_id }} \
-o "{{ release_dir }}"
just _fix-chown "{{ release_dir }}"
mv "{{ justfile_directory() }}/target" "{{ cargo_dir }}"
# Clean Cargo crap.
@clean:
# Most things go here.
[ ! -d "{{ cargo_dir }}" ] || rm -rf "{{ cargo_dir }}"
# But some Cargo apps place shit in subdirectories even if
# they place *other* shit in the designated target dir. Haha.
[ ! -d "{{ justfile_directory() }}/target" ] || rm -rf "{{ justfile_directory() }}/target"
[ ! -d "{{ pkg_dir1 }}/target" ] || rm -rf "{{ pkg_dir1 }}/target"
[ ! -d "{{ pkg_dir2 }}/target" ] || rm -rf "{{ pkg_dir2 }}/target"
cargo update -w
# Clippy.
@clippy:
clear
fyi task "Clippy (Workspace)"
cargo clippy \
--workspace \
--all-features \
--target-dir "{{ cargo_dir }}"
fyi task "Clippy (Lib)."
cargo clippy \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo clippy \
--features=fitted \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo clippy \
--features=timestamps \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo clippy \
--features=fitted,timestamps \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo clippy \
--features=progress \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo clippy \
--all-features \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
# Generate CREDITS.
@credits:
cargo bashman -m "{{ pkg_dir1 }}/Cargo.toml" -t x86_64-unknown-linux-gnu
just _fix-chown "{{ justfile_directory() }}/CREDITS.md"
# Build Docs.
@doc:
# Make the docs.
cargo +nightly rustdoc \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--release \
--all-features \
--target-dir "{{ cargo_dir }}" \
-- \
--cfg docsrs
# Move the docs and clean up ownership.
[ ! -d "{{ doc_dir }}" ] || rm -rf "{{ doc_dir }}"
mv "{{ cargo_dir }}/doc" "{{ justfile_directory() }}"
just _fix-chown "{{ doc_dir }}"
# Build and Run Example.
@ex DEMO:
clear
cargo run \
-q \
--all-features \
--release \
--example "{{ DEMO }}" \
--target-dir "{{ cargo_dir }}"
# Test Run.
@run +ARGS:
cargo run \
--bin "{{ pkg_id }}" \
--release \
--target-dir "{{ cargo_dir }}" \
-- {{ ARGS }}
# Unit tests!
@test:
clear
fyi task "Testing Bin (Debug)."
cargo test \
--manifest-path "{{ pkg_dir1 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
fyi task "Testing Bin (Release)."
cargo test \
--release \
--manifest-path "{{ pkg_dir1 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
fyi task "Testing Lib (Debug)."
cargo test \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--features=fitted \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--features=timestamps \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--features=fitted,timestamps \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--features=progress \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--all-features \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
fyi task "Testing Lib (Release)."
cargo test \
--release \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--release \
--features=fitted \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--release \
--features=timestamps \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--release \
--features=fitted,timestamps \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--release \
--features=progress \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
cargo test \
--release \
--all-features \
--manifest-path "{{ pkg_dir2 }}/Cargo.toml" \
--target-dir "{{ cargo_dir }}"
# Get/Set version.
version:
#!/usr/bin/env bash
# Current version.
_ver1="$( toml get "{{ pkg_dir1 }}/Cargo.toml" package.version | \
sed 's/"//g' )"
# Find out if we want to bump it.
_ver2="$( whiptail --inputbox "Set {{ pkg_name }} version:" --title "Release Version" 0 0 "$_ver1" 3>&1 1>&2 2>&3 )"
exitstatus=$?
if [ $exitstatus != 0 ] || [ "$_ver1" = "$_ver2" ]; then
exit 0
fi
fyi success "Setting version to $_ver2."
# Set the release version!
just _version "{{ pkg_dir1 }}" "$_ver2"
just _version "{{ pkg_dir2 }}" "$_ver2"
# Set version for real.
@_version DIR VER:
[ -f "{{ DIR }}/Cargo.toml" ] || exit 1
# Set the release version!
toml set "{{ DIR }}/Cargo.toml" package.version "{{ VER }}" > /tmp/Cargo.toml
just _fix-chown "/tmp/Cargo.toml"
mv "/tmp/Cargo.toml" "{{ DIR }}/Cargo.toml"
# Init dependencies.
@_init:
# env RUSTUP_PERMIT_COPY_RENAME=true rustup default beta
# env RUSTUP_PERMIT_COPY_RENAME=true rustup component add clippy
# Fix file/directory permissions.
@_fix-chmod PATH:
[ ! -e "{{ PATH }}" ] || find "{{ PATH }}" -type f -exec chmod 0644 {} +
[ ! -e "{{ PATH }}" ] || find "{{ PATH }}" -type d -exec chmod 0755 {} +
# Fix file/directory ownership.
@_fix-chown PATH:
[ ! -e "{{ PATH }}" ] || chown -R --reference="{{ justfile() }}" "{{ PATH }}"