• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ergrelet / resym / 4337479543

pending completion
4337479543

push

github

ergrelet
Support wasm32-unknown-unknown for resym

94 of 94 new or added lines in 5 files covered. (100.0%)

781 of 2148 relevant lines covered (36.36%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/resym_core/src/diffing.rs
1
#[cfg(target_arch = "wasm32")]
2
use instant::Instant;
3
use similar::{ChangeTag, TextDiff};
4

5
#[cfg(not(target_arch = "wasm32"))]
6
use std::time::Instant;
7
use std::{fmt::Write, io};
8

9
use crate::{
10
    error::{Result, ResymCoreError},
11
    pdb_file::PdbFile,
12
    pdb_types::PrimitiveReconstructionFlavor,
13
    PKG_VERSION,
14
};
15

16
pub type DiffChange = ChangeTag;
17
pub type DiffIndices = (Option<usize>, Option<usize>);
18

19
#[derive(Default)]
20
pub struct DiffedType {
21
    pub metadata: Vec<(DiffIndices, DiffChange)>,
22
    pub data: String,
23
}
24
pub struct DiffLine {
25
    pub indices: DiffIndices,
26
    pub change: DiffChange,
27
    pub line: String,
28
}
29

30
pub fn diff_type_by_name<'p, T>(
1✔
31
    pdb_file_from: &PdbFile<'p, T>,
32
    pdb_file_to: &PdbFile<'p, T>,
33
    type_name: &str,
34
    primitives_flavor: PrimitiveReconstructionFlavor,
35
    print_header: bool,
36
    reconstruct_dependencies: bool,
37
    print_access_specifiers: bool,
38
) -> Result<DiffedType>
39
where
40
    T: io::Seek + io::Read + 'p,
41
{
42
    let diff_start = Instant::now();
1✔
43
    // Prepend header if needed
44
    let (mut reconstructed_type_from, mut reconstructed_type_to) = if print_header {
3✔
45
        let diff_header = generate_diff_header(pdb_file_from, pdb_file_to);
×
46
        (diff_header.clone(), diff_header)
×
47
    } else {
48
        (String::default(), String::default())
1✔
49
    };
50

51
    // Reconstruct type from both PDBs
52
    {
53
        let reconstructed_type_from_tmp = pdb_file_from
2✔
54
            .reconstruct_type_by_name(
55
                type_name,
56
                primitives_flavor,
57
                reconstruct_dependencies,
58
                print_access_specifiers,
59
            )
60
            .unwrap_or_default();
61
        let reconstructed_type_to_tmp = pdb_file_to
2✔
62
            .reconstruct_type_by_name(
63
                type_name,
64
                primitives_flavor,
65
                reconstruct_dependencies,
66
                print_access_specifiers,
67
            )
68
            .unwrap_or_default();
69
        if reconstructed_type_from_tmp.is_empty() && reconstructed_type_to_tmp.is_empty() {
2✔
70
            // Make it obvious an error occured
71
            return Err(ResymCoreError::TypeNameNotFoundError(type_name.to_owned()));
1✔
72
        }
73
        reconstructed_type_from.push_str(&reconstructed_type_from_tmp);
2✔
74
        reconstructed_type_to.push_str(&reconstructed_type_to_tmp);
1✔
75
    }
76

77
    // Diff reconstructed reprensentations
78
    let mut diff_metadata = vec![];
1✔
79
    let mut diff_data = String::default();
1✔
80
    {
81
        let reconstructed_type_diff =
1✔
82
            TextDiff::from_lines(&reconstructed_type_from, &reconstructed_type_to);
83
        for change in reconstructed_type_diff.iter_all_changes() {
3✔
84
            diff_metadata.push(((change.old_index(), change.new_index()), change.tag()));
1✔
85
            let prefix = match change.tag() {
1✔
86
                ChangeTag::Insert => "+",
1✔
87
                ChangeTag::Delete => "-",
1✔
88
                ChangeTag::Equal => " ",
1✔
89
            };
90
            write!(&mut diff_data, "{prefix}{change}")?;
1✔
91
        }
92
    }
93

94
    log::debug!("Type diffing took {} ms", diff_start.elapsed().as_millis());
2✔
95

96
    Ok(DiffedType {
1✔
97
        metadata: diff_metadata,
1✔
98
        data: diff_data,
1✔
99
    })
100
}
101

102
fn generate_diff_header<'p, T>(
×
103
    pdb_file_from: &PdbFile<'p, T>,
104
    pdb_file_to: &PdbFile<'p, T>,
105
) -> String
106
where
107
    T: io::Seek + io::Read + 'p,
108
{
109
    format!(
×
110
        concat!(
111
            "//\n",
112
            "// Showing differences between two PDB files:\n",
113
            "//\n",
114
            "// Reference PDB file: {}\n",
115
            "// Image architecture: {}\n",
116
            "//\n",
117
            "// New PDB file: {}\n",
118
            "// Image architecture: {}\n",
119
            "//\n",
120
            "// Information extracted with resym v{}\n",
121
            "//\n"
122
        ),
123
        pdb_file_from.file_path.display(),
×
124
        pdb_file_from.machine_type,
125
        pdb_file_to.file_path.display(),
×
126
        pdb_file_to.machine_type,
127
        PKG_VERSION,
128
    )
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc