Document MachOShim.

This commit is contained in:
Markus Reiter 2020-08-25 00:28:26 +02:00
parent f7cb6a95b6
commit 390deeb5ac

View File

@ -3,19 +3,21 @@
require "macho" require "macho"
require "os/mac/architecture_list" require "os/mac/architecture_list"
# {Pathname} extension for dealing with Mach-O files.
#
# @api private
module MachOShim module MachOShim
extend Forwardable extend Forwardable
delegate [:dylib_id, :rpaths, :delete_rpath] => :macho delegate [:dylib_id, :rpaths, :delete_rpath] => :macho
# @private
def macho def macho
@macho ||= begin @macho ||= begin
MachO.open(to_s) MachO.open(to_s)
end end
end end
private :macho
# @private
def mach_data def mach_data
@mach_data ||= begin @mach_data ||= begin
machos = [] machos = []
@ -55,6 +57,7 @@ module MachOShim
[] []
end end
end end
private :mach_data
def dynamically_linked_libraries(except: :none) def dynamically_linked_libraries(except: :none)
lcs = macho.dylib_load_commands.reject { |lc| lc.type == except } lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }
@ -94,19 +97,16 @@ module MachOShim
arch == :ppc64 arch == :ppc64
end end
# @private
def dylib? def dylib?
mach_data.any? { |m| m.fetch(:type) == :dylib } mach_data.any? { |m| m.fetch(:type) == :dylib }
end end
# @private
def mach_o_executable? def mach_o_executable?
mach_data.any? { |m| m.fetch(:type) == :executable } mach_data.any? { |m| m.fetch(:type) == :executable }
end end
alias binary_executable? mach_o_executable? alias binary_executable? mach_o_executable?
# @private
def mach_o_bundle? def mach_o_bundle?
mach_data.any? { |m| m.fetch(:type) == :bundle } mach_data.any? { |m| m.fetch(:type) == :bundle }
end end