xref: /optee_os/scripts/checkpatch_inc.sh (revision 9fc2442cc66c279cb962c90c4375746fc9b28bb9)
1#!/bin/bash
2
3CHECKPATCH="${CHECKPATCH:-checkpatch.pl}"
4# checkpatch.pl will ignore the following paths
5CHECKPATCH_IGNORE=$(echo \
6		core/include/gen-asm-defines.h \
7		core/lib/lib{fdt,tomcrypt} core/lib/zlib \
8		lib/libutils lib/libmbedtls \
9		lib/libutee/include/elf.h \
10		core/arch/arm/include/arm{32,64}.h \
11		core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h \
12		core/arch/arm/dts)
13_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done)
14
15function _checkpatch() {
16		# Use --typedefsfile if supported by the checkpatch tool
17		typedefs_opt="--typedefsfile typedefs.checkpatch"
18		$CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \
19				typedefs_opt="";
20		# Ignore NOT_UNIFIED_DIFF in case patch has no diff
21		# (e.g., all paths filtered out)
22		$CHECKPATCH $typedefs_opt -
23}
24
25function checkpatch() {
26	git show --oneline --no-patch $1
27	# The first git 'format-patch' shows the commit message
28	# The second one produces the diff (might be empty if _CP_EXCL
29	# filters out all diffs)
30	(git format-patch $1^..$1 --stdout | sed -n '/^diff --git/q;p'; \
31	 git format-patch $1^..$1 --stdout -- $_CP_EXCL . | \
32		sed -n '/^diff --git/,$p') | _checkpatch
33}
34
35function checkstaging() {
36		git diff --cached -- . $_CP_EXCL | _checkpatch
37}
38
39function checkworking() {
40		git diff -- . $_CP_EXCL | _checkpatch
41}
42
43function checkdiff() {
44		git diff $1...$2 -- . $_CP_EXCL | _checkpatch
45}
46
47