Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relative paths #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions cmake/CoverallsGenerateGcov.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# SOFTWARE.
#
# Copyright (C) 2014 Joakim Söderberg <[email protected]>
# Copyright (C) 2017 Kamil Strzempowicz <[email protected]>
#
# This is intended to be run by a custom target in a CMake project like this.
# 0. Compile program with coverage support.
Expand Down Expand Up @@ -160,7 +161,7 @@ endif()
#
# /path/to/project/root/subdir/the_file.c
#
macro(get_source_path_from_gcov_filename _SRC_FILENAME _GCOV_FILENAME)
macro(get_source_path_from_gcov_filename _GCOV_SRC_ABS_PATH _GCOV_FILENAME)

# /path/to/project/root/build/#path#to#project#root#subdir#the_file.c.gcov
# ->
Expand All @@ -170,7 +171,16 @@ macro(get_source_path_from_gcov_filename _SRC_FILENAME _GCOV_FILENAME)
# #path#to#project#root#subdir#the_file.c.gcov -> /path/to/project/root/subdir/the_file.c
string(REGEX REPLACE "\\.gcov$" "" SRC_FILENAME_TMP ${_GCOV_FILENAME_WEXT})
string(REGEX REPLACE "\#" "/" SRC_FILENAME_TMP ${SRC_FILENAME_TMP})
set(${_SRC_FILENAME} "${SRC_FILENAME_TMP}")

if(${SRC_FILENAME_TMP} MATCHES "^\\/.*")
set(GCOV_SRC_ABS_PATH "${SRC_FILENAME_TMP}")
else()
if(${SRC_FILENAME_TMP} MATCHES "\\^.*")
string(REGEX REPLACE "\\^" ".." SRC_FILENAME_TMP "${SRC_FILENAME_TMP}")
endif()
get_filename_component(GCOV_SRC_ABS_PATH "${SRC_FILENAME_TMP}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
endif()
set(${_GCOV_SRC_ABS_PATH} "${GCOV_SRC_ABS_PATH}")
endmacro()

##############################################################################
Expand Down Expand Up @@ -250,12 +260,16 @@ foreach (GCOV_FILE ${ALL_GCOV_FILES})
# /path/to/project/root/build/#path#to#project#root#subdir#the_file.c.gcov
# ->
# /path/to/project/root/subdir/the_file.c
get_source_path_from_gcov_filename(GCOV_SRC_PATH ${GCOV_FILE})
file(RELATIVE_PATH GCOV_SRC_REL_PATH "${PROJECT_ROOT}" "${GCOV_SRC_PATH}")
get_source_path_from_gcov_filename(GCOV_SRC_ABS_PATH ${GCOV_FILE})
if(${GCOV_SRC_ABS_PATH} MATCHES "^\\/usr\\/.*")
file(REMOVE "${GCOV_FILE}")
message("Removing system file from list: ${GCOV_FILE}")
continue()
endif()

# Is this in the list of source files?
# TODO: We want to match against relative path filenames from the source file root...
list(FIND COVERAGE_SRCS ${GCOV_SRC_PATH} WAS_FOUND)
list(FIND COVERAGE_SRCS_REMAINING ${GCOV_SRC_ABS_PATH} WAS_FOUND)

if (NOT WAS_FOUND EQUAL -1)
message("YES: ${GCOV_FILE}")
Expand All @@ -264,7 +278,11 @@ foreach (GCOV_FILE ${ALL_GCOV_FILES})
# We remove it from the list, so we don't bother searching for it again.
# Also files left in COVERAGE_SRCS_REMAINING after this loop ends should
# have coverage data generated from them (no lines are covered).
list(REMOVE_ITEM COVERAGE_SRCS_REMAINING ${GCOV_SRC_PATH})
list(REMOVE_ITEM COVERAGE_SRCS_REMAINING ${GCOV_SRC_ABS_PATH})
if(NOT COVERAGE_SRCS_REMAINING)
log("All files covered")
break()
endif()
else()
message("NO: ${GCOV_FILE}")
endif()
Expand Down Expand Up @@ -448,7 +466,7 @@ foreach(NOT_COVERED_SRC ${COVERAGE_SRCS_REMAINING})
set(GCOV_FILE_SOURCE "")

foreach (SOURCE ${SRC_LINES})
set(GCOV_FILE_COVERAGE "${GCOV_FILE_COVERAGE}null, ")
set(GCOV_FILE_COVERAGE "${GCOV_FILE_COVERAGE}0, ")

string(REPLACE "\\" "\\\\" SOURCE "${SOURCE}")
string(REGEX REPLACE "\"" "\\\\\"" SOURCE "${SOURCE}")
Expand Down Expand Up @@ -477,6 +495,5 @@ string(CONFIGURE ${JSON_TEMPLATE} JSON)

file(WRITE "${COVERALLS_OUTPUT_FILE}" "${JSON}")
message("###########################################################################")
message("Generated coveralls JSON containing coverage data:")
message("${COVERALLS_OUTPUT_FILE}")
message("Generated coveralls JSON containing coverage data: ${COVERALLS_OUTPUT_FILE}")
message("###########################################################################")