-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgen_constants_rs.py
45 lines (36 loc) · 1.21 KB
/
gen_constants_rs.py
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
from doxybindgen.constants import generate_constants_in, has_constants
import os
import subprocess
import xml.etree.ElementTree as ET
PROLOGUE = '''\
#![allow(dead_code)]
#![allow(non_upper_case_globals)]
#![allow(unused_parens)]
// FIXME: workaround for windows (LLP64)
#![allow(overflowing_literals)]
use std::os::raw::{c_int, c_long};
use crate::manual::*;
'''
# place wxWidgets doxygen xml files in wxml/ dir and run this.
def main():
outpath = 'wx-base/src/constants.rs'
with open(outpath, 'w', newline='\n') as f:
print(PROLOGUE, file=f)
for file in xml_files_in('wxml/'):
# print(file)
tree = ET.parse(file)
root = tree.getroot()
for line in generate_constants_in(root):
print(line, file=f)
print(subprocess.check_output(['rustfmt', outpath]))
def xml_files_in(dir):
index = os.path.join(dir, 'index.xml')
with open(index, 'r') as f:
tree = ET.parse(f)
root = tree.getroot()
for compound in root.findall('./compound'):
if has_constants(compound):
xml = compound.get('refid') + '.xml'
yield os.path.join(dir, xml)
if __name__ == '__main__':
main()