Merge pull request #12745 from carlocab/dupe-rpath-handling

extend/os/mac/keg_relocate: fix duplicate RPATH handling
This commit is contained in:
Carlo Cabrera 2022-01-18 20:40:34 +08:00 committed by GitHub
commit 15567e0a4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View File

@ -31,7 +31,6 @@ class Keg
change_install_name(old_name, new_name, file) if new_name change_install_name(old_name, new_name, file) if new_name
end end
if ENV["HOMEBREW_RELOCATE_RPATHS"]
each_linkage_for(file, :rpaths) do |old_name| each_linkage_for(file, :rpaths) do |old_name|
new_name = relocated_name_for(old_name, relocation) new_name = relocated_name_for(old_name, relocation)
change_rpath(old_name, new_name, file) if new_name change_rpath(old_name, new_name, file) if new_name
@ -39,7 +38,6 @@ class Keg
end end
end end
end end
end
def fix_dynamic_linkage def fix_dynamic_linkage
mach_o_files.each do |file| mach_o_files.each do |file|
@ -56,11 +54,20 @@ 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
each_linkage_for(file, :rpaths) do |bad_name| # Keep track of the rpath counts for deletion of duplicates.
# Strip rpaths rooted in the build directory # We need to track this here since we cache the MachO data [0]
next if !bad_name.start_with?(HOMEBREW_TEMP.to_s) && # and this cache is not updated after modification with #delete_rpath.
!bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) #
# [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|
# Strip duplicate rpaths and 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) &&
(rpath_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

@ -1229,12 +1229,8 @@ class FormulaInstaller
keg = Keg.new(formula.prefix) keg = Keg.new(formula.prefix)
skip_linkage = formula.bottle_specification.skip_relocation? skip_linkage = formula.bottle_specification.skip_relocation?
# TODO: Remove `with_env` when bottles are built with RPATH relocation enabled
# https://github.com/Homebrew/brew/issues/11329
with_env(HOMEBREW_RELOCATE_RPATHS: "1") do
keg.replace_placeholders_with_locations tab.changed_files, skip_linkage: skip_linkage keg.replace_placeholders_with_locations tab.changed_files, skip_linkage: skip_linkage
end end
end
sig { params(output: T.nilable(String)).void } sig { params(output: T.nilable(String)).void }
def problem_if_output(output) def problem_if_output(output)