forked from ouster-lidar/ouster-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clang-linting.sh
executable file
·52 lines (46 loc) · 1.12 KB
/
clang-linting.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
#!/bin/bash
set -euo pipefail
help='false'
apply='false'
check='true'
SUBCOMMAND='--Werror --dry-run'
#Input arguments
while getopts 'ha' flag
do
case "${flag}" in
h) help='true';;
a) apply='true';;
esac
done
if [[ $help == 'true' ]]; then
echo """
How to run:
cd ouster-sdk; then run ./clang-linting.sh
Default: performs a clang format check and prints errors if they exist
./clang-linting.sh -a
applies the clang format to the files
"""
fi
if [[ $apply == 'true' ]]; then
check='false'
SUBCOMMAND=''
fi
# Ignore the ./ouster_client/include/optional-lite/nonstd/optional.hpp file while formatting files
run_command() {
find . -regex '.*\.\(cpp\|hpp\|cu\|c\|h\)' -not -path './ouster_client/include/optional-lite/nonstd/optional.hpp' \
-and -not -path './thirdparty/*' \
-exec clang-format ${SUBCOMMAND} -style=file -i {} \;
echo "Exit code: $?"
}
# grep returns an exit code of 1 if it finds no matches.
set +e
OUTPUT=$(run_command 2>&1 | grep error)
set -e
echo "OUTPUT $OUTPUT"
if [ -z "$OUTPUT" ]; then
echo "clang-format check passed! No errors"
exit 0;
else
run_command
exit 1;
fi