-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.sh
executable file
·83 lines (61 loc) · 1.67 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
### This script is used to run clang-format on the source files.
# Directory containing this bash script.
readonly DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
readonly PREV_DIR=$(pwd)
readonly DOT_CLANG_FORMAT=$DIR/.clang-format
delete_file_if_exists () {
if [ -e $1 ]; then
rm -f $1
fi
}
format_cmake () {
if [ "$(which cmake-format)" == "" ]; then
printf "cmake-format was not found, skipping.\n" >&2
return
fi
cmakelists_file=$1
tmp_file="${cmakelists_file}.tmp"
cmake-format $cmakelists_file > $tmp_file
rm -f $cmakelists_file
mv $tmp_file $cmakelists_file
}
format () {
if [ "$(which clang-format)" == "" ]; then
printf "clang-format was not found, skipping.\n" >&2
return
fi
cd $1
delete_file_if_exists ./.clang-format
cp $DOT_CLANG_FORMAT ./.clang-format
find -name '*.cpp' -o -name '*.hh' -o -name '*.hpp' -o -name '*.h' | xargs clang-format -i
rm -f ./.clang-format
file=$(find -name 'CMakeLists.txt')
file_array=(${file})
for f in "${file_array[@]}"; do
format_cmake "$f"
done
}
format_python() {
python_src_file="$1"
if [ "$(which yapf)" == "" ]; then
printf "yapf was not found, skipping.\n" >&2
return
fi
yapf -i --style='{based_on_style: pep8, indent_width: 2}' $python_src_file
}
cd $DIR
python_files=$(find "$DIR/python" -name '*.py')
for python_file in "${python_files[@]}"; do
format_python "$python_file"
done
format_cmake $DIR/CMakeLists.txt
# Format the source files.
format "$DIR/compare_segmentation"
format "$DIR/confusion_matrix"
format "$DIR/counting"
format "$DIR/csv_lib"
format "$DIR/feature_extraction"
format "$DIR/fix_csv"
cd $PREV_DIR
exit 0