Fix bad install names in executables
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
f589644aa4
commit
186a76c741
@ -6,19 +6,17 @@ class Keg
|
|||||||
system MacOS.locate("install_name_tool"), "-id", id, file if file.dylib?
|
system MacOS.locate("install_name_tool"), "-id", id, file if file.dylib?
|
||||||
|
|
||||||
bad_names.each do |bad_name|
|
bad_names.each do |bad_name|
|
||||||
new_name = bad_name
|
# If file is a dylib or bundle itself, look for the dylib named by
|
||||||
new_name = Pathname.new(bad_name).basename unless (file.parent + new_name).exist?
|
# bad_name relative to the lib directory, so that we can skip the more
|
||||||
|
# expensive recursive search if possible.
|
||||||
# First check to see if the dylib is present in the current
|
if file.dylib? or file.mach_o_bundle? and (file.parent + bad_name).exist?
|
||||||
# directory, so we can skip the more expensive search.
|
system MacOS.locate("install_name_tool"), "-change", bad_name, "@loader_path/#{bad_name}", file
|
||||||
if (file.parent + new_name).exist?
|
elsif file.mach_o_executable? and (lib/bad_name).exist?
|
||||||
system MacOS.locate("install_name_tool"), "-change", bad_name, "@loader_path/#{new_name}", file
|
system MacOS.locate("install_name_tool"), "-change", bad_name, "#{lib}/#{bad_name}", file
|
||||||
else
|
else
|
||||||
# Otherwise, try and locate the appropriate dylib by walking
|
# Otherwise, try and locate the dylib by walking the entire
|
||||||
# the entire 'lib' tree recursively.
|
# lib tree recursively.
|
||||||
abs_name = (self+'lib').find do |pn|
|
abs_name = find_dylib(Pathname.new(bad_name).basename)
|
||||||
break pn if pn.basename == Pathname.new(new_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
if abs_name and abs_name.exist?
|
if abs_name and abs_name.exist?
|
||||||
system MacOS.locate("install_name_tool"), "-change", bad_name, abs_name, file
|
system MacOS.locate("install_name_tool"), "-change", bad_name, abs_name, file
|
||||||
@ -36,6 +34,8 @@ class Keg
|
|||||||
|
|
||||||
OTOOL_RX = /\t(.*) \(compatibility version (\d+\.)*\d+, current version (\d+\.)*\d+\)/
|
OTOOL_RX = /\t(.*) \(compatibility version (\d+\.)*\d+, current version (\d+\.)*\d+\)/
|
||||||
|
|
||||||
|
def lib; join 'lib' end
|
||||||
|
|
||||||
def bad_install_names_for file
|
def bad_install_names_for file
|
||||||
ENV['HOMEBREW_MACH_O_FILE'] = file.to_s # solves all shell escaping problems
|
ENV['HOMEBREW_MACH_O_FILE'] = file.to_s # solves all shell escaping problems
|
||||||
install_names = `#{MacOS.locate("otool")} -L "$HOMEBREW_MACH_O_FILE"`.split "\n"
|
install_names = `#{MacOS.locate("otool")} -L "$HOMEBREW_MACH_O_FILE"`.split "\n"
|
||||||
@ -43,8 +43,8 @@ class Keg
|
|||||||
install_names.shift # first line is fluff
|
install_names.shift # first line is fluff
|
||||||
install_names.map!{ |s| OTOOL_RX =~ s && $1 }
|
install_names.map!{ |s| OTOOL_RX =~ s && $1 }
|
||||||
|
|
||||||
# Bundles don't have an ID
|
# Bundles and executables do not have an ID
|
||||||
id = install_names.shift unless file.mach_o_bundle?
|
id = install_names.shift if file.dylib?
|
||||||
|
|
||||||
install_names.compact!
|
install_names.compact!
|
||||||
install_names.reject!{ |fn| fn =~ /^@(loader|executable)_path/ }
|
install_names.reject!{ |fn| fn =~ /^@(loader|executable)_path/ }
|
||||||
@ -67,6 +67,12 @@ class Keg
|
|||||||
yield id, install_names
|
yield id, install_names
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_dylib name
|
||||||
|
(join 'lib').find do |pn|
|
||||||
|
break pn if pn.basename == Pathname.new(name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def mach_o_files
|
def mach_o_files
|
||||||
mach_o_files = []
|
mach_o_files = []
|
||||||
if (lib = join 'lib').directory?
|
if (lib = join 'lib').directory?
|
||||||
@ -75,6 +81,13 @@ class Keg
|
|||||||
mach_o_files << pn if pn.dylib? or pn.mach_o_bundle?
|
mach_o_files << pn if pn.dylib? or pn.mach_o_bundle?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (bin = join 'bin').directory?
|
||||||
|
bin.find do |pn|
|
||||||
|
next if pn.symlink? or pn.directory?
|
||||||
|
mach_o_files << pn if pn.mach_o_executable?
|
||||||
|
end
|
||||||
|
end
|
||||||
mach_o_files
|
mach_o_files
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user