-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_xen_headers.py
executable file
·90 lines (66 loc) · 2.58 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!python -u
import os, sys
import shutil
import subprocess
import re
def shell(command, dir = '.'):
print("in '%s' execute '%s'" % (dir, ' '.join(command)))
sys.stdout.flush()
sub = subprocess.Popen(' '.join(command), cwd=dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for line in sub.stdout:
print(line.decode(sys.getdefaultencoding()).rstrip())
sub.wait()
return sub.returncode
def get_repo(url, working):
shell(['git', 'clone', '--no-checkout', url, working])
def get_branch(tag, working):
shell(['git', 'checkout', '-b', 'tmp', tag], working)
def put_branch(working):
shell(['git', 'checkout', 'master'], working)
shell(['git', 'branch', '-d', 'tmp'], working)
def copy_file(working, dir, name):
try:
os.makedirs('include\\xen\\%s' % dir)
except OSError:
None
src = open('%s\\xen\\include\\%s\\%s' % (working, dir, name), 'r')
dst = open('include\\xen\\%s\\%s' % (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)
shell(['git', 'rm', '-r', '-f', 'xen'], 'include')
copy_file(working, 'public', 'xen.h')
copy_file(working, 'public', 'physdev.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', 'version.h')
copy_file(working, 'public', 'features.h')
copy_file(working, 'public', 'errno.h')
copy_file(working, 'xen', 'errno.h')
copy_file(working, 'public\\arch-x86', 'xen.h')
copy_file(working, 'public\\arch-x86', 'xen-x86_32.h')
copy_file(working, 'public\\arch-x86', 'xen-x86_64.h')
copy_file(working, 'public\\hvm', 'hvm_op.h')
copy_file(working, 'public\\hvm', 'params.h')
copy_file(working, 'public\\hvm', 'hvm_info_table.h')
copy_file(working, 'public\\io', 'xs_wire.h')
copy_file(working, 'public\\io', 'console.h')
put_branch(working)
shell(['git', 'add', 'xen'], 'include')