Created
August 16, 2017 17:57
-
-
Save automactic/230b0030cea4e85e000b43f17b150107 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
def change_install_name(lib_install_path: str): | |
def get_name_map(dir_path: str): | |
files = {} | |
for file in os.listdir(dir): | |
if file.endswith('.dylib') and not os.path.islink(dir_path+'/'+file): | |
files[file.split('.')[0]] = file | |
return files | |
dylibs = get_name_map(lib_install_path) | |
for dylib_name, file_name in dylibs.items(): | |
subprocess.run(['install_name_tool', '-id', '@rpath/{}'.format(file_name), file_name], cwd=lib_install_path) | |
process = subprocess.run(['otool', '-L', file_name], cwd=lib_install_path, stdout=subprocess.PIPE) | |
dependencies = process.stdout.decode().split('\n')[2:-1] | |
dependencies = [d.strip() for d in dependencies] | |
for d in dependencies: | |
if not d.startswith('/usr/lib/'): | |
old_name = d.split(' ')[0] | |
dylib_name = old_name.split('/')[-1].split('.')[0] | |
new_name = '@rpath/{}'.format(dylibs[dylib_name]) | |
subprocess.run(['install_name_tool', '-change', old_name, new_name, file_name], cwd=dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment