-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'coverage-refactor' into 'master'
[cmake] Refactored coverage. See merge request ogs/ogs!4776
- Loading branch information
Showing
11 changed files
with
66 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule collection
updated
from 5949ed to b24633
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
$<TARGET_FILE:testrunner> | ||
-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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
if(_IS_SUBPROJECT) | ||
if(NOT PROJECT_IS_TOP_LEVEL) | ||
include(CPack) | ||
return() | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters