xref: /netbsd-src/external/bsd/jemalloc/dist/scripts/check-formatting.sh (revision 7bdf38e5b7a28439665f2fdeff81e36913eef7dd)
1*7bdf38e5Schristos#!/bin/bash
2*7bdf38e5Schristos
3*7bdf38e5Schristos# The files that need to be properly formatted.  We'll grow this incrementally
4*7bdf38e5Schristos# until it includes all the jemalloc source files (as we convert things over),
5*7bdf38e5Schristos# and then just replace it with
6*7bdf38e5Schristos#    find -name '*.c' -o -name '*.h' -o -name '*.cpp
7*7bdf38e5SchristosFILES=(
8*7bdf38e5Schristos)
9*7bdf38e5Schristos
10*7bdf38e5Schristosif command -v clang-format &> /dev/null; then
11*7bdf38e5Schristos  CLANG_FORMAT="clang-format"
12*7bdf38e5Schristoselif command -v clang-format-8 &> /dev/null; then
13*7bdf38e5Schristos  CLANG_FORMAT="clang-format-8"
14*7bdf38e5Schristoselse
15*7bdf38e5Schristos  echo "Couldn't find clang-format."
16*7bdf38e5Schristosfi
17*7bdf38e5Schristos
18*7bdf38e5Schristosif ! $CLANG_FORMAT -version | grep "version 8\." &> /dev/null; then
19*7bdf38e5Schristos  echo "clang-format is the wrong version."
20*7bdf38e5Schristos  exit 1
21*7bdf38e5Schristosfi
22*7bdf38e5Schristos
23*7bdf38e5Schristosfor file in ${FILES[@]}; do
24*7bdf38e5Schristos  if ! cmp --silent $file <($CLANG_FORMAT $file) &> /dev/null; then
25*7bdf38e5Schristos    echo "Error: $file is not clang-formatted"
26*7bdf38e5Schristos    exit 1
27*7bdf38e5Schristos  fi
28*7bdf38e5Schristosdone
29