forked from cjp256/xenusbdevice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_xen_headers.py
More file actions
90 lines (65 loc) · 2.43 KB
/
get_xen_headers.py
File metadata and controls
90 lines (65 loc) · 2.43 KB
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(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, dirlist, name):
parts = [working, 'xen', 'include'] + dirlist + [name]
srcpath = os.path.join(*parts)
parts = ['include', 'xen'] + dirlist
dstdirpath = os.path.join(*parts)
parts.append(name)
dstpath = os.path.join(*parts)
try:
print('creating:', dstdirpath)
os.makedirs(dstdirpath)
except OSError:
None
src = open(srcpath, 'r')
dst = open(dstpath, 'w', newline='\n')
print('%s -> %s' % (srcpath, dstpath))
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'], 'usbif.h')
copy_file(working, ['public', 'io'], 'xenbus.h')
put_branch(working)
shell(['git', 'add', 'xen'], 'include')