xref: /aosp_15_r20/external/bcc/scripts/c-style-check.sh (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard Worker#!/bin/bash
2*387f9dfdSAndroid Build Coastguard Worker
3*387f9dfdSAndroid Build Coastguard Worker# Runs clang-format on the files changed between HEAD and $1, which defaults to
4*387f9dfdSAndroid Build Coastguard Worker# origin/master.
5*387f9dfdSAndroid Build Coastguard Worker
6*387f9dfdSAndroid Build Coastguard Worker# to pick up git-clang-format from scripts/
7*387f9dfdSAndroid Build Coastguard Workerexport PATH=$(dirname $0):$PATH
8*387f9dfdSAndroid Build Coastguard Worker
9*387f9dfdSAndroid Build Coastguard WorkerCLANG_FORMAT=${CLANG_FORMAT:-clang-format}
10*387f9dfdSAndroid Build Coastguard WorkerGITREF=${1:-origin/master}
11*387f9dfdSAndroid Build Coastguard Worker
12*387f9dfdSAndroid Build Coastguard Workerif ! hash $CLANG_FORMAT 2> /dev/null; then
13*387f9dfdSAndroid Build Coastguard Worker  echo "Could not find clang-format tool" 1>&2
14*387f9dfdSAndroid Build Coastguard Worker  exit 1
15*387f9dfdSAndroid Build Coastguard Workerfi
16*387f9dfdSAndroid Build Coastguard Worker
17*387f9dfdSAndroid Build Coastguard Workercmd="git clang-format $GITREF --binary $CLANG_FORMAT --diff --extensions h,c,cc"
18*387f9dfdSAndroid Build Coastguard Worker
19*387f9dfdSAndroid Build Coastguard Workern=$($cmd --quiet | wc -l)
20*387f9dfdSAndroid Build Coastguard Workerif [ $n -gt 0 ]; then
21*387f9dfdSAndroid Build Coastguard Worker  $cmd -v
22*387f9dfdSAndroid Build Coastguard Worker  exit 1
23*387f9dfdSAndroid Build Coastguard Workerfi
24