diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-06-08 00:50:39 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-06-18 06:33:23 +0000 |
commit | 96b7fdb723e5a8d2d7143c7c7a6abc433e0b3da0 (patch) | |
tree | 04bcc0057f228675f1c0c183a0927754bab40c23 /mesonbuild/scripts | |
parent | 69f817b0e36f8fba7d2bd81cf569d9ad09bb7a2b (diff) | |
download | meson-96b7fdb723e5a8d2d7143c7c7a6abc433e0b3da0.zip meson-96b7fdb723e5a8d2d7143c7c7a6abc433e0b3da0.tar.gz meson-96b7fdb723e5a8d2d7143c7c7a6abc433e0b3da0.tar.bz2 |
macos: Rewrite install_name for dependent built libraries on install
On macOS, we set the install_name for built libraries to
@rpath/libfoo.dylib, and when linking to the library, we set the RPATH
to its path in the build directory. This allows all built binaries to
be run as-is from the build directory (uninstalled).
However, on install, we have to strip all the RPATHs because they
point to the build directory, and we change the install_name of all
built libraries to the absolute path to the library. This causes the
install name in binaries to be out of date.
We now change that install name to point to the absolute path to each
built library after installation.
Fixes https://github.com/mesonbuild/meson/issues/3038
Fixes https://github.com/mesonbuild/meson/issues/3077
With this, the default workflow on macOS matches what everyone seems
to do, including Autotools and CMake. The next step is providing a way
for build files to override the install_name that is used after
installation for use with, f.ex., private libraries when combined with
the install_rpath: kwarg on targets.
Diffstat (limited to 'mesonbuild/scripts')
-rw-r--r-- | mesonbuild/scripts/depfixer.py | 7 | ||||
-rw-r--r-- | mesonbuild/scripts/meson_install.py | 16 |
2 files changed, 14 insertions, 9 deletions
diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py index 132cc72..40f47c0 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, final_path): +def fix_darwin(fname, new_rpath, final_path, install_name_mappings): try: rpaths = get_darwin_rpaths_to_remove(fname) except subprocess.CalledProcessError: @@ -385,6 +385,9 @@ def fix_darwin(fname, new_rpath, final_path): # Rewrite -install_name @rpath/libfoo.dylib to /path/to/libfoo.dylib if fname.endswith('dylib'): args += ['-id', final_path] + if install_name_mappings: + for old, new in install_name_mappings.items(): + args += ['-change', old, new] if args: subprocess.check_call(['install_name_tool', fname] + args, stdout=subprocess.DEVNULL, @@ -393,7 +396,7 @@ def fix_darwin(fname, new_rpath, final_path): raise sys.exit(0) -def fix_rpath(fname, new_rpath, final_path, verbose=True): +def fix_rpath(fname, new_rpath, final_path, install_name_mappings, verbose=True): # Static libraries never have rpaths if fname.endswith('.a'): return diff --git a/mesonbuild/scripts/meson_install.py b/mesonbuild/scripts/meson_install.py index 00c6019..3fbb1cc 100644 --- a/mesonbuild/scripts/meson_install.py +++ b/mesonbuild/scripts/meson_install.py @@ -360,14 +360,16 @@ def check_for_stampfile(fname): def install_targets(d): for t in d.targets: - fname = check_for_stampfile(t[0]) - outdir = get_destdir_path(d, t[1]) + fname = check_for_stampfile(t.fname) + outdir = get_destdir_path(d, t.outdir) + final_path = os.path.join(d.prefix, t.outdir, fname) outname = os.path.join(outdir, os.path.basename(fname)) final_path = os.path.join(d.prefix, outname) - aliases = t[2] - should_strip = t[3] - install_rpath = t[4] - install_mode = t[5] + aliases = t.aliases + should_strip = t.strip + install_name_mappings = t.install_name_mappings + install_rpath = t.install_rpath + install_mode = t.install_mode print('Installing %s to %s' % (fname, outname)) d.dirmaker.makedirs(outdir, exist_ok=True) if not os.path.exists(fname): @@ -416,7 +418,7 @@ def install_targets(d): if os.path.isfile(outname): try: depfixer.fix_rpath(outname, install_rpath, final_path, - verbose=False) + install_name_mappings, verbose=False) except SystemExit as e: if isinstance(e.code, int) and e.code == 0: pass |