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,11 +31,9 @@ class Keg
change_install_name(old_name, new_name, file) if new_name
end
if ENV["HOMEBREW_RELOCATE_RPATHS"]
each_linkage_for(file, :rpaths) do |old_name|
new_name = relocated_name_for(old_name, relocation)
change_rpath(old_name, new_name, file) if new_name
end
each_linkage_for(file, :rpaths) do |old_name|
new_name = relocated_name_for(old_name, relocation)
change_rpath(old_name, new_name, file) if new_name
end
end
end
@ -56,11 +54,20 @@ class Keg
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)
# 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|
# 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)
end
end

View File

@ -1229,11 +1229,7 @@ class FormulaInstaller
keg = Keg.new(formula.prefix)
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
end
keg.replace_placeholders_with_locations tab.changed_files, skip_linkage: skip_linkage
end
sig { params(output: T.nilable(String)).void }