From 8c5ec3a54dc15b894ff85d9d51d9fd7eb3d501a7 Mon Sep 17 00:00:00 2001 From: Stefan Doehla Date: Mon, 22 Aug 2022 12:27:01 +0200 Subject: [PATCH 1/3] [fix] check-format.sh script to also work with git --- scripts/check-format.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/check-format.sh b/scripts/check-format.sh index c88442c959..1fc0b99bf3 100755 --- a/scripts/check-format.sh +++ b/scripts/check-format.sh @@ -35,7 +35,7 @@ if [ ! -d "lib_com" ]; then echo "not in root directory! - please run in IVAS root" - exit 1 + exit 255 fi CLANG_FORMAT=clang-format @@ -161,7 +161,7 @@ fi if [ -z "$FILES" ]; then if [ $ALL ]; then FILES=$(ls lib*/*.[c,h] apps/*.[c,h]) - else + elif [ -d ".svn" ]; then if [ ! -x "$(command -v svn)" ]; then echo "Subversion doesn't seem to be installed. Please ensure svn is in your PATH" exit 3 @@ -171,6 +171,19 @@ if [ -z "$FILES" ]; then else FILES=$(svn st | grep '^M' | cut -b 9- | grep '\.c$\|\.h$') fi + elif [ -d ".git" ]; then + if [ ! -x "$(command -v git)" ]; then + echo "GIT doesn't seem to be installed. Please ensure git is in your PATH" + exit 3 + fi + if [[ "$OSTYPE" == "darwin"* ]]; then + FILES=$(git status | grep 'modified: ' | cut -b 14- | grep -E "\.c|\.h") + else + FILES=$(git status | grep 'modified: ' | cut -b 14- | grep '\.c$\|\.h$') + fi + else + echo "Warning: no files checked (either no cmdl params or no modified files)" + exit 0 fi for i in ${EXCLUDE_FILES}; do FILES=$(echo ${FILES} | xargs -n 1 | grep -v ${i} | tr '\n' ' ') @@ -189,7 +202,7 @@ if [[ $NUMPROCS -lt 2 ]]; then done if [[ $NUMFAILS -gt 0 ]]; then echo "Total fails: $NUMFAILS" - exit 1 + exit $NUMFAILS fi else # parallel processing. Note that return code is always 0 then and fails are not counted @@ -200,7 +213,7 @@ else cl-format-apply $i fi ) & while [[ $(jobs -r -p | wc -l) -ge $NUMPROCS ]];do - sleep 0.1 + sleep 0.1 done done wait -- GitLab From 23cd10b2e87d5ac5dccdbd26de22b8ec82fc3e5c Mon Sep 17 00:00:00 2001 From: Stefan Doehla Date: Mon, 22 Aug 2022 18:08:23 +0200 Subject: [PATCH 2/3] [fix] multi-threaded count of unformatted files --- scripts/check-format.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/check-format.sh b/scripts/check-format.sh index 1fc0b99bf3..f84be58984 100755 --- a/scripts/check-format.sh +++ b/scripts/check-format.sh @@ -58,7 +58,7 @@ Usage: $(basename "$0") [OPTIONS] [FILES] -p NUMPROCS run in parallel -h display help EOM - exit 2 + exit 254 } cl-format-check-version() { @@ -147,14 +147,14 @@ FILES="$@" if [ ! -d "lib_com" ]; then echo "not in root directory! - please run in IVAS root" - exit 1 + exit 253 fi if [ ! $NOVERSION ]; then if [[ $(cl-format-check-version) != "${CLANG_FORMAT_REQUIRED_VERSION}"* ]]; then echo "clang-format must be version ${CLANG_FORMAT_REQUIRED_VERSION} but is $(cl-format-check-version) !!!" echo "Executables for Win32 could be downloaded from https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/LLVM-13.0.1-win32.exe" - exit 2 + exit 252 fi fi @@ -164,7 +164,7 @@ if [ -z "$FILES" ]; then elif [ -d ".svn" ]; then if [ ! -x "$(command -v svn)" ]; then echo "Subversion doesn't seem to be installed. Please ensure svn is in your PATH" - exit 3 + exit 251 fi if [[ "$OSTYPE" == "darwin"* ]]; then FILES=$(svn st | grep '^M' | cut -b 9- | grep -E "\.c|\.h") @@ -174,7 +174,7 @@ if [ -z "$FILES" ]; then elif [ -d ".git" ]; then if [ ! -x "$(command -v git)" ]; then echo "GIT doesn't seem to be installed. Please ensure git is in your PATH" - exit 3 + exit 251 fi if [[ "$OSTYPE" == "darwin"* ]]; then FILES=$(git status | grep 'modified: ' | cut -b 14- | grep -E "\.c|\.h") @@ -205,10 +205,18 @@ if [[ $NUMPROCS -lt 2 ]]; then exit $NUMFAILS fi else + NUMFAILS=0 + NUMFAILSTMPFILE=$(mktemp) # parallel processing. Note that return code is always 0 then and fails are not counted for i in ${FILES}; do ( cl-format-check $i $COLOR + RET=$? + if [[ $RET -gt 0 ]] + then + echo "1" >> "$NUMFAILSTMPFILE" + fi + ((NUMFAILS+=RET)) if [ $FORMAT ]; then cl-format-apply $i fi ) & @@ -217,6 +225,12 @@ else done done wait + NUMFAILS=`cat $NUMFAILSTMPFILE | wc -l` + rm "$NUMFAILSTMPFILE" + if [[ $NUMFAILS -gt 0 ]]; then + echo "Total fails: $NUMFAILS" + exit $NUMFAILS + fi fi exit 0 -- GitLab From 1007d4a9290246ecd8183195037b859b3ffac0a5 Mon Sep 17 00:00:00 2001 From: Stefan Doehla Date: Mon, 22 Aug 2022 18:13:55 +0200 Subject: [PATCH 3/3] modify to return 0 always regardless of formatting state but return error code when intial checks fail --- scripts/check-format.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check-format.sh b/scripts/check-format.sh index f84be58984..1302b5e03d 100755 --- a/scripts/check-format.sh +++ b/scripts/check-format.sh @@ -202,7 +202,7 @@ if [[ $NUMPROCS -lt 2 ]]; then done if [[ $NUMFAILS -gt 0 ]]; then echo "Total fails: $NUMFAILS" - exit $NUMFAILS +# exit $NUMFAILS ## uncomment if script should have num fails as return code fi else NUMFAILS=0 @@ -229,7 +229,7 @@ else rm "$NUMFAILSTMPFILE" if [[ $NUMFAILS -gt 0 ]]; then echo "Total fails: $NUMFAILS" - exit $NUMFAILS +# exit $NUMFAILS ## uncomment if script should have num fails as return code fi fi -- GitLab