This commit is contained in:
34
fix-rpaths.py
Normal file
34
fix-rpaths.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import subprocess
|
||||
import sys
|
||||
from os.path import join
|
||||
import os
|
||||
|
||||
app_bundle = sys.argv[1]
|
||||
|
||||
app_binary = join(app_bundle, 'Contents/MacOS', app_bundle.split(".")[0])
|
||||
app_frameworks = join(app_bundle, 'Contents/Frameworks')
|
||||
|
||||
binaries = [app_binary] + [join(app_frameworks, library) for library in os.listdir(app_frameworks)]
|
||||
|
||||
dependency_map = {binary:subprocess.check_output(["otool", "-L", binary], text=True).splitlines()[1:] for binary in binaries}
|
||||
|
||||
for binary, dependencies in dependency_map.items():
|
||||
print(binary)
|
||||
|
||||
if binary == app_binary:
|
||||
print('\tAdding rpath: @loader_path/../Frameworks')
|
||||
print('\t' + subprocess.check_output(['install_name_tool', '-add_rpath', '@loader_path/../Frameworks', binary], text=True))
|
||||
for dependency in dependencies:
|
||||
end_index = dependency.index('(')
|
||||
dep = dependency[0:end_index].strip()
|
||||
|
||||
dep_short_name = dep[dep.rfind('/')+1:]
|
||||
for key in dependency_map:
|
||||
if key.endswith(dep_short_name):
|
||||
if binary == app_binary:
|
||||
print(f'\t{dep} -> @rpath/{dep_short_name}')
|
||||
print('\t' + subprocess.check_output(['install_name_tool', '-change', dep, f'@rpath/{dep_short_name}', binary], text=True))
|
||||
else:
|
||||
print(f'\t{dep} -> @loader_path/{dep_short_name}')
|
||||
print('\t' + subprocess.check_output(['install_name_tool', '-change', dep, f'@loader_path/{dep_short_name}', binary], text=True))
|
||||
break
|
Reference in New Issue
Block a user