Fix clang-format version checking

This commit is contained in:
Petri Lehtinen 2019-10-21 07:33:12 +03:00
parent f912430cda
commit bb4f99e919
2 changed files with 12 additions and 12 deletions

View File

@ -1,10 +1,12 @@
env: env:
global:
- CLANG_FORMAT_VERSION=9
matrix: matrix:
- JANSSON_BUILD_METHOD=cmake JANSSON_CMAKE_OPTIONS="-DJANSSON_TEST_WITH_VALGRIND=ON" JANSSON_EXTRA_INSTALL="valgrind" - JANSSON_BUILD_METHOD=cmake JANSSON_CMAKE_OPTIONS="-DJANSSON_TEST_WITH_VALGRIND=ON" JANSSON_EXTRA_INSTALL="valgrind"
- JANSSON_BUILD_METHOD=autotools - 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=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=fuzzer
- JANSSON_BUILD_METHOD=lint - JANSSON_BUILD_METHOD=lint CLANG_FORMAT=clang-format-9
dist: bionic dist: bionic
language: c language: c
compiler: compiler:
@ -17,7 +19,7 @@ matrix:
- compiler: clang - compiler: clang
env: JANSSON_BUILD_METHOD=fuzzer env: JANSSON_BUILD_METHOD=fuzzer
- compiler: gcc - compiler: gcc
env: JANSSON_BUILD_METHOD=lint env: JANSSON_BUILD_METHOD=lint CLANG_FORMAT=clang-format-9
allow_failures: 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" - env: JANSSON_BUILD_METHOD=coverage JANSSON_CMAKE_OPTIONS="-DJANSSON_COVERAGE=ON -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug" JANSSON_EXTRA_INSTALL="lcov curl"
install: 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" = "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" = "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" = "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

View File

@ -1,21 +1,19 @@
#!/bin/bash #!/bin/bash
clangformat="clang-format" CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
if [ -n "$1" ]; then CLANG_FORMAT_VERSION=${CLANG_FORMAT_VERSION:-}
clangformat="clang-format-$1"
fi
if ! type $clangformat >/dev/null; then if ! type $CLANG_FORMAT >/dev/null || \
# clang-format not found. If running tests, mark this test as ! $CLANG_FORMAT --version | grep -q "version ${CLANG_FORMAT_VERSION}"; then
# skipped. # If running tests, mark this test as skipped.
exit 77 exit 77
fi fi
errors=0 errors=0
paths=$(find . -type f -a '(' -name '*.c' -o -name '*.h' ')') paths=$(git ls-files | grep '\.[ch]$')
for path in $paths; do for path in $paths; do
in=$(cat $path) in=$(cat $path)
out=$($clangformat $path) out=$($CLANG_FORMAT $path)
if [ "$in" != "$out" ]; then if [ "$in" != "$out" ]; then
diff -u -L $path -L "$path.formatted" $path - <<<$out diff -u -L $path -L "$path.formatted" $path - <<<$out