@@ -72,27 +72,55 @@ run_gcov <- function(path, quiet = TRUE, clean = TRUE,
7272 return ()
7373 }
7474
75- gcov_inputs <- list.files(path , pattern = rex :: rex(" .gcno" , end ), recursive = TRUE , full.names = TRUE )
75+ res <- withr :: local_dir(src_path )
76+
77+ gcov_inputs <- list.files(" ." , pattern = rex :: rex(" .gcno" , end ), recursive = TRUE , full.names = TRUE )
78+
7679 if (! nzchar(gcov_path )) {
7780 if (length(gcov_inputs )) stop(' gcov not found' )
7881 return ()
7982 }
83+
8084 run_gcov_one <- function (src ) {
8185 system_check(gcov_path ,
8286 args = c(gcov_args , src , " -p" , " -o" , dirname(src )),
8387 quiet = quiet , echo = ! quiet )
84- gcov_outputs <- list.files(path , pattern = rex :: rex(" .gcov" , end ), recursive = TRUE , full.names = TRUE )
88+ gcov_outputs <- list.files(" ." , pattern = rex :: rex(" .gcov" , end ), recursive = TRUE , full.names = TRUE )
89+
90+ if (! quiet ) {
91+ writeLines(paste0(" gcov output for " , src , " :" ))
92+ writeLines(gcov_outputs )
93+ }
94+
8595 if (clean ) {
8696 on.exit(unlink(gcov_outputs ))
97+ } else {
98+ gcov_output_base <- file.path(" .." , " covr" , src )
99+ gcov_output_targets <- sub(" ." , gcov_output_base , gcov_outputs )
100+
101+ if (! quiet ) {
102+ writeLines(paste0(" gcov output targets for " , src , " :" ))
103+ writeLines(gcov_output_targets )
104+ }
105+
106+ lapply(
107+ unique(dirname(gcov_output_targets )),
108+ function (.x ) dir.create(.x , recursive = TRUE , showWarnings = FALSE )
109+ )
110+
111+ on.exit({
112+ file.rename(gcov_outputs , gcov_output_targets )
113+ })
87114 }
115+
88116 unlist(lapply(gcov_outputs , parse_gcov , package_path = c(path , getOption(" covr.gcov_additional_paths" , NULL ))), recursive = FALSE )
89117 }
90118
91- res <- withr :: with_dir(src_path , {
92- compact(unlist(lapply(gcov_inputs , run_gcov_one ), recursive = FALSE ))
93- })
119+ res <- compact(unlist(lapply(gcov_inputs , run_gcov_one ), recursive = FALSE ))
120+
94121 if (! length(res ) && length(gcov_inputs ))
95122 warning(' parsed gcov output was empty' )
123+
96124 res
97125}
98126
0 commit comments