Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleberre committed Apr 5, 2024
1 parent 809d5e4 commit d69bb3d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
10 changes: 2 additions & 8 deletions toolchain/bootstrap/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ done

log "Formatting MFC:"

if ! find ${@:-src} -type f | grep -Ev 'autogen' | grep -E '\.(f90|fpp)$' | \
parallel --jobs ${JOBS:-1} -- \
echo "\> {}" \&\& \
python3 toolchain/indenter.py "{}" \&\& \
fprettify "{}" --silent --indent 4 --c-relations --enable-replacements \
--enable-decl --whitespace-comma 1 --whitespace-multdiv 0 \
--whitespace-plusminus 1 --case 1 1 1 1 --strict-indent \
--line-length 1000\;; then
if ! find ${@:-src} -type f | grep -Ev 'autogen' | grep -E '\.(f90|fpp)$' \
| xargs -L 1 -P ${JOBS:-1} $SHELL toolchain/bootstrap/format_file.sh; then
error "Formatting MFC failed."
exit 1
fi
Expand Down
37 changes: 37 additions & 0 deletions toolchain/bootstrap/format_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

. toolchain/util.sh

echo "> $1"

niter=0
old_file=""

while :
do
niter=$((niter+1))
new_file=`cat "$1"`
if [[ "$new_file" == "$old_file" ]]; then
break
fi
old_file="$new_file"

if [[ "$niter" -gt 4 ]]; then
error "Failed to format $1: No steady-state (after $niter iterations)."
exit 1
fi

if ! python3 toolchain/indenter.py "$1"; then
error "Failed to format $1: indenter.py."
exit 1
fi

if ! fprettify "$1" --silent --indent 4 --c-relations --enable-replacements \
--enable-decl --whitespace-comma 1 --whitespace-multdiv 0 \
--whitespace-plusminus 1 --case 1 1 1 1 --strict-indent \
--line-length 1000; then
error "Failed to format $1: fprettify."
exit 1
fi
done

0 comments on commit d69bb3d

Please sign in to comment.