Skip to content
Snippets Groups Projects
Commit 40e09453 authored by Administrator's avatar Administrator
Browse files

Improve code format checker

Don't download the external packages when running the code format checker.
This improves the run time from more than 4 minutes to less than  1 minute.
Test each file individually such that the results on CDash are shown for each
file separately.
parent 066848c1
No related branches found
No related tags found
1 merge request!60Code test 1
...@@ -326,7 +326,7 @@ EndIf(BUILD_UNITTESTS) ...@@ -326,7 +326,7 @@ EndIf(BUILD_UNITTESTS)
### Subdirectories to be compiled ##### ### Subdirectories to be compiled #####
### Externals included as svn externals ### Externals included and build from sveral sources
add_subdirectory (external) add_subdirectory (external)
### Base directories ### Base directories
...@@ -359,10 +359,50 @@ add_custom_target(cleantest ...@@ -359,10 +359,50 @@ add_custom_target(cleantest
find_package2(PRIVATE ClangFormat) find_package2(PRIVATE ClangFormat)
if(ClangFormat_FOUND) if(ClangFormat_FOUND)
if (FAIRROOT_FORMAT_BASE)
set(BASE_COMMIT ${FAIRROOT_FORMAT_BASE})
else()
set(BASE_COMMIT upstream/master)
endif()
if (FAIRROOT_GIT_CLANG_FORMAT_BIN)
set(GIT_CLANG_FORMAT_BIN ${FAIRROOT_GIT_CLANG_FORMAT_BIN})
else()
set(GIT_CLANG_FORMAT_BIN git-clang-format)
endif()
# Create a list C, C++ and header files which have been changed in the
# current commit
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/cmake/scripts/find_files.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE FileList
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE " " ";" FileList "${FileList}")
# Loop over the files and create the code whch is executed when running
# "make FormatCheck".
# The produced code will run clang-format on one of the files. If
# clang-format finds code which are not satisfying our code rules a
# detailed error message is created. This error message can be checked on
# our CDash web page.
foreach(file ${FileList})
set(file1 ${CMAKE_BINARY_DIR}/${file}.cf_out)
list(APPEND myfilelist ${file1})
add_custom_command(OUTPUT ${file1}
COMMAND ${CMAKE_SOURCE_DIR}/cmake/scripts/check-format-1.sh ${file} ${file1}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endforeach()
# Create the target FormatCheck which only depends on the files creted in
# previous step. When running "make FormatCheck" clang-format is executed
# for all C, C++ and header files which have changed in the commit.
add_custom_target(FormatCheck add_custom_target(FormatCheck
${CMAKE_COMMAND} -E env FAIRROOT_GIT_CLANG_FORMAT_BIN=${GIT_CLANG_FORMAT_BIN} ${CMAKE_SOURCE_DIR}/cmake/scripts/check-format.sh DEPENDS ${myfilelist}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )
)
endif() endif()
Option(BUILD_DOXYGEN "Build Doxygen" OFF) Option(BUILD_DOXYGEN "Build Doxygen" OFF)
......
#!/bin/bash
infile=$1
outfile=$2
BASE_COMMIT=${FAIRROOT_FORMAT_BASE:-HEAD}
GIT_CLANG_FORMAT_BIN=${FAIRROOT_GIT_CLANG_FORMAT_BIN:-git-clang-format}
RESULT=$($GIT_CLANG_FORMAT_BIN --commit $BASE_COMMIT --diff $infile --extensions h,hpp,c,C,cpp,cxx,tpl)
if [ "$RESULT" == "no modified files to format" ] || [ "$RESULT" == "clang-format did not modify any files" ]; then
exit 0
else
echo "ERROR: format check failed for file $infile. Suggested changes:" > $outfile
echo >> $outfile
echo "$RESULT" >> $outfile
echo "ERROR: format check failed for file $infile. Suggested changes:"
echo
echo "$RESULT"
exit 1
fi
cmake_host_system_information(RESULT fqdn QUERY FQDN) cmake_host_system_information(RESULT fqdn QUERY FQDN)
set(CTEST_SOURCE_DIRECTORY .) Set(CTEST_SOURCE_DIRECTORY $ENV{SOURCEDIR})
set(CTEST_BINARY_DIRECTORY build) Set(CTEST_BINARY_DIRECTORY $ENV{BUILDDIR})
Set(CTEST_PROJECT_NAME "CbmRoot") Set(CTEST_PROJECT_NAME "CbmRoot")
set(CTEST_CMAKE_GENERATOR "Unix Makefiles") set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
set(CTEST_USE_LAUNCHERS ON) set(CTEST_USE_LAUNCHERS ON)
Set(CTEST_CONFIGURE_COMMAND " \"${CMAKE_EXECUTABLE_NAME}\" \"-G${CTEST_CMAKE_GENERATOR}\" \"-DCTEST_USE_LAUNCHERS=${CTEST_USE_LAUNCHERS}\" \"-DDOWNLOAD_EXTERNALS=OFF\" \"${CTEST_SOURCE_DIRECTORY}\" ")
if ("$ENV{CTEST_SITE}" STREQUAL "") if ("$ENV{CTEST_SITE}" STREQUAL "")
set(CTEST_SITE "${fqdn}") set(CTEST_SITE "${fqdn}")
else() else()
......
#!/bin/bash
BASE_COMMIT=${FAIRROOT_FORMAT_BASE:-HEAD}
GIT_CLANG_FORMAT_BIN=${FAIRROOT_GIT_CLANG_FORMAT_BIN:-git-clang-format}
FILES=$(git diff --name-only $BASE_COMMIT | grep -E '.*\.(h|hpp|c|C|cpp|cxx|tpl)$' | grep -viE '.*LinkDef.h$')
echo $FILES
# Build all libraries which come from external sources like other subversion or git repositories # Build all libraries which come from external sources like other subversion or git repositories
download_project_if_needed(PROJECT cppzmq # Exclude dowload of external packages. The external packages are not needed
GIT_REPOSITORY "https://github.com/zeromq/cppzmq/" # to run the code format checker and slows down the execution.
GIT_TAG "05a0256d0eeea8063690fde6a156e14b70ed2280" # Without the externals it isn't possible to build CbmRoot so don't switch
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cppzmq # it off execept for the checker.
TEST_FILE zmq.hpp Option(DOWNLOAD_EXTERNALS "Download the code from the external repositories." ON)
)
download_project_if_needed(PROJECT flib_dpb_20 if(DOWNLOAD_EXTERNALS)
GIT_REPOSITORY "https://git.cbm.gsi.de/f.uhlig/flib_dpb_20.git" download_project_if_needed(PROJECT cppzmq
GIT_TAG "9ce7c7c0ccc7c9ea2f8c396c35d7fe39ac9aafb6" GIT_REPOSITORY "https://github.com/zeromq/cppzmq/"
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/flib_dpb_20 GIT_TAG "05a0256d0eeea8063690fde6a156e14b70ed2280"
TEST_FILE CMakeLists.txt SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cppzmq
) TEST_FILE zmq.hpp
)
Set(IPC_INCLUDE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ipc/ipc/lib/fles_ipc PARENT_SCOPE) download_project_if_needed(PROJECT flib_dpb_20
Set(IPCLOG_INCLUDE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ipc/ipc/lib/logging PARENT_SCOPE) GIT_REPOSITORY "https://git.cbm.gsi.de/f.uhlig/flib_dpb_20.git"
GIT_TAG "9ce7c7c0ccc7c9ea2f8c396c35d7fe39ac9aafb6"
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/flib_dpb_20
TEST_FILE CMakeLists.txt
)
Add_Subdirectory(ipc) Set(IPC_INCLUDE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ipc/ipc/lib/fles_ipc PARENT_SCOPE)
Add_Subdirectory(ipc_legacy) Set(IPCLOG_INCLUDE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ipc/ipc/lib/logging PARENT_SCOPE)
Add_Subdirectory(flib_dpb)
Add_Subdirectory(flib_dpb_20)
Add_Subdirectory(spadic)
Include(InstallVC.cmake) Add_Subdirectory(ipc)
Include(InstallKFParticle.cmake) Add_Subdirectory(ipc_legacy)
Include(InstallDataTree.cmake) Add_Subdirectory(flib_dpb)
Include(InstallDataTreeQA.cmake) Add_Subdirectory(flib_dpb_20)
Include(InstallNicaFemto.cmake) Add_Subdirectory(spadic)
Include(InstallAnalysisTree.cmake)
Include(InstallAnalysisTreeQA.cmake)
Include(InstallParameter.cmake) Include(InstallVC.cmake)
Include(InstallInput.cmake) Include(InstallKFParticle.cmake)
Include(InstallGeometry.cmake) Include(InstallDataTree.cmake)
Include(InstallDataTreeQA.cmake)
Include(InstallNicaFemto.cmake)
Include(InstallAnalysisTree.cmake)
Include(InstallAnalysisTreeQA.cmake)
Include(InstallParameter.cmake)
Include(InstallInput.cmake)
Include(InstallGeometry.cmake)
else()
# Define targets which are needed by CbmRoot but are not available
# whithout the external packages
add_library(DATATREE SHARED IMPORTED GLOBAL)
add_library(ANALYSISTREE SHARED IMPORTED GLOBAL)
add_library(NICAFEMTO SHARED IMPORTED GLOBAL)
add_library(KFPARTICLE SHARED IMPORTED GLOBAL)
endif()
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# the array . # the array .
# The extension is already found. Any number of sources could be listed here. # The extension is already found. Any number of sources could be listed here.
If(NOT EXISTS geodb.tar.gz) If(NOT EXISTS geodb.tar.gz AND DOWNLOAD_EXTERNALS)
Message(STATUS "Download geometry database") Message(STATUS "Download geometry database")
FILE(DOWNLOAD http://cbmdb.jinr.ru/geometry/download_file.php?type=all&tag=all ${CMAKE_BINARY_DIR}/geodb.tar.gz SHOW_PROGRESS) FILE(DOWNLOAD http://cbmdb.jinr.ru/geometry/download_file.php?type=all&tag=all ${CMAKE_BINARY_DIR}/geodb.tar.gz SHOW_PROGRESS)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment