-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
format-all
executable file
·71 lines (65 loc) · 1.85 KB
/
format-all
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
#! /bin/bash
# Call this script to format every c[pp] & h[pp] file
# in the parent directory using clang-format
#
# Returns
# 0 on success
# 2 is clang-format 8 could not be found
# Detect clang-format version
if command -v clang-format-8 > /dev/null; then
BINARY="clang-format-8"
elif command -v clang-format > /dev/null; then
BINARY="clang-format"
VERSION=$(clang-format --version | grep -o '[0-9]\+.[0-9]\+.[0-9]\+' | head -1 | cut -d '.' -f 1)
if (( $VERSION != 8 )); then
echo "clang-format version 8 expected, but ${VERSION} found!"
echo "Please install a suffixed binary (clang-format-8) or install clang-format version 8."
exit 2
fi
else
echo "clang-format not found!"
echo "Please install clang-format version 8."
exit 2
fi
echo "Using binary: $BINARY"
# Detect GNU parallel
if command -v parallel > /dev/null ; then
echo "GNU parallel detected."
HAS_PARALLEL=true
else
echo "Install GNU parallel to format in parallel."
HAS_PARALLEL=false
fi
# Format C/C++
CFILES=$(git ls-files -- '*.[ch]pp' '*.[ch]' ':!thirdparty')
echo "Formatting $(echo "$CFILES" | wc -l) C/C++ files"
if $HAS_PARALLEL; then
echo "$CFILES" | parallel --bar "${BINARY} -style=file -i {}"
else
for cfile in $CFILES; do
${BINARY} -style=file -i $cfile
echo -n "."
done
echo
fi
# Detect python3
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if command -v python3 > /dev/null; then
PYCMD="python3"
else
PYCMD="python"
fi
XMLFILES="$(git ls-files -- '*.xml' '!docs')"
XMLFMT="$SCRIPTDIR/config-formatter"
echo "Formatting $(echo "$XMLFILES" | wc -l) XML files"
if $HAS_PARALLEL; then
echo "$XMLFILES" | parallel --bar "$PYMCD $XMLFMT -i {}"
else
for xmlfile in $XMLFILES; do
$PYCMD $XMLFMT -i $xmlfile
echo -n "."
done
echo
fi
echo -e "\nDone"
exit 0