diff options
| author | Jack Nagel | 2014-04-13 13:53:46 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-04-13 14:57:11 -0500 |
| commit | dfddb2a76118a749c506fbc692f48ef326141079 (patch) | |
| tree | d99659b642ec3ba826a2bee75d40c8a957ba5244 /Library/Homebrew | |
| parent | dd9b253b44687f59ca43d7e23de6b185430377c9 (diff) | |
| download | brew-dfddb2a76118a749c506fbc692f48ef326141079.tar.bz2 | |
Allow access to both the linked dylibs and the dylib ID
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/mach.rb | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/Library/Homebrew/mach.rb b/Library/Homebrew/mach.rb index 54e65a0a9..8da667acd 100644 --- a/Library/Homebrew/mach.rb +++ b/Library/Homebrew/mach.rb @@ -144,27 +144,43 @@ module MachO mach_data.any? { |m| m.fetch(:type) == :bundle } end + class Metadata + attr_reader :path, :dylib_id, :dylibs + + def initialize(path) + @path = path + @dylib_id, @dylibs = parse_otool_L_output + end + + def parse_otool_L_output + ENV["HOMEBREW_MACH_O_FILE"] = path.expand_path.to_s + libs = `#{MacOS.locate("otool")} -L "$HOMEBREW_MACH_O_FILE"`.split("\n") + + libs.shift # first line is the filename + + id = libs.shift[OTOOL_RX, 1] if path.dylib? + libs.map! { |lib| lib[OTOOL_RX, 1] }.compact! + + return id, libs + ensure + ENV.delete "HOMEBREW_MACH_O_FILE" + end + end + + def mach_metadata + @mach_metadata ||= Metadata.new(self) + end + # Returns an array containing all dynamically-linked libraries, based on the # output of otool. This returns the install names, so these are not guaranteed # to be absolute paths. # Returns an empty array both for software that links against no libraries, # and for non-mach objects. def dynamically_linked_libraries - # 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? + mach_metadata.dylibs + end - libs.map! { |lib| lib[OTOOL_RX, 1] } - libs.compact! - libs - ensure - ENV.delete 'HOMEBREW_MACH_O_FILE' + def dylib_id + mach_metadata.dylib_id end end |
