Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# covr (development version)

* Performance improvement for compiled code with a lot of compilation units (@krlmlr, #611)

* Messages are now displayed using cli instead of crayon (@olivroy, #591).

* covr now uses `testthat::with_mocked_bindings()` for its internal testing (@olivroy, #595).
Expand Down
41 changes: 36 additions & 5 deletions R/compiled.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,58 @@ run_gcov <- function(path, quiet = TRUE, clean = TRUE,
return()
}

gcov_inputs <- list.files(path, pattern = rex::rex(".gcno", end), recursive = TRUE, full.names = TRUE)
withr::local_dir(src_path)

gcov_inputs <- list.files(".", pattern = rex::rex(".gcno", end), recursive = TRUE, full.names = TRUE)

if (!nzchar(gcov_path)) {
if (length(gcov_inputs)) stop('gcov not found')
return()
}

run_gcov_one <- function(src) {
system_check(gcov_path,
args = c(gcov_args, src, "-p", "-o", dirname(src)),
quiet = quiet, echo = !quiet)
gcov_outputs <- list.files(path, pattern = rex::rex(".gcov", end), recursive = TRUE, full.names = TRUE)
gcov_outputs <- list.files(".", pattern = rex::rex(".gcov", end), recursive = TRUE, full.names = TRUE)

if (!quiet) {
message("gcov output for ", src, ":")
message(paste(gcov_outputs, collapse = "\n"))
}

if (clean) {
on.exit(unlink(gcov_outputs))
} else {
gcov_output_base <- file.path("..", "covr", src)
gcov_output_targets <- sub(".", gcov_output_base, gcov_outputs)

if (!quiet) {
message("gcov output targets for ", src, ":")
message(paste(gcov_output_targets, collapse = "\n"))
}

lapply(
unique(dirname(gcov_output_targets)),
function(.x) dir.create(.x, recursive = TRUE, showWarnings = FALSE)
)

on.exit({
if (!quiet) {
message("Moving gcov outputs to covr directory.\n")
}
file.rename(gcov_outputs, gcov_output_targets)
})
}

unlist(lapply(gcov_outputs, parse_gcov, package_path = c(path, getOption("covr.gcov_additional_paths", NULL))), recursive = FALSE)
}

res <- withr::with_dir(src_path, {
compact(unlist(lapply(gcov_inputs, run_gcov_one), recursive = FALSE))
})
res <- compact(unlist(lapply(gcov_inputs, run_gcov_one), recursive = FALSE))

if (!length(res) && length(gcov_inputs))
warning('parsed gcov output was empty')

res
}

Expand Down