wasmcov/
report.rs

1use crate::llvm;
2use crate::utils::run_command;
3
4use anyhow::Result;
5
6use glob::glob;
7use std::path::PathBuf;
8
9pub fn merge_profraw_to_profdata(profraw_dir: &PathBuf, profdata_path: &PathBuf, extra_args: Vec<String>) -> Result<()> {
10    // find all .profraw files in the profraw directory
11    let profraw_files: Vec<String> = glob(profraw_dir.join("*.profraw").to_str().unwrap())?
12        .filter_map(|entry| entry.ok())
13        .map(|path| path.to_string_lossy().into_owned())
14        .collect();
15
16    // Prepare the command arguments
17    let mut args = vec![
18        "merge".to_string(),
19        "-sparse".to_string(),
20        "-o".to_string(),
21        profdata_path.to_str().unwrap().to_string(),
22    ];
23    args.extend(extra_args);
24    args.extend(profraw_files);
25
26    // Run the command
27    run_command(
28        &llvm::get_tooling()?.llvm_profdata,
29        args.as_slice()
30            .iter()
31            .map(AsRef::as_ref)
32            .collect::<Vec<&str>>()
33            .as_slice(),
34        None,
35    )?;
36
37    Ok(())
38}
39
40pub fn generate_report(
41    profdata_path: &PathBuf,
42    object_file: &PathBuf,
43    report_dir: &PathBuf,
44    llvm_cov_args: &Vec<String>,
45) -> Result<()> {
46    let mut cov_args = vec![
47        "show",
48        "--instr-profile",
49        profdata_path.to_str().unwrap(),
50        object_file.to_str().unwrap(),
51        "--output-dir",
52        report_dir.to_str().unwrap(),
53        "--show-instantiations=false",
54        "--format=html",
55        "-show-directory-coverage",
56    ];
57    cov_args.extend(
58        llvm_cov_args
59            .as_slice()
60            .iter()
61            .map(AsRef::as_ref)
62            .collect::<Vec<&str>>()
63            .as_slice(),
64    );
65    run_command(&llvm::get_tooling()?.llvm_cov, cov_args.as_slice(), None)?;
66    Ok(())
67}