xref: /optee_os/scripts/checkpatch_inc.sh (revision c1d47bcf985f2f45ff380239e0d20876a207258b)
11c93c2b5SIgor Opaniuk#!/bin/bash
21c93c2b5SIgor Opaniuk
35392ae31SAndrew F. DavisCHECKPATCH="${CHECKPATCH:-checkpatch.pl}"
41c93c2b5SIgor Opaniuk# checkpatch.pl will ignore the following paths
55849875fSAndrew F. DavisCHECKPATCH_IGNORE=$(echo core/lib/lib{fdt,tomcrypt} lib/lib{png,utils,zlib} \
638f23772SAndrew F. Davis		core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h)
71c93c2b5SIgor Opaniuk_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done)
81c93c2b5SIgor Opaniuk
91c93c2b5SIgor Opaniukfunction _checkpatch() {
10*c1d47bcfSEtienne Carriere		# Use --typedefsfile if supported by the checkpatch tool
11*c1d47bcfSEtienne Carriere		typedefs_opt="--typedefsfile typedefs.checkpatch"
12*c1d47bcfSEtienne Carriere		$CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \
13*c1d47bcfSEtienne Carriere				typedefs_opt="";
14*c1d47bcfSEtienne Carriere
151c93c2b5SIgor Opaniuk		$CHECKPATCH --quiet --ignore FILE_PATH_CHANGES \
16*c1d47bcfSEtienne Carriere				--ignore GERRIT_CHANGE_ID --no-tree \
17*c1d47bcfSEtienne Carriere				$typedefs_opt \
18*c1d47bcfSEtienne Carriere				-
191c93c2b5SIgor Opaniuk}
201c93c2b5SIgor Opaniuk
211c93c2b5SIgor Opaniukfunction checkpatch() {
221c93c2b5SIgor Opaniuk		git show --oneline --no-patch $1
231c93c2b5SIgor Opaniuk		git format-patch -1 $1 --stdout -- $_CP_EXCL . | _checkpatch
241c93c2b5SIgor Opaniuk}
251c93c2b5SIgor Opaniuk
261c93c2b5SIgor Opaniukfunction checkstaging() {
271c93c2b5SIgor Opaniuk		git diff --cached -- . $_CP_EXCL | _checkpatch
281c93c2b5SIgor Opaniuk}
291c93c2b5SIgor Opaniuk
301c93c2b5SIgor Opaniukfunction checkworking() {
311c93c2b5SIgor Opaniuk		git diff -- . $_CP_EXCL | _checkpatch
321c93c2b5SIgor Opaniuk}
331c93c2b5SIgor Opaniuk
341c93c2b5SIgor Opaniukfunction checkdiff() {
351c93c2b5SIgor Opaniuk		git diff $1...$2 -- . $_CP_EXCL | _checkpatch
361c93c2b5SIgor Opaniuk}
371c93c2b5SIgor Opaniuk
38