Commit d53c7104 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

CI: switch to clang-format-8

parent f3337a02
......@@ -160,6 +160,9 @@ ADD_RUNTIME_DEP(thisroot.sh)
# Load cpp format and check tools #
###################################
# Set the clang-format version required by the CI for correct formatting:
SET(CLANG_FORMAT_VERSION "8")
# Set the source files to clang-format (FIXME: determine this better)
FILE(GLOB_RECURSE
CHECK_CXX_SOURCE_FILES
......
......@@ -21,34 +21,47 @@ IF(NOT CHECK_CXX_SOURCE_FILES)
ENDIF()
# Adding clang-format check and formatter if found
FIND_PROGRAM(CLANG_FORMAT NAMES "clang-format-6.0" "clang-format-5.0" "clang-format-4.0" "clang-format" "clang-format-7")
FIND_PROGRAM(CLANG_FORMAT NAMES "clang-format-8" "clang-format")
IF(CLANG_FORMAT)
MESSAGE(STATUS "Found ${CLANG_FORMAT}, adding formatting targets")
ADD_CUSTOM_TARGET(
format
COMMAND
${CLANG_FORMAT}
-i
-style=file
${CHECK_CXX_SOURCE_FILES}
COMMENT "Auto formatting of all source files"
)
EXEC_PROGRAM(${CLANG_FORMAT} ${CMAKE_CURRENT_SOURCE_DIR} ARGS --version OUTPUT_VARIABLE CLANG_VERSION)
STRING(REGEX REPLACE ".*([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" CLANG_MAJOR_VERSION ${CLANG_VERSION})
ADD_CUSTOM_TARGET(
check-format
COMMAND
${CLANG_FORMAT}
-style=file
-output-replacements-xml
${CHECK_CXX_SOURCE_FILES}
# print output
| tee ${CMAKE_BINARY_DIR}/check_format_file.txt | grep -c "replacement " |
tr -d "[:cntrl:]" && echo " replacements necessary"
# WARNING: fix to stop with error if there are problems
COMMAND ! grep -c "replacement "
${CMAKE_BINARY_DIR}/check_format_file.txt > /dev/null
COMMENT "Checking format compliance"
)
# We currently require version 8 - which is not available on OSX...
IF(${CLANG_MAJOR_VERSION} EQUAL ${CLANG_FORMAT_VERSION} OR DEFINED ${APPLE})
IF(DEFINED ${APPLE})
MESSAGE(WARNING "Found ${CLANG_FORMAT} version ${CLANG_MAJOR_VERSION}, this might lead to incompatible formatting")
ELSE()
MESSAGE(STATUS "Found ${CLANG_FORMAT} version ${CLANG_FORMAT_VERSION}, adding formatting targets")
ENDIF()
ADD_CUSTOM_TARGET(
format
COMMAND
${CLANG_FORMAT}
-i
-style=file
${CHECK_CXX_SOURCE_FILES}
COMMENT "Auto formatting of all source files"
)
ADD_CUSTOM_TARGET(
check-format
COMMAND
${CLANG_FORMAT}
-style=file
-output-replacements-xml
${CHECK_CXX_SOURCE_FILES}
# print output
| tee ${CMAKE_BINARY_DIR}/check_format_file.txt | grep -c "replacement " |
tr -d "[:cntrl:]" && echo " replacements necessary"
# WARNING: fix to stop with error if there are problems
COMMAND ! grep -c "replacement "
${CMAKE_BINARY_DIR}/check_format_file.txt > /dev/null
COMMENT "Checking format compliance"
)
ELSE()
MESSAGE(STATUS "Could only find version ${CLANG_MAJOR_VERSION} of clang-format, but version ${CLANG_FORMAT_VERSION} is required.")
ENDIF()
ELSE()
MESSAGE(STATUS "Could NOT find clang-format")
ENDIF()
......@@ -59,7 +72,7 @@ IF(${CMAKE_CXX_STANDARD})
SET(CXX_STD ${CMAKE_CXX_STANDARD})
ENDIF()
FIND_PROGRAM(CLANG_TIDY NAMES "clang-tidy-6.0" "clang-tidy-5.0" "clang-tidy-4.0" "clang-tidy")
FIND_PROGRAM(CLANG_TIDY NAMES "clang-tidy-8" "clang-tidy")
# Enable clang tidy only if using a clang compiler
IF(CLANG_TIDY AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# If debug build enabled do automatic clang tidy
......
......@@ -9,7 +9,7 @@ This chapter contains details on the standard installation process and informati
\section{Supported Operating Systems}
\label{sec:os}
\corry is designed to run without issues on either a recent Linux distribution or Mac OS\,X.
Furthermore, the continuous integration of the project ensures correct building and functioning of the software framework on CentOS\,7 (with GCC and LLVM), SLC\,6 (with GCC and LLVM) and Mac OS Mojave (OS X 10.14, with AppleClang).
Furthermore, the continuous integration of the project ensures correct building and functioning of the software framework on CentOS\,7 (with GCC and LLVM), SLC\,6 (with GCC only) and Mac OS Mojave (OS X 10.14, with AppleClang).
\section{CMVFS}
\label{sec:cvmfs_install}
......
......@@ -8,7 +8,7 @@
##################################################################
# SETTINGS
# set path to clang-format binary
for bin in "clang-format-6.0" "clang-format-5.0" "clang-format-4.0" "clang-format-7" "clang-format";
for bin in "clang-format-8" "clang-format";
do
CLANG_FORMAT=$(which "$bin")
[ -n "$CLANG_FORMAT" ] && break
......@@ -60,26 +60,37 @@ if [ ! -x "$CLANG_FORMAT" ] ; then
exit 1
fi
if ! "$CLANG_FORMAT" --version | grep 'clang-format version 8\.0' >/dev/null 2>/dev/null; then
# Be indulgent with OSX users, no 4.0 seems to be available...
if [[ "$OSTYPE" != "darwin"* ]]; then
printf "Error: clang-format version 8.0 is required (exactly), cannot check format!\n"
exit 1
else
printf "Warning: clang-format version 8.0 is required, formatting might be incompatible!\n"
fi
fi
# create one patch containing all changes to the files
git diff-index --cached --diff-filter=ACMR --name-only $against -- src/ | while read file;
git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
do
# ignore file if we do check for file extensions and the file
# does not match any of the extensions specified in $FILE_EXTS
if ! matches_extension "$file"; then
continue;
fi
# temporary save the staged file to work with this instead of the real file
git show :$file > $staged_file
# clang-format our sourcefile, create a patch and append it to our $patch
cat "$staged_file" | "$CLANG_FORMAT" -assume-filename=$file -style=file | \
git diff --no-index -- "$staged_file" - | \
sed -e "s|--- a$staged_file|--- a/$file|" | \
sed -e "s|+++ b/-|+++ b/$file|" >> "$patch"
# also make a colored patch for displaying if needed
if [ "$VERBOSE" -ne 0 ] ; then
sed -e "s|+++ b/-|+++ b/$file|" >> "$patch"
# also make a colored patch for displaying if needed
if [ "$VERBOSE" -ne 0 ] ; then
cat "$staged_file" | "$CLANG_FORMAT" -assume-filename=$file -style=file | \
git diff --color --no-index -- "$staged_file" - | \
sed -e "s|--- a$staged_file|--- a/$file|" | \
......@@ -89,7 +100,7 @@ done
# if no patch has been generated all is ok, clean up the file stub and exit
if [ ! -s "$patch" ] ; then
if [ "$VERBOSE" -ne 0 ] ; then
if [ "$VERBOSE" -ne 0 ] ; then
printf "Changes in this commit comply with the clang-format rules.\n"
fi
rm -f "$patch"
......@@ -108,7 +119,7 @@ if [ $? -ne 0 ] ; then
rm -f "$patch";
rm -f "$patch_color";
rm -f "$staged_file"
exit 1;
exit 1;
fi
# a patch has been created, let the user know about it
......@@ -118,24 +129,24 @@ if [ "$VERBOSE" -ne 0 ] ; then
printf "The following differences were found between the code to commit "
printf "and the clang-format rules:\n"
cat "$patch_color"
printf "\n"
printf "\n"
fi
# assign stdin back to keyboard
# assign stdin back to keyboard
exec < /dev/tty
# ask what we want to do with the patch
while true; do
read -p "Do you want to install the patch (yes - commit with patch, no - do not commit)? [y/n] " yn
case $yn in
[Yy] )
git apply --index $patch;
[Yy] )
git apply --index $patch;
rm -f "$patch";
rm -f "$patch_color";
rm -f "$staged_file"
exit 0
;;
[Nn] )
[Nn] )
printf "Changes are not applied! You can apply these changes manually with:\n";
printf " git apply --index $patch\n";
printf " (needs to be called from the root directory of your repository)\n";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment