Debian Codegraph @

util/lint/lint-extended-015-final-newlines

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. sh
2 #
3 # SPDX-License-Identifier: GPL-2.0-only
4
5 # DESCR: Check that files end with a single newline
6
7 LINTDIR="$(
8 cd -- "$(dirnamescip-shell system . . dirname. "$0")" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || return
9 pwdscip-shell system . . pwd. -P
10 )"
11
12 # shellcheck source=helper_functions.sh
13 . "${LINTDIR}/helper_functions.sh"
14
15 PIDS=""
16 INCLUDED_DIRS_AND_FILES='util/* src/* payloads/* configs/* Makefile *.mk'
17 EXCLUDED_DIRS="\
18 src/vendorcode/\|\
19 cbfstool/lzma/\|\
20 cbfstool/lz4/\|\
21 Documentation/\|\
22 build/\|\
23 3rdparty/\|\
24 \.git/\|\
25 coreboot-builds/\|\
26 util/nvidia/cbootimage/\|\
27 ^util/goswid/vendor\|\
28 ^util/riscv/starfive-jh7110-spl-tool"
29 EXCLUDED_FILES='\.gif$\|\.jpg$\|\.cksum$\|\.bin$\|\.vbt$\|\.hex$\|\.ico$\|\.o$\|\.bz2$\|\.xz$\|^.tmpconfig\|\.pyc$\|_shipped$\|sha256$\|\.png$\|\.patch$\|\.apcb$'
30
31 HAVE_FILE=$(command -v file 1>/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; echoscip-shell system . . echo. $?)
32
33 is_eligible_executablescip-shell shell coreboot 25.09+dfsg-1 is_eligible_executable().() {
34 if [scip-shell system . . `[`. "$HAVE_FILE" -ne 0 ]; then
35 return 1
36 fi
37 if { LC_ALL=C; filescip-shell system . . file. --brief "$filename" | grepscip-shell system . . grep. -Eqw \
38 "^(Bourne shell|POSIX shell|Perl|Python) script"; };
39 then
40 return 0
41 else
42 return 1
43 fi
44 }
45
46 test_for_final_newlinescip-shell shell coreboot 25.09+dfsg-1 test_for_final_newline().() {
47 while read filename; do
48 # Only check regular files and script executables
49 if [scip-shell system . . `[`. -f "$filename" ] && { [scip-shell system . . `[`. ! -x "$filename" ] || \
50 is_eligible_executable "$filename"; };
51 then
52 # Verify that there is a newline at the end
53 # $() strips trailing newlines
54 if [scip-shell system . . `[`. -n "$(tailscip-shell system . . tail. -c 1 "$filename")" ]; then
55 echoscip-shell system . . echo. "$filename has no final newline."
56
57 # Verify that the file ends with only a single newline
58 # and that the file isn't empty
59 elif [scip-shell system . . `[`. -z "$(tailscip-shell system . . tail. -c 2 "$filename")" ] && \
60 [ -n "$(headscip-shell system . . head. -n 5 "$filename")" ]; then
61 echoscip-shell system . . echo. "$filename has multiple final newlines."
62 fi
63 fi
64 done
65 }
66
67 for dir_or_file in $INCLUDED_DIRS_AND_FILES; do
68 if [scip-shell system . . `[`. -e "${dir_or_file}" ] || [scip-shell system . . `[`. -d "${dir_or_file}" ]; then
69 ${FIND_FILES} "${dir_or_file}" ${FINDOPTS} | sedscip-shell system . . sed. 's|^\./||' | sortscip-shell system . . sort. | \
70 grep -v "$EXCLUDED_DIRS" | \
71 grep -v "$EXCLUDED_FILES" | \
72 test_for_final_newline &
73 PIDS="$PIDS $!"
74 fi
75 done
76
77 # wait for tests to finish.
78 for pid in $PIDS; do
79 wait "$pid"
80 done