xref: /optee_os/scripts/checkpatch.sh (revision 33977c011f1fa884da30e6faf2903ac8226dfc95)
11c93c2b5SIgor Opaniuk#!/bin/bash
21c93c2b5SIgor Opaniuk
31c93c2b5SIgor OpaniukDIR="${BASH_SOURCE%/*}"
41c93c2b5SIgor Opaniuk
5*33977c01SMarkus S. Wamser# if no CHECKPATCH is explicitly given by the environment, try to
6*33977c01SMarkus S. Wamser# locate checkpatch.pl: first take the one from the path, then check
7*33977c01SMarkus S. Wamser# for a local copy of the linux headers, finally try sources downloaded
8*33977c01SMarkus S. Wamser# with OP-TEE (for QEMU)
9*33977c01SMarkus S. Wamserif [ -z "$CHECKPATCH" ]; then
10*33977c01SMarkus S. Wamser  CHECKPATCH=$(command -v checkpatch.pl)
11*33977c01SMarkus S. Wamserfi
12*33977c01SMarkus S. Wamserif [ -z "$CHECKPATCH" ]; then
13*33977c01SMarkus S. Wamser  CHECKPATCH=$(find /usr/src/linux-headers* -name checkpatch.pl -print -quit)
14*33977c01SMarkus S. Wamserfi
15*33977c01SMarkus S. Wamserif [ -z "$CHECKPATCH" ]; then
16*33977c01SMarkus S. Wamser  CHECKPATCH=$(find "$PWD/../linux" -name checkpatch.pl -print -quit)
17*33977c01SMarkus S. Wamserfi
18*33977c01SMarkus S. Wamser
191c93c2b5SIgor Opaniuksource "$DIR/checkpatch_inc.sh"
201c93c2b5SIgor Opaniuk
211c93c2b5SIgor Opaniukhash $CHECKPATCH 2>/dev/null ||
221c93c2b5SIgor Opaniuk		{ echo >&2 "Could not find checkpatch.pl, aborting"; exit 1; }
231c93c2b5SIgor Opaniuk
241c93c2b5SIgor Opaniukusage() {
251c93c2b5SIgor Opaniuk  SCR=$(basename "$0")
261c93c2b5SIgor Opaniuk  echo "Usage: $SCR [--working]                 Check working area"
27849b17bdSJerome Forissier  echo "       $SCR <commit>...                 Check specific commit(s)"
281c93c2b5SIgor Opaniuk  echo "       $SCR --diff <commit1> <commit2>  Check diff commit1...commit2"
291c93c2b5SIgor Opaniuk  echo "       $SCR --cached                    Check staging area"
301c93c2b5SIgor Opaniuk  echo "       $SCR --help                      This help"
311c93c2b5SIgor Opaniuk  exit 1
321c93c2b5SIgor Opaniuk}
331c93c2b5SIgor Opaniuk
341c93c2b5SIgor Opaniukop=${1:---working}
351c93c2b5SIgor Opaniukcase "$op" in
361c93c2b5SIgor Opaniuk	--cached)
371c93c2b5SIgor Opaniuk		echo "Checking staging area:  "
381c93c2b5SIgor Opaniuk		checkstaging
391c93c2b5SIgor Opaniuk		;;
401c93c2b5SIgor Opaniuk	--diff)
411c93c2b5SIgor Opaniuk		echo "Checking diff (diff $1...$2)"
421c93c2b5SIgor Opaniuk		checkdiff "$2" "$3"
431c93c2b5SIgor Opaniuk		;;
441c93c2b5SIgor Opaniuk	--working)
451c93c2b5SIgor Opaniuk		echo "Checking working area:  "
461c93c2b5SIgor Opaniuk		checkworking
471c93c2b5SIgor Opaniuk		;;
481c93c2b5SIgor Opaniuk	--help|-h)
491c93c2b5SIgor Opaniuk		usage
501c93c2b5SIgor Opaniuk		;;
511c93c2b5SIgor Opaniuk	*)
52849b17bdSJerome Forissier		echo "Checking commit(s):"
53849b17bdSJerome Forissier		for c in $*; do checkpatch $c; done
541c93c2b5SIgor Opaniuk		;;
551c93c2b5SIgor Opaniuk
561c93c2b5SIgor Opaniukesac
57