|
|
@ -25,9 +25,34 @@ if ((major < required_major)) || ((minor < required_minor)) || ((patch < require
|
|
|
|
exit 1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Match all *.c and *.h files in ./runtime
|
|
|
|
help() {
|
|
|
|
# Excluding those in the jsmn or http-parser submodules
|
|
|
|
echo "Usage: $0 [OPTION]..."
|
|
|
|
# And format them with clang-format
|
|
|
|
echo "Formats source code in the repository, applying formatting in place by default"
|
|
|
|
find ./runtime -type f -path "./*.[ch]" |
|
|
|
|
echo ""
|
|
|
|
grep --invert-match -E "./runtime/thirdparty/*|./runtime/tests/gocr/*|./runtime/tests/TinyEKF/*|./runtime/tests/CMSIS_5_NN/*|./runtime/tests/sod/*|**/thirdparty/*" |
|
|
|
|
echo "-h, --help Print Help"
|
|
|
|
xargs clang-format -i
|
|
|
|
echo "-d, --dry-run Dry run formatters, returning 0 when code passes, 1 otherwise"
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo "Exit status:"
|
|
|
|
|
|
|
|
echo "0 if code required no formatting"
|
|
|
|
|
|
|
|
echo "non-zero exit status otherwise"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dry_run() {
|
|
|
|
|
|
|
|
find runtime \
|
|
|
|
|
|
|
|
\( -path "runtime/thirdparty" -o -path "runtime/tests/gocr" -o -path "runtime/tests/TinyEKF" -o -path "runtime/tests/CMSIS_5_NN" -o -path "runtime/tests/sod" -o -path "runtime/tests/**/thirdparty" \) -prune -false -o \
|
|
|
|
|
|
|
|
-type f \( -iname \*.h -o -iname \*.c -o -iname \*.s \) -print |
|
|
|
|
|
|
|
|
xargs clang-format -Werror -n -ferror-limit=0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
format() {
|
|
|
|
|
|
|
|
find runtime \
|
|
|
|
|
|
|
|
\( -path "runtime/thirdparty" -o -path "runtime/tests/gocr" -o -path "runtime/tests/TinyEKF" -o -path "runtime/tests/CMSIS_5_NN" -o -path "runtime/tests/sod" -o -path "runtime/tests/**/thirdparty" \) -prune -false -o \
|
|
|
|
|
|
|
|
-type f \( -iname \*.h -o -iname \*.c -o -iname \*.s \) -print |
|
|
|
|
|
|
|
|
xargs clang-format -i
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
|
|
|
|
"-h" | "--help") help ;;
|
|
|
|
|
|
|
|
"-d" | "--dry-run") dry_run ;;
|
|
|
|
|
|
|
|
"") format ;;
|
|
|
|
|
|
|
|
esac
|
|
|
|