os/mac/*_mach: move shared code into 'SharedMachO' (#282)

Both the `CctoolsMachO` and `RubyMachO` module implement a common set of
methods that simplify querying `mach_data`. Move these into a shared
module, that gets included after either of these implementations is
loaded and included in `Pathname`.
This commit is contained in:
Martin Afanasjew 2016-05-27 23:13:51 +02:00
parent 78f8c60343
commit 9cf2710dc9
4 changed files with 54 additions and 97 deletions

View File

@ -1,5 +1,3 @@
require "os/mac/architecture_list"
module CctoolsMachO
# @private
OTOOL_RX = /\t(.*) \(compatibility version (?:\d+\.)*\d+, current version (?:\d+\.)*\d+\)/
@ -54,53 +52,6 @@ module CctoolsMachO
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
# @private
class Metadata
attr_reader :path, :dylib_id, :dylibs

View File

@ -1,3 +1,5 @@
require "os/mac/shared_mach"
class Pathname
if ENV["HOMEBREW_RUBY_MACHO"]
require "os/mac/ruby_mach"
@ -6,4 +8,6 @@ class Pathname
require "os/mac/cctools_mach"
include CctoolsMachO
end
include SharedMachO
end

View File

@ -1,5 +1,4 @@
require "vendor/macho/macho"
require "os/mac/architecture_list"
module RubyMachO
# @private
@ -54,53 +53,6 @@ module RubyMachO
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

View File

@ -0,0 +1,50 @@
require "os/mac/architecture_list"
module SharedMachO
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
end