forked from xenserver/win-xenvbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_xen_headers.py
73 lines (54 loc) · 2.07 KB
/
get_xen_headers.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
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
#!python -u
import os, sys
import shutil
import subprocess
import re
def shell(command):
print(command)
sys.stdout.flush()
pipe = os.popen(' '.join(command), 'r', 1)
for line in pipe:
print(line.rstrip())
return pipe.close()
def get_repo(url, working):
shell(['git', 'clone', '--no-checkout', url, working])
def get_branch(tag, working):
cwd = os.getcwd()
os.chdir(working)
shell(['git', 'checkout', '-b', tag])
os.chdir(cwd)
def copy_file(working, src_dir, dst_dir, name):
try:
os.makedirs('include\\xen\\%s' % dst_dir)
except OSError:
None
src = open('%s\\xen\\include\\%s\\%s' % (working, src_dir, name), 'r')
dst = open('include\\xen\\%s\\%s' % (dst_dir, name), 'w', newline='\n')
print(name)
for line in src:
line = re.sub(' unsigned long', ' ULONG_PTR', line)
line = re.sub('\(unsigned long', '(ULONG_PTR', line)
line = re.sub(' long', ' LONG_PTR', line)
line = re.sub('\(long', '(LONG_PTR', line)
dst.write(line)
dst.close()
src.close()
if __name__ == '__main__':
tag = sys.argv[1]
working = sys.argv[2]
get_repo('git://xenbits.xen.org/xen.git', working)
get_branch(tag, working)
copy_file(working, 'public', '.', 'xen.h')
copy_file(working, 'public', '.', 'xen-compat.h')
copy_file(working, 'public', '.', 'trace.h')
copy_file(working, 'public', '.', 'memory.h')
copy_file(working, 'public', '.', 'sched.h')
copy_file(working, 'public', '.', 'event_channel.h')
copy_file(working, 'public', '.', 'grant_table.h')
copy_file(working, 'public\\arch-x86', 'arch-x86', 'xen.h')
copy_file(working, 'public\\arch-x86', 'arch-x86', 'xen-x86_32.h')
copy_file(working, 'public\\arch-x86', 'arch-x86', 'xen-x86_64.h')
copy_file(working, 'public\\hvm', 'hvm', 'hvm_op.h')
copy_file(working, 'public\\hvm', 'hvm', 'params.h')
copy_file(working, 'public\\io', 'io', 'xs_wire.h')
copy_file(working, 'public\\io', 'io', 'blkif.h')