summaryrefslogtreecommitdiffstats
path: root/Utilities/Scripts/clang-format.bash
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-05-17 13:33:02 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2016-05-17 13:33:02 (GMT)
commit7d2a0aa76c25d92f1e2a03778f5666bdd7e56b92 (patch)
tree2bdcf15abfef8e197173b5a135fe6b8391e43316 /Utilities/Scripts/clang-format.bash
parent930ac45cbafca79eec9ae68e07c547b5c81b8c2c (diff)
parentd9fd2f5402eeaa345691313658e02b51038f570b (diff)
downloadCMake-7d2a0aa76c25d92f1e2a03778f5666bdd7e56b92.zip
CMake-7d2a0aa76c25d92f1e2a03778f5666bdd7e56b92.tar.gz
CMake-7d2a0aa76c25d92f1e2a03778f5666bdd7e56b92.tar.bz2
Merge topic 'clang-format-source'
d9fd2f54 Revise C++ coding style using clang-format 82df6dea Empty commit at end of history preceding clang-format style transition 6a13f43f CONTRIBUTING: Add a section on coding style bf451d9f Add a script to run clang-format on the entire source tree 1e90d78f Configure clang-format for CMake source tree da60adc3 Tell Git to use a distinct conflict marker size in `.rst` files
Diffstat (limited to 'Utilities/Scripts/clang-format.bash')
-rwxr-xr-xUtilities/Scripts/clang-format.bash91
1 files changed, 91 insertions, 0 deletions
diff --git a/Utilities/Scripts/clang-format.bash b/Utilities/Scripts/clang-format.bash
new file mode 100755
index 0000000..2090a1a
--- /dev/null
+++ b/Utilities/Scripts/clang-format.bash
@@ -0,0 +1,91 @@
+#!/usr/bin/env bash
+#=============================================================================
+# Copyright 2015-2016 Kitware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#=============================================================================
+
+usage='usage: clang-format.bash [<options>] [--]
+
+ --clang-format <tool> Use given clang-format tool.
+'
+
+die() {
+ echo "$@" 1>&2; exit 1
+}
+
+#-----------------------------------------------------------------------------
+
+# Parse command-line arguments.
+clang_format=''
+while test "$#" != 0; do
+ case "$1" in
+ --clang-format) shift; clang_format="$1" ;;
+ --) shift ; break ;;
+ -*) die "$usage" ;;
+ *) break ;;
+ esac
+ shift
+done
+test "$#" = 0 || die "$usage"
+
+# Find a default tool.
+tools='
+ clang-format
+ clang-format-3.8
+'
+if test "x$clang_format" = "x"; then
+ for tool in $tools; do
+ if type -p "$tool" >/dev/null; then
+ clang_format="$tool"
+ break
+ fi
+ done
+fi
+
+# Verify that we have a tool.
+if ! type -p "$clang_format" >/dev/null; then
+ echo "Unable to locate '$clang_format'"
+ exit 1
+fi
+
+# Filter sources to which our style should apply.
+git ls-files -z -- '*.c' '*.cc' '*.cpp' '*.cxx' '*.h' '*.hh' '*.hpp' '*.hxx' |
+
+ # Exclude lexer/parser generator input and output.
+ egrep -z -v '^Source/cmCommandArgumentLexer\.' |
+ egrep -z -v '^Source/cmCommandArgumentParser(\.y|\.cxx|Tokens\.h)' |
+ egrep -z -v '^Source/cmDependsJavaLexer\.' |
+ egrep -z -v '^Source/cmDependsJavaParser(\.y|\.cxx|Tokens\.h)' |
+ egrep -z -v '^Source/cmExprLexer\.' |
+ egrep -z -v '^Source/cmExprParser(\.y|\.cxx|Tokens\.h)' |
+ egrep -z -v '^Source/cmFortranLexer\.' |
+ egrep -z -v '^Source/cmFortranParser(\.y|\.cxx|Tokens\.h)' |
+ egrep -z -v '^Source/cmListFileLexer(\.in\.l|\.c)' |
+
+ # Exclude third-party sources.
+ egrep -z -v '^Source/(cm_sha2|bindexplib)' |
+ egrep -z -v '^Source/(kwsys|CursesDialog/form)/' |
+ egrep -z -v '^Utilities/(KW|cm).*/' |
+
+ # Exclude reference content.
+ egrep -z -v '^Tests/Module/GenerateExportHeader/reference/' |
+
+ # Exclude manually-formatted sources (e.g. with long lines).
+ egrep -z -v '^Tests/PositionIndependentTargets/pic_test.h' |
+
+ # Exclude sources with encoding not suported by clang-format.
+ egrep -z -v '^Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h' |
+
+ # Update sources in-place.
+ xargs -0 "$clang_format" -i