-
Notifications
You must be signed in to change notification settings - Fork 1
/
tidy.sh
executable file
·76 lines (68 loc) · 2.22 KB
/
tidy.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
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Detect if a command exits. Additionally, return the command if it exits
function tidy_command_exists() {
local cmd=$1
if ! command -v "$cmd" &> /dev/null; then
exit 1
else
echo "$cmd"
exit 0
fi
}
# Stop checking once a working command is found
while : ; do
# Tidy command for ubuntu
tidy_command=$(tidy_command_exists run-clang-tidy-10) && break
# Tidy command for archlinux
tidy_command=$(tidy_command_exists /usr/share/clang/run-clang-tidy.py) && break
# Guard (do not remove)
echo "clang-tidy command could not be found"
exit 1
done
modified=0
if [ $# -eq 0 ]
then
cd "$DIR" || return
for package in `ls "$DIR"/.clang-tidy-builds`; do
# Check if the project is compiled with clang
compiler=$(cat "$DIR"/.clang-tidy-builds/"$package"/compiler.txt)
if [[ $compiler != clang* ]]
then
echo "Cannot tidy $package. Tidyer requires compilation with Clang"
exit 2
fi
echo "Working on $package"
"$tidy_command" -quiet -fix -j $(nproc) -header-filter='.*\.hpp' -format -p="$DIR"/.clang-tidy-builds/"$package" -extra-arg="-DCLANG_TIDIER"
tidy_ret=$?
if [ $tidy_ret -ne 0 ]
then
echo "exit code $tidy_ret when tidying $package"
modified=1
fi
echo "Exit code: $tidy_ret"
echo
done
else
echo "Tidying up directories: ${*:1}"
for package in "$@"; do
# Check if the project is compiled with clang
compiler=$(cat "$DIR"/.clang-tidy-builds/"$package"/compiler.txt)
if [[ $compiler != clang* ]]
then
echo "Cannot tidy $package. Tidyer requires compilation with Clang"
exit 2
fi
echo "Working on $package"
"$tidy_command" -quiet -fix -j $(nproc) -header-filter='.*\.hpp' -format -p="$DIR"/.clang-tidy-builds/"$package" -extra-arg="-DCLANG_TIDIER"
tidy_ret=$?
if [ $tidy_ret -ne 0 ]
then
echo "exit code $tidy_ret when tidying $package"
modified=1
fi
echo "Exit code: $tidy_ret"
echo
done
fi
exit $modified