
"shared/nm-std-aux/unaligned.h" is taken from systemd and frequently re-imported via the "systemd" branch. It is not our code, and should not be formatted with our clang-format.
76 lines
2.0 KiB
Bash
Executable File
76 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
while (( $# )); do
|
|
case $1 in
|
|
-i)
|
|
FLAGS="-i"
|
|
shift
|
|
;;
|
|
-h)
|
|
printf "Usage: %s [OPTION]... [FILE]...\n" $(basename $0)
|
|
printf "Reformat source files using NetworkManager's code-style.\n\n"
|
|
printf "If no file is given the script runs on the whole codebase.\n"
|
|
printf "If no flag is given no file is touch but errors are reported.\n\n"
|
|
printf "OPTIONS:\n"
|
|
printf " -i Reformat files\n"
|
|
printf " -h Print this help message\n"
|
|
exit 0
|
|
;;
|
|
*)
|
|
FILES+=($1)
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
NM_ROOT=$(git rev-parse --show-toplevel)
|
|
EXCLUDE="
|
|
:(exclude)shared/c-list
|
|
:(exclude)shared/c-list
|
|
:(exclude)shared/c-list
|
|
:(exclude)shared/c-rbtree
|
|
:(exclude)shared/c-siphash
|
|
:(exclude)shared/c-stdaux
|
|
:(exclude)shared/n-acd
|
|
:(exclude)shared/n-dhcp4
|
|
:(exclude)shared/nm-std-aux/unaligned.h
|
|
:(exclude)shared/systemd/src
|
|
:(exclude)src/systemd/src
|
|
"
|
|
|
|
if ! command -v clang-format &> /dev/null; then
|
|
echo -n "Error: clang-format is not installed, "
|
|
echo "on RHEL/Fedora/CentOS run 'dnf install clang-tools-extra'"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f ${NM_ROOT}/.clang-format ]; then
|
|
echo "Error: the clang-format file does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
FLAGS=${FLAGS:-"--Werror -n --ferror-limit=1"}
|
|
|
|
if [ -z "${FILES[@]}" ]; then
|
|
cd $NM_ROOT
|
|
FILES=($(git ls-files --full-name -- '*.[ch]' ${EXCLUDE}))
|
|
fi
|
|
|
|
for f in "${FILES[@]}"; do
|
|
if [ -f $f ]; then
|
|
if ! clang-format $FLAGS $f &> /dev/null; then
|
|
TMP_FILE=$(mktemp)
|
|
clang-format $f > $TMP_FILE
|
|
git --no-pager diff $f $TMP_FILE || true
|
|
rm $TMP_FILE
|
|
echo "Error: $(basename $f) code-style is wrong, fix it by running '$0 -i $f)"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "Error: $f No such file"
|
|
fi
|
|
done
|