@@ -72,27 +72,55 @@ run_gcov <- function(path, quiet = TRUE, clean = TRUE,
72
72
return ()
73
73
}
74
74
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
+
76
79
if (! nzchar(gcov_path )) {
77
80
if (length(gcov_inputs )) stop(' gcov not found' )
78
81
return ()
79
82
}
83
+
80
84
run_gcov_one <- function (src ) {
81
85
system_check(gcov_path ,
82
86
args = c(gcov_args , src , " -p" , " -o" , dirname(src )),
83
87
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
+
85
95
if (clean ) {
86
96
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
+ })
87
114
}
115
+
88
116
unlist(lapply(gcov_outputs , parse_gcov , package_path = c(path , getOption(" covr.gcov_additional_paths" , NULL ))), recursive = FALSE )
89
117
}
90
118
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
+
94
121
if (! length(res ) && length(gcov_inputs ))
95
122
warning(' parsed gcov output was empty' )
123
+
96
124
res
97
125
}
98
126
0 commit comments