From e21acd7e0bf23dbb91865489a864a556d77718d0 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Fri, 17 May 2024 09:11:27 +0200 Subject: [PATCH 1/2] Add function ensure-one-newline to scripts/check-format.sh since clang-13 seems unable to handle this --- scripts/check-format.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/check-format.sh b/scripts/check-format.sh index 1ad2a1bb88..99e4b74c9c 100755 --- a/scripts/check-format.sh +++ b/scripts/check-format.sh @@ -69,6 +69,12 @@ cl-format-apply() { ${CLANG_FORMAT} -i $1 } +ensure-one-newline() +{ + sed -i -e '$a\' $1 + sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' $1 +} + cl-format-check() { local I=$1 local COLOR=$2 @@ -197,6 +203,7 @@ if [[ $NUMPROCS -lt 2 ]]; then RET=$? ((NUMFAILS+=RET)) if [ $FORMAT ]; then + ensure-one-newline $i cl-format-apply $i fi done @@ -218,6 +225,7 @@ else fi ((NUMFAILS+=RET)) if [ $FORMAT ]; then + ensure-one-newline $i cl-format-apply $i fi ) & while [[ $(jobs -r -p | wc -l) -ge $NUMPROCS ]];do -- GitLab From db1515cbda8e155e2bf91fc600254d39358c2c57 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Wed, 22 May 2024 14:34:29 +0200 Subject: [PATCH 2/2] add comments about sed commands --- scripts/check-format.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/check-format.sh b/scripts/check-format.sh index 99e4b74c9c..db6c681e9d 100755 --- a/scripts/check-format.sh +++ b/scripts/check-format.sh @@ -71,7 +71,11 @@ cl-format-apply() { ensure-one-newline() { + # first command adds a newline at the end of the file if there might be none + # -> clang-format-13 does not add them and warnings e.g. on MacOS are triggered by them sed -i -e '$a\' $1 + # second command removes multiple newlines at the end of a file so that there is only one left + # -> clang-format-13 does not do that, but complains about it sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' $1 } -- GitLab