Skip to content

Commit

Permalink
check coding style in travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Norihiro Watanabe committed Mar 11, 2016
1 parent c132ad6 commit 99983a3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
14 changes: 12 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ matrix:
- env: TRAVIS_EMPTY_JOB_WORKAROUND=true

include:
# check coding style
- env: CASE=codingstyle
addons:
apt:
sources:
- llvm-toolchain-precise-3.7
- ubuntu-toolchain-r-test
packages:
- clang-format-3.7
# check typical OGS builds
- env: CASE=FEM
- env: CASE=IPQC
Expand Down Expand Up @@ -44,8 +53,9 @@ install:
- if [[ "$CASE" == "PETSC" ]]; then travis_retry sudo apt-get install -qq libpetsc3.4.2-dev; fi

script:
- mkdir build && cd build && cmake -DOGS_CONFIG=${CASE} $CMAKE_ARGS -DOGS_CPU_ARCHITECTURE=generic .. && cmake ..
- make
- if [[ "$CASE" != "codingstyle" ]]; then mkdir build && cd build && cmake -DOGS_CONFIG=${CASE} $CMAKE_ARGS -DOGS_CPU_ARCHITECTURE=generic .. && cmake ..; fi
- if [[ "$CASE" != "codingstyle" ]]; then make; fi
- if [[ "$CASE" == "codingstyle" ]]; then chmod +x ./scripts/ci/check_code_format.sh && ./scripts/ci/check_code_format.sh; fi

notifications:
email:
Expand Down
30 changes: 30 additions & 0 deletions scripts/ci/check_code_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
#
# Modified from https://github.com/google/closure-library/tree/master/scripts/ci
#
# Script to determine if files in Pull Request are properly formatted.
# Exits with non 0 exit code if formatting is needed.

CLANG_FORMAT_DIFF=clang-format-diff-3.7

FILES_TO_CHECK=$(git diff --name-only master | grep -E "\.h|\.cpp$")

if [ -z "${FILES_TO_CHECK}" ]; then
echo "No files to check for formatting."
exit 0
fi

FORMAT_DIFF=$(git diff -U0 master -- ${FILES_TO_CHECK} |
${CLANG_FORMAT_DIFF} -p1 -style=file)

if [ -z "${FORMAT_DIFF}" ]; then
# No formatting necessary.
echo "All files in PR properly formatted."
exit 0
else
# Found diffs.
echo "ERROR: Found formatting errors!"
echo "${FORMAT_DIFF}"
echo "See https://goo.gl/wUEkW9 for instructions to format your PR."
exit 1
fi

0 comments on commit 99983a3

Please sign in to comment.