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:
		
							parent
							
								
									78f8c60343
								
							
						
					
					
						commit
						9cf2710dc9
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										50
									
								
								Library/Homebrew/os/mac/shared_mach.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								Library/Homebrew/os/mac/shared_mach.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user