diff options
| author | William Woodruff | 2016-02-01 14:19:29 -0500 |
|---|---|---|
| committer | Mike McQuaid | 2016-02-03 21:25:40 +0000 |
| commit | afe0fde49ceb29aba6f152967582ced5ba206c32 (patch) | |
| tree | 53150351cfd4f4c96fa3f94d2d4f7e08fb890f1b /Library/Homebrew/os/mac/ruby_mach.rb | |
| parent | 1cb6a2ad186624b9013eb63fb0a5f14a1336a53c (diff) | |
| download | brew-afe0fde49ceb29aba6f152967582ced5ba206c32.tar.bz2 | |
os/mac: optionally use ruby_macho.
- and branch for dylib_id_and_dylibs
- add branches for dylib id changing and change_install_name
- rename MachO module to HomebrewMachO to prevent namespace clashes
with MachO in ruby-macho. this will eventually be replaced entirely
with direct calls to ruby-macho methods
- break ruby-macho implementation out into separate RubyMachO module,
and include either RubyMachO or CctoolsMachO (the original
implementation) based on the HOMEBREW_RUBY_MACHO env var
- move ArchitectureListExtension and RubyMachO into separate files
- create {ruby_,cctools_,,}relocate.rb for isolation of different
methods of mach-o relocation (ruby-macho vs. cctools)
- fill in require_install_name_tool? for ruby_relocate.rb
- rename {ruby_,cctools_,,}relocate.rb to keg, isolate requires in
os/mac
Closes Homebrew/homebrew#45001.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/os/mac/ruby_mach.rb')
| -rw-r--r-- | Library/Homebrew/os/mac/ruby_mach.rb | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/Library/Homebrew/os/mac/ruby_mach.rb b/Library/Homebrew/os/mac/ruby_mach.rb new file mode 100644 index 000000000..3cd0ac0b9 --- /dev/null +++ b/Library/Homebrew/os/mac/ruby_mach.rb @@ -0,0 +1,103 @@ +require "vendor/macho/macho" +require "os/mac/architecture_list" + +module RubyMachO + # @private + def macho + @macho ||= begin + MachO.open(to_s) + end + end + + # @private + def mach_data + @mach_data ||= begin + machos = [] + mach_data = [] + + if MachO.fat_magic?(macho.magic) + machos = macho.machos + else + machos << macho + end + + machos.each do |m| + arch = case m.cputype + when "CPU_TYPE_I386" then :i386 + when "CPU_TYPE_X86_64" then :x86_64 + when "CPU_TYPE_POWERPC" then :ppc7400 + when "CPU_TYPE_POWERPC64" then :ppc64 + else :dunno + end + + type = case m.filetype + when "MH_EXECUTE" then :executable + when "MH_DYLIB" then :dylib + when "MH_BUNDLE" then :bundle + else :dunno + end + + mach_data << { :arch => arch, :type => type } + end + + mach_data + rescue + [] + end + end + + def archs + mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension) + end + + def arch + case archs.length + when 0 then :dunno + when 1 then archs.first + else :universal + end + end + + def universal? + arch == :universal + end + + def i386? + arch == :i386 + end + + def x86_64? + arch == :x86_64 + end + + def ppc7400? + arch == :ppc7400 + end + + def ppc64? + arch == :ppc64 + end + + # @private + def dylib? + mach_data.any? { |m| m.fetch(:type) == :dylib } + end + + # @private + def mach_o_executable? + mach_data.any? { |m| m.fetch(:type) == :executable } + end + + # @private + def mach_o_bundle? + mach_data.any? { |m| m.fetch(:type) == :bundle } + end + + def dynamically_linked_libraries + macho.linked_dylibs + end + + def dylib_id + macho.dylib_id + end +end |
