aboutsummaryrefslogtreecommitdiff
path: root/scripts/clang-format-ci
blob: 6854fc23c0867063bf8567cb910ae32055fc9db3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

clangformat="clang-format"
if [ -n "$1" ]; then
    clangformat="clang-format-$1"
fi

errors=0
paths=$(find . -type f -a '(' -name '*.c' -o -name '*.h' ')')
for path in $paths; do
    in=$(cat $path)
    out=$($clangformat $path)

    if [ "$in" != "$out" ]; then
        diff -u -L $path -L "$path.formatted" $path - <<<$out
        errors=1
    fi
done

if [ $errors -ne 0 ]; then
    echo "Formatting errors detected, run ./scripts/clang-format to fix!"
    exit 1
fi