Skip to content

Commit

Permalink
Merge pull request #425 from seoklab/build/clean-gcda
Browse files Browse the repository at this point in the history
build: cleanup stale coverage data before linking
  • Loading branch information
jnooree authored Dec 5, 2024
2 parents af02dfc + 4c81aa8 commit 8b2ee8a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
21 changes: 21 additions & 0 deletions cmake/NuriKitClearCoverage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Project NuriKit - Copyright 2024 SNU Compbio Lab.
# SPDX-License-Identifier: Apache-2.0
#

if(NOT CMAKE_SCRIPT_MODE_FILE)
message(WARNING "This file must be executed with CMake in script mode, not included with include() or add_subdirectory().")
return()
endif()

if(NOT NURI_COVERAGE_DATA_DIR)
message(FATAL_ERROR "No parent directory provided.")
endif()

file(GLOB_RECURSE nuri_gcda LIST_DIRECTORIES OFF "${NURI_COVERAGE_DATA_DIR}/*.gcda")

if(nuri_gcda)
list(LENGTH nuri_gcda nuri_gcda_count)
message(NOTICE "Removing ${nuri_gcda_count} gcda files in ${NURI_COVERAGE_DATA_DIR}")
file(REMOVE ${nuri_gcda})
endif()
8 changes: 4 additions & 4 deletions cmake/NuriKitClearStubs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ if(NOT CMAKE_SCRIPT_MODE_FILE)
return()
endif()

if(NOT CMAKE_ARGV1)
if(NOT NURI_STUBS_DIR)
message(FATAL_ERROR "No parent directory provided.")
endif()

file(GLOB_RECURSE nuri_stubs LIST_DIRECTORIES OFF "${CMAKE_ARGV1}/*.pyi")
file(GLOB_RECURSE nuri_stubs LIST_DIRECTORIES OFF "${NURI_STUBS_DIR}/*.pyi")

if(nuri_stubs)
list(JOIN nuri_stubs ", \n" nuri_stubs_msg)
message(NOTICE "Removing the following stubs:\n${nuri_stubs_msg}")
list(JOIN nuri_stubs "\n\t" nuri_stubs_msg)
message(NOTICE "Removing the following stubs:\n\t${nuri_stubs_msg}")
file(REMOVE ${nuri_stubs})
endif()
5 changes: 3 additions & 2 deletions cmake/NuriKitPythonUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ add_custom_command(
TARGET nuri_python
POST_BUILD
COMMAND "${CMAKE_COMMAND}"
"-DNURI_STUBS_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
-P "${PROJECT_SOURCE_DIR}/cmake/NuriKitClearStubs.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}"
VERBATIM)
VERBATIM
)

find_program(PYBIND11_STUBGEN pybind11-stubgen)
mark_as_advanced(PYBIND11_STUBGEN)
Expand Down
11 changes: 11 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ target_link_libraries(nuri_lib
target_system_include_directories(nuri_lib Eigen3::Eigen Spectra::Spectra)
handle_boost_dependency(nuri_lib)

if(NURI_TEST_COVERAGE)
add_custom_command(
TARGET nuri_lib
PRE_LINK
COMMAND "${CMAKE_COMMAND}"
"-DNURI_COVERAGE_DATA_DIR=${CMAKE_CURRENT_BINARY_DIR}"
-P "${PROJECT_SOURCE_DIR}/cmake/NuriKitClearCoverage.cmake"
VERBATIM
)
endif()

if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND NURI_LIBRARY_FLAGS
-fno-math-errno
Expand Down

0 comments on commit 8b2ee8a

Please sign in to comment.