-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfmt.sh
More file actions
executable file
·35 lines (28 loc) · 1018 Bytes
/
Copy pathfmt.sh
File metadata and controls
executable file
·35 lines (28 loc) · 1018 Bytes
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
#!/bin/bash
# Used to format files to the given format using clang format.
# example runs:
# ./scripts/fmt.sh
# ./scripts/fmt.sh format # This will write changes to file
APPLY_FORMAT=${1:-""}
# Variable that will hold the name of the clang-format command
FMT=""
# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
# that the version number be part of the command. We prefer clang-format if
# that's present, otherwise we check clang-format-16
for clangfmt in clang-format{,-16}; do
if which "$clangfmt" &>/dev/null; then
FMT="$clangfmt"
break
fi
done
# Check if we found a working clang-format
if [ -z "$FMT" ]; then
echo "failed to find clang-format. Please install clang-format version 16 or above"
exit 1
fi
files=$(find . \( -path ./build -prune -o -path ./.git -prune -o -path ./third_party -prune \) -o -type f -name "*[h|c]pp" -print)
if [[ ${APPLY_FORMAT} = "format" ]]; then
${FMT} -i ${files}
else
${FMT} --dry-run --Werror ${files}
fi