Factor out MacOS.locate("install_name_tool") calls

This commit is contained in:
Jack Nagel 2013-05-22 11:11:21 -05:00
parent a69552a57d
commit 2488cfa55a

View File

@ -4,23 +4,23 @@ class Keg
mach_o_files.each do |file|
install_names_for file do |id, bad_names|
file.ensure_writable do
system MacOS.locate("install_name_tool"), "-id", id, file if file.dylib?
install_name_tool("-id", id, file) if file.dylib?
bad_names.each do |bad_name|
# 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
# expensive recursive search if possible.
if file.dylib? or file.mach_o_bundle? and (file.parent + bad_name).exist?
system MacOS.locate("install_name_tool"), "-change", bad_name, "@loader_path/#{bad_name}", file
install_name_tool("-change", bad_name, "@loader_path/#{bad_name}", file)
elsif file.mach_o_executable? and (lib/bad_name).exist?
system MacOS.locate("install_name_tool"), "-change", bad_name, "#{lib}/#{bad_name}", file
install_name_tool("-change", bad_name, "#{lib}/#{bad_name}", file)
else
# Otherwise, try and locate the dylib by walking the entire
# lib tree recursively.
abs_name = find_dylib(Pathname.new(bad_name).basename)
if abs_name and abs_name.exist?
system MacOS.locate("install_name_tool"), "-change", bad_name, abs_name, file
install_name_tool("-change", bad_name, abs_name, file)
else
opoo "Could not fix install names for #{file}"
end
@ -36,11 +36,11 @@ class Keg
install_names_for(file, relocate_reject_proc(old_prefix)) do |id, old_prefix_names|
file.ensure_writable do
new_prefix_id = id.to_s.gsub old_prefix, new_prefix
system MacOS.locate("install_name_tool"), "-id", new_prefix_id, file if file.dylib?
install_name_tool("-id", new_prefix_id, file) if file.dylib?
old_prefix_names.each do |old_prefix_name|
new_prefix_name = old_prefix_name.to_s.gsub old_prefix, new_prefix
system MacOS.locate("install_name_tool"), "-change", old_prefix_name, new_prefix_name, file
install_name_tool("-change", old_prefix_name, new_prefix_name, file)
end
end
end
@ -49,7 +49,7 @@ class Keg
file.ensure_writable do
old_cellar_names.each do |old_cellar_name|
new_cellar_name = old_cellar_name.to_s.gsub old_cellar, new_cellar
system MacOS.locate("install_name_tool"), "-change", old_cellar_name, new_cellar_name, file
install_name_tool("-change", old_cellar_name, new_cellar_name, file)
end
end
end
@ -60,6 +60,10 @@ class Keg
OTOOL_RX = /\t(.*) \(compatibility version (\d+\.)*\d+, current version (\d+\.)*\d+\)/
def install_name_tool(*args)
system(MacOS.locate("install_name_tool"), *args)
end
def lib; join 'lib' end
def default_reject_proc