Unify install name parsing
This commit is contained in:
parent
de20814162
commit
ce19fa2223
@ -72,14 +72,13 @@ module Homebrew extend self
|
||||
keg_ref_files.each do |file|
|
||||
puts "#{Tty.red}#{file}#{Tty.reset}"
|
||||
|
||||
linked_libraries = []
|
||||
|
||||
# Check dynamic library linkage. Importantly, do not run otool on static
|
||||
# libraries, which will falsely report "linkage" to themselves.
|
||||
if file.mach_o_executable? or file.dylib? or file.mach_o_bundle?
|
||||
linked_libraries.concat `otool -L "#{file}"`.split("\n").drop(1)
|
||||
linked_libraries.map! { |lib| lib[Keg::OTOOL_RX, 1] }
|
||||
linked_libraries = file.dynamically_linked_libraries
|
||||
linked_libraries = linked_libraries.select { |lib| lib.include? string }
|
||||
else
|
||||
linked_libraries = []
|
||||
end
|
||||
|
||||
linked_libraries.each do |lib|
|
||||
|
||||
@ -80,8 +80,6 @@ class Keg
|
||||
|
||||
private
|
||||
|
||||
OTOOL_RX = /\t(.*) \(compatibility version (\d+\.)*\d+, current version (\d+\.)*\d+\)/
|
||||
|
||||
def install_name_tool(*args)
|
||||
system(MacOS.locate("install_name_tool"), *args)
|
||||
end
|
||||
@ -109,19 +107,9 @@ class Keg
|
||||
def lib; join 'lib' end
|
||||
|
||||
def each_install_name_for file, &block
|
||||
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.shift # first line is fluff
|
||||
install_names.map!{ |s| OTOOL_RX =~ s && $1 }
|
||||
|
||||
# For dylibs, the next line is the ID
|
||||
install_names.shift if file.dylib?
|
||||
|
||||
install_names.compact!
|
||||
install_names.reject!{ |fn| fn =~ /^@(loader_|executable_|r)path/ }
|
||||
|
||||
install_names.each(&block)
|
||||
dylibs = file.dynamically_linked_libraries
|
||||
dylibs.reject! { |fn| fn =~ /^@(loader_|executable_|r)path/ }
|
||||
dylibs.each(&block)
|
||||
end
|
||||
|
||||
def dylib_id_for file, options={}
|
||||
|
||||
@ -46,6 +46,8 @@ module ArchitectureListExtension
|
||||
end
|
||||
|
||||
module MachO
|
||||
OTOOL_RX = /\t(.*) \(compatibility version (\d+\.)*\d+, current version (\d+\.)*\d+\)/
|
||||
|
||||
# Mach-O binary methods, see:
|
||||
# /usr/include/mach-o/loader.h
|
||||
# /usr/include/mach-o/fat.h
|
||||
@ -148,8 +150,21 @@ module MachO
|
||||
# Returns an empty array both for software that links against no libraries,
|
||||
# and for non-mach objects.
|
||||
def dynamically_linked_libraries
|
||||
`#{MacOS.locate("otool")} -L "#{expand_path}"`.chomp.split("\n")[1..-1].map do |line|
|
||||
line[/\t(.+) \([^(]+\)/, 1]
|
||||
end
|
||||
# Use an environment variable to avoid escaping problems
|
||||
ENV['HOMEBREW_MACH_O_FILE'] = expand_path.to_s
|
||||
|
||||
libs = `#{MacOS.locate("otool")} -L "$HOMEBREW_MACH_O_FILE"`.split("\n")
|
||||
|
||||
# First line is the filename
|
||||
libs.shift
|
||||
|
||||
# For dylibs, the next line is the ID
|
||||
libs.shift if dylib?
|
||||
|
||||
libs.map! { |lib| lib[OTOOL_RX, 1] }
|
||||
libs.compact!
|
||||
libs
|
||||
ensure
|
||||
ENV.delete 'HOMEBREW_MACH_O_FILE'
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user