forked from ChariotEngine/Chariot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all-crates-do
executable file
·75 lines (69 loc) · 2.04 KB
/
all-crates-do
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
#!/bin/bash
# Builds and runs tests on every individual crate in the repo
cargo=cargo
function run_in() {
arg_directory=$1
arg_cmd=$2
check_status=$3
pushd "$arg_directory" &>/dev/null
echo $arg_cmd $arg_directory
$arg_cmd
result=$?
popd &>/dev/null
if [ $check_status -eq 1 ]; then
if [ $result -ne 0 ]; then
echo "FAILED"
exit 1
fi
fi
}
function build_test_dir() {
arg_directory=$1
travis=$2
echo "********************************************"
echo "* Building/testing $arg_directory"
echo "********************************************"
run_in "$arg_directory" "$cargo build" 1
run_in "$arg_directory" "$cargo test" 1
# travis-cargo doesn't currently support building examples
if [ $travis -eq 0 ]; then
example_dir="$arg_directory/examples"
if [ -d $example_dir ]; then
examples=`find $example_dir -iname "*.rs"`
for example in $examples; do
example_name=`basename $example .rs`
run_in "$example_dir" "$cargo build --example $example_name" 1
done
else
echo "No examples to build"
fi
else
echo "Skipping example builds for now"
fi
}
function print_usage() {
echo "Usage: all-crates-do [test|test-travis|clean|fmt]"
exit 1
}
if [ $# -ne 1 ]; then
print_usage
else
cmd=$1
crate_manifests=$(find . -type f -iname "Cargo.toml" -not -path "*target*")
for crate_manifest in $crate_manifests; do
crate_dir=`dirname $crate_manifest`
if [ $cmd == "test" ]; then
build_test_dir "$crate_dir" 0
elif [ $cmd == "test-travis" ]; then
cargo=travis-cargo
build_test_dir "$crate_dir" 1
elif [ $cmd == "clean" ]; then
run_in "$crate_dir" "$cargo clean" 1
elif [ $cmd == "fmt" ]; then
run_in "$crate_dir" "$cargo fmt" 0
else
echo "Unrecognized command: $cmd"
print_usage
fi
done
fi