diff --git a/.travis.yml b/.travis.yml index a1f736b..bc4e23c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,12 @@ env: + global: + - CLANG_FORMAT_VERSION=9 matrix: - JANSSON_BUILD_METHOD=cmake JANSSON_CMAKE_OPTIONS="-DJANSSON_TEST_WITH_VALGRIND=ON" JANSSON_EXTRA_INSTALL="valgrind" - JANSSON_BUILD_METHOD=autotools - JANSSON_BUILD_METHOD=coverage JANSSON_CMAKE_OPTIONS="-DJANSSON_COVERAGE=ON -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug" JANSSON_EXTRA_INSTALL="lcov curl" - JANSSON_BUILD_METHOD=fuzzer - - JANSSON_BUILD_METHOD=lint + - JANSSON_BUILD_METHOD=lint CLANG_FORMAT=clang-format-9 dist: bionic language: c compiler: @@ -17,7 +19,7 @@ matrix: - compiler: clang env: JANSSON_BUILD_METHOD=fuzzer - compiler: gcc - env: JANSSON_BUILD_METHOD=lint + env: JANSSON_BUILD_METHOD=lint CLANG_FORMAT=clang-format-9 allow_failures: - env: JANSSON_BUILD_METHOD=coverage JANSSON_CMAKE_OPTIONS="-DJANSSON_COVERAGE=ON -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug" JANSSON_EXTRA_INSTALL="lcov curl" install: @@ -29,4 +31,4 @@ script: - if [ "$JANSSON_BUILD_METHOD" = "cmake" ]; then mkdir build && cd build && cmake $JANSSON_CMAKE_OPTIONS .. && cmake --build . && ctest --output-on-failure; fi - if [ "$JANSSON_BUILD_METHOD" = "coverage" ]; then mkdir build && cd build && cmake $JANSSON_CMAKE_OPTIONS .. && cmake --build . && cmake --build . --target coveralls; fi - if [ "$JANSSON_BUILD_METHOD" = "fuzzer" ]; then ./test/ossfuzz/travisoss.sh; fi - - if [ "$JANSSON_BUILD_METHOD" = "lint" ]; then ./scripts/clang-format-check 9; fi + - if [ "$JANSSON_BUILD_METHOD" = "lint" ]; then ./scripts/clang-format-check; fi diff --git a/scripts/clang-format-check b/scripts/clang-format-check index f3f0f6d..983e55d 100755 --- a/scripts/clang-format-check +++ b/scripts/clang-format-check @@ -1,21 +1,19 @@ #!/bin/bash -clangformat="clang-format" -if [ -n "$1" ]; then - clangformat="clang-format-$1" -fi +CLANG_FORMAT=${CLANG_FORMAT:-clang-format} +CLANG_FORMAT_VERSION=${CLANG_FORMAT_VERSION:-} -if ! type $clangformat >/dev/null; then - # clang-format not found. If running tests, mark this test as - # skipped. +if ! type $CLANG_FORMAT >/dev/null || \ + ! $CLANG_FORMAT --version | grep -q "version ${CLANG_FORMAT_VERSION}"; then + # If running tests, mark this test as skipped. exit 77 fi errors=0 -paths=$(find . -type f -a '(' -name '*.c' -o -name '*.h' ')') +paths=$(git ls-files | grep '\.[ch]$') for path in $paths; do in=$(cat $path) - out=$($clangformat $path) + out=$($CLANG_FORMAT $path) if [ "$in" != "$out" ]; then diff -u -L $path -L "$path.formatted" $path - <<<$out