Merge pull request #5413 from woodruffw-forks/rewrite-rpaths-in-install-names
mac/keg_relocate: Rewrite rpaths in install names
This commit is contained in:
commit
ab06303ee6
@ -69,12 +69,32 @@ class Keg
|
|||||||
new_name = fixed_name(file, bad_name)
|
new_name = fixed_name(file, bad_name)
|
||||||
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
|
||||||
|
|
||||||
|
# If none of the install names reference RPATH(s), then we can safely
|
||||||
|
# remove all RPATHs from the file.
|
||||||
|
if file.dynamically_linked_libraries.none? { |lib| lib.start_with?("@rpath") }
|
||||||
|
# Note: This could probably be made more efficient by reverse-sorting
|
||||||
|
# the RPATHs by offset and calling MachOFile#delete_command
|
||||||
|
# with repopulate: false.
|
||||||
|
file.rpaths.each { |r| file.delete_rpath(r) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
generic_fix_dynamic_linkage
|
generic_fix_dynamic_linkage
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expand_rpath(file, bad_name)
|
||||||
|
suffix = bad_name.sub(/^@rpath/, "")
|
||||||
|
|
||||||
|
file.rpaths.each do |rpath|
|
||||||
|
return rpath/suffix if (rpath/suffix).exist?
|
||||||
|
end
|
||||||
|
|
||||||
|
opoo "Could not find library #{bad_name} for #{file}"
|
||||||
|
bad_name
|
||||||
|
end
|
||||||
|
|
||||||
# If file is a dylib or bundle itself, look for the dylib named by
|
# If file is a dylib or bundle itself, look for the dylib named by
|
||||||
# bad_name relative to the lib directory, so that we can skip the more
|
# bad_name relative to the lib directory, so that we can skip the more
|
||||||
# expensive recursive search if possible.
|
# expensive recursive search if possible.
|
||||||
@ -87,6 +107,8 @@ class Keg
|
|||||||
"@loader_path/#{bad_name}"
|
"@loader_path/#{bad_name}"
|
||||||
elsif file.mach_o_executable? && (lib + bad_name).exist?
|
elsif file.mach_o_executable? && (lib + bad_name).exist?
|
||||||
"#{lib}/#{bad_name}"
|
"#{lib}/#{bad_name}"
|
||||||
|
elsif bad_name.start_with?("@rpath") && ENV["HOMEBREW_RELOCATE_METAVARS"]
|
||||||
|
expand_rpath file, bad_name
|
||||||
elsif (abs_name = find_dylib(bad_name)) && abs_name.exist?
|
elsif (abs_name = find_dylib(bad_name)) && abs_name.exist?
|
||||||
abs_name.to_s
|
abs_name.to_s
|
||||||
else
|
else
|
||||||
@ -97,7 +119,7 @@ class Keg
|
|||||||
|
|
||||||
def each_install_name_for(file, &block)
|
def each_install_name_for(file, &block)
|
||||||
dylibs = file.dynamically_linked_libraries
|
dylibs = file.dynamically_linked_libraries
|
||||||
dylibs.reject! { |fn| fn =~ /^@(loader_|executable_|r)path/ }
|
dylibs.reject! { |fn| fn =~ /^@(loader|executable)_path/ }
|
||||||
dylibs.each(&block)
|
dylibs.each(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,10 @@ require "macho"
|
|||||||
require "os/mac/architecture_list"
|
require "os/mac/architecture_list"
|
||||||
|
|
||||||
module MachOShim
|
module MachOShim
|
||||||
|
extend Forwardable
|
||||||
|
|
||||||
|
delegate [:dylib_id, :rpaths, :delete_rpath] => :macho
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def macho
|
def macho
|
||||||
@macho ||= begin
|
@macho ||= begin
|
||||||
@ -56,10 +60,6 @@ module MachOShim
|
|||||||
lcs.map(&:name).map(&:to_s).uniq
|
lcs.map(&:name).map(&:to_s).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def dylib_id
|
|
||||||
macho.dylib_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def archs
|
def archs
|
||||||
mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension)
|
mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user