Skip to content

Commit

Permalink
Ormolu script improvements (#1458)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pcapriotti authored Apr 19, 2021
1 parent 3cd446d commit 9226082
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tools/ormolu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9226082

Please sign in to comment.