xref: /aosp_15_r20/external/OpenCL-CTS/check-format.sh (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1#!/usr/bin/env bash
2
3# Arg used to specify non-'origin/main' comparison branch
4ORIGIN_BRANCH=${1:-"origin/main"}
5CLANG_BINARY=${2:-"`which clang-format-11`"}
6
7# Run git-clang-format to check for violations
8CLANG_FORMAT_OUTPUT=$(git-clang-format --diff $ORIGIN_BRANCH --extensions c,cpp,h,hpp --binary $CLANG_BINARY)
9
10# Check for no-ops
11grep '^no modified files to format$' <<<"$CLANG_FORMAT_OUTPUT" && exit 0
12grep '^clang-format did not modify any files$' <<<"$CLANG_FORMAT_OUTPUT" && exit 0
13
14# Dump formatting diff and signal failure
15echo -e "\n==== FORMATTING VIOLATIONS DETECTED ====\n"
16echo "$CLANG_FORMAT_OUTPUT"
17exit 1
18