blob: a9cf782885135d44c855d0b0fde424cbf3be0bc4 [file] [log] [blame]
Martin Roth0ad5fbd2020-12-24 12:06:38 -07001#!/usr/bin/env sh
Stefan Reinauerb18f5222015-02-11 01:53:42 +01002#
Patrick Georgi7333a112020-05-08 20:48:04 +02003# SPDX-License-Identifier: GPL-2.0-only
4
Martin Roth1ce2ba62016-08-29 15:40:57 -06005# DESCR: Checkpatch on .c, .h, & Kconfig files in the tree
Stefan Reinauerb18f5222015-02-11 01:53:42 +01006
Martin Rothd81debd2022-06-03 00:06:57 -06007LINTDIR="$(
8 cd -- "$(dirname "$0")" > /dev/null 2>&1 || return
9 pwd -P
10)"
11
12# shellcheck source=helper_functions.sh
13. "${LINTDIR}/helper_functions.sh"
Martin Roth1ce2ba62016-08-29 15:40:57 -060014
15# GNU BRE syntax list of files to examine
16INCLUDED_FILES='.*\.[ch]\|Kconfig.*$'
17
18EXCLUDED_DIRS="^payloads/libpayload/util/kconfig\|\
19^payloads/libpayload/curses/PDCurses\|\
Sean Rhodesc9bc7a72021-11-10 11:22:19 +000020^util/coreboot-configurator\|\
Patrick Georgi54867862018-05-30 15:54:08 +020021^util/crossgcc/patches\|\
Nico Huber55e3a6a2019-02-12 12:53:07 +010022^util/inteltool\|\
Martin Roth1ce2ba62016-08-29 15:40:57 -060023^util/kconfig\|\
Nico Huberbfae9a82018-08-19 11:54:57 +020024^util/superiotool\|\
Martin Roth2a063be2017-04-05 21:29:06 -060025^Documentation"
Martin Roth1ce2ba62016-08-29 15:40:57 -060026
Patrick Georgi7945f752019-02-27 19:57:23 +010027opts="--max-line-length 96"
28
Patrick Georgi54867862018-05-30 15:54:08 +020029# default: test src and util
Martin Roth1ce2ba62016-08-29 15:40:57 -060030if [ "$1" = "" ]; then
Jan Dabrosffa58cf2020-07-16 13:38:01 +020031 INCLUDED_DIRS="src util tests"
Patrick Georgi54867862018-05-30 15:54:08 +020032# special mode: take diff from stdin, but exclude the dirs
33elif [ "$1" = "diff" ]; then
34 args=$( echo $EXCLUDED_DIRS | \
35 sed -e 's,\\|, ,g' -e 's,\^,--exclude=,g' )
Patrick Georgi7945f752019-02-27 19:57:23 +010036 util/lint/checkpatch.pl --quiet --no-signoff $opts $args -
Patrick Georgi54867862018-05-30 15:54:08 +020037 exit $?
38# Space separated list of directories to test
Martin Roth1ce2ba62016-08-29 15:40:57 -060039else
40 INCLUDED_DIRS="$1"
41fi
42
43# We want word splitting here, so disable the shellcheck warnings
44# shellcheck disable=SC2046,SC2086
Martin Rothd81debd2022-06-03 00:06:57 -060045FILELIST=$( ${FIND_FILES} $INCLUDED_DIRS | \
Martin Roth1ce2ba62016-08-29 15:40:57 -060046 grep $INCLUDED_FILES | \
47 grep -v $EXCLUDED_DIRS )
48
49for FILE in $FILELIST; do
Patrick Georgi7945f752019-02-27 19:57:23 +010050 util/lint/checkpatch.pl --show-types --file --quiet $opts "$FILE"
Martin Roth1ce2ba62016-08-29 15:40:57 -060051done