forked from MRPT/mrpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_style.sh
executable file
·83 lines (64 loc) · 1.66 KB
/
check_style.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
83
#!/usr/bin/env bash
# Given a set of commits current script checks the style based on clang_format
# on the list of changed files that exist in the commits.
#
# Script should be called from a travis.yml file.
# Functions
######################
# This is run by travis automatically from the root of the project
set +e
DIRS_IN="libs apps samples python"
DIRS_OUT="3rdparty"
LANGS=cpp
FORMAT_CODE_BIN="scripts/clang_git_format/format_code.py"
function lint() {
# Get list of changed files for lint to run on. Grep only .h, .cpp files and
# mind the DIRS_IN, DIRS_OUT vars
# Following command fails if you "git commit --amend" - Works correctly on
# standard commits
echo "commit_range: $TRAVIS_COMMIT_RANGE"
changed_files=$(git diff --name-only $TRAVIS_COMMIT_RANGE)
printf "Summary of changed files:\n\n${changed_files}\n\n"
# include
regexp_in=
for i in $DIRS_IN; do
if [ -n "${regexp_in}" ]; then
regexp_in="${regexp_in}\|${i}"
else
regexp_in="${i}"
fi
done
# exclude
regexp_out=
for i in $DIRS_OUT; do
if [ -n "${regexp_out}" ]; then
regexp_out="${regexp_out}\|${i}"
else
regexp_out="${i}"
fi
done
echo "regexp_in: ${regexp_in}"
echo "regexp_out: ${regexp_out}"
valid_files=$(echo ${changed_files} \
| xargs -d' ' -n 1 \
| grep -i -e "${regexp_in}" \
| grep -v "${regexp_out}" \
| grep -ie ".*\.h$\|.*\.cpp")
printf "Valid files for lint:\n\t${valid_files}\n"
if [ -n "${valid_files}" ]; then
${FORMAT_CODE_BIN} -g . --lint_files ${valid_files}
else
true
fi
exit $?
}
function lint_all() {
${FORMAT_CODE_BIN} -g . --lang ${LANGS} \
-o ${DIRS_OUT} -i ${DIRS_IN} \
-l
exit $?
}
case $TASK in
lint ) lint;;
lint_all) lint_all;;
esac