diff options
| author | Jack Nagel | 2013-12-14 09:35:58 -0600 |
|---|---|---|
| committer | Jack Nagel | 2013-12-14 09:35:58 -0600 |
| commit | ce19fa222361839d2c04986f81ae66c8a8748a61 (patch) | |
| tree | 4fb44bafdc84eeed8df963a189dcf4b0dad56d50 | |
| parent | de208141628daf6cb93839572721a8810079df58 (diff) | |
| download | brew-ce19fa222361839d2c04986f81ae66c8a8748a61.tar.bz2 | |
Unify install name parsing
| -rw-r--r-- | Library/Homebrew/cmd/bottle.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/keg_fix_install_names.rb | 18 | ||||
| -rw-r--r-- | Library/Homebrew/mach.rb | 21 |
3 files changed, 24 insertions, 22 deletions
diff --git a/Library/Homebrew/cmd/bottle.rb b/Library/Homebrew/cmd/bottle.rb index 935ca149e..1e5ec4ba3 100644 --- a/Library/Homebrew/cmd/bottle.rb +++ b/Library/Homebrew/cmd/bottle.rb @@ -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| diff --git a/Library/Homebrew/keg_fix_install_names.rb b/Library/Homebrew/keg_fix_install_names.rb index b6cc38313..2b9760379 100644 --- a/Library/Homebrew/keg_fix_install_names.rb +++ b/Library/Homebrew/keg_fix_install_names.rb @@ -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={} diff --git a/Library/Homebrew/mach.rb b/Library/Homebrew/mach.rb index e943bd134..a7a4b1a70 100644 --- a/Library/Homebrew/mach.rb +++ b/Library/Homebrew/mach.rb @@ -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 |
