forked from elastic/ml-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
clang-format.sh
executable file
·35 lines (28 loc) · 1.33 KB
/
clang-format.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.
#
# Reformats Ml native source code, using clang-format, to ensure consistency.
# Ensure $CPP_SRC_HOME is set
CPP_SRC_HOME=${CPP_SRC_HOME:-`git rev-parse --show-toplevel`}
# Ensure clang-format is available
which clang-format > /dev/null 2>&1
if [ $? != 0 ] ; then
echo "ERROR: The clang-format code formatter is not available. Exiting."
exit 1
fi
REQUIRED_CLANG_FORMAT_VERSION=5.0.1
FOUND_CLANG_FORMAT_VERSION=$(expr "`clang-format --version`" : ".* \([0-9].[0-9].[0-9]\)")
if [ -z "${FOUND_CLANG_FORMAT_VERSION}" ] ; then
echo "ERROR: Required clang-format major version ${REQUIRED_CLANG_FORMAT_VERSION} not found."
echo " Could not determine clang-format version."
exit 2
fi
if [ "${REQUIRED_CLANG_FORMAT_VERSION}" != "${FOUND_CLANG_FORMAT_VERSION}" ] ; then
echo "ERROR: Required clang-format major version ${REQUIRED_CLANG_FORMAT_VERSION} not found."
echo " Detected clang-format version ${FOUND_CLANG_FORMAT_VERSION}"
exit 3
fi
find $CPP_SRC_HOME \( -name 3rd_party -o -name build-setup \) -prune -o \( -name \*.cc -o -name \*.h \) -exec clang-format -i {} \;