aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-09-24 13:03:44 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-09-24 13:03:44 -0700
commitddf3a511aaf519f699c3cd0fdee4f5275ecf600a (patch)
treec0c6c4da9e919ba52019149e3e53835a19ccaa84 /tools
parent5cf7013c4b736c23ab0ad0d1337ff4b0e78d5748 (diff)
Add clang-format to sanity
Diffstat (limited to 'tools')
-rwxr-xr-xtools/distrib/clang_format_code.sh13
-rw-r--r--tools/dockerfile/grpc_clang_format/Dockerfile6
-rwxr-xr-xtools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh30
-rwxr-xr-xtools/run_tests/run_sanity.sh2
4 files changed, 51 insertions, 0 deletions
diff --git a/tools/distrib/clang_format_code.sh b/tools/distrib/clang_format_code.sh
new file mode 100755
index 0000000000..55f4c52ec2
--- /dev/null
+++ b/tools/distrib/clang_format_code.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -ex
+
+# change to root directory
+cd $(dirname $0)/../..
+
+# build clang-format docker image
+docker build -t grpc_clang_format tools/dockerfile/grpc_clang_format
+
+# run clang-format against the checked out codebase
+docker run -e TEST=$TEST --rm=true -v `pwd`:/local-code -t grpc_clang_format /clang_format_all_the_things.sh
+
diff --git a/tools/dockerfile/grpc_clang_format/Dockerfile b/tools/dockerfile/grpc_clang_format/Dockerfile
new file mode 100644
index 0000000000..a0fff2f2b5
--- /dev/null
+++ b/tools/dockerfile/grpc_clang_format/Dockerfile
@@ -0,0 +1,6 @@
+FROM ubuntu:vivid
+RUN apt-get update
+RUN apt-get -y install clang-format-3.6
+ADD clang_format_all_the_things.sh /
+CMD ["echo 'Run with tools/distrib/clang_format_code.sh'"]
+
diff --git a/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh b/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh
new file mode 100755
index 0000000000..5aa265800d
--- /dev/null
+++ b/tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# directories to run against
+DIRS="src/core src/cpp test/core test/cpp include"
+
+# file matching patterns to check
+GLOB="*.h *.cpp"
+
+# clang format command
+CLANG_FORMAT=clang-format-3.6
+
+files=
+for dir in $DIRS
+do
+ for glob in $GLOB
+ do
+ files="$files `find /local-code/$dir -name $glob`"
+ done
+done
+
+if [ "x$TEST" = "x" ]
+then
+ echo $files | xargs $CLANG_FORMAT -i
+else
+ for file in $files
+ do
+ $CLANG_FORMAT $file | diff $file -
+ done
+fi
+
diff --git a/tools/run_tests/run_sanity.sh b/tools/run_tests/run_sanity.sh
index 4b367dcbc7..1e8fe5c1a7 100755
--- a/tools/run_tests/run_sanity.sh
+++ b/tools/run_tests/run_sanity.sh
@@ -58,3 +58,5 @@ if [ -f cache.mk ] ; then
fi
./tools/buildgen/generate_projects.sh
+./tools/distrib/clang_format_code.sh
+