aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/mach.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/mach.rb')
-rw-r--r--Library/Homebrew/mach.rb21
1 files changed, 18 insertions, 3 deletions
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