Skip to content

Commit b6fb06b

Browse files
authored
run format_exercises.sh in parallel (#2031)
1 parent e777561 commit b6fb06b

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

bin/format_exercises.sh

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,33 @@ set -eo pipefail
55

66
repo=$(git rev-parse --show-toplevel)
77

8+
echo "Formatting exercise files..."
9+
10+
format_one_exercise() {
11+
exercise_dir="$1"
12+
source_file_name="$2"
13+
14+
cd "$exercise_dir"
15+
config_file="$exercise_dir/.meta/config.json"
16+
if jq --exit-status '.custom?."allowed-to-not-compile"?' "$config_file" &> /dev/null; then
17+
exit 0
18+
fi
19+
cargo fmt
20+
file_name=".meta/$source_file_name.rs"
21+
if [ -f "$file_name" ]; then
22+
rustfmt "$file_name"
23+
fi
24+
}
25+
826
# traverse either concept or practice exercise
927
# directory and format Rust files
1028
format_exercises() {
1129
exercises_path="$repo/exercises/$1"
1230
source_file_name="$2"
1331
for exercise_dir in "$exercises_path"/*; do
14-
(
15-
cd "$exercise_dir"
16-
config_file="$exercise_dir/.meta/config.json"
17-
if jq --exit-status '.custom?."allowed-to-not-compile"?' "$config_file"; then
18-
exercise=$(basename "$exercise_dir")
19-
echo "$exercise's stub is allowed to not compile"
20-
# exit the subshell successfully to continue
21-
# to the next exercise directory
22-
exit 0
23-
fi
24-
cargo fmt
25-
file_name=".meta/$source_file_name.rs"
26-
if [ -f "$file_name" ]; then
27-
rustfmt "$file_name"
28-
fi
29-
)
32+
format_one_exercise "$exercise_dir" "$source_file_name" &
3033
done
34+
wait
3135
}
3236
# https://github.com/exercism/docs/blob/main/anatomy/tracks/concept-exercises.md#file-exemplar-implementation
3337
format_exercises "concept" "exemplar"

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test:
2121
./bin/check_exercises.sh
2222
CLIPPY=true ./bin/check_exercises.sh
2323
cd rust-tooling && cargo test
24-
# TODO format exercises
24+
./bin/format_exercises.sh ; git diff --exit-code
2525

2626
add-exercise *args="":
2727
cd rust-tooling/generate; cargo run --quiet --release -- add {{ args }}

0 commit comments

Comments
 (0)