-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_xen_headers.py
81 lines (58 loc) · 2.19 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
#!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', 'xen-compat.h')
copy_file(working, 'public', 'trace.h')
copy_file(working, 'public', 'grant_table.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\\io', 'ring.h')
copy_file(working, 'public\\io', 'kbdif.h')
copy_file(working, 'public\\io', 'xenbus.h')
put_branch(working)
shell(['git', 'add', 'xen'], 'include')