diff --git a/.codeclimate.yml b/.codeclimate.yml index c83baafea..7878866d0 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,38 +1,38 @@ checks: duplicate: enabled: true exclude_patterns: - "test/" - "examples/" structure: enabled: true exclude_patterns: - "test/" plugins: editorconfig: enabled: false config: editorconfig: .editorconfig exclude_patterns: - ".clangd/" - ".cache/" pep8: enabled: true exclude_patterns: - "test/test_fe_engine/py_engine/py_engine.py" cppcheck: - enabled: true + enabled: false project: compile_commands.json language: c++ check: warning, style, performance stds: [c++14] fixme: enabled: true exclude_patterns: - "doc/" exclude_patterns: - "third-party/" - "build*/" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b9cd94c7d..3178068f5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,303 +1,322 @@ stages: - configure - build - check-warnings - test - deploy .docker_build: image: 'docker:19.03.11' stage: .pre services: - docker:19.03.11-dind variables: # Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled DOCKER_HOST: tcp://docker:2376 DOCKER_TLS_CERTDIR: "/certs" before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - cd test/ci/${IMAGE_NAME}/ - docker build -t registry.gitlab.com/akantu/akantu/${IMAGE_NAME} . - docker push registry.gitlab.com/akantu/akantu/${IMAGE_NAME} docker build:debian-testing: variables: IMAGE_NAME: debian:testing extends: .docker_build rules: - changes: - test/ci/debian:testing/Dockerfile docker build:ubuntu-lts: variables: IMAGE_NAME: ubuntu:lts extends: .docker_build rules: - changes: - test/ci/ubuntu:lts/Dockerfile .configure: stage: configure except: - tags variables: BLA_VENDOR: 'Generic' script: - cmake -E make_directory build - cd build - cmake -DAKANTU_COHESIVE_ELEMENT:BOOL=TRUE -DAKANTU_IMPLICIT:BOOL=TRUE -DAKANTU_PARALLEL:BOOL=TRUE -DAKANTU_STRUCTURAL_MECHANICS:BOOL=TRUE -DAKANTU_HEAT_TRANSFER:BOOL=TRUE -DAKANTU_DAMAGE_NON_LOCAL:BOOL=TRUE -DAKANTU_PYTHON_INTERFACE:BOOL=TRUE -DAKANTU_EXAMPLES:BOOL=TRUE -DAKANTU_BUILD_ALL_EXAMPLES:BOOL=TRUE -DAKANTU_TEST_EXAMPLES:BOOL=FALSE -DAKANTU_TESTS:BOOL=TRUE -DAKANTU_RUN_IN_DOCKER:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Coverage .. - cp compile_commmands.json .. artifacts: when: on_success paths: - build - compile_commands.json expire_in: 10h .build: stage: build script: - cmake --build build/src > >(tee -a ${output}-out.log) 2> >(tee -a ${output}-err.log >&2) - cmake --build build/python > >(tee -a ${output}-out.log) 2> >(tee -a ${output}-err.log >&2) - cmake --build build/test/ > >(tee -a ${output}-out.log) 2> >(tee -a ${output}-err.log >&2) - cmake --build build/examples > >(tee -a ${output}-out.log) 2> >(tee -a ${output}-err.log >&2) artifacts: when: on_success paths: - build/ #- ${output}-out.log - ${output}-err.log - compile_commands.json expire_in: 10h .tests: stage: test script: - cd build - ctest -T test --no-compress-output --timeout 1800 after_script: - cd build - tag=$(head -n 1 < Testing/TAG) - if [ -e Testing/${tag}/Test.xml ]; then - xsltproc -o ./juint.xml ${CI_PROJECT_DIR}/test/ci/ctest2junit.xsl Testing/${tag}/Test.xml; - fi - gcovr --xml --output coverage.xml --object-directory ${CI_PROJECT_DIR}/build --root ${CI_PROJECT_DIR} -s || true artifacts: when: always paths: - build/juint.xml - build/coverage.xml reports: junit: - build/juint.xml cobertura: - build/coverage.xml .analyse_build: stage: check-warnings script: - if [[ $(cat ${output}-err.log | grep warning -i) ]]; then - cat ${output}-err.log; - exit 1; - fi allow_failure: true artifacts: when: on_failure paths: - "$output-err.log" # ------------------------------------------------------------------------------ .cache_build: variables: CCACHE_BASEDIRE: ${CI_PROJECT_DIR}/build CCACHE_DIR: ${CI_PROJECT_DIR}/.ccache CCACHE_NOHASHDIR: 1 CCACHE_COMPILERCHECK: content cache: key: ${output} policy: pull-push paths: - .ccache/ - third-party/google-test - third-party/pybind11 before_script: - ccache --zero-stats || true after_script: - ccache --show-stats || true # ------------------------------------------------------------------------------ .image_debian_testing: image: registry.gitlab.com/akantu/akantu/debian:testing .image_ubuntu_lts: image: registry.gitlab.com/akantu/akantu/ubuntu:lts # ------------------------------------------------------------------------------ .compiler_gcc: variables: CC: /usr/lib/ccache/gcc CXX: /usr/lib/ccache/g++ FC: gfortran .compiler_clang: variables: CC: /usr/lib/ccache/clang CXX: /usr/lib/ccache/clang++ FC: gfortran # ------------------------------------------------------------------------------ .debian_testing_gcc: variables: output: debian_testing_gcc extends: - .compiler_gcc - .image_debian_testing - .cache_build .debian_testing_clang: variables: output: debian_testing_clang extends: - .compiler_clang - .image_debian_testing - .cache_build .ubuntu_lts_gcc: variables: output: ubuntu_lts_gcc extends: - .compiler_gcc - .image_ubuntu_lts - .cache_build # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ configure:debian_testing_gcc: extends: - .debian_testing_gcc - .configure cache: policy: pull-push build:debian_testing_gcc: extends: - .debian_testing_gcc - .build dependencies: - configure:debian_testing_gcc test:debian_testing_gcc: extends: - .debian_testing_gcc - .tests dependencies: - build:debian_testing_gcc analyse_build:debian_testing_gcc: extends: - .debian_testing_gcc - .analyse_build dependencies: - build:debian_testing_gcc # ------------------------------------------------------------------------------ configure:debian_testing_clang: extends: - .debian_testing_clang - .configure cache: policy: pull-push build:debian_testing_clang: extends: - .debian_testing_clang - .build dependencies: - configure:debian_testing_clang test:debian_testing_clang: extends: - .debian_testing_clang - .tests dependencies: - build:debian_testing_clang analyse_build:debian_testing_clang: extends: - .debian_testing_clang - .analyse_build dependencies: - build:debian_testing_clang # ------------------------------------------------------------------------------ configure:ubuntu_lts_gcc: extends: - .ubuntu_lts_gcc - .configure cache: policy: pull-push build:ubuntu_lts_gcc: extends: - .ubuntu_lts_gcc - .build dependencies: - configure:ubuntu_lts_gcc analyse_build:ubuntu_lts_gcc: extends: - .ubuntu_lts_gcc - .analyse_build dependencies: - build:ubuntu_lts_gcc test:ubuntu_lts_gcc: extends: - .ubuntu_lts_gcc - .tests dependencies: - build:ubuntu_lts_gcc # ------------------------------------------------------------------------------ include: - template: Code-Quality.gitlab-ci.yml code_quality: dependencies: - build:debian_testing_clang artifacts: paths: [gl-code-quality-report.json] +code_quality_clang_tidy: + dependencies: + - build:debian_testing_clang + stage: test + script: + - cmake --build build --target clang-tidy-all > >(tee -a clang-tidy-all-out.log) 2> >(tee -a clang-tidy-all-err.log >&2) + - python3 ./test/ci/scripts/clang-tidy2code-quality.py + artifacts: + when: on_success + paths: + - clang-tidy-all-err.log + - clang-tidy-all-out.log + - code-quality-clang.json + expire_in: 10h + artifacts: + reports: + codequality: + - code-quality-clang.json + # ------------------------------------------------------------------------------ pages: stage: deploy extends: - .debian_testing_gcc script: - cd build - cmake -DAKANTU_DOCUMENTATION_DEVELOPER_MANUAL=ON .. - cmake --build . -t sphinx-doc - mv doc/dev-doc/html ../public dependencies: - build:debian_testing_gcc artifacts: paths: - public only: - features/doc diff --git a/cmake/AkantuCleaning.cmake b/cmake/AkantuCleaning.cmake index 8fd50e667..d852abf84 100644 --- a/cmake/AkantuCleaning.cmake +++ b/cmake/AkantuCleaning.cmake @@ -1,82 +1,103 @@ #=============================================================================== # @file AkantuCleaning.cmake # # @author Nicolas Richart # # @date creation: Thu Jun 1, 2017 # # @brief set of tools to clean the code # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . #=============================================================================== # Adding clang-format target if executable is found -find_program(CLANG_FORMAT "clang-format") -mark_as_advanced(CLANG_FORMAT) -macro(register_code_to_format) - if(CLANG_FORMAT) - add_custom_target( - clang-format-all - COMMAND ${CLANG_FORMAT} - -i - -style=file - ${ARGN} - ) - endif() -endmacro() - +find_program(CLANG_FORMAT_EXECUTABLE "clang-format") # Adding clang-tidy target if executable is found -find_program(CLANG_TIDY "clang-tidy") -mark_as_advanced(CLANG_TIDY) -macro(register_target_to_tidy target) - if(CLANG_TIDY) - option(AKANTU_CLANG_TIDY_AUTOFIX OFF) - mark_as_advanced(AKANTU_CLANG_TIDY_AUTOFIX) +find_program(CLANG_TIDY_EXECUTABLE "clang-tidy") +find_program(RUN_CLANG_TIDY_EXECUTABLE "run-clang-tidy") - set(_autofix_option) - if(AKANTU_CLANG_TIDY_AUTOFIX) - set(_autofix_option -fix) - endif() - get_target_property(_sources ${target} SOURCES) +mark_as_advanced( + CLANG_FORMAT_EXECUTABLE + CLANG_TIDY_EXECUTABLE + RUN_CLANG_TIDY_EXECUTABLE + ) - file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/clang-tidy) +function(register_code_to_format) + if(NOT CLANG_FORMAT_EXECUTABLE) + endif() + + add_custom_target( + clang-format-all + COMMAND ${CLANG_FORMAT_EXECUTABLE} + -style=file + --output-replacements-xml + ${ARGN} || /bin/true + ) +endfunction() + +function(register_tidy_all directory) + if(NOT RUN_CLANG_TIDY_EXECUTABLE) + return() + endif() - set(_depends) + add_custom_target( + clang-tidy-all + COMMAND ${RUN_CLANG_TIDY_EXECUTABLE} + ${ARGN} + ) +endfunction() - foreach(_src ${_sources}) - get_filename_component(_src_dir ${_src} DIRECTORY) - file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/clang-tidy/${_src_dir}) +function(register_target_to_tidy target) + if(NOT CLANG_TIDY_EXECUTABLE) + return() + endif() - add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/clang-tidy/${_src}.yaml - COMMAND ${CLANG_TIDY} - -p=${PROJECT_BINARY_DIR} - -export-fixes=${PROJECT_BINARY_DIR}/clang-tidy/${_src}.yaml - ${_autofix_option} - ${_src} - COMMENT "Tidying ${_src}" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) + option(AKANTU_CLANG_TIDY_AUTOFIX OFF) + mark_as_advanced(AKANTU_CLANG_TIDY_AUTOFIX) - list(APPEND _depends ${PROJECT_BINARY_DIR}/clang-tidy/${_src}.yaml) - endforeach() - add_custom_target(clang-tidy DEPENDS ${_depends}) + set(_autofix_option) + if(AKANTU_CLANG_TIDY_AUTOFIX) + set(_autofix_option -fix) endif() -endmacro() + get_target_property(_sources ${target} SOURCES) + + file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/clang-tidy) + + set(_depends) + + foreach(_src ${_sources}) + get_filename_component(_src_dir ${_src} DIRECTORY) + file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/clang-tidy/${_src_dir}) + + add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/clang-tidy/${_src}.yaml + COMMAND ${CLANG_TIDY_EXECUTABLE} + -p=${PROJECT_BINARY_DIR} + -export-fixes=${PROJECT_BINARY_DIR}/clang-tidy/${_src}.yaml + ${_autofix_option} + ${_src} + COMMENT "Tidying ${_src}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + list(APPEND _depends ${PROJECT_BINARY_DIR}/clang-tidy/${_src}.yaml) + endforeach() + add_custom_target(clang-tidy DEPENDS ${_depends}) +endfunction() diff --git a/cmake/AkantuExtraCompilationProfiles.cmake b/cmake/AkantuExtraCompilationProfiles.cmake index fd0fb5ae4..e8095cb09 100644 --- a/cmake/AkantuExtraCompilationProfiles.cmake +++ b/cmake/AkantuExtraCompilationProfiles.cmake @@ -1,87 +1,93 @@ #Profiling set(_profiling "-g -ggdb3 -pg -DNDEBUG -DAKANTU_NDEBUG -O2") set(CMAKE_CXX_FLAGS_PROFILING ${_profiling} CACHE STRING "Flags used by the compiler during profiling builds") set(CMAKE_C_FLAGS_PROFILING ${_profiling} CACHE STRING "Flags used by the compiler during profiling builds") set(CMAKE_Fortran_FLAGS_PROFILING ${_profiling} CACHE STRING "Flags used by the compiler during profiling builds") set(CMAKE_EXE_LINKER_FLAGS_PROFILING "-pg" CACHE STRING "Flags used by the linker during profiling builds") set(CMAKE_SHARED_LINKER_FLAGS_PROFILING "-pg" CACHE STRING "Flags used by the linker during profiling builds") mark_as_advanced( CMAKE_CXX_FLAGS_PROFILING CMAKE_C_FLAGS_PROFILING CMAKE_Fortran_FLAGS_PROFILING CMAKE_EXE_LINKER_FLAGS_PROFILING CMAKE_SHARED_LINKER_FLAGS_PROFILING ) # Sanitize the code if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.2") OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(_sanitize "-g -ggdb3 -O2 -fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-omit-frame-pointer -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/cmake/sanitize-blacklist.txt") set(CMAKE_CXX_FLAGS_SANITIZE ${_sanitize} CACHE STRING "Flags used by the compiler during sanitizing builds") set(CMAKE_C_FLAGS_SANITIZE ${_sanitize} CACHE STRING "Flags used by the compiler during sanitizing builds") set(CMAKE_Fortran_FLAGS_SANITIZE ${_sanitize} CACHE STRING "Flags used by the compiler during sanitizing builds") set(CMAKE_EXE_LINKER_FLAGS_SANITIZE ${_sanitize} CACHE STRING "Flags used by the linker during sanitizing builds") set(CMAKE_SHARED_LINKER_FLAGS_SANITIZE ${_sanitize} CACHE STRING "Flags used by the linker during sanitizing builds") mark_as_advanced( CMAKE_CXX_FLAGS_SANITIZE CMAKE_C_FLAGS_SANITIZE CMAKE_Fortran_FLAGS_SANITIZE CMAKE_SHARED_LINKER_FLAGS_SANITIZE CMAKE_EXE_LINKER_FLAGS_SANITIZE ) endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(_sanitize "-g -ggdb3 -O2 -fPIE -fsanitize=memory -fsanitize-memory-track-origins -fsanitize-recover=all -fno-omit-frame-pointer -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/cmake/sanitize-blacklist.txt") set(CMAKE_CXX_FLAGS_SANITIZEMEMORY ${_sanitize} CACHE STRING "Flags used by the compiler during sanitizing builds") set(CMAKE_C_FLAGS_SANITIZEMEMORY ${_sanitize} CACHE STRING "Flags used by the compiler during sanitizing builds") set(CMAKE_Fortran_FLAGS_SANITIZEMEMORY ${_sanitize} CACHE STRING "Flags used by the compiler during sanitizing builds") set(CMAKE_EXE_LINKER_FLAGS_SANITIZEMEMORY ${_sanitize} CACHE STRING "Flags used by the linker during sanitizing builds") set(CMAKE_SHARED_LINKER_FLAGS_SANITIZEMEMORY ${_sanitize} CACHE STRING "Flags used by the linker during sanitizing builds") mark_as_advanced( CMAKE_CXX_FLAGS_SANITIZEMEMORY CMAKE_C_FLAGS_SANITIZEMEMORY CMAKE_Fortran_FLAGS_SANITIZEMEMORY CMAKE_SHARED_LINKER_FLAGS_SANITIZEMEMORY CMAKE_EXE_LINKER_FLAGS_SANITIZEMEMORY ) endif() find_program(GCOV_EXECUTABLE gcov) if (GCOV_EXECUTABLE) - set(_coverage "-g -ggdb3 -DNDEBUG -DAKANTU_NDEBUG -O2 -fprofile-arcs -ftest-coverage") + set(_coverage "-g -ggdb3 -DNDEBUG -DAKANTU_NDEBUG -O2 --coverage") set(CMAKE_CXX_FLAGS_COVERAGE ${_coverage} CACHE STRING "Flags used by the compiler during profiling builds") set(CMAKE_C_FLAGS_COVERAGE ${_coverage} CACHE STRING "Flags used by the compiler during profiling builds") set(CMAKE_Fortran_FLAGS_COVERAGE ${_coverage} CACHE STRING "Flags used by the compiler during profiling builds") + set(CMAKE_SHARED_LINLER_FLAGS_COVERAGE ${_coverage} + CACHE STRING "Flags used by the compiler during profiling builds") + set(CMAKE_EXE_LINKER_FLAGS_COVERAGE ${_coverage} + CACHE STRING "Flags used by the linker during sanitizing builds") mark_as_advanced( CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE CMAKE_Fortran_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_SANITIZEMEMORY + CMAKE_EXE_LINKER_FLAGS_SANITIZEMEMORY ) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5829f302..1e52131e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,258 +1,264 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux # @author Nicolas Richart # # @date creation: Mon Jun 14 2010 # @date last modification: Tue Feb 13 2018 # # @brief CMake file for the library # # @section LICENSE # # Copyright (©) 2010-2018 EPFL (Ecole Polytechnique Fédérale de Lausanne) # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see . # #=============================================================================== #=============================================================================== # Package Management #=============================================================================== package_get_all_source_files( AKANTU_LIBRARY_SRCS AKANTU_LIBRARY_PUBLIC_HDRS AKANTU_LIBRARY_PRIVATE_HDRS ) package_get_all_include_directories( AKANTU_LIBRARY_INCLUDE_DIRS ) package_get_all_external_informations( PRIVATE_INCLUDE AKANTU_PRIVATE_EXTERNAL_INCLUDE_DIR INTERFACE_INCLUDE AKANTU_INTERFACE_EXTERNAL_INCLUDE_DIR LIBRARIES AKANTU_EXTERNAL_LIBRARIES ) package_get_all_compilation_flags(CXX _cxx_flags) set(AKANTU_EXTRA_CXX_FLAGS "${_cxx_flags}" CACHE STRING "Extra flags defined by loaded packages" FORCE) mark_as_advanced(AKANTU_EXTRA_CXX_FLAGS) foreach(src_ ${AKANTU_SPIRIT_SOURCES}) set_property(SOURCE ${src_} PROPERTY COMPILE_FLAGS "-g0 -Werror") endforeach() #=========================================================================== # header for blas/lapack (any other fortran libraries) #=========================================================================== package_is_activated(BLAS _blas_activated) package_is_activated(LAPACK _lapack_activated) if(_blas_activated OR _lapack_activated) if(CMAKE_Fortran_COMPILER) # ugly hack set(CMAKE_Fortran_COMPILER_LOADED TRUE) endif() include(FortranCInterface) FortranCInterface_HEADER( "${CMAKE_CURRENT_BINARY_DIR}/aka_fortran_mangling.hh" MACRO_NAMESPACE "AKA_FC_") mark_as_advanced(CDEFS) list(APPEND AKANTU_LIBRARY_PUBLIC_HDRS "${CMAKE_CURRENT_BINARY_DIR}/aka_fortran_mangling.hh" ) endif() list(APPEND AKANTU_LIBRARY_INCLUDE_DIRS "${CMAKE_CURRENT_BINARY_DIR}") set(AKANTU_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} ${AKANTU_LIBRARY_INCLUDE_DIRS} CACHE INTERNAL "Internal include directories to link with Akantu as a subproject") #=========================================================================== # configurations #=========================================================================== package_get_all_material_includes(AKANTU_MATERIAL_INCLUDES) package_get_all_material_lists(AKANTU_MATERIAL_LISTS) configure_file(model/solid_mechanics/material_list.hh.in "${CMAKE_CURRENT_BINARY_DIR}/material_list.hh" @ONLY) package_get_element_lists() configure_file(common/aka_element_classes_info.hh.in "${CMAKE_CURRENT_BINARY_DIR}/aka_element_classes_info.hh" @ONLY) configure_file(common/aka_config.hh.in "${CMAKE_CURRENT_BINARY_DIR}/aka_config.hh" @ONLY) list(APPEND AKANTU_LIBRARY_PUBLIC_HDRS "${CMAKE_CURRENT_BINARY_DIR}/material_list.hh" "${CMAKE_CURRENT_BINARY_DIR}/aka_element_classes_info.hh" "${CMAKE_CURRENT_BINARY_DIR}/aka_config.hh") #=============================================================================== # Debug infos #=============================================================================== set(AKANTU_GDB_DIR ${PROJECT_SOURCE_DIR}/cmake) if(UNIX AND NOT APPLE) string(TOUPPER "${CMAKE_BUILD_TYPE}" _u_build_type) if(_u_build_type STREQUAL "DEBUG" OR _u_build_type STREQUAL "RELWITHDEBINFO") configure_file(${PROJECT_SOURCE_DIR}/cmake/libakantu-gdb.py.in "${PROJECT_BINARY_DIR}/libakantu-gdb.py" @ONLY) configure_file(${PROJECT_SOURCE_DIR}/cmake/akantu-debug.cc.in "${PROJECT_BINARY_DIR}/akantu-debug.cc" @ONLY) list(APPEND AKANTU_LIBRARY_SRCS ${PROJECT_BINARY_DIR}/akantu-debug.cc) endif() else() find_program(GDB_EXECUTABLE gdb) if(GDB_EXECUTABLE) execute_process(COMMAND ${GDB_EXECUTABLE} --batch -x "${PROJECT_SOURCE_DIR}/cmake/gdb_python_path" OUTPUT_VARIABLE AKANTU_PYTHON_GDB_DIR ERROR_QUIET RESULT_VARIABLE _res) if(_res EQUAL 0 AND UNIX) set(GDB_USER_CONFIG $ENV{HOME}/.gdb/auto-load) file(MAKE_DIRECTORY ${GDB_USER_CONFIG}) configure_file(${PROJECT_SOURCE_DIR}/cmake/libakantu-gdb.py.in "${GDB_USER_CONFIG}/${CMAKE_SHARED_LIBRARY_PREFIX}akantu${CMAKE_SHARED_LIBRARY_SUFFIX}.${AKANTU_VERSION}-gdb.py" @ONLY) endif() endif() endif() #=============================================================================== # GIT info #=============================================================================== #include(AkantuBuildOptions) #git_version_info(akantu_git_info ALL # OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/akantu_git_info.hh # ) #list(APPEND AKANTU_LIBRARY_SRCS ${CMAKE_CURRENT_BINARY_DIR}/akantu_git_info.hh) #=============================================================================== # Library generation #=============================================================================== add_library(akantu ${AKANTU_LIBRARY_SRCS}) target_include_directories(akantu PRIVATE $ INTERFACE $ ) # small trick for build includes in public set_property(TARGET akantu APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $) target_include_directories(akantu SYSTEM PUBLIC ${AKANTU_INTERFACE_EXTERNAL_INCLUDE_DIR} ) target_include_directories(akantu SYSTEM PRIVATE ${AKANTU_PRIVATE_EXTERNAL_INCLUDE_DIR} ) target_link_libraries(akantu PUBLIC ${AKANTU_EXTERNAL_LIBRARIES}) set_target_properties(akantu PROPERTIES ${AKANTU_LIBRARY_PROPERTIES} # this contains the version COMPILE_FLAGS "${_cxx_flags}" #PRIVATE_HEADER ${AKANTU_LIBRARY_PRIVATE_HDRS} ) if(AKANTU_LIBRARY_PUBLIC_HDRS) set_property(TARGET akantu PROPERTY PUBLIC_HEADER ${AKANTU_LIBRARY_PUBLIC_HDRS}) endif() if(AKANTU_LIBRARY_PRIVATE_HDRS) set_property(TARGET akantu PROPERTY PRIVATE_HEADER ${AKANTU_LIBRARY_PRIVATE_HDRS}) endif() if(NOT CMAKE_VERSION VERSION_LESS 3.1) package_get_all_features_public(_PUBLIC_features) package_get_all_features_private(_PRIVATE_features) foreach(_type PRIVATE PUBLIC) if(_${_type}_features) target_compile_features(akantu ${_type} ${_${_type}_features}) endif() endforeach() else() set_target_properties(akantu PROPERTIES CXX_STANDARD 14 ) endif() package_get_all_extra_dependencies(_extra_target_dependencies) if(_extra_target_dependencies) # This only adding todo: find a solution for when a dependency was add the is removed... add_dependencies(akantu ${_extra_target_dependencies}) endif() package_get_all_export_list(AKANTU_EXPORT_LIST) list(APPEND AKANTU_EXPORT_LIST akantu) # TODO separate public from private headers install(TARGETS akantu EXPORT ${AKANTU_TARGETS_EXPORT} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Akantu_runtime # NAMELINK_ONLY # LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # COMPONENT Akantu_development # NAMELINK_SKIP Akantu_development ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Akantu_runtime RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Akantu_runtime PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/akantu/ COMPONENT Akantu_development ) if("${AKANTU_TARGETS_EXPORT}" STREQUAL "AkantuTargets") install(EXPORT AkantuTargets DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME} COMPONENT dev) #Export for build tree export(EXPORT AkantuTargets FILE "${CMAKE_BINARY_DIR}/AkantuTargets.cmake") export(PACKAGE Akantu) endif() #=============================================================================== # Adding module names for debug package_get_all_packages(_pkg_list) foreach(_pkg ${_pkg_list}) _package_get_real_name(${_pkg} _pkg_name) _package_get_source_files(${_pkg} _srcs _public_hdrs _private_hdrs) string(TOLOWER "${_pkg_name}" _l_package_name) set_property(SOURCE ${_srcs} ${_public_hdrs} ${_private_hdrs} APPEND PROPERTY COMPILE_DEFINITIONS AKANTU_MODULE=${_l_package_name}) endforeach() # print out the list of materials generate_material_list() register_target_to_tidy(akantu) +register_tidy_all(${AKANTU_LIBRARY_SRCS}) +register_code_to_format( + ${AKANTU_LIBRARY_SRCS} + ${AKANTU_LIBRARY_PUBLIC_HDRS} + ${AKANTU_LIBRARY_PRIVATE_HDRS} + ) diff --git a/test/ci/scripts/clang-tidy2code-quality.py b/test/ci/scripts/clang-tidy2code-quality.py new file mode 100644 index 000000000..1fb7cb05c --- /dev/null +++ b/test/ci/scripts/clang-tidy2code-quality.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +import re +import os +import hashlib +import json + + +# 7-bit C1 ANSI sequences +ansi_escape = re.compile(r''' + \x1B # ESC + (?: # 7-bit C1 Fe (except CSI) + [@-Z\\-_] + | # or [ for CSI, followed by a control sequence + \[ + [0-?]* # Parameter bytes + [ -/]* # Intermediate bytes + [@-~] # Final byte + ) +''', re.VERBOSE) + +re_log_parse = re.compile( + r'(?P.*\.(cc|hh)):(?P[0-9]+):(?P[0-9]+): warning: (?P.*) \[(?P.*)\]' # noqa +) + + +categories = { + "bugprone": "Bug Risk", + "modernize": "Clarity", + "mpi": "Bug Risk", + "openmp": "Bug Risk", + "performance": "Performance", + "readability": "Clarity", +} + +issues = [] + +with open('clang-tidy-all-out.log', 'r') as log: + for line in log: + clean_line = ansi_escape.sub('', line) + match = re_log_parse.match(clean_line) + if match: + line_dict = match.groupdict() + line_dict['file'] = os.path.relpath(line_dict['file']) + + line_dict['fingerprint'] = hashlib.md5( + '{file}:{line}:{column}:{type}'.format(**line_dict).encode() + ).hexdigest() + + issue = { + 'type': 'issue', + 'description': line_dict['detail'], + 'fingerprint': line_dict['fingerprint'], + 'location': { + "path": line_dict['file'], + "lines": { + "begin": { + "line": int(line_dict['line']), + "column": int(line_dict['column']), + }, + } + }, + 'severity': 'minor', + } + + category = line_dict['type'].split('-')[0] + if category in categories: + issue['category'] = categories[category] + + issues.append(issue) + +with open('code-quality-clang.json', 'w') as jsoncq: + json.dump(issues, jsoncq)