eive-obsw/scripts/auto-formatter.sh

45 lines
1.2 KiB
Bash
Raw Permalink Normal View History

2022-05-17 13:40:19 +02:00
#!/bin/bash
if [[ ! -f README.md ]]; then
cd ..
fi
folder_list=(
2023-02-23 23:56:11 +01:00
"./watchdog"
2022-05-17 13:40:19 +02:00
"./mission"
"./linux"
"./bsp_q7s"
"./bsp_linux_board"
"./bsp_hosted"
"./bsp_egse"
"./test"
"./common"
2022-06-17 08:31:36 +02:00
"./dummies"
2022-05-17 13:40:19 +02:00
)
cmake_fmt="cmake-format"
file_selectors="-iname CMakeLists.txt"
if command -v ${cmake_fmt} &> /dev/null; then
echo "Auto-formatting all CMakeLists.txt files"
${cmake_fmt} -i CMakeLists.txt
for dir in ${folder_list[@]}; do
find ${dir} ${file_selectors} | xargs ${cmake_fmt} -i
done
2022-08-26 00:39:06 +02:00
${cmake_fmt} -i ./thirdparty/gomspace-sw/CMakeLists.txt
2022-05-17 13:40:19 +02:00
else
echo "No ${cmake_fmt} tool found, not formatting CMake files"
fi
cpp_format="clang-format"
2023-04-04 14:01:13 +02:00
file_selectors="( -iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp )"
file_excludes="( -not -iname translateObjects.cpp -not -iname translateEvents.cpp )"
2022-05-17 13:40:19 +02:00
if command -v ${cpp_format} &> /dev/null; then
for dir in ${folder_list[@]}; do
echo "Auto-formatting C/C++ files in ${dir} recursively"
2023-04-04 14:01:13 +02:00
find ${dir} ${file_excludes} -and ${file_selectors} | xargs ${cpp_format} --style=file -i
2022-05-17 13:40:19 +02:00
done
find ./unittest ${file_selectors} -o -type d -name build -prune | \
2023-04-04 13:48:50 +02:00
xargs ${cpp_format} --style=file -i
2022-05-17 13:40:19 +02:00
else
echo "No ${cpp_format} tool found, not formatting C++/C files"
fi