1use std::fs::{File, remove_file};
2use std::io::Write;
3use std::process::Command;
4
5pub fn render_dot_graphs(dot_graphs: Vec<(String, String)>) {
7 Command::new("mkdir")
8 .args(["SafetyFlow"])
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([
20 "-Tpng",
21 &file_name,
22 "-o",
23 &format!("SafetyFlow/{}.png", dot.0),
24 ])
25 .output()
26 .expect("Failed to execute Graphviz dot command");
27
28 remove_file(&file_name).expect("Failed to delete .dot file");
29 }
30}
31
32pub fn render_dot_string(name: String, dot_graph: String) {
33 Command::new("mkdir")
34 .args(["MIR_dot_graph"])
35 .output()
36 .expect("Failed to create directory");
37
38 let file_name = format!("{}.dot", name);
39 rap_debug!("render graph {:?}", file_name);
40 let mut file = File::create(&file_name).expect("Unable to create file");
41 file.write_all(dot_graph.as_bytes())
42 .expect("Unable to write data");
43
44 Command::new("dot")
45 .args([
46 "-Tpng",
47 &file_name,
48 "-o",
49 &format!("MIR_dot_graph/{}.png", name),
50 ])
51 .output()
52 .expect("Failed to execute Graphviz dot command");
53
54 remove_file(&file_name).expect("Failed to delete .dot file");
55}