From 92260820b183fbedf467b63d45d40a5adf4e633d Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Mon, 19 Apr 2021 16:26:51 +0200 Subject: [PATCH] Ormolu script improvements (#1458) * Condense ormolu output when in a tty * Improve Ctrl-C detection of ormolu script It seems that ormolu returns exit code 0 on SIGTERM, and this causes the ormolu script to not react to Ctrl-C, if the ormolu process happens to receive it (as opposed to the rest of the shell script). To fix this, run ormolu in background, and wait on the corresponding process. This makes the wait call handle the interrupt, so that we can distinguish between normal failure (exit code 100), success (exit code 0) and abnormal failure. --- tools/ormolu.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/ormolu.sh b/tools/ormolu.sh index b7bc03d99d5..c3dc08e8d94 100755 --- a/tools/ormolu.sh +++ b/tools/ormolu.sh @@ -72,14 +72,26 @@ echo "language extensions: $LANGUAGE_EXTS" FAILURES=0 +if [ -t 1 ]; then + : ${ORMOLU_CONDENSE_OUTPUT:=1} +fi + for hsfile in $(git ls-files | grep '\.hsc\?$'); do FAILED=0 - ormolu --mode $ARG_ORMOLU_MODE --check-idempotence $LANGUAGE_EXTS "$hsfile" || FAILED=1 - if [ "$FAILED" == "1" ]; then + + # run in background so that we can detect Ctrl-C properly + ormolu --mode $ARG_ORMOLU_MODE --check-idempotence $LANGUAGE_EXTS "$hsfile" & + wait $! && err=0 || err=$? + + if [ "$err" == "100" ]; then ((++FAILURES)) echo "$hsfile... *** FAILED" + clear="" + elif [ "$err" == "0" ]; then + echo -e "$clear$hsfile... ok" + [ "$ORMOLU_CONDENSE_OUTPUT" == "1" ] && clear="\033[A\r\033[K" else - echo "$hsfile... ok" + exit "$err" fi done