
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`.
51 lines
758 B
Ruby
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
|