aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2018-04-02 22:24:31 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2018-04-08 19:48:31 +0300
commitaed11affd3a68ec22a0527d82457c8ff365639ec (patch)
treea56815d6a444b05c2af05ebca3862d3e20c2dad9 /mesonbuild
parent269db40445829e503ad12768dc53c4440d3842fa (diff)
downloadmeson-aed11affd3a68ec22a0527d82457c8ff365639ec.zip
meson-aed11affd3a68ec22a0527d82457c8ff365639ec.tar.gz
meson-aed11affd3a68ec22a0527d82457c8ff365639ec.tar.bz2
Update depfixer to fix rpaths also on OSX.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/scripts/depfixer.py60
-rw-r--r--mesonbuild/scripts/meson_install.py3
2 files changed, 52 insertions, 11 deletions
diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py
index ee63147..5c1216c 100644
--- a/mesonbuild/scripts/depfixer.py
+++ b/mesonbuild/scripts/depfixer.py
@@ -14,6 +14,7 @@
import sys, struct
+import shutil, subprocess
SHT_STRTAB = 3
DT_NEEDED = 1
@@ -337,20 +338,61 @@ class Elf(DataSizes):
entry.write(self.bf)
return None
+def fix_elf(fname, new_rpath, verbose=True):
+ with Elf(fname, verbose) as e:
+ if new_rpath is None:
+ e.print_rpath()
+ e.print_runpath()
+ else:
+ e.fix_rpath(new_rpath)
+
+def get_darwin_rpaths_to_remove(fname):
+ out = subprocess.check_output(['otool', '-l', fname], universal_newlines=True)
+ result = []
+ current_cmd = 'FOOBAR'
+ for line in out.split('\n'):
+ if ' ' not in line:
+ continue
+ key, value = line.strip().split(' ', 1)
+ if key == 'cmd':
+ current_cmd = value
+ if key == 'path' and current_cmd == 'LC_RPATH':
+ rp = value.split('(', 1)[0].strip()
+ result.append(rp)
+ return result
+
+def fix_darwin(fname, new_rpath):
+ try:
+ for rp in get_darwin_rpaths_to_remove(fname):
+ subprocess.check_call(['install_name_tool', '-delete_rpath', rp, fname])
+ if new_rpath != '':
+ subprocess.check_call(['install_name_tool', '-add_rpath', new_rpath, fname])
+ except Exception as e:
+ raise
+ sys.exit(0)
+
+def fix_rpath(fname, new_rpath, verbose=True):
+ try:
+ fix_elf(fname, new_rpath, verbose)
+ return 0
+ except SystemExit as e:
+ if isinstance(e.code, int) and e.code == 0:
+ pass
+ else:
+ raise
+ if shutil.which('install_name_tool'):
+ fix_darwin(fname, new_rpath)
+ return 0
+
def run(args):
if len(args) < 1 or len(args) > 2:
print('This application resets target rpath.')
print('Don\'t run this unless you know what you are doing.')
print('%s: <binary file> <prefix>' % sys.argv[0])
sys.exit(1)
- with Elf(args[0]) as e:
- if len(args) == 1:
- e.print_rpath()
- e.print_runpath()
- else:
- new_rpath = args[1]
- e.fix_rpath(new_rpath)
- return 0
+ fname = args[0]
+ new_rpath = None if len(args) == 1 else args[1]
+ return fix_rpath(fname, new_rpath)
if __name__ == '__main__':
- run(sys.argv[1:])
+ sys.exit(run(sys.argv[1:]))
diff --git a/mesonbuild/scripts/meson_install.py b/mesonbuild/scripts/meson_install.py
index 1414ace..6fa3d0d 100644
--- a/mesonbuild/scripts/meson_install.py
+++ b/mesonbuild/scripts/meson_install.py
@@ -374,8 +374,7 @@ def install_targets(d):
printed_symlink_error = True
if is_elf_platform() and os.path.isfile(outname):
try:
- e = depfixer.Elf(outname, False)
- e.fix_rpath(install_rpath)
+ depfixer.fix_rpath(outname, install_rpath, False)
except SystemExit as e:
if isinstance(e.code, int) and e.code == 0:
pass