Skip to content

Commit b8bd1ab

Browse files
author
Tamas Vajk
committed
Handle zero profraw files gracefully in coverage collection
When a test target is not instrumented (e.g. due to --instrumentation_filter), no .profraw files are produced. Previously llvm-profdata merge would fail with "no input files specified". Write an empty coverage file and exit successfully instead, so that uninstrumented test targets don't break coverage collection.
1 parent 3c19d3d commit b8bd1ab

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

util/collect_coverage/collect_coverage.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ fn main() {
166166
})
167167
.collect();
168168

169+
// No profraw files means no instrumented code ran (e.g. a test target
170+
// that wasn't instrumented due to --instrumentation_filter). Write an
171+
// empty coverage file and exit successfully.
172+
if profraw_files.is_empty() {
173+
debug_log!("No profraw files found, writing empty coverage output");
174+
fs::write(&coverage_output_file, "").expect("Failed to write empty coverage file");
175+
process::exit(0);
176+
}
177+
169178
let mut llvm_profdata_cmd = process::Command::new(llvm_profdata);
170179
llvm_profdata_cmd
171180
.arg("merge")

0 commit comments

Comments
 (0)