blob: 7a76878f60b035ad1055ccf7536ffc653628c9d8 [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\|\
Patrick Georgi54867862018-05-30 15:54:08 +020014^util/crossgcc/patches\|\
Nico Huber55e3a6a2019-02-12 12:53:07 +010015^util/inteltool\|\
Martin Roth1ce2ba62016-08-29 15:40:57 -060016^util/kconfig\|\
Nico Huberbfae9a82018-08-19 11:54:57 +020017^util/superiotool\|\
Martin Roth2a063be2017-04-05 21:29:06 -060018^Documentation"
Martin Roth1ce2ba62016-08-29 15:40:57 -060019
Patrick Georgi7945f752019-02-27 19:57:23 +010020opts="--max-line-length 96"
21
Patrick Georgi54867862018-05-30 15:54:08 +020022# default: test src and util
Martin Roth1ce2ba62016-08-29 15:40:57 -060023if [ "$1" = "" ]; then
Jan Dabrosffa58cf2020-07-16 13:38:01 +020024 INCLUDED_DIRS="src util tests"
Patrick Georgi54867862018-05-30 15:54:08 +020025# special mode: take diff from stdin, but exclude the dirs
26elif [ "$1" = "diff" ]; then
27 args=$( echo $EXCLUDED_DIRS | \
28 sed -e 's,\\|, ,g' -e 's,\^,--exclude=,g' )
Patrick Georgi7945f752019-02-27 19:57:23 +010029 util/lint/checkpatch.pl --quiet --no-signoff $opts $args -
Patrick Georgi54867862018-05-30 15:54:08 +020030 exit $?
31# Space separated list of directories to test
Martin Roth1ce2ba62016-08-29 15:40:57 -060032else
33 INCLUDED_DIRS="$1"
34fi
35
36# We want word splitting here, so disable the shellcheck warnings
37# shellcheck disable=SC2046,SC2086
38FILELIST=$( git ls-files $INCLUDED_DIRS | \
39 grep $INCLUDED_FILES | \
40 grep -v $EXCLUDED_DIRS )
41
42for FILE in $FILELIST; do
Patrick Georgi7945f752019-02-27 19:57:23 +010043 util/lint/checkpatch.pl --show-types --file --quiet $opts "$FILE"
Martin Roth1ce2ba62016-08-29 15:40:57 -060044done