-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathfixBinaries.py
47 lines (37 loc) · 1.68 KB
/
fixBinaries.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
'''
This module contains code that copies CBC libraries into CyLP's source,
and make CyLP binaries' refernces to them relative.
'''
import distutils.util
import sys
import os
from os.path import join, basename, exists
from os import makedirs
import subprocess
platform_dir = 'lib.%s-%s.%s' % (distutils.util.get_platform(),
sys.version_info.major,
sys.version_info.minor)
relative_path = join('@loader_path', '..', 'cbclibs', platform_dir)
cylp_libs_dir = join('build', platform_dir, 'cylp', 'cy')
def install_name_tool(binaryFile, lib_origin_path, lib_new_path):
os.system('install_name_tool -change %s %s %s' % (lib_origin_path, lib_new_path, binaryFile))
def fixBinary(file):
s = subprocess.check_output('otool -L %s' % file, shell=True)
lib_origin_paths = [libline.decode('utf-8').split()[0] for libline in s.splitlines()[1:] if 'Cbc' in libline.decode('utf-8')]
for lib_origin_path in lib_origin_paths:
lib = basename(lib_origin_path)
install_name_tool(file, lib_origin_path, join(relative_path, lib))
def copy_in_cbc_libs():
print('Copying CBC libs into CyLP...')
dest_dir = join('cylp', 'cbclibs', platform_dir)
if not exists(dest_dir):
print('Creating', dest_dir)
makedirs(dest_dir)
os.system('cp %s %s' % (join(cbc_libs_dir, '*.dylib'), dest_dir))
def fixAll():
copy_in_cbc_libs()
for file in os.listdir(cylp_libs_dir):
if file.endswith('so'):
fullpath = join(cylp_libs_dir, file)
print('Fixing %s...' % fullpath)
fixBinary(fullpath)