From dee3638653067fd569535af798e3a49293cc2f3d Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Fri, 11 Feb 2022 23:05:02 +0800 Subject: [PATCH] os/mac/{keg,mach}: fix cache invalidation We were rewriting dylib IDs and install names using `MachO::Tools`, which doesn't update the state of the file in memory. This leads to those changes being undone when we call `delete_rpath`. We fix this by making sure the state of the file in memory always matches the state of file on disk. Closes #12832. --- Library/Homebrew/os/mac/keg.rb | 6 +++--- Library/Homebrew/os/mac/mach.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/os/mac/keg.rb b/Library/Homebrew/os/mac/keg.rb index ef4395bb66..ead4ad6d71 100644 --- a/Library/Homebrew/os/mac/keg.rb +++ b/Library/Homebrew/os/mac/keg.rb @@ -7,7 +7,7 @@ class Keg @require_relocation = true odebug "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" - MachO::Tools.change_dylib_id(file, id, strict: false) + file.change_dylib_id(id, strict: false) apply_ad_hoc_signature(file) rescue MachO::MachOError onoe <<~EOS @@ -23,7 +23,7 @@ class Keg @require_relocation = true odebug "Changing install name in #{file}\n from #{old}\n to #{new}" - MachO::Tools.change_install_name(file, old, new, strict: false) + file.change_install_name(old, new, strict: false) apply_ad_hoc_signature(file) rescue MachO::MachOError onoe <<~EOS @@ -39,7 +39,7 @@ class Keg @require_relocation = true odebug "Changing rpath in #{file}\n from #{old}\n to #{new}" - MachO::Tools.change_rpath(file, old, new, strict: false) + file.change_rpath(old, new, strict: false) apply_ad_hoc_signature(file) rescue MachO::MachOError onoe <<~EOS diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index bd636ffba9..abadcf8fd6 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -64,6 +64,21 @@ module MachOShim macho.write! end + def change_rpath(old, new, **options) + macho.change_rpath(old, new, options) + macho.write! + end + + def change_dylib_id(id, **options) + macho.change_dylib_id(id, options) + macho.write! + end + + def change_install_name(old, new, **options) + macho.change_install_name(old, new, options) + macho.write! + end + def dynamically_linked_libraries(except: :none) lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }