2020-09-02 12:55:55 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
2021-01-13 11:22:53 +01:00
|
|
|
die() {
|
|
|
|
|
printf '%s\n' "$*" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
2020-09-02 12:55:55 +02:00
|
|
|
|
2021-01-13 11:22:53 +01:00
|
|
|
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"
|
all: move "src/" directory to "src/core/"
Currently "src/" mostly contains the source code of the daemon.
I say mostly, because that is not true, there are also the device,
settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp
helper, and probably more.
Also we have source code under libnm-core/, libnm/, clients/, and
shared/ directories. That is all confusing.
We should have one "src" directory, that contains subdirectories. Those
subdirectories should contain individual parts (libraries or
applications), that possibly have dependencies on other subdirectories.
There should be a flat hierarchy of directories under src/, which
contains individual modules.
As the name "src/" is already taken, that prevents any sensible
restructuring of the code.
As a first step, move "src/" to "src/core/". This gives space to
reorganize the code better by moving individual components into "src/".
For inspiration, look at systemd's "src/" directory.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
2021-02-03 15:25:56 +01:00
|
|
|
":(exclude)src/core/systemd/src"
|
2021-02-18 17:37:47 +01:00
|
|
|
":(exclude)src/libnm-std-aux/unaligned.h"
|
2021-02-18 08:13:35 +01:00
|
|
|
":(exclude)src/libnm-systemd-shared/src"
|
2021-01-13 11:22:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
NM_ROOT="$(git rev-parse --show-toplevel)" || die "not inside a git repository"
|
|
|
|
|
NM_PREFIX="$(git rev-parse --show-prefix)" || die "not inside a git repository"
|
|
|
|
|
|
|
|
|
|
if [ ! -f "$NM_ROOT/.clang-format" ]; then
|
|
|
|
|
die "Error: the clang-format file in \"$NM_ROOT\" does not exist"
|
|
|
|
|
fi
|
2020-09-02 12:55:55 +02:00
|
|
|
|
2020-12-11 11:11:57 +01:00
|
|
|
if ! command -v clang-format &> /dev/null; then
|
2021-01-13 11:22:53 +01:00
|
|
|
die "Error: clang-format is not installed. On RHEL/Fedora/CentOS run 'dnf install clang-tools-extra'"
|
2020-09-02 12:55:55 +02:00
|
|
|
fi
|
|
|
|
|
|
2021-01-13 11:22:53 +01:00
|
|
|
if test -n "$NM_PREFIX"; then
|
|
|
|
|
_EXCLUDE=()
|
|
|
|
|
for e in "${EXCLUDE[@]}"; do
|
|
|
|
|
REGEX='^:\(exclude\)'"$NM_PREFIX"'([^/].*)$'
|
|
|
|
|
if [[ "$e" =~ $REGEX ]]; then
|
|
|
|
|
_EXCLUDE+=(":(exclude)${BASH_REMATCH[1]}")
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
EXCLUDE=("${_EXCLUDE[@]}")
|
2020-09-02 12:55:55 +02:00
|
|
|
fi
|
|
|
|
|
|
2021-01-13 11:22:53 +01:00
|
|
|
FILES=()
|
|
|
|
|
HAS_EXPLICIT_FILES=0
|
|
|
|
|
SHOW_FILENAMES=0
|
|
|
|
|
TEST_ONLY=1
|
2020-09-02 12:55:55 +02:00
|
|
|
|
2021-01-13 11:22:53 +01:00
|
|
|
usage() {
|
|
|
|
|
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 " -n Only check the files (this is the default)\n"
|
|
|
|
|
printf " -h Print this help message\n"
|
|
|
|
|
printf " --show-filenames Only print the filenames that would be checked\n"
|
|
|
|
|
printf " -- Separate options from filenames/directories\n"
|
|
|
|
|
}
|
2020-09-02 12:55:55 +02:00
|
|
|
|
2021-01-13 11:22:53 +01:00
|
|
|
HAD_DASHDASH=0
|
|
|
|
|
while (( $# )); do
|
|
|
|
|
if [ "$HAD_DASHDASH" = 0 ]; then
|
|
|
|
|
case "$1" in
|
|
|
|
|
-h)
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
--show-filenames)
|
|
|
|
|
SHOW_FILENAMES=1
|
|
|
|
|
shift
|
|
|
|
|
continue
|
|
|
|
|
;;
|
|
|
|
|
-n)
|
|
|
|
|
TEST_ONLY=1
|
|
|
|
|
shift
|
|
|
|
|
continue
|
|
|
|
|
;;
|
|
|
|
|
-i)
|
|
|
|
|
TEST_ONLY=0
|
|
|
|
|
shift
|
|
|
|
|
continue
|
|
|
|
|
;;
|
|
|
|
|
--)
|
|
|
|
|
HAD_DASHDASH=1
|
|
|
|
|
shift
|
|
|
|
|
continue
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
|
|
|
|
if [ -d "$1" ]; then
|
|
|
|
|
FILES+=( $(git ls-files -- "${1}/*.[hc]" "${EXCLUDE[@]}" ) )
|
|
|
|
|
elif [ -f "$1" ]; then
|
|
|
|
|
FILES+=("$1")
|
|
|
|
|
else
|
|
|
|
|
usage >&2
|
|
|
|
|
echo >&2
|
|
|
|
|
die "Unknown argument \"$1\" which also is neither a file nor a directory."
|
|
|
|
|
fi
|
|
|
|
|
shift
|
|
|
|
|
HAS_EXPLICIT_FILES=1
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ $HAS_EXPLICIT_FILES = 0 ]; then
|
|
|
|
|
FILES=( $(git ls-files -- '*.[ch]' "${EXCLUDE[@]}") )
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $SHOW_FILENAMES = 1 ]; then
|
|
|
|
|
printf '%s\n' "${FILES[@]}"
|
|
|
|
|
exit 0
|
2020-09-02 12:55:55 +02:00
|
|
|
fi
|
|
|
|
|
|
2021-01-13 13:27:51 +01:00
|
|
|
if [ "${#FILES[@]}" = 0 ]; then
|
|
|
|
|
die "Error: no files to check"
|
|
|
|
|
fi
|
|
|
|
|
|
2021-01-13 11:22:53 +01:00
|
|
|
FLAGS_TEST=( --Werror -n --ferror-limit=1 )
|
|
|
|
|
|
|
|
|
|
if [ $TEST_ONLY = 1 ]; then
|
|
|
|
|
# We assume that all formatting is correct. In that mode, passing
|
|
|
|
|
# all filenames to clang-format is significantly faster.
|
|
|
|
|
#
|
|
|
|
|
# Only in case of an error, we iterate over the files one by one
|
|
|
|
|
# until we find the first invalid file.
|
|
|
|
|
for f in "${FILES[@]}"; do
|
|
|
|
|
[ -f $f ] || die "Error: file \"$f\" does not exist (or is not a regular file)"
|
|
|
|
|
done
|
|
|
|
|
clang-format "${FLAGS_TEST[@]}" "${FILES[@]}" &>/dev/null && exit 0
|
|
|
|
|
for f in "${FILES[@]}"; do
|
|
|
|
|
[ -f $f ] || die "Error: file \"$f\" does not exist (or is not a regular file)"
|
|
|
|
|
if ! clang-format "${FLAGS_TEST[@]}" "$f" &>/dev/null; then
|
|
|
|
|
FF="$(mktemp)"
|
|
|
|
|
trap 'rm -f "$FF"' EXIT
|
|
|
|
|
clang-format "$f" 2>/dev/null > "$FF"
|
|
|
|
|
git --no-pager diff "$f" "$FF" || :
|
|
|
|
|
die "Error: file \"$f\" has code-style is wrong. Fix it by running "'`'"\"$0\" -i \"$f\""'`'
|
2020-09-02 12:55:55 +02:00
|
|
|
fi
|
2021-01-13 11:22:53 +01:00
|
|
|
done
|
|
|
|
|
die "an unknown error happened."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
clang-format -i "${FILES[@]}"
|