summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Moreau <dev@pmoreau.org>2018-04-26 17:01:01 +0200
committerAlexey Sotkin <alexey.sotkin@intel.com>2018-06-09 15:32:48 +0300
commit06888bdfcbe8501d2c894021901355dbadddc9a1 (patch)
tree52bf8bafb4d8573b33ee7c9abd2cf3895a8299c5
parentebc2625f1df6c873ad16fad8f8cc65689b5071f4 (diff)
Run clang-format from Travis on modified files
-rw-r--r--.travis.yml34
-rwxr-xr-xutils/check_code_format.sh44
2 files changed, 69 insertions, 9 deletions
diff --git a/.travis.yml b/.travis.yml
index f44c074..bc3de64 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,6 +10,10 @@ sudo: false
git:
depth: 1
+branches:
+ only:
+ - master
+
addons:
apt:
sources:
@@ -19,6 +23,7 @@ addons:
packages:
- llvm-7-tools
- llvm-7-dev
+ - clang-format-7
compiler:
- gcc
@@ -27,6 +32,7 @@ compiler:
env:
global:
- MAKEFLAGS="-j2"
+ - CHECK_FORMAT=0
matrix:
- BUILD_TYPE=Release BUILD_EXTERNAL=1 SHARED_LIBS=ON MAKE_TARGETS="" MAKE_TEST_TARGET="test"
- BUILD_TYPE=Debug BUILD_EXTERNAL=1 SHARED_LIBS=ON MAKE_TARGETS="" MAKE_TEST_TARGET="test"
@@ -47,6 +53,8 @@ matrix:
- os: osx
env: BUILD_TYPE=Debug BUILD_EXTERNAL=0 MAKE_TARGETS="llvm-spirv" MAKE_TEST_TARGET="check-llvm-spirv"
osx_image: xcode9.3
+
+ - env: BUILD_EXTERNAL=1 CHECK_FORMAT=1
allow_failures:
- compiler: clang
- os: osx
@@ -63,14 +71,16 @@ script:
- mkdir build && cd build
- |
if [ $BUILD_EXTERNAL == "1" ]; then
- cmake .. \
- -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
- -DBUILD_SHARED_LIBS=${SHARED_LIBS} \
- -DLLVM_BUILD_TOOLS=ON \
- -DLLVM_EXTERNAL_LIT="/usr/lib/llvm-7/build/utils/lit/lit.py" \
- -DLLVM_INCLUDE_TESTS=ON \
- -DCMAKE_INSTALL_PREFIX=../install/ \
- -G "Unix Makefiles"
+ if [ $CHECK_FORMAT != "1" ]; then
+ cmake .. \
+ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
+ -DBUILD_SHARED_LIBS=${SHARED_LIBS} \
+ -DLLVM_BUILD_TOOLS=ON \
+ -DLLVM_EXTERNAL_LIT="/usr/lib/llvm-7/build/utils/lit/lit.py" \
+ -DLLVM_INCLUDE_TESTS=ON \
+ -DCMAKE_INSTALL_PREFIX=../install/ \
+ -G "Unix Makefiles"
+ fi
else
cmake ../llvm/ \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
@@ -81,4 +91,10 @@ script:
-DLLVM_LIT_ARGS="-sv --no-progress-bar" \
-G "Unix Makefiles"
fi
- - make $MAKE_TARGETS && make $MAKE_TEST_TARGET && if [ $BUILD_EXTERNAL == "1" ]; then make install; fi
+ - if [ $CHECK_FORMAT == "1" ]; then
+ cd ..;
+ ln -s /usr/share/clang/clang-format-7/clang-format-diff.py utils/;
+ ./utils/check_code_format.sh;
+ else
+ make $MAKE_TARGETS && make $MAKE_TEST_TARGET && if [ $BUILD_EXTERNAL == "1" ]; then make install; fi
+ fi
diff --git a/utils/check_code_format.sh b/utils/check_code_format.sh
new file mode 100755
index 0000000..821edea
--- /dev/null
+++ b/utils/check_code_format.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+# Copyright (c) 2017 Google 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.
+#
+# Script to determine if source code in Pull Request is properly formatted.
+# Exits with non 0 exit code if formatting is needed.
+#
+# This script assumes to be invoked at the project root directory.
+
+# Changes made to the initial version from
+# https://github.com/KhronosGroup/SPIRV-Tools:
+# * Renamed FILES_TO_CHECK to MODIFIED_FILES;
+# * Add a filtering step on the files to check, with the result stored in
+# FILES_TO_CHECK.
+
+MODIFIED_FILES=$(git diff --name-only master | grep -E ".*\.(cpp|cc|c\+\+|cxx|c|h|hpp)$")
+FILES_TO_CHECK=$(echo "${MODIFIED_FILES}" | grep -v -E "Mangler/*|runtime/*|libSPIRV/(OpenCL.std.h|spirv.hpp)$")
+
+if [ -z "${FILES_TO_CHECK}" ]; then
+ echo "No source code to check for formatting."
+ exit 0
+fi
+
+FORMAT_DIFF=$(git diff -U0 master -- ${FILES_TO_CHECK} | python ./utils/clang-format-diff.py -p1 -style=file)
+
+if [ -z "${FORMAT_DIFF}" ]; then
+ echo "All source code in PR properly formatted."
+ exit 0
+else
+ echo "Found formatting errors!"
+ echo "${FORMAT_DIFF}"
+ exit 1
+fi