Skip to content

Commit d77f0fd

Browse files
authored
Add clang-tidy-diff hook to Travis CI (#2060)
This adds clang-tidy hook to Travis CI. This runs clang-tidy to the diff between the current HEAD and master. (It takes very long time to run clang-tidy on the whole repo, so it is not feasible anyway.)
2 parents a360a68 + a81f5cb commit d77f0fd

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ jobs:
6464
- ./scripts/gen-s-parser.py | diff src/gen-s-parser.inc -
6565
- BUILD_SUBDIR=${BUILD_SUBDIR:-.}
6666
- mkdir -p ${BUILD_SUBDIR} && cd ${BUILD_SUBDIR}
67-
- cmake ${TRAVIS_BUILD_DIR} -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_INSTALL_PREFIX=install
67+
- cmake ${TRAVIS_BUILD_DIR} -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_INSTALL_PREFIX=install -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
68+
# clang-tidy-diff.sh may not exist when BUILD_SUBDIR is a subdirectory
69+
- if [ -f clang-tidy-diff.sh ]; then ./clang-tidy-diff.sh; fi
6870
- make -j2 install
6971
- cd ${TRAVIS_BUILD_DIR}
7072
- ./check.py --binaryen-bin=${BUILD_SUBDIR}/install/bin

clang-tidy-diff.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
CLANG_DIR=$(dirname $(dirname $(which clang-tidy)))
3+
CLANG_TIDY_DIFF=$CLANG_DIR/share/clang/clang-tidy-diff.py
4+
MERGE_BASE=$(git merge-base master HEAD)
5+
TIDY_MSG=$(git diff -U0 $MERGE_BASE | $CLANG_TIDY_DIFF -quiet -p1 2> /dev/null)
6+
if [ -n "$TIDY_MSG" -a "$TIDY_MSG" != "No relevant changes found." ]
7+
then
8+
echo "Fix clang-tidy errors before committing!"
9+
echo
10+
# Run clang-tidy once again to show the error
11+
git diff -U0 $MERGE_BASE | $CLANG_TIDY_DIFF -quiet -p1
12+
exit 1
13+
fi

0 commit comments

Comments
 (0)