21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

clang-tidy.sh 1.53 KB
Newer Older
1
2
3
4
5
6
7
#!/bin/bash

exit_flag=false

# for compilation database
mkdir -p build
cd build
8
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DELSA_CUDA_VECTOR=ON
9
10
11
12
13
14
15
16
cd ..

target_branch="master"
echo
echo "clang-tidy checking changed files compared to target branch ${target_branch}"

# function to check if C++ file (based on suffix)
function checkCPP(){
17
    if [[ -f $1 ]] && [[ $1 == *.cpp ]]; then
18
19
20
21
22
23
24
25
26
27
28
29
30
        return 0
    fi
    return 1
}

clang-tidy-8 --version
echo

# Retrieve list of files that were changed in source branch with respect to master (target branch)
filelist=`git diff origin/${target_branch} --name-only`

# check list of files
for f in $filelist; do
31
32
    # check if .cpp file and in compilation DB
    if checkCPP $f && [[ -n $(grep $f build/compile_commands.json) ]]; then
33
34
        echo "Checking matching file ${f}"
        touch output.txt
35
        clang-tidy-8 -p=build ${f} --extra-arg=--cuda-host-only > output.txt
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        # decide if error or warning fail
        if [[ -n $(grep "warning: " output.txt) ]] || [[ -n $(grep "error: " output.txt) ]]; then
            echo ""
            echo "You must pass the clang tidy checks before submitting a pull request"
            echo ""
            grep --color -E '^|warning: |error: ' output.txt
            if [[ -n $(grep "error: " output.txt) ]]; then
                exit_flag=true
            fi
        else
            echo -e "\033[1;32m\xE2\x9C\x93 passed:\033[0m $1";
        fi
        rm output.txt
    fi
done

if [ "$exit_flag" = true ]; then
    exit -1
fi

echo "clang-tidy check passed"

exit 0