forked from squeaky-pl/portable-pypy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_portable
executable file
·139 lines (96 loc) · 3.41 KB
/
make_portable
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python
bundle = ['sqlite3', 'ssl', 'crypto', 'ffi', 'expat', 'tcl', 'tk', 'gdbm', 'lzma']
from os import chdir, mkdir, symlink
from os.path import dirname, relpath, join, samefile, exists, basename
from shutil import copy2, copytree
from sys import argv
from glob import glob
from subprocess import check_output, check_call
def get_deps(binary):
deps = {}
output = check_output(['ldd', binary])
for line in output.splitlines():
if not '=>' in line:
continue
line = line.strip()
needed, path = line.split(' => ')
if path == 'not found':
print('Broken dependency in ' + binary)
path = path.split(' ')[0]
if not path:
continue
if needed[3:].split('.', 1)[0] not in bundle:
continue
deps[needed] = path
deps.update(get_deps(path))
return deps
def gather_deps(binaries):
deps = {}
for binary in binaries:
deps.update(get_deps(binary))
return deps
def symlink_deps(folder):
symlinks = {}
for lib in glob(join(folder, '*.so*')):
if lib.endswith('.so'):
continue
lnkname, _, _ = lib.partition('.so.')
lnkname += '.so'
src = basename(lib)
symlink(src, lnkname)
symlinks[lnkname] = src
print lnkname, src
return symlinks
def copy_deps(deps):
copied = {}
for needed, path in deps.items():
if exists('lib/' + needed) and samefile(path, 'lib/' + needed):
continue
copy2(path, 'lib/' + needed)
copied[path] = 'lib/' + needed
return copied
def rpath_binaries(binaries):
rpaths = {}
for binary in binaries:
rpath = join('$ORIGIN', relpath('lib', dirname(binary)))
check_call(['patchelf', '--set-rpath', rpath, binary])
rpaths[binary] = rpath
return rpaths
def strip(binaries):
for binary in binaries:
check_call(['chmod', 'a+w', binary])
check_call(['strip', binary])
check_call(['chmod', 'a-w', binary])
def main():
binaries = ['bin/libpypy-c.so']
binaries.extend(glob('lib_pypy/*_cffi.pypy*.so'))
binaries.extend(glob('lib_pypy/_tkinter/*_cffi.pypy*.so'))
deps = gather_deps(binaries)
copied = copy_deps(deps)
for path, item in copied.items():
print('Copied {0} to {1}'.format(path, item))
binaries.extend(copied.values())
rpaths = rpath_binaries(binaries)
for binary, rpath in rpaths.items():
print('Set RPATH of {0} to {1}'.format(binary, rpath))
strip(copied.values())
symlink_deps('lib')
check_call('cp -Lr /opt/prefix/include/* include', shell=True)
return deps
if __name__ == '__main__':
chdir(argv[1])
try:
mkdir('lib')
except OSError:
pass
main()
# tcl/tk library
copytree('/opt/prefix/lib/tcl8.6', 'lib/tcl')
copytree('/opt/prefix/lib/tk8.6', 'lib/tk')
check_call(['patch', 'lib_pypy/_tkinter/app.py', '/src/_tkinter_app.py.patch'])
if exists('lib-python/3'):
check_call(['patch', 'lib-python/3/subprocess.py', '/src/subprocess3.py.patch'])
check_call(['patch', 'lib-python/3/distutils/sysconfig_pypy.py', '/src/sysconfig_pypy.py.patch'])
else:
check_call(['patch', 'lib-python/2.7/subprocess.py', '/src/subprocess.py.patch'])
check_call(['patch', 'lib-python/2.7/distutils/sysconfig_pypy.py', '/src/sysconfig_pypy.py.patch'])