From 69f817b0e36f8fba7d2bd81cf569d9ad09bb7a2b Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 8 Jun 2018 00:37:24 +0530 Subject: depfixer: Rewrite install_name for dylibs on install The install name is used by consumers of the library to find the library at runtime. If it's @rpath/libfoo.dylib, all consumers must manually add the library path to RPATH, which is not what people expect. Almost everyone sets the library install name as the full path to the library, and this is done at install time with install_name_tool. --- mesonbuild/scripts/depfixer.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'mesonbuild/scripts/depfixer.py') diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py index 1d2cc60..132cc72 100644 --- a/mesonbuild/scripts/depfixer.py +++ b/mesonbuild/scripts/depfixer.py @@ -364,7 +364,7 @@ def get_darwin_rpaths_to_remove(fname): result.append(rp) return result -def fix_darwin(fname, new_rpath): +def fix_darwin(fname, new_rpath, final_path): try: rpaths = get_darwin_rpaths_to_remove(fname) except subprocess.CalledProcessError: @@ -372,30 +372,38 @@ def fix_darwin(fname, new_rpath): # non-executable target. Just return. return try: + args = [] if rpaths: - args = [] for rp in rpaths: args += ['-delete_rpath', rp] subprocess.check_call(['install_name_tool', fname] + args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + args = [] if new_rpath: - subprocess.check_call(['install_name_tool', '-add_rpath', new_rpath, fname], + args += ['-add_rpath', new_rpath] + # Rewrite -install_name @rpath/libfoo.dylib to /path/to/libfoo.dylib + if fname.endswith('dylib'): + args += ['-id', final_path] + if args: + subprocess.check_call(['install_name_tool', fname] + args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) except Exception as e: raise sys.exit(0) -def fix_rpath(fname, new_rpath, verbose=True): +def fix_rpath(fname, new_rpath, final_path, verbose=True): + # Static libraries never have rpaths + if fname.endswith('.a'): + return try: fix_elf(fname, new_rpath, verbose) - return 0 + return 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 + fix_darwin(fname, new_rpath, final_path, install_name_mappings) -- cgit v1.1