-
Notifications
You must be signed in to change notification settings - Fork 32
/
fix_xapian_includes.py
executable file
·90 lines (81 loc) · 3.78 KB
/
fix_xapian_includes.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import re
def main():
GENERATED_H = (
'xapian/languages/sbl-dispatch.h',
'xapian/languages/allsnowballheaders.h',
'xapian/queryparser/queryparser_token.h',
'xapian/unicode/c_istab.h',
'xapian/errordispatch.h',
'xapian/error.h',
'xapian/version.h',
)
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'src'))
prefix_len = len(os.path.dirname(os.path.abspath('xapian'))) + 1
for dirpath, dirnames, filenames in os.walk('xapian'):
if dirpath not in ('.deps', '.libs'):
for filename in filenames:
printed_path = [False]
root, ext = os.path.splitext(filename)
if ext in ('.cc', '.h', '.lemony', '.lt', '.tcl') or filename in ('generate-exceptions',):
def fn(m):
include = m.group(3)
if include and include not in ('config.h', 'xapian.h'):
for q in (dirpath, 'xapian/common', 'xapian', ''):
tmp = os.path.abspath(os.path.join(q, include))
tmp = tmp[prefix_len:]
if os.path.exists(tmp) or tmp in GENERATED_H:
# parents = ''
# basepath = dirpath
# while basepath:
# if tmp.startswith(basepath + '/'):
# tmp = parents + tmp[len(basepath) + 1:]
# break
# parents += '../'
# basepath = os.path.dirname(basepath)
include = tmp
break
else:
if not printed_path[0]:
printed_path[0] = True
print(path)
print(" Include not found:", m.group(2))
elif not include:
include = m.group(4)
if ext == '.tcl':
return m.group(1) + '\\"' + include + '\\"'
else:
return m.group(1) + '"' + include + '"'
path = os.path.join(dirpath, filename)
with open(path) as f:
file = f.read()
file = re.sub(r'(\n\s*#\s*include )("([^"]+)"|<(config\.h|xapian\.h|xapian/[^>]+)>)', fn, file)
with open(path, 'w') as f:
f.write(file)
def fn(m):
include = m.group(3)
if not os.path.exists(include) and include not in GENERATED_H:
print('xapian.h')
print(" Include not found:", m.group(2))
return m.group(1) + '"' + include + '"'
with open('xapian.h') as f:
file = f.read()
file = re.sub(r'(\n\s*#\s*include )(<(xapian/[^>]+)>)', fn, file)
with open('xapian.h', 'w') as f:
f.write(file)
with open('xapian/languages/compiler/generator.c') as f:
file = f.read()
file = file.replace('<config.h>', '\\"config.h\\"')
file = file.replace('\\"steminternal.h\\"', '\\"xapian/languages/steminternal.h\\"')
with open('xapian/languages/compiler/generator.c', 'w') as f:
f.write(file)
with open('xapian/generate-exceptions') as f:
file = f.read()
file = file.replace('include/xapian/', 'xapian/')
with open('xapian/generate-exceptions', 'w') as f:
f.write(file)
if __name__ == '__main__':
main()