Replace clang-format with uncrustify
LLVM/clang is not used for any compilation due to it not supporting the 8-bit architectures we use (MCS-51, AVR). This means we are effectively installing 250+ MiB of dependencies for a C formatting tool. Replace it with uncrustify, which uses only ~600 KiB of space and has more granular control of formatting (800+ options). Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
committed by
Tim Crawford
parent
6c3b34ee6e
commit
d3894392d5
@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
readarray -t FILES < <(git ls-files '*.c' '*.h')
|
||||
|
||||
FMT_OPTS=(
|
||||
"-style=file"
|
||||
"--fallback-style=none"
|
||||
"--Werror"
|
||||
)
|
||||
|
||||
if [[ "$1" = "apply" ]]; then
|
||||
clang-format "${FMT_OPTS[@]}" -i "${FILES[@]}"
|
||||
else
|
||||
clang-format "${FMT_OPTS[@]}" --dry-run "${FILES[@]}"
|
||||
fi
|
@ -19,7 +19,6 @@ if [[ "${ID}" =~ "debian" ]] || [[ "${ID_LIKE}" =~ "debian" ]]; then
|
||||
--yes \
|
||||
avr-libc \
|
||||
avrdude \
|
||||
clang-format \
|
||||
curl \
|
||||
gcc \
|
||||
gcc-avr \
|
||||
@ -30,6 +29,7 @@ if [[ "${ID}" =~ "debian" ]] || [[ "${ID_LIKE}" =~ "debian" ]]; then
|
||||
pkgconf \
|
||||
sdcc \
|
||||
shellcheck \
|
||||
uncrustify \
|
||||
xxd
|
||||
elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then
|
||||
sudo dnf install \
|
||||
@ -37,13 +37,13 @@ elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then
|
||||
avr-gcc \
|
||||
avr-libc \
|
||||
avrdude \
|
||||
clang-tools-extra \
|
||||
curl \
|
||||
gcc \
|
||||
make \
|
||||
sdcc \
|
||||
ShellCheck \
|
||||
systemd-devel \
|
||||
uncrustify \
|
||||
vim-common
|
||||
elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
|
||||
sudo pacman -S \
|
||||
@ -51,7 +51,6 @@ elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
|
||||
avr-gcc \
|
||||
avr-libc \
|
||||
avrdude \
|
||||
clang \
|
||||
curl \
|
||||
gcc \
|
||||
make \
|
||||
@ -59,6 +58,7 @@ elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then
|
||||
sdcc \
|
||||
shellcheck \
|
||||
systemd-libs \
|
||||
uncrustify \
|
||||
vim
|
||||
else
|
||||
msg "Please add support for your distribution to:"
|
||||
|
@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# Check if any C files or headers need to be formatted.
|
||||
|
||||
LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
|
||||
. "$LINT_DIR/util.sh"
|
||||
|
||||
echo -n "Checking C style..."
|
||||
|
||||
if ! command -v clang-format > /dev/null; then
|
||||
skipped "clang-format not found"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
readarray -t FILES < <(git ls-files '*.c' '*.h')
|
||||
|
||||
FMT_OPTS=(
|
||||
"-style=file"
|
||||
"--fallback-style=none"
|
||||
"--dry-run"
|
||||
"--Werror"
|
||||
)
|
||||
|
||||
# NOTE: It is too slow to run clang-format on every file individually to report
|
||||
# which ones fail. Leave it up to the user to apply formatting via `make fmt`.
|
||||
|
||||
_output=$(clang-format "${FMT_OPTS[@]}" "${FILES[@]}" 2>&1)
|
||||
if [[ $_output != "" ]]; then
|
||||
failed
|
||||
exit 1
|
||||
fi
|
||||
|
||||
passed
|
36
scripts/lint/02-uncrustify.sh
Executable file
36
scripts/lint/02-uncrustify.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# Check if any C files or headers need to be formatted.
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
LINT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
|
||||
. "$LINT_DIR/util.sh"
|
||||
|
||||
echo -n "Checking C style..."
|
||||
|
||||
if ! command -v uncrustify > /dev/null; then
|
||||
skipped "uncrustify not found"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
needs_formatting=()
|
||||
|
||||
for file in $(git ls-files '*.c' '*.h'); do
|
||||
if ! uncrustify -c .uncrustify.cfg -q --check "$file" >/dev/null 2>&1; then
|
||||
needs_formatting+=("$file")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "${#needs_formatting[@]}" != "0" ]]; then
|
||||
failed
|
||||
|
||||
for file in "${needs_formatting[@]}"; do
|
||||
echo "- $file"
|
||||
done
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
passed
|
Reference in New Issue
Block a user