From b6cbb101dc6a3953195f4c4e8abb98beac4471c3 Mon Sep 17 00:00:00 2001 From: Lars Bilke Date: Thu, 26 Oct 2023 13:04:07 +0200 Subject: [PATCH 1/6] [cmake] Don't find venvs in sibling build dirs on mac. --- scripts/cmake/PythonCreateVirtualEnv.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/cmake/PythonCreateVirtualEnv.cmake b/scripts/cmake/PythonCreateVirtualEnv.cmake index 2769a0afad5..9e62605c962 100644 --- a/scripts/cmake/PythonCreateVirtualEnv.cmake +++ b/scripts/cmake/PythonCreateVirtualEnv.cmake @@ -2,12 +2,12 @@ message(STATUS "┌─ PythonCreateVirtualEnv.cmake") list(APPEND CMAKE_MESSAGE_INDENT "│ ") -# Prefer unix location over frameworks (Apple-only) -set(Python_FIND_FRAMEWORK LAST) - # Prefer more recent Python version set(Python_FIND_STRATEGY VERSION) +# Don't use venv +set(Python_FIND_VIRTUALENV STANDARD) + find_package(Python ${python_version} COMPONENTS Interpreter REQUIRED) if(${Python_VERSION} VERSION_GREATER_EQUAL 3.9) From e5eb7eaf485680c6c47b47fafeb273c49c7ad2d5 Mon Sep 17 00:00:00 2001 From: Lars Bilke Date: Thu, 26 Oct 2023 13:08:14 +0200 Subject: [PATCH 2/6] [cmake] Refactored coverage. - uses gcovr only - implementation based on Prof. CMake 16th Edition by Craig Scott --- CMakeLists.txt | 4 +- CMakePresets.json | 1 - scripts/ci/jobs/code-coverage.yml | 27 ++---- scripts/cmake/Coverage.cmake | 144 ++++++++---------------------- scripts/cmake/gcovr.cfg.in | 7 ++ 5 files changed, 54 insertions(+), 129 deletions(-) create mode 100644 scripts/cmake/gcovr.cfg.in diff --git a/CMakeLists.txt b/CMakeLists.txt index c38d3ace083..c1de517d7af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,9 +97,7 @@ if(OGS_USE_CONAN AND OGS_USE_NETCDF) endif() include(DocumentationSetup) include(test/Test) -if(OGS_COVERAGE AND NOT _IS_SUBPROJECT) - include(Coverage) -endif() +include(Coverage) include(CppCheck) # ---- More Options ---- diff --git a/CMakePresets.json b/CMakePresets.json index 99becffebab..e983c4b7cd1 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -168,7 +168,6 @@ "debug" ], "cacheVariables": { - "CODE_COVERAGE_VERBOSE": "ON", "OGS_COVERAGE": "ON", "OGS_CTEST_MAX_RUNTIME": "5", "OGS_USE_MFRONT": "ON" diff --git a/scripts/ci/jobs/code-coverage.yml b/scripts/ci/jobs/code-coverage.yml index 57415adf66a..2897757a48b 100644 --- a/scripts/ci/jobs/code-coverage.yml +++ b/scripts/ci/jobs/code-coverage.yml @@ -2,39 +2,28 @@ code coverage: stage: check extends: - .template-build-linux - tags: [shell, envinf] + tags: [shell, envinf23] needs: [meta] variables: CMAKE_PRESET: coverage - TARGETS: "testrunner_coverage ctest_coverage" - # default python on arch is 3.10; there are no vtk wheels for it (VTUInterface) + TARGETS: "tests ctest" CMAKE_ARGS: >- -DOGS_USE_PIP=ON -DBUILD_SHARED_LIBS=ON after_script: - - cd ../build/coverage - - source .venv/bin/activate - - fastcov --branch-coverage -C testrunner_coverage.info ctest_coverage.info --lcov -o coverage.info - - fastcov --branch-coverage -C testrunner_coverage.info ctest_coverage.info -o coverage.json - - genhtml --branch-coverage --demangle-cpp -o coverage_report coverage.info - - wget https://raw.github.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py - - python lcov_cobertura.py coverage.info --base-dir $CI_PROJECT_DIR - - ./generate_coverage_vis_data.py - coverage: '/lines......: \d+\.\d+/' + - cmake --build --preset $CMAKE_PRESET -t process_coverage + coverage: '/lines: \d+\.\d+/' artifacts: when: always paths: - - Coverage.html - - build/coverage/coverage_report - - build/coverage/coverage.json - - build/coverage/coverage.xml - - build/coverage/coverage_reports/*.json + - build/coverage/coverage/html + - build/coverage/coverage/coverage.xml - build/coverage/logs/*.txt expire_in: 1 week reports: coverage_report: coverage_format: cobertura - path: build/coverage/coverage.xml + path: build/coverage/coverage/cobertura.xml environment: name: code coverage $CI_MERGE_REQUEST_IID - url: ${ARTIFACTS_PAGES_URL}/build/coverage/coverage_report/index.html + url: ${ARTIFACTS_PAGES_URL}/build/coverage/coverage/html/index.html diff --git a/scripts/cmake/Coverage.cmake b/scripts/cmake/Coverage.cmake index 506fbd71cda..a7171a27696 100644 --- a/scripts/cmake/Coverage.cmake +++ b/scripts/cmake/Coverage.cmake @@ -1,116 +1,48 @@ -find_program(FASTCOV_PATH NAMES fastcov fastcov.py) -if(NOT FASTCOV_PATH AND NOT OGS_USE_PIP) - message( - FATAL_ERROR "Code coverage requires either fastcov or OGS_USE_PIP=ON." +if(NOT (OGS_COVERAGE AND PROJECT_IS_TOP_LEVEL)) + return() +endif() + +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + set(CMAKE_CXX_FLAGS_DEBUG "-g -Og --coverage") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fprofile-abs-path") + endif() + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "--coverage") + set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "--coverage") + set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "--coverage") +else() + message(FATAL_ERROR "OGS_COVERAGE requires clang or gcc compiler!") +endif() + +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + execute_process( + COMMAND xcrun --find gcov OUTPUT_VARIABLE GCOV_EXECUTABLE + OUTPUT_STRIP_TRAILING_WHITESPACE ) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + find_program(LLVM_COV_EXECUTABLE llvm-cov REQUIRED) + file(CREATE_LINK ${LLVM_COV_EXECUTABLE} ${CMAKE_BINARY_DIR}/gcov SYMBOLIC) + set(GCOV_EXECUTABLE "${LLVM_COV_EXECUTABLE} gcov") +else() # Assuming gcc for this example + find_program(GCOV_EXECUTABLE gcov REQUIRED) endif() +configure_file(scripts/cmake/gcovr.cfg.in gcovr.cfg @ONLY) -# cmake-lint: disable=E1126 - -# https://github.com/linux-test-project/lcov/pull/125 -if(APPLE) - set(GENHTML_PATH ${PROJECT_BINARY_DIR}/bin/genhtml) - file( - DOWNLOAD - https://raw.githubusercontent.com/linux-test-project/lcov/41d8655951d6898511f98be2a2dbcfbe662f0b17/bin/genhtml - ${GENHTML_PATH} - ) - file( - DOWNLOAD - https://raw.githubusercontent.com/linux-test-project/lcov/41d8655951d6898511f98be2a2dbcfbe662f0b17/bin/get_version.sh - ${PROJECT_BINARY_DIR}/bin/get_version.sh - ) - file( - CHMOD - ${GENHTML_PATH} - ${PROJECT_BINARY_DIR}/bin/get_version.sh - FILE_PERMISSIONS - OWNER_READ - OWNER_WRITE - OWNER_EXECUTE - ) -endif() - -include(CodeCoverage) -append_coverage_compiler_flags() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og") - -# cmake-lint: disable=C0103 -if(NOT FASTCOV_PATH) - list(APPEND OGS_PYTHON_PACKAGES "fastcov==1.14") - set(FASTCOV_PATH ${LOCAL_VIRTUALENV_BIN_DIR}/fastcov CACHE INTERNAL "") +find_program(GCOVR_EXECUTABLE NAMES gcovr) +if(NOT GCOVR_EXECUTABLE) + list(APPEND OGS_PYTHON_PACKAGES "gcovr==6.0") + set(GCOVR_EXECUTABLE ${LOCAL_VIRTUALENV_BIN_DIR}/gcovr CACHE PATH "" FORCE) endif() -if(DEFINED ENV{CI}) - set(COVERAGE_ADDITIONAL_ARGS SKIP_HTML) -endif() +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/coverage/html) -if(APPLE) - # System gcov does not work: - # https://github.com/RPGillespie6/fastcov/issues/36. Search for Homebrew - # installed gcov (included in gcc package). - find_program( - GCOV_PATH NAMES gcov-12 gcov-11 gcov-10 HINTS $ENV{HOMEBREW_PREFIX}/bin - REQUIRED - ) -endif() - -if(OGS_BUILD_TESTING) - setup_target_for_coverage_fastcov( - NAME - testrunner_coverage - BASE_DIRECTORY - ${PROJECT_BINARY_DIR} - EXECUTABLE - $ - -l - warn - --gtest_filter=-GeoLib.SearchNearestPointsInDenseGrid - DEPENDENCIES - testrunner - FASTCOV_ARGS - --branch-coverage - --include - ${PROJECT_SOURCE_DIR} - ${COVERAGE_ADDITIONAL_ARGS} - EXCLUDE - Applications/CLI/ - ProcessLib/ - ) -endif() - -if(OGS_BUILD_CLI) - setup_target_for_coverage_fastcov( - NAME - ctest_coverage - BASE_DIRECTORY - ${PROJECT_BINARY_DIR} - EXECUTABLE - ctest - DEPENDENCIES - all - FASTCOV_ARGS - --branch-coverage - --include - ${PROJECT_SOURCE_DIR} - ${COVERAGE_ADDITIONAL_ARGS} - EXCLUDE - Applications/CLI/ - POST_CMD - perl - -i - -pe - s!${PROJECT_SOURCE_DIR}/!!g - ctest_coverage.json - NO_DEMANGLE - ) -endif() +add_custom_target( + process_coverage + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Running gcovr to process coverage results" + COMMAND ${GCOVR_EXECUTABLE} --config gcovr.cfg . +) if(UNIX) add_custom_target(clean_coverage find . -name '*.gcda' -delete) endif() - -configure_file( - ${PROJECT_SOURCE_DIR}/scripts/test/generate_coverage_vis_data.in.py - ${PROJECT_BINARY_DIR}/generate_coverage_vis_data.py @ONLY -) diff --git a/scripts/cmake/gcovr.cfg.in b/scripts/cmake/gcovr.cfg.in new file mode 100644 index 00000000000..ca16c406613 --- /dev/null +++ b/scripts/cmake/gcovr.cfg.in @@ -0,0 +1,7 @@ +root = @CMAKE_SOURCE_DIR@ +cobertura = @CMAKE_BINARY_DIR@/coverage/cobertura.xml +# html-nested shows wrong paths: build/coverage/[DIR] +html-details = @CMAKE_BINARY_DIR@/coverage/html/index.html +gcov-executable = @GCOV_EXECUTABLE@ +gcov-parallel = yes +print-summary = yes \ No newline at end of file From 4967d95ee3761ad33b39f0da64c66eb081bdf17e Mon Sep 17 00:00:00 2001 From: Lars Bilke Date: Thu, 26 Oct 2023 13:13:03 +0200 Subject: [PATCH 3/6] [cmake] Remove bilke/cmake-modules dependency. --- scripts/cmake/CMakeSetup.cmake | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/scripts/cmake/CMakeSetup.cmake b/scripts/cmake/CMakeSetup.cmake index c4934c16b57..5d8999825a3 100644 --- a/scripts/cmake/CMakeSetup.cmake +++ b/scripts/cmake/CMakeSetup.cmake @@ -23,14 +23,7 @@ if(EXISTS ${_collection}/ufz/vtkdiff/CMakeLists.txt AND GUIX_BUILD) include(${_collection}/Setup.cmake) endif() -# Set additional CMake modules path -CPMAddPackage( - NAME cmake-modules - GITHUB_REPOSITORY bilke/cmake-modules - GIT_TAG d98828f54f6974717798e63195cfbf08fe2daad0 - DOWNLOAD_ONLY YES -) -# To be replaced later. See +# Set additional CMake modules path To be replaced later. See # https://gitlab.kitware.com/cmake/cmake/-/issues/22831 CPMAddPackage( NAME findmkl_cmake @@ -44,7 +37,6 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/scripts/cmake/jedbrown" "${PROJECT_SOURCE_DIR}/scripts/cmake/vector-of-bool" "${findmkl_cmake_SOURCE_DIR}/cmake" - "${cmake-modules_SOURCE_DIR}" ) list( From 765fad69c716a08c304e711f4e1e0e6754d7a0b8 Mon Sep 17 00:00:00 2001 From: Lars Bilke Date: Thu, 26 Oct 2023 13:15:48 +0200 Subject: [PATCH 4/6] [cmake] Remove variable _IS_SUBPROJECT (use PROJECT_IS_TOP_LEVEL instead). --- Applications/CMakeLists.txt | 4 ++-- CMakeLists.txt | 2 +- scripts/cmake/CMakeSetup.cmake | 4 +--- scripts/cmake/packaging/Pack.cmake | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Applications/CMakeLists.txt b/Applications/CMakeLists.txt index 209135a39f0..2ff44d65b13 100644 --- a/Applications/CMakeLists.txt +++ b/Applications/CMakeLists.txt @@ -2,11 +2,11 @@ add_subdirectory(ApplicationsLib) add_subdirectory(DataHolderLib) add_subdirectory(FileIO) -if(OGS_BUILD_UTILS AND NOT _IS_SUBPROJECT) +if(OGS_BUILD_UTILS AND PROJECT_IS_TOP_LEVEL) add_subdirectory(Utils) elseif(OGS_BUILD_GUI) add_subdirectory(Utils/OGSFileConverter) -endif() # OGS_BUILD_UTILS AND NOT _IS_SUBPROJECT +endif() if(OGS_BUILD_GUI) add_subdirectory(DataExplorer) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1de517d7af..2b85cfcc8e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -228,7 +228,7 @@ if(OGS_BUILD_CLI OR OGS_BUILD_UTILS OR OGS_BUILD_TESTING) add_subdirectory(ProcessLib) add_subdirectory(Tests/xdmfdiff) endif() -if(OGS_BUILD_TESTING AND NOT _IS_SUBPROJECT) +if(OGS_BUILD_TESTING AND PROJECT_IS_TOP_LEVEL) add_subdirectory(Tests) endif() diff --git a/scripts/cmake/CMakeSetup.cmake b/scripts/cmake/CMakeSetup.cmake index 5d8999825a3..733d133d0ea 100644 --- a/scripts/cmake/CMakeSetup.cmake +++ b/scripts/cmake/CMakeSetup.cmake @@ -53,9 +53,7 @@ include(ProcessorCount) ProcessorCount(NUM_PROCESSORS) set(NUM_PROCESSORS ${NUM_PROCESSORS} CACHE STRING "Processor count") -# Check if this project is included in another -if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(_IS_SUBPROJECT ON CACHE INTERNAL "" FORCE) +if(NOT PROJECT_IS_TOP_LEVEL) set(OGS_BUILD_CLI OFF CACHE BOOL "" FORCE) endif() diff --git a/scripts/cmake/packaging/Pack.cmake b/scripts/cmake/packaging/Pack.cmake index 5aedf2ea139..e3359bd3c7d 100644 --- a/scripts/cmake/packaging/Pack.cmake +++ b/scripts/cmake/packaging/Pack.cmake @@ -1,4 +1,4 @@ -if(_IS_SUBPROJECT) +if(NOT PROJECT_IS_TOP_LEVEL) include(CPack) return() endif() From a8c26ad98cf769a855b575d75e61983a65c162b7 Mon Sep 17 00:00:00 2001 From: Lars Bilke Date: Thu, 26 Oct 2023 13:19:00 +0200 Subject: [PATCH 5/6] Removed bilke/cmake-modules from ThirdParty/collection submodule. --- ThirdParty/collection | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ThirdParty/collection b/ThirdParty/collection index 5949ed1c39a..b2463383eb2 160000 --- a/ThirdParty/collection +++ b/ThirdParty/collection @@ -1 +1 @@ -Subproject commit 5949ed1c39a2b3b2a04ac56e97a012806e7c3917 +Subproject commit b2463383eb2925131842c02cb78c6b1afd6f52a3 From 4d0e5818cddd539094c4d1ce6968962365417662 Mon Sep 17 00:00:00 2001 From: project_120_bot2 Date: Thu, 26 Oct 2023 11:35:04 +0000 Subject: [PATCH 6/6] [versions] Updated cpm cache info. --- web/data/versions.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/data/versions.json b/web/data/versions.json index 69e74d3bfa4..0685f0472e0 100644 --- a/web/data/versions.json +++ b/web/data/versions.json @@ -72,8 +72,8 @@ } }, "cpm": { - "package_file_id": 1028, - "package_file_sha256": "815ef4ca37e05232526afe50e3eafe8a1d6366bce3ae3d509fac1214ab6b5f98" + "package_file_id": 1029, + "package_file_sha256": "baca0a575a0c7053e4c7a5bffb32bb30d8dce0ae97308858b3bf8a690063b303" }, "ext": { "cache_hash": "4ebd62e0ce484732dbf3cd9932f60b67762e156b"