Commit 23cd10b2 authored by Stefan Doehla's avatar Stefan Doehla
Browse files

[fix] multi-threaded count of unformatted files

parent 8c5ec3a5
Loading
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -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