-
Notifications
You must be signed in to change notification settings - Fork 91
/
cpplinter.sh
executable file
·55 lines (45 loc) · 1.18 KB
/
cpplinter.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
#!/bin/bash
# Copyright 2019 Intel Corporation
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
if [ $# -eq 0 ] || [ -z $1 ]; then
echo "Missing top folder input parameter for $0"
exit 1
fi
FILES_TO_PARSE=`find $1 -iname *.cpp -o -iname *.h -o -iname *.c`
RET=0
EXCLUDED_PATTERNS="\
common/protobuf \
common/base64 \
common/json \
enclave_u.c \
enclave_u.h \
enclave_t.c \
enclave_t.h \
/_build \
.pb. \
/node_modules \
common/crypto/pdo \
/vendor \
"
for FILE in $FILES_TO_PARSE; do
#skip file checking for certain folders
for EP in $EXCLUDED_PATTERNS; do
echo $FILE | grep -F $EP > /dev/null && continue 2
done
#do format (if specified) or simply check format
if [[ $2 == 'DO_FORMAT' ]]
then
clang-format -i $FILE
else
clang-format $FILE -output-replacements-xml | grep "</replacement>" > /dev/null &&\
echo "ERROR in format: $FILE" && RET=1
fi
done
#if check fails, provide instructions for fixing the format
if [[ $RET != 0 ]]
then
echo "Format check failed. Run '$0 <top folder> DO_FORMAT' to fix the format."
fi
exit $RET