From 92e4d89f6458a5d6be6fd0742499cac8080b3ad6 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Tue, 12 Mar 2019 10:46:58 -0700 Subject: [PATCH] [travis] check/fix EOF newline on pretty/pretty-check (#3671) --- script/clang-format-check.sh | 16 +++++++++++++++- script/clang-format.sh | 21 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/script/clang-format-check.sh b/script/clang-format-check.sh index 784f9c211..1a2824d11 100755 --- a/script/clang-format-check.sh +++ b/script/clang-format-check.sh @@ -35,7 +35,21 @@ set -x +die() { + echo " *** ERROR: " $* + exit 1 +} + # from `man diff`: # Exit status is 0 if inputs are the same, 1 if different, 2 if trouble. -$(dirname "$0")/clang-format.sh -style=file $@ | diff -u $@ - +$(dirname "$0")/clang-format.sh -style=file $@ | diff -u $@ - || die + +for arg; do true; done +file=$arg +[ -n "$(tail -c1 $file)" ] && { + echo " *** ERROR: Missing EOF newline: " $file + exit 1 +} + +exit 0 diff --git a/script/clang-format.sh b/script/clang-format.sh index d07796749..2b54a40af 100755 --- a/script/clang-format.sh +++ b/script/clang-format.sh @@ -48,4 +48,23 @@ else die "clang-format 6.0 required" fi -clang-format $@ +clang-format $@ || die + +# ensure EOF newline +REPLACE=no +for arg +do + case $arg in + -i) + REPLACE=yes + ;; + esac +done + +file=$arg + +[ $REPLACE != yes ] || { + [ -n "$(tail -c1 $file)" ] && echo >> $file +} + +exit 0