forked from Consti10/wifibroadcast
-
Notifications
You must be signed in to change notification settings - Fork 10
/
run_clang_format.sh
executable file
·51 lines (41 loc) · 1.33 KB
/
run_clang_format.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# OpenHD clang-format checking.
# Performed steps:
# Step1: Generate list of all .cpp / .h / .hpp files of this project
# (excluding subdirectories)
# Step 2: Run clang-format
# Arguments: run with 'f' to fix things (otherwise, default, only check and report
# error if clang-format finds any issues
function append_all_sources_headers() {
# We use .h, .cpp and .hpp in OpenHD
TMP_FILE_LIST="$(find "$1" | grep -E ".*(\.cpp|\.h|\.hpp)$")"
#TMP_FILE_LIST+='\n'
FILE_LIST+=$'\n'
FILE_LIST+=$TMP_FILE_LIST
}
THIS_PATH="$(realpath "$0")"
THIS_DIR="$(dirname "$THIS_PATH")"
append_all_sources_headers "$THIS_DIR/wifibroadcast/src"
append_all_sources_headers "$THIS_DIR/wifibroadcast/executables"
echo "Files found to format = \n\"\"\"\n$FILE_LIST\n\"\"\""
# Checks for clang-format issues and returns error if they exist
function check_warning(){
clang-format --dry-run --Werror --verbose -i --style=file $FILE_LIST
if [ "$?" -eq "0" ]; then
echo "Everything formatted correctly"
else
echo "There are formatting errors ! Please fix first."
exit 1
fi
}
# fixes any issues (re-formats everything)
function fix_warnings() {
clang-format --verbose -i --style=file $FILE_LIST
}
if [ "$1" == "f" ]; then
echo "Fixing warnings"
fix_warnings
else
echo "Checking warnings"
check_warning
fi