File indexing completed on 2024-04-21 04:52:59

0001 #!/bin/bash
0002 
0003 # SPDX-License-Identifier: BSD-2-Clause
0004 # SPDX-FileCopyrightText: Nicolas Carion <french.ebook.lover@gmail.com>
0005 
0006 if [ -f compile_commands.json ]; then
0007     echo "Using the existing compilation db"
0008 else
0009     echo "Generating the compile db"
0010     cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
0011 fi
0012 
0013 echo "Retrieving the list of files to process..."
0014 git ls-files > file_list
0015 touch to_process
0016 touch headers
0017 
0018 echo "Cleaning the list of files to process..."
0019 for file in `cat file_list`;
0020 do
0021     if grep -Fq "${file}" compile_commands.json
0022     then
0023         echo $file >> to_process
0024     fi
0025     if echo $file | grep -q "\.[ih][p]*$"
0026     then
0027         echo $file >> headers
0028     fi
0029 done;
0030 
0031 echo "Formatting source files"
0032 parallel -j 8 clang-format -i -style=file {} :::: to_process
0033 echo "Formatting header files"
0034 parallel -j 8 clang-format -i -style=file {} :::: headers
0035 
0036 echo "Linting"
0037 parallel -j 8 clang-tidy -fix -config="" {} :::: to_process
0038 
0039 echo "Reformatting source files"
0040 parallel -j 8 clang-format -i -style=file {} :::: to_process
0041 echo "Reformatting header files"
0042 parallel -j 8 clang-format -i -style=file {} :::: headers
0043 
0044 rm file_list
0045 rm to_process
0046 rm headers