From 1b598213aade733c5efd0ec747bf559cde442674 Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Thu, 17 Sep 2015 22:02:05 -0700 Subject: [PATCH] Check formatting in Travis Summary: Check code formatting before running tests. Goal is to make it easier to deal with external pull requests. Test Plan: See https://travis-ci.org/facebook/rocksdb/builds/80952963 Reviewers: igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D47211 --- .travis.yml | 4 +++- build_tools/format-diff.sh | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 948de4886..0734177bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,8 @@ install: # Build gflags # TODO(noetzli): Remove when gflags available through Travis - pushd /tmp/ && curl -L https://github.com/gflags/gflags/archive/v2.1.2.tar.gz -o gflags.tar.gz && tar xfz gflags.tar.gz && cd gflags-2.1.2 && cmake . && make && popd + # Download clang-format-diff.py to check source code formatting + - pushd /tmp/ && curl -L http://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format-diff.py -o clang-format-diff.py && chmod +x clang-format-diff.py && popd before_script: # Add gflags to include/library paths @@ -30,7 +32,7 @@ before_script: # Lousy hack to disable use and testing of fallocate, which doesn't behave quite # as EnvPosixTest::AllocateTest expects within the Travis OpenVZ environment. -script: OPT=-DTRAVIS V=1 make -j4 check && OPT=-DTRAVIS V=1 make clean jclean rocksdbjava jtest +script: OPT=-DTRAVIS CLANG_FORMAT_DIFF=/tmp/clang-format-diff.py make format && OPT=-DTRAVIS V=1 make -j4 check && OPT=-DTRAVIS V=1 make clean jclean rocksdbjava jtest notifications: email: diff --git a/build_tools/format-diff.sh b/build_tools/format-diff.sh index 2d6062009..5b2efdd1a 100755 --- a/build_tools/format-diff.sh +++ b/build_tools/format-diff.sh @@ -79,6 +79,12 @@ echo -e "Detect lines that doesn't follow the format rules:\r" echo "$diffs" | sed -e "s/\(^-.*$\)/`echo -e \"$COLOR_RED\1$COLOR_END\"`/" | sed -e "s/\(^+.*$\)/`echo -e \"$COLOR_GREEN\1$COLOR_END\"`/" + +if [[ "$OPT" == *"-DTRAVIS"* ]] +then + exit 1 +fi + echo -e "Would you like to fix the format automatically (y/n): \c" # Make sure under any mode, we can read user input. -- GitLab