Skip to content

Commit

Permalink
run format_exercises.sh in parallel (#2031)
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor authored Feb 21, 2025
1 parent e777561 commit b6fb06b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 20 additions & 16 deletions bin/format_exercises.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@ set -eo pipefail

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

echo "Formatting exercise files..."

format_one_exercise() {
exercise_dir="$1"
source_file_name="$2"

cd "$exercise_dir"
config_file="$exercise_dir/.meta/config.json"
if jq --exit-status '.custom?."allowed-to-not-compile"?' "$config_file" &> /dev/null; then
exit 0
fi
cargo fmt
file_name=".meta/$source_file_name.rs"
if [ -f "$file_name" ]; then
rustfmt "$file_name"
fi
}

# traverse either concept or practice exercise
# directory and format Rust files
format_exercises() {
exercises_path="$repo/exercises/$1"
source_file_name="$2"
for exercise_dir in "$exercises_path"/*; do
(
cd "$exercise_dir"
config_file="$exercise_dir/.meta/config.json"
if jq --exit-status '.custom?."allowed-to-not-compile"?' "$config_file"; then
exercise=$(basename "$exercise_dir")
echo "$exercise's stub is allowed to not compile"
# exit the subshell successfully to continue
# to the next exercise directory
exit 0
fi
cargo fmt
file_name=".meta/$source_file_name.rs"
if [ -f "$file_name" ]; then
rustfmt "$file_name"
fi
)
format_one_exercise "$exercise_dir" "$source_file_name" &
done
wait
}
# https://github.com/exercism/docs/blob/main/anatomy/tracks/concept-exercises.md#file-exemplar-implementation
format_exercises "concept" "exemplar"
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test:
./bin/check_exercises.sh
CLIPPY=true ./bin/check_exercises.sh
cd rust-tooling && cargo test
# TODO format exercises
./bin/format_exercises.sh ; git diff --exit-code

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

0 comments on commit b6fb06b

Please sign in to comment.