Martin Roth | 0ad5fbd | 2020-12-24 12:06:38 -0700 | [diff] [blame] | 1 | #!/usr/bin/env sh |
Stefan Reinauer | b18f522 | 2015-02-11 01:53:42 +0100 | [diff] [blame] | 2 | # |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
Martin Roth | 1ce2ba6 | 2016-08-29 15:40:57 -0600 | [diff] [blame] | 5 | # DESCR: Checkpatch on .c, .h, & Kconfig files in the tree |
Stefan Reinauer | b18f522 | 2015-02-11 01:53:42 +0100 | [diff] [blame] | 6 | |
| 7 | LC_ALL=C export LC_ALL |
Martin Roth | 1ce2ba6 | 2016-08-29 15:40:57 -0600 | [diff] [blame] | 8 | |
| 9 | # GNU BRE syntax list of files to examine |
| 10 | INCLUDED_FILES='.*\.[ch]\|Kconfig.*$' |
| 11 | |
| 12 | EXCLUDED_DIRS="^payloads/libpayload/util/kconfig\|\ |
| 13 | ^payloads/libpayload/curses/PDCurses\|\ |
Patrick Georgi | 5486786 | 2018-05-30 15:54:08 +0200 | [diff] [blame] | 14 | ^util/crossgcc/patches\|\ |
Nico Huber | 55e3a6a | 2019-02-12 12:53:07 +0100 | [diff] [blame] | 15 | ^util/inteltool\|\ |
Martin Roth | 1ce2ba6 | 2016-08-29 15:40:57 -0600 | [diff] [blame] | 16 | ^util/kconfig\|\ |
Nico Huber | bfae9a8 | 2018-08-19 11:54:57 +0200 | [diff] [blame] | 17 | ^util/superiotool\|\ |
Martin Roth | 2a063be | 2017-04-05 21:29:06 -0600 | [diff] [blame] | 18 | ^Documentation" |
Martin Roth | 1ce2ba6 | 2016-08-29 15:40:57 -0600 | [diff] [blame] | 19 | |
Patrick Georgi | 7945f75 | 2019-02-27 19:57:23 +0100 | [diff] [blame] | 20 | opts="--max-line-length 96" |
| 21 | |
Patrick Georgi | 5486786 | 2018-05-30 15:54:08 +0200 | [diff] [blame] | 22 | # default: test src and util |
Martin Roth | 1ce2ba6 | 2016-08-29 15:40:57 -0600 | [diff] [blame] | 23 | if [ "$1" = "" ]; then |
Jan Dabros | ffa58cf | 2020-07-16 13:38:01 +0200 | [diff] [blame] | 24 | INCLUDED_DIRS="src util tests" |
Patrick Georgi | 5486786 | 2018-05-30 15:54:08 +0200 | [diff] [blame] | 25 | # special mode: take diff from stdin, but exclude the dirs |
| 26 | elif [ "$1" = "diff" ]; then |
| 27 | args=$( echo $EXCLUDED_DIRS | \ |
| 28 | sed -e 's,\\|, ,g' -e 's,\^,--exclude=,g' ) |
Patrick Georgi | 7945f75 | 2019-02-27 19:57:23 +0100 | [diff] [blame] | 29 | util/lint/checkpatch.pl --quiet --no-signoff $opts $args - |
Patrick Georgi | 5486786 | 2018-05-30 15:54:08 +0200 | [diff] [blame] | 30 | exit $? |
| 31 | # Space separated list of directories to test |
Martin Roth | 1ce2ba6 | 2016-08-29 15:40:57 -0600 | [diff] [blame] | 32 | else |
| 33 | INCLUDED_DIRS="$1" |
| 34 | fi |
| 35 | |
| 36 | # We want word splitting here, so disable the shellcheck warnings |
| 37 | # shellcheck disable=SC2046,SC2086 |
| 38 | FILELIST=$( git ls-files $INCLUDED_DIRS | \ |
| 39 | grep $INCLUDED_FILES | \ |
| 40 | grep -v $EXCLUDED_DIRS ) |
| 41 | |
| 42 | for FILE in $FILELIST; do |
Patrick Georgi | 7945f75 | 2019-02-27 19:57:23 +0100 | [diff] [blame] | 43 | util/lint/checkpatch.pl --show-types --file --quiet $opts "$FILE" |
Martin Roth | 1ce2ba6 | 2016-08-29 15:40:57 -0600 | [diff] [blame] | 44 | done |