brew/Library/Homebrew/os/mac/shared_mach.rb
Martin Afanasjew 9cf2710dc9 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`.
2016-05-27 23:13:51 +02:00

51 lines
758 B
Ruby

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