FixesHomebrew/homebrew#6065.
My pre-emptive fix that avoided calling Pathname.ensure_writable because I was not convinced it worked broke this function due to incorrect logic.
The lesson is, don’t write pre-emptive fixes. Wait until you've seen the bug first. All code has bugs in, so write less. I'm an idiot sometimes.
FixesHomebrew/homebrew#2709.
By forcing dylibs to have an install_name id that is the HOMEBREW_PREFIX path, ie. the symlink’s path. Stuff that links to these dylibs will use this id and thus by immune to upgrades of underlying libraries.
Thus whatever keg is "current" ie. linked, will be the library that is used by the tool.
This fix is not retroactive. So there will still be breakage for existing installations of stuff.
The fix_install step in install is moved after the link step as the symlinking
is required to determine the eventual ids for each dylib.