xref: /aosp_15_r20/external/coreboot/util/lint/lint-007-checkpatch (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1#!/usr/bin/env sh
2#
3# SPDX-License-Identifier: GPL-2.0-only
4
5# DESCR: Checkpatch on .c, .h, & Kconfig files in the tree
6
7LINTDIR="$(
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"
14
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\|\
20^src/vendorcode/wuffs\|\
21^util/coreboot-configurator\|\
22^util/crossgcc/patches\|\
23^util/inteltool\|\
24^util/kconfig\|\
25^util/superiotool\|\
26^Documentation"
27
28opts="--max-line-length 96"
29
30# default: test src and util
31if [ "$1" = "" ]; then
32	INCLUDED_DIRS="src util tests"
33# 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' )
37	util/lint/checkpatch.pl --quiet --no-signoff $opts $args -
38	exit $?
39# Space separated list of directories to test
40else
41	INCLUDED_DIRS="$1"
42fi
43
44# We want word splitting here, so disable the shellcheck warnings
45# shellcheck disable=SC2046,SC2086
46FILELIST=$( ${FIND_FILES} $INCLUDED_DIRS | \
47		grep $INCLUDED_FILES | \
48		grep -v $EXCLUDED_DIRS )
49
50for FILE in $FILELIST; do
51	util/lint/checkpatch.pl --show-types --file --quiet $opts "$FILE"
52done
53