blob: f8a8095e39af16d7835abd34bd7c9cd28eaa8717 [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\|\
Patrick Georgi1d029b42023-10-06 20:19:15 +020020^src/vendorcode/wuffs\|\
Sean Rhodesc9bc7a72021-11-10 11:22:19 +000021^util/coreboot-configurator\|\
Patrick Georgi54867862018-05-30 15:54:08 +020022^util/crossgcc/patches\|\
Nico Huber55e3a6a2019-02-12 12:53:07 +010023^util/inteltool\|\
Martin Roth1ce2ba62016-08-29 15:40:57 -060024^util/kconfig\|\
Nico Huberbfae9a82018-08-19 11:54:57 +020025^util/superiotool\|\
Martin Roth2a063be2017-04-05 21:29:06 -060026^Documentation"
Martin Roth1ce2ba62016-08-29 15:40:57 -060027
Patrick Georgi7945f752019-02-27 19:57:23 +010028opts="--max-line-length 96"
29
Patrick Georgi54867862018-05-30 15:54:08 +020030# default: test src and util
Martin Roth1ce2ba62016-08-29 15:40:57 -060031if [ "$1" = "" ]; then
Jan Dabrosffa58cf2020-07-16 13:38:01 +020032 INCLUDED_DIRS="src util tests"
Patrick Georgi54867862018-05-30 15:54:08 +020033# special mode: take diff from stdin, but exclude the dirs
34elif [ "$1" = "diff" ]; then
35 args=$( echo $EXCLUDED_DIRS | \
36 sed -e 's,\\|, ,g' -e 's,\^,--exclude=,g' )
Patrick Georgi7945f752019-02-27 19:57:23 +010037 util/lint/checkpatch.pl --quiet --no-signoff $opts $args -
Patrick Georgi54867862018-05-30 15:54:08 +020038 exit $?
39# Space separated list of directories to test
Martin Roth1ce2ba62016-08-29 15:40:57 -060040else
41 INCLUDED_DIRS="$1"
42fi
43
44# We want word splitting here, so disable the shellcheck warnings
45# shellcheck disable=SC2046,SC2086
Martin Rothd81debd2022-06-03 00:06:57 -060046FILELIST=$( ${FIND_FILES} $INCLUDED_DIRS | \
Martin Roth1ce2ba62016-08-29 15:40:57 -060047 grep $INCLUDED_FILES | \
48 grep -v $EXCLUDED_DIRS )
49
50for FILE in $FILELIST; do
Patrick Georgi7945f752019-02-27 19:57:23 +010051 util/lint/checkpatch.pl --show-types --file --quiet $opts "$FILE"
Martin Roth1ce2ba62016-08-29 15:40:57 -060052done