From d69bb3d2d9c2dfc8bca2a51e82c3bb367b8df4a8 Mon Sep 17 00:00:00 2001 From: Henry Le Berre Date: Thu, 4 Apr 2024 23:28:38 -0400 Subject: [PATCH] Format: Fix #384 & #383 --- toolchain/bootstrap/format.sh | 10 ++------ toolchain/bootstrap/format_file.sh | 37 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 toolchain/bootstrap/format_file.sh diff --git a/toolchain/bootstrap/format.sh b/toolchain/bootstrap/format.sh index 0a2ec24a1..a2ca71248 100644 --- a/toolchain/bootstrap/format.sh +++ b/toolchain/bootstrap/format.sh @@ -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 diff --git a/toolchain/bootstrap/format_file.sh b/toolchain/bootstrap/format_file.sh new file mode 100644 index 000000000..5f086e17b --- /dev/null +++ b/toolchain/bootstrap/format_file.sh @@ -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 +