rapx/analysis/unsafety_isolation/
draw_dot.rs

1use std::fs::{File, remove_file};
2use std::io::Write;
3use std::process::Command;
4
5// please ensure 'graphviz' has been installed
6pub fn render_dot_graphs(dot_graphs: Vec<(String, String)>) {
7    Command::new("mkdir")
8        .args(["UPG"])
9        .output()
10        .expect("Failed to create directory");
11
12    for (_index, dot) in dot_graphs.into_iter().enumerate() {
13        let file_name = format!("{}.dot", dot.0);
14        let mut file = File::create(&file_name).expect("Unable to create file");
15        file.write_all(dot.1.as_bytes())
16            .expect("Unable to write data");
17
18        Command::new("dot")
19            .args(["-Tpng", &file_name, "-o", &format!("UPG/{}.png", dot.0)])
20            .output()
21            .expect("Failed to execute Graphviz dot command");
22
23        remove_file(&file_name).expect("Failed to delete .dot file");
24    }
25}
26
27pub fn render_dot_string(name: String, dot_graph: String) {
28    let file_name = format!("{}.dot", name);
29    let mut file = File::create(&file_name).expect("Unable to create file");
30    file.write_all(dot_graph.as_bytes())
31        .expect("Unable to write data");
32
33    Command::new("dot")
34        .args([
35            "-Tpng",
36            &file_name,
37            "-o",
38            &format!("RAPx_bugs/{}.png", name),
39        ])
40        .output()
41        .expect("Failed to execute Graphviz dot command");
42
43    remove_file(&file_name).expect("Failed to delete .dot file");
44}