-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrustfmt.sh
executable file
·65 lines (57 loc) · 1.27 KB
/
rustfmt.sh
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
#!/bin/bash
set -euo pipefail
cargo=${CARGO:-cargo}
version="$($cargo fmt -- -V)"
case "$version" in
*nightly*)
# all good, no additional flags required
;;
*)
# assume we're using some sort of rustup setup
cargo="$cargo +nightly"
;;
esac
return=0
while read file; do
test=no
fail=no
ok=yes
# check if this is a test which is allowed to fail
# also, ignore anything in the target folder
case "$file" in
*/target/*)
continue
;;
*/fail/*)
fail=yes
test=yes
;;
*/tests/*)
test=yes
;;
*)
;;
esac
echo -e "\e[1m ==> Formatting project $file ...\e[0m"
# check that the project compiles (unless fail) without modifying the lock file
if [ "$test" == "yes" ]; then
cargo check --manifest-path "$file" --locked || ok=no
if [ "$fail" == "yes" ] && [ "$ok" == "no" ] && ! cargo check --manifest-path "$file" &>/dev/null; then
echo -e "\e[1;33m -> Ignored\e[0m"
continue
fi
fi
# run rustfmt with the provided flags
if [ "$ok" == "yes" ]; then
$cargo fmt --manifest-path "$file" -- \
--config-path "$(dirname "$0")/rustfmt.toml" "$@" \
|| ok=no
fi
if [ "$ok" == "yes" ]; then
echo -e "\e[1;32m -> Success\e[0m"
else
echo -e "\e[1;31m -> Failed\e[0m"
return=1
fi
done < <(find . -name 'Cargo.toml' -type f)
exit $return