-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-format.sh
executable file
·49 lines (44 loc) · 1.4 KB
/
check-format.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
#!/usr/bin/env bash
# set -e
realpath() {
OURPWD=$PWD
cd "$(dirname "$1")"
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")"
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD"
echo "$REALPATH"
}
SCRIPT_NAME=
if [ -z $BASH_SOURCE ]; then
SCRIPT_NAME=$0
else
SCRIPT_NAME=${BASH_SOURCE[0]}
fi
SCRIPT_DIR=$(realpath "$(dirname "$SCRIPT_NAME")")
source $SCRIPT_DIR/env.sh
export CF=clang-format
# FIXME: required until LLVM 16 when fix for .inc hits the release
export CF=$ZIRCON_HOME/../llvm/llvm-project/build/bin/clang-format
export STYLE=$ZIRCON_HOME/.clang-format
check_format() {
file=$1
diff <($CF --Werror --style=file:$STYLE $file) $file >/dev/null 2>&1
}
check_format_python() {
file=$1
python3 -m black --quiet --check $file >/dev/null 2>&1
}
export -f check_format
export -f check_format_python
FILES=("*.c" "*.cpp" "*.cc" "*.h" "*.hpp" "*.inc")
for s in "${FILES[@]}"; do
(find $ZIRCON_HOME/src -ipath $s -type f -exec bash -c 'check_format "$0" && test $? -eq 0 || echo $(echo $0 | sed "s;$ZIRCON_HOME/;;g") needs to be formatted' {} \; )
done
DIRS=("src" "test" "tests" "scripts")
for d in "${DIRS[@]}"; do
(find $ZIRCON_HOME/$d -ipath '*.py' -type f -exec bash -c 'check_format_python "$0" && test $? -eq 0 || echo $(echo $0 | sed "s;$ZIRCON_HOME/;;g") needs to be formatted' {} \; )
done