soc/intel/xeon_sp: Drop uncore_fill_ssdt
[coreboot2.git] / util / lint / lint-extended-015-final-newlines
blob4ea4536124ecf035dc0e178bb3463388d6660505
1 #!/usr/bin/env sh
3 # SPDX-License-Identifier: GPL-2.0-only
5 # DESCR: Check that files end with a single newline
7 LINTDIR="$(
8 cd -- "$(dirname "$0")" > /dev/null 2>&1 || return
9 pwd -P
12 # shellcheck source=helper_functions.sh
13 . "${LINTDIR}/helper_functions.sh"
15 PIDS=""
16 INCLUDED_DIRS_AND_FILES='util/* src/* payloads/* configs/* Makefile *.inc'
17 EXCLUDED_DIRS='src/vendorcode/\|cbfstool/lzma/\|cbfstool/lz4/\|Documentation/\|build/\|3rdparty/\|\.git/\|coreboot-builds/\|util/nvidia/cbootimage/\|^util/goswid/vendor'
18 EXCLUDED_FILES='\.gif$\|\.jpg$\|\.cksum$\|\.bin$\|\.vbt$\|\.hex$\|\.ico$\|\.o$\|\.bz2$\|\.xz$\|^.tmpconfig\|\.pyc$\|_shipped$\|sha256$\|\.png$\|\.patch$\|\.apcb$'
20 HAVE_FILE=$(command -v file 1>/dev/null 2>&1; echo $?)
22 is_eligible_executable() {
23 if [ "$HAVE_FILE" -ne 0 ]; then
24 return 1
26 if { LC_ALL=C; file --brief "$filename" | grep -Eqw \
27 "^(Bourne shell|POSIX shell|Perl|Python) script"; };
28 then
29 return 0
30 else
31 return 1
35 test_for_final_newline() {
36 while read filename; do
37 # Only check regular files and script executables
38 if [ -f "$filename" ] && { [ ! -x "$filename" ] || \
39 is_eligible_executable "$filename"; };
40 then
41 # Verify that there is a newline at the end
42 # $() strips trailing newlines
43 if [ -n "$(tail -c 1 "$filename")" ]; then
44 echo "$filename has no final newline."
46 # Verify that the file ends with only a single newline
47 # and that the file isn't empty
48 elif [ -z "$(tail -c 2 "$filename")" ] && \
49 [ -n "$(head -n 5 "$filename")" ]; then
50 echo "$filename has multiple final newlines."
53 done
56 for directory in $INCLUDED_DIRS_AND_FILES ; do
57 ${FIND_FILES} "${directory}" | sed 's|^\./||' | sort | \
58 grep -v "$EXCLUDED_DIRS" | \
59 grep -v "$EXCLUDED_FILES" | \
60 test_for_final_newline &
61 PIDS="$PIDS $!"
62 done
64 # wait for tests to finish.
65 for pid in $PIDS; do
66 wait "$pid"
67 done