Module: MachOShim

Defined in:
Library/Homebrew/os/mac/mach.rb

Instance Method Summary collapse

Instance Method Details

#archObject



68
69
70
71
72
73
74
# File 'Library/Homebrew/os/mac/mach.rb', line 68

def arch
  case archs.length
  when 0 then :dunno
  when 1 then archs.first
  else :universal
  end
end

#archsObject



64
65
66
# File 'Library/Homebrew/os/mac/mach.rb', line 64

def archs
  mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension)
end

#dylib?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'Library/Homebrew/os/mac/mach.rb', line 97

def dylib?
  mach_data.any? { |m| m.fetch(:type) == :dylib }
end

#dylib_idObject



60
61
62
# File 'Library/Homebrew/os/mac/mach.rb', line 60

def dylib_id
  macho.dylib_id
end

#dynamically_linked_libraries(except: :none) ⇒ Object



54
55
56
57
58
# File 'Library/Homebrew/os/mac/mach.rb', line 54

def dynamically_linked_libraries(except: :none)
  lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }

  lcs.map(&:name).map(&:to_s).uniq
end

#i386?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'Library/Homebrew/os/mac/mach.rb', line 80

def i386?
  arch == :i386
end

#mach_dataObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'Library/Homebrew/os/mac/mach.rb', line 13

def mach_data
  @mach_data ||= begin
    machos = []
    mach_data = []

    if MachO::Utils.fat_magic?(macho.magic)
      machos = macho.machos
    else
      machos << macho
    end

    machos.each do |m|
      arch = case m.cputype
      when :x86_64, :i386, :ppc64 then m.cputype
      when :ppc then :ppc7400
      else :dunno
      end

      type = case m.filetype
      when :dylib, :bundle then m.filetype
      when :execute then :executable
      else :dunno
      end

      mach_data << { arch: arch, type: type }
    end

    mach_data
  rescue MachO::NotAMachOError
    # Silently ignore errors that indicate the file is not a Mach-O binary ...
    []
  rescue
    # ... but complain about other (parse) errors for further investigation.
    if ARGV.homebrew_developer?
      onoe "Failed to read Mach-O binary: #{self}"
      raise
    end
    []
  end
end

#mach_o_bundle?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'Library/Homebrew/os/mac/mach.rb', line 109

def mach_o_bundle?
  mach_data.any? { |m| m.fetch(:type) == :bundle }
end

#mach_o_executable?Boolean Also known as: binary_executable?

Returns:

  • (Boolean)


102
103
104
# File 'Library/Homebrew/os/mac/mach.rb', line 102

def mach_o_executable?
  mach_data.any? { |m| m.fetch(:type) == :executable }
end

#machoObject



6
7
8
9
10
# File 'Library/Homebrew/os/mac/mach.rb', line 6

def macho
  @macho ||= begin
    MachO.open(to_s)
  end
end

#ppc64?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'Library/Homebrew/os/mac/mach.rb', line 92

def ppc64?
  arch == :ppc64
end

#ppc7400?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'Library/Homebrew/os/mac/mach.rb', line 88

def ppc7400?
  arch == :ppc7400
end

#universal?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'Library/Homebrew/os/mac/mach.rb', line 76

def universal?
  arch == :universal
end

#x86_64?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'Library/Homebrew/os/mac/mach.rb', line 84

def x86_64?
  arch == :x86_64
end