1#!/bin/sh
2
3#
4# Bail on OS X for testing this functionality.
5#
6if [ "$TRAVIS_OS_NAME" == "osx" ]; then
7    exit 0
8fi
9
10#
11# Only works with GCC.
12#
13case "$CC" in
14    clang*|llvm*) exit 0;;
15esac
16
17sudo add-apt-repository -y 'deb http://apt.llvm.org/precise/ llvm-toolchain-precise-3.8 main'
18wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
19sudo apt-get update -qq
20sudo apt-get install --allow-unauthenticated -y -qq clang-format-3.8
21
22# check formatting matches clang-format-3.8. Since newer versions can have
23# changes in formatting even without any rule changes, we have to fix on a
24# single version.
25. ./build/clang_format_all.sh
26
27git clean -f
28
29# Print any diff here, so the error message below is the last thing
30git diff
31
32git diff --quiet || (
33  echo "***************************************************";
34  echo "*** The code is not clean against clang-format  ***";
35  echo "*** Please run clang-format-3.8 and fix the     ***";
36  echo "*** differences then rebase/squash them into    ***";
37  echo "*** the relevant commits. Do not add a commit   ***";
38  echo "*** for just formatting fixes. Thanks!          ***";
39  echo "***************************************************";
40  exit 1;
41  )
42
43exit 0
44