-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
cargo-for-all-lock-files.sh
executable file
·55 lines (49 loc) · 1.22 KB
/
cargo-for-all-lock-files.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
#!/usr/bin/env bash
here="$(dirname "$0")"
cargo="$(readlink -f "${here}/../cargo")"
set -e
shifted_args=()
while [[ -n $1 ]]; do
if [[ $1 = -- ]]; then
escape_marker=found
shift
break
elif [[ $1 = "--ignore-exit-code" ]]; then
ignore=1
shift
else
shifted_args+=("$1")
shift
fi
done
# When "--" appear at the first and shifted_args is empty, consume it here
# to unambiguously pass and use any other "--" for cargo
if [[ -n $escape_marker && ${#shifted_args[@]} -gt 0 ]]; then
files="${shifted_args[*]}"
for file in $files; do
if [[ $file = "${file%Cargo.lock}" ]]; then
echo "$0: unrecognizable as Cargo.lock path (prepend \"--\"?): $file" >&2
exit 1
fi
done
shifted_args=()
else
files="$(git ls-files :**Cargo.lock)"
fi
for lock_file in $files; do
if [[ -n $CI ]]; then
echo "--- [$lock_file]: cargo " "${shifted_args[@]}" "$@"
fi
if (set -x && cd "$(dirname "$lock_file")" && "$cargo" "${shifted_args[@]}" "$@"); then
# noop
true
else
failed_exit_code=$?
if [[ -n $ignore ]]; then
echo "$0: WARN: ignoring last cargo command failed exit code as requested:" $failed_exit_code
true
else
exit $failed_exit_code
fi
fi
done