Merge pull request #12750 from carlocab/machofile

os/mac/keg: use `MachOFile#delete_rpath` instead of `MachO::Tools`
This commit is contained in:
Carlo Cabrera 2022-01-20 02:02:29 +08:00 committed by GitHub
commit 7b1e47558b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 10 deletions

View File

@ -54,20 +54,12 @@ class Keg
change_install_name(bad_name, new_name, file) unless new_name == bad_name change_install_name(bad_name, new_name, file) unless new_name == bad_name
end end
# Keep track of the rpath counts for deletion of duplicates.
# We need to track this here since we cache the MachO data [0]
# and this cache is not updated after modification with #delete_rpath.
#
# [0] See os/mac/mach.rb.
rpath_count = Hash.new { |h, k| h[k] = file.rpaths.count(k) }
each_linkage_for(file, :rpaths) do |bad_name| each_linkage_for(file, :rpaths) do |bad_name|
# Strip duplicate rpaths and rpaths rooted in the build directory. # Strip duplicate rpaths and rpaths rooted in the build directory.
next if !bad_name.start_with?(HOMEBREW_TEMP.to_s) && next if !bad_name.start_with?(HOMEBREW_TEMP.to_s) &&
!bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) && !bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) &&
(rpath_count[bad_name] == 1) (file.rpaths.count(bad_name) == 1)
rpath_count[bad_name] -= 1
delete_rpath(bad_name, file) delete_rpath(bad_name, file)
end end
end end

View File

@ -52,7 +52,7 @@ class Keg
def delete_rpath(rpath, file) def delete_rpath(rpath, file)
odebug "Deleting rpath #{rpath} in #{file}" odebug "Deleting rpath #{rpath} in #{file}"
MachO::Tools.delete_rpath(file, rpath, strict: false) file.delete_rpath(rpath, strict: false)
apply_ad_hoc_signature(file) apply_ad_hoc_signature(file)
rescue MachO::MachOError rescue MachO::MachOError
onoe <<~EOS onoe <<~EOS

View File

@ -57,6 +57,13 @@ module MachOShim
end end
private :mach_data private :mach_data
# TODO: See if the `#write!` call can be delayed until
# we know we're not making any changes to the rpaths.
def delete_rpath(rpath, **options)
macho.delete_rpath(rpath, options)
macho.write!
end
def dynamically_linked_libraries(except: :none) def dynamically_linked_libraries(except: :none)
lcs = macho.dylib_load_commands.reject { |lc| lc.type == except } lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }