Skip to content

Commit bb4f99e

Browse files
committed
Fix clang-format version checking
1 parent f912430 commit bb4f99e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

.travis.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
env:
2+
global:
3+
- CLANG_FORMAT_VERSION=9
24
matrix:
35
- JANSSON_BUILD_METHOD=cmake JANSSON_CMAKE_OPTIONS="-DJANSSON_TEST_WITH_VALGRIND=ON" JANSSON_EXTRA_INSTALL="valgrind"
46
- JANSSON_BUILD_METHOD=autotools
57
- JANSSON_BUILD_METHOD=coverage JANSSON_CMAKE_OPTIONS="-DJANSSON_COVERAGE=ON -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug" JANSSON_EXTRA_INSTALL="lcov curl"
68
- JANSSON_BUILD_METHOD=fuzzer
7-
- JANSSON_BUILD_METHOD=lint
9+
- JANSSON_BUILD_METHOD=lint CLANG_FORMAT=clang-format-9
810
dist: bionic
911
language: c
1012
compiler:
@@ -17,7 +19,7 @@ matrix:
1719
- compiler: clang
1820
env: JANSSON_BUILD_METHOD=fuzzer
1921
- compiler: gcc
20-
env: JANSSON_BUILD_METHOD=lint
22+
env: JANSSON_BUILD_METHOD=lint CLANG_FORMAT=clang-format-9
2123
allow_failures:
2224
- env: JANSSON_BUILD_METHOD=coverage JANSSON_CMAKE_OPTIONS="-DJANSSON_COVERAGE=ON -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug" JANSSON_EXTRA_INSTALL="lcov curl"
2325
install:
@@ -29,4 +31,4 @@ script:
2931
- if [ "$JANSSON_BUILD_METHOD" = "cmake" ]; then mkdir build && cd build && cmake $JANSSON_CMAKE_OPTIONS .. && cmake --build . && ctest --output-on-failure; fi
3032
- if [ "$JANSSON_BUILD_METHOD" = "coverage" ]; then mkdir build && cd build && cmake $JANSSON_CMAKE_OPTIONS .. && cmake --build . && cmake --build . --target coveralls; fi
3133
- if [ "$JANSSON_BUILD_METHOD" = "fuzzer" ]; then ./test/ossfuzz/travisoss.sh; fi
32-
- if [ "$JANSSON_BUILD_METHOD" = "lint" ]; then ./scripts/clang-format-check 9; fi
34+
- if [ "$JANSSON_BUILD_METHOD" = "lint" ]; then ./scripts/clang-format-check; fi

scripts/clang-format-check

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
#!/bin/bash
22

3-
clangformat="clang-format"
4-
if [ -n "$1" ]; then
5-
clangformat="clang-format-$1"
6-
fi
3+
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
4+
CLANG_FORMAT_VERSION=${CLANG_FORMAT_VERSION:-}
75

8-
if ! type $clangformat >/dev/null; then
9-
# clang-format not found. If running tests, mark this test as
10-
# skipped.
6+
if ! type $CLANG_FORMAT >/dev/null || \
7+
! $CLANG_FORMAT --version | grep -q "version ${CLANG_FORMAT_VERSION}"; then
8+
# If running tests, mark this test as skipped.
119
exit 77
1210
fi
1311

1412
errors=0
15-
paths=$(find . -type f -a '(' -name '*.c' -o -name '*.h' ')')
13+
paths=$(git ls-files | grep '\.[ch]$')
1614
for path in $paths; do
1715
in=$(cat $path)
18-
out=$($clangformat $path)
16+
out=$($CLANG_FORMAT $path)
1917

2018
if [ "$in" != "$out" ]; then
2119
diff -u -L $path -L "$path.formatted" $path - <<<$out

0 commit comments

Comments
 (0)