tidy.sh 1.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/bin/bash


if [ -f compile_commands.json ]; then
    echo "Using the existing compilation db"
else
    echo "Generating the compile db"
    cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
fi

echo "Retrieving the list of files to process..."
git ls-files > file_list
touch to_process
touch headers

echo "Cleaning the list of files to process..."
for file in `cat file_list`;
do
    if grep -Fq "${file}" compile_commands.json
    then
        echo $file >> to_process
    fi
    if echo $file | grep -q "\.[ih][p]*$"
    then
        echo $file >> headers
    fi
done;

29
echo "Formatting source files"
30
parallel -j 8 clang-format -i -style=file {} :::: to_process
31
echo "Formatting header files"
32 33 34 35 36
parallel -j 8 clang-format -i -style=file {} :::: headers

echo "Linting"
parallel -j 8 clang-tidy -fix -config="" {} :::: to_process

37
echo "Reformatting source files"
38
parallel -j 8 clang-format -i -style=file {} :::: to_process
39
echo "Reformatting header files"
40 41 42 43 44
parallel -j 8 clang-format -i -style=file {} :::: headers

rm file_list
rm to_process
rm headers