Commit e613a765 authored by multrus's avatar multrus
Browse files

Merge branch 'fhg/update-check-format' into 'main'

[fix] check-format.sh script to also work with git

See merge request !88
parents edc72906 1007d4a9
Loading
Loading
Loading
Loading
Loading
+35 −8
Original line number Diff line number Diff line
@@ -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
@@ -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,30 +147,43 @@ 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

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
            exit 251
        fi
        if [[ "$OSTYPE" == "darwin"* ]]; then
            FILES=$(svn st | grep '^M' | cut -b 9- | grep -E "\.c|\.h")
        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 251
        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,13 +202,21 @@ if [[ $NUMPROCS -lt 2 ]]; then
    done
    if [[ $NUMFAILS -gt 0 ]]; then
        echo "Total fails:  $NUMFAILS"
        exit 1
#        exit $NUMFAILS  ## uncomment if script should have num fails as return code
    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 ) &
@@ -204,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  ## uncomment if script should have num fails as return code
    fi
fi

exit 0