fsfw/scripts/apply-clang-format.sh

23 lines
697 B
Bash
Raw Normal View History

#!/bin/bash
if [[ ! -f README.md ]]; then
2022-05-13 11:49:01 +02:00
cd ..
fi
2022-05-13 11:37:58 +02:00
cmake_fmt="cmake-format"
2022-05-13 11:35:59 +02:00
if command -v ${cmake_fmt} &> /dev/null; then
2022-05-13 11:49:01 +02:00
cmake_fmt_cmd="${cmake_fmt} -i CMakeLists.txt"
eval ${cmake_fmt_cmd}
else
2022-05-13 11:49:01 +02:00
echo "No ${cmake_fmt} tool found, not formatting CMake files"
2022-05-13 11:35:59 +02:00
fi
cpp_format="clang-format"
2022-05-13 11:55:19 +02:00
file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp"
2022-05-13 11:46:59 +02:00
if command -v ${cpp_format} &> /dev/null; then
2022-05-13 11:55:19 +02:00
find ./src ${file_selectors} | xargs clang-format --style=file -i
find ./hal ${file_selectors} | xargs clang-format --style=file -i
find ./tests ${file_selectors} | xargs clang-format --style=file -i
else
2022-05-13 11:49:01 +02:00
echo "No ${cpp_format} tool found, not formatting C++/C files"
2022-05-13 11:55:19 +02:00
fi