-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.rs
56 lines (53 loc) · 1.73 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use dbus_codegen::{generate, GenOpts, ServerAccess};
fn generate_code(interfaces: &[(&str, GenOpts)], outfile: &str) {
let mut code = String::new();
for (n, (file, opts)) in interfaces.iter().enumerate() {
let mut f = File::open(file).unwrap();
let mut xml = String::new();
f.read_to_string(&mut xml).unwrap();
code.push_str(&format!("mod n{} {{\n", n));
code.push_str(&generate(&xml, &opts).unwrap());
code.push_str(&format!("\n}}\npub use n{}::*;\n", n));
}
let out_dir = env::var("OUT_DIR").unwrap();
let path = Path::new(&out_dir).join(outfile);
let mut f = File::create(path).unwrap();
(&mut f as &mut dyn Write)
.write_all(code.as_bytes())
.unwrap();
}
fn main() {
generate_code(
&[
(
"dbus_interfaces/StatusNotifierWatcher.xml",
GenOpts {
methodtype: None,
skipprefix: Some("org.kde.".into()),
..Default::default()
},
),
(
"dbus_interfaces/StatusNotifierItem.xml",
GenOpts {
serveraccess: ServerAccess::AsRefClosure,
skipprefix: Some("org.kde.".into()),
..Default::default()
},
),
(
"dbus_interfaces/DBusMenu.xml",
GenOpts {
serveraccess: ServerAccess::AsRefClosure,
skipprefix: Some("com.canonical.".into()),
..Default::default()
},
),
],
"dbus_interfaces.rs",
);
}