From 0e329816bd74187c46ceb21c79a497b4886a7da9 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Thu, 18 Jan 2018 22:55:07 +0000 Subject: util/lint: Apply `final newlines` check to scripts The `lint-extended-015-final-newlines` script skips over executable files and thus leaves script files unchecked. Use `file` to find scripts and include them in the `final newlines` checks. Whitelisting is used including bash, perl, python and sh scripts. Change-Id: I8649b261b7e2cbbac7f9b90a9ace3f1c7b0eedeb Signed-off-by: Alex Thiessen Reviewed-on: https://review.coreboot.org/23325 Reviewed-by: Paul Menzel Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth --- util/lint/lint-extended-015-final-newlines | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/util/lint/lint-extended-015-final-newlines b/util/lint/lint-extended-015-final-newlines index 1315dbdee5..5c60ddf54d 100755 --- a/util/lint/lint-extended-015-final-newlines +++ b/util/lint/lint-extended-015-final-newlines @@ -28,10 +28,27 @@ else FIND_FILES="find . " fi +HAVE_FILE=$(command -v file 1>/dev/null 2>&1; echo $?) + +is_eligible_executable() { + if [ "$HAVE_FILE" -ne 0 ]; then + return 1 + fi + if { LC_ALL=C; file --brief "$filename" | grep -Eqw \ + "^(Bourne shell|POSIX shell|Perl|Python) script"; }; + then + return 0 + else + return 1 + fi +} + test_for_final_newline() { while read filename; do - # Only check non-executable regular files - if [ -f "$filename" ] && [ ! -x "$filename" ]; then + # Only check regular files and script executables + if [ -f "$filename" ] && { [ ! -x "$filename" ] || \ + is_eligible_executable "$filename"; }; + then # Verify that there is a newline at the end # $() strips trailing newlines -- cgit v1.2.3