Skip to content

Commit

Permalink
Problem: CI_REQUIRE_GOOD_CLANG_FORMAT not supported in CMake recipes
Browse files Browse the repository at this point in the history
Solution: add support for the feature and for clang-format-check-CI target

Signed-off-by: Jim Klimov <EvgenyKlimov@eaton.com>
  • Loading branch information
jimklimov committed Aug 21, 2018
1 parent 4d451a6 commit aef46cc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
7 changes: 7 additions & 0 deletions builds/cmake/Modules/ClangFormat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ add_custom_target(
COMMENT "Checking correct formatting according to .clang-format file using ${CLANG_FORMAT}"
)

add_custom_target(
clang-format-check-CI
COMMAND chmod +x clang-format-check.sh
COMMAND ./clang-format-check.sh --CI
COMMENT "Checking correct formatting according to .clang-format file using ${CLANG_FORMAT}"
)

add_custom_target(
clang-format-diff
COMMAND ${CLANG_FORMAT} -style=file -i ${ALL_SOURCE_FILES}
Expand Down
15 changes: 14 additions & 1 deletion builds/cmake/clang-format-check.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FAILED=0
IFS=";"
FILES="@ALL_SOURCE_FILES@"
IDS=$(echo -en "\n\b")
[ -n "$MAKE" ] || MAKE=make
for FILE in $FILES
do
@CLANG_FORMAT@ -style=file -output-replacements-xml "$FILE" | grep "<replacement " >/dev/null && \
Expand All @@ -14,4 +15,16 @@ do
FAILED=1
}
done
if [ "$FAILED" -eq "1" ] ; then exit 1 ; fi
if [ "$FAILED" -eq "1" ] ; then
if [ "$1" = "--CI" ] ; then
echo "Style mismatches were found by clang-format; detailing below:" >&2
${MAKE} clang-format-diff
if test x"${CI_REQUIRE_GOOD_CLANG_FORMAT}" = xtrue ; then
echo "FAILED : Style checks have failed and CI_REQUIRE_GOOD_CLANG_FORMAT==true" >&2
exit 1
fi
echo "WARNING : Style checks have failed, but the result is not-fatal because CI_REQUIRE_GOOD_CLANG_FORMAT!=true" >&2
exit 0
fi
exit 1
fi
22 changes: 21 additions & 1 deletion zproject_cmake.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,13 @@ add_custom_target(
COMMENT "Checking correct formatting according to .clang-format file using ${CLANG_FORMAT}"
)

add_custom_target(
clang-format-check-CI
COMMAND chmod +x clang-format-check.sh
COMMAND ./clang-format-check.sh --CI
COMMENT "Checking correct formatting according to .clang-format file using ${CLANG_FORMAT}"
)

add_custom_target(
clang-format-diff
COMMAND ${CLANG_FORMAT} -style=file -i ${ALL_SOURCE_FILES}
Expand All @@ -945,6 +952,7 @@ FAILED=0
IFS=";"
FILES="@ALL_SOURCE_FILES@"
IDS=\$\(echo -en "\\n\\b")
[ -n "\$MAKE" ] || MAKE=make
for FILE in $FILES
do
@CLANG_FORMAT@ -style=file -output-replacements-xml "$FILE" | grep "<replacement " >/dev/null && \\
Expand All @@ -953,7 +961,19 @@ do
FAILED=1
}
done
if [ "$FAILED" -eq "1" ] ; then exit 1 ; fi
if [ "\$FAILED" -eq "1" ] ; then
if [ "\$1" = "--CI" ] ; then
echo "Style mismatches were found by clang-format; detailing below:" >&2
\$\{MAKE} clang-format-diff
if test x"\$\{CI_REQUIRE_GOOD_CLANG_FORMAT}" = xtrue ; then
echo "FAILED : Style checks have failed and CI_REQUIRE_GOOD_CLANG_FORMAT==true" >&2
exit 1
fi
echo "WARNING : Style checks have failed, but the result is not-fatal because CI_REQUIRE_GOOD_CLANG_FORMAT!=true" >&2
exit 0
fi
exit 1
fi
.close
.output "builds/cmake/Config.cmake.in"
@PACKAGE_INIT@
Expand Down

0 comments on commit aef46cc

Please sign in to comment.