blob: d7443b3b2c38d879b459ed81fa3225553af63208 [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
7LC_ALL=C export LC_ALL
Martin Roth1ce2ba62016-08-29 15:40:57 -06008
9# GNU BRE syntax list of files to examine
10INCLUDED_FILES='.*\.[ch]\|Kconfig.*$'
11
12EXCLUDED_DIRS="^payloads/libpayload/util/kconfig\|\
13^payloads/libpayload/curses/PDCurses\|\
Sean Rhodesc9bc7a72021-11-10 11:22:19 +000014^util/coreboot-configurator\|\
Patrick Georgi54867862018-05-30 15:54:08 +020015^util/crossgcc/patches\|\
Nico Huber55e3a6a2019-02-12 12:53:07 +010016^util/inteltool\|\
Martin Roth1ce2ba62016-08-29 15:40:57 -060017^util/kconfig\|\
Nico Huberbfae9a82018-08-19 11:54:57 +020018^util/superiotool\|\
Martin Roth2a063be2017-04-05 21:29:06 -060019^Documentation"
Martin Roth1ce2ba62016-08-29 15:40:57 -060020
Patrick Georgi7945f752019-02-27 19:57:23 +010021opts="--max-line-length 96"
22
Patrick Georgi54867862018-05-30 15:54:08 +020023# default: test src and util
Martin Roth1ce2ba62016-08-29 15:40:57 -060024if [ "$1" = "" ]; then
Jan Dabrosffa58cf2020-07-16 13:38:01 +020025 INCLUDED_DIRS="src util tests"
Patrick Georgi54867862018-05-30 15:54:08 +020026# special mode: take diff from stdin, but exclude the dirs
27elif [ "$1" = "diff" ]; then
28 args=$( echo $EXCLUDED_DIRS | \
29 sed -e 's,\\|, ,g' -e 's,\^,--exclude=,g' )
Patrick Georgi7945f752019-02-27 19:57:23 +010030 util/lint/checkpatch.pl --quiet --no-signoff $opts $args -
Patrick Georgi54867862018-05-30 15:54:08 +020031 exit $?
32# Space separated list of directories to test
Martin Roth1ce2ba62016-08-29 15:40:57 -060033else
34 INCLUDED_DIRS="$1"
35fi
36
37# We want word splitting here, so disable the shellcheck warnings
38# shellcheck disable=SC2046,SC2086
39FILELIST=$( git ls-files $INCLUDED_DIRS | \
40 grep $INCLUDED_FILES | \
41 grep -v $EXCLUDED_DIRS )
42
43for FILE in $FILELIST; do
Patrick Georgi7945f752019-02-27 19:57:23 +010044 util/lint/checkpatch.pl --show-types --file --quiet $opts "$FILE"
Martin Roth1ce2ba62016-08-29 15:40:57 -060045done