-
Notifications
You must be signed in to change notification settings - Fork 511
Expand file tree
/
Copy pathcodeformat.sh
More file actions
executable file
·50 lines (45 loc) · 1.82 KB
/
codeformat.sh
File metadata and controls
executable file
·50 lines (45 loc) · 1.82 KB
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
#!/usr/bin/env bash
CLANG_FORMAT="${HOME}/.local/bin/clang-format"
if [ ! -f "$CLANG_FORMAT" ]; then
CLANG_FORMAT=$(which clang-format 2>/dev/null || true)
fi
if [[ $(uname) == 'Darwin' ]]; then
clangformat=$($CLANG_FORMAT --version 2>/dev/null)
if [[ $clangformat =~ "14." ]]; then
echo "----$clangformat----"
else
MAC_REQUIRED_TOOLS="python3 pipx"
for TOOL in ${MAC_REQUIRED_TOOLS[@]}; do
if [ ! $(which $TOOL) ]; then
if [ ! $(which brew) ]; then
echo "Homebrew not found. Trying to install..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ||
exit 1
fi
echo "$TOOL not found. Trying to install..."
brew install $TOOL || exit 1
fi
done
echo "----install clang-format----"
pipx install clang-format==14
CLANG_FORMAT="${HOME}/.local/bin/clang-format"
fi
fi
echo "----begin to scan code format----"
find include/ -iname '*.h' -print0 | xargs $CLANG_FORMAT -i
# shellcheck disable=SC2038
find src -name "*.cpp" -print -o -name "*.h" -print -o -name "*.mm" -print -o -name "*.m" -print | xargs $CLANG_FORMAT -i
# shellcheck disable=SC2038
find test \( -path test/framework/lzma \) -prune -o -name "*.cpp" -print -o -name "*.h" -print | xargs $CLANG_FORMAT -i
find viewer/src -name "*.cpp" -print -o -name "*.h" -print -o -name "*.mm" -print -o -name "*.m" -print -o -name "*.hpp" -print | xargs $CLANG_FORMAT -i
find exporter/src -name "*.cpp" -print -o -name "*.h" -print -o -name "*.mm" -print -o -name "*.m" -print -o -name "*.hpp" -print | xargs $CLANG_FORMAT -i
git diff
result=`git diff`
if [[ $result =~ "diff" ]]
then
echo "----Failed to pass coding specification----"
exit 1
else
echo "----Pass coding specification----"
fi
echo "----Complete the scan code format-----"