This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
84 lines (78 loc) · 1.9 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use std::path::Path;
macro_rules! include_files {
($($name: literal),*) => {
const NAMES: &[&str] = &[
$($name),*
];
const FILE_NAMES: &[&str] = &[
$(concat!("xml/", $name, ".xml")),*
];
const FILES: &[&str] = &[
$(include_str!(concat!("xml/", $name, ".xml"))),*
];
}
}
include_files![
"Accessibility",
"Accessible",
"Action",
"Application",
"Cache",
"Collection",
"Component",
"DeviceEventController",
"DeviceEventListener",
"Document",
"EditableText",
"Event",
"Hyperlink",
"Hypertext",
"Image",
"Processed",
"Registry",
"Selection",
"Socket",
"TableCell",
"Table",
"Text",
"Value"
];
fn main() {
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let opts = dbus_codegen::GenOpts {
methodtype: None,
#[cfg(feature = "nonblock")]
connectiontype: dbus_codegen::ConnectionType::Nonblock,
..Default::default()
};
for i in 0..NAMES.len() {
let name = NAMES[i];
let file_name = FILE_NAMES[i];
let file = FILES[i];
println!("cargo:rerun-if-changed={}", file_name);
let mut out_path = Path::new(&out_dir).join(cammel_to_snake(name));
out_path.set_extension("rs");
// Run codegen
let code = dbus_codegen::generate(file, &opts).unwrap();
// Save generated code
std::fs::write(out_path, &code).unwrap();
}
}
fn cammel_to_snake(input: &str) -> String {
let mut out = String::with_capacity(input.len());
let mut chars = input.chars();
if let Some(c) = chars.next() {
for c in c.to_lowercase() {
out.push(c);
}
}
for c in chars {
if c.is_uppercase() {
out.push('_');
}
for c in c.to_lowercase() {
out.push(c);
}
}
out
}