Merge pull request #11382 from carlocab/build-rpaths

extend/os/mac/keg_relocate: remove `RPATH`s rooted in build directory
This commit is contained in:
Carlo Cabrera 2021-05-15 01:04:25 +01:00 committed by GitHub
commit d45832bbfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -55,6 +55,14 @@ class Keg
new_name = fixed_name(file, bad_name)
change_install_name(bad_name, new_name, file) unless new_name == bad_name
end
each_linkage_for(file, :rpaths) do |bad_name|
# Strip rpaths rooted in the build directory
next if !bad_name.start_with?(HOMEBREW_TEMP.to_s) &&
!bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s)
delete_rpath(bad_name, file)
end
end
end

View File

@ -50,6 +50,17 @@ class Keg
raise
end
def delete_rpath(rpath, file)
odebug "Deleting rpath #{rpath} in #{file}"
MachO::Tools.delete_rpath(file, rpath, strict: false)
apply_ad_hoc_signature(file)
rescue MachO::MachOError
onoe <<~EOS
Failed deleting rpath #{rpath} in #{file}
EOS
raise
end
def apply_ad_hoc_signature(file)
return if MacOS.version < :big_sur
return unless Hardware::CPU.arm?

View File

@ -10,7 +10,7 @@ require "os/mac/architecture_list"
module MachOShim
extend Forwardable
delegate [:dylib_id, :rpaths, :delete_rpath] => :macho
delegate [:dylib_id, :rpaths] => :macho
def macho
@macho ||= MachO.open(to_s)