| 161 | } |
| 162 | |
| 163 | fn generate_report(llvm_cov: &Path, binaries: &[String], profdata_file: &Path, report_dir: &Path) { |
| 164 | eprintln!("=== Generating HTML coverage report ==="); |
| 165 | if report_dir.exists() { |
| 166 | fs::remove_dir_all(report_dir).expect("failed to clean report dir"); |
| 167 | } |
| 168 | |
| 169 | let mut cmd = Command::new(llvm_cov); |
| 170 | cmd.arg("show") |
| 171 | .arg("--format=html") |
| 172 | .arg(format!("--output-dir={}", report_dir.display())) |
| 173 | .arg("--ignore-filename-regex=/.cargo/registry") |
| 174 | .arg("--ignore-filename-regex=/rustc/") |
| 175 | .arg("--ignore-filename-regex=/.rustup/") |
| 176 | .arg(format!("--instr-profile={}", profdata_file.display())) |
| 177 | .arg("--show-line-counts-or-regions") |
| 178 | .arg("--show-instantiations") |
| 179 | .arg("--show-region-summary") |
| 180 | .arg("--show-branch-summary"); |
| 181 | |
| 182 | cmd.arg(&binaries[0]); |
| 183 | for b in &binaries[1..] { |
| 184 | cmd.arg("--object").arg(b); |
| 185 | } |
| 186 | |
| 187 | if has_command("rustfilt") { |
| 188 | cmd.arg("-Xdemangler=rustfilt"); |
| 189 | } |
| 190 | |
| 191 | let status = cmd.status().expect("failed to run llvm-cov"); |
| 192 | if !status.success() { |
| 193 | eprintln!("llvm-cov show failed with {status}"); |
| 194 | std::process::exit(1); |
| 195 | } |
| 196 | |
| 197 | eprintln!( |
| 198 | "=== Coverage report written to {}/index.html ===", |
| 199 | report_dir.display() |
| 200 | ); |
| 201 | } |
| 202 | |
| 203 | fn find_repo_root() -> PathBuf { |
| 204 | let mut dir = env::current_dir().expect("failed to get cwd"); |