Module: MachOShim Private

Extended by:
Forwardable
Included in:
Pathname
Defined in:
os/mac/mach.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Pathname extension for dealing with Mach-O files.

Instance Method Summary collapse

Instance Method Details

#archObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



131
132
133
134
135
136
137
# File 'os/mac/mach.rb', line 131

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

#archsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



127
128
129
# File 'os/mac/mach.rb', line 127

def archs
  mach_data.map { |m| m.fetch :arch }
end

#change_dylib_id(id, **options) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



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

def change_dylib_id(id, **options)
  macho.change_dylib_id(id, options)
  macho.write!
end

#change_install_name(old, new, **options) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



85
86
87
88
# File 'os/mac/mach.rb', line 85

def change_install_name(old, new, **options)
  macho.change_install_name(old, new, options)
  macho.write!
end

#change_rpath(old, new, **options) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



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

def change_rpath(old, new, **options)
  macho.change_rpath(old, new, options)
  macho.write!
end

#delete_rpath(rpath, **options) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'os/mac/mach.rb', line 62

def delete_rpath(rpath, **options)
  candidates = rpaths(resolve_variable_references: false).select do |r|
    resolve_variable_name(r) == resolve_variable_name(rpath)
  end

  # Delete the last instance to avoid changing the order in which rpaths are searched.
  rpath_to_delete = candidates.last
  options[:last] = true

  macho.delete_rpath(rpath_to_delete, options)
  macho.write!
end

#dylib?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


159
160
161
# File 'os/mac/mach.rb', line 159

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

#dynamically_linked_libraries(except: :none, resolve_variable_references: true) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



90
91
92
93
94
95
96
# File 'os/mac/mach.rb', line 90

def dynamically_linked_libraries(except: :none, resolve_variable_references: true)
  lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }
  names = lcs.map(&:name).map(&:to_s).uniq
  names.map!(&method(:resolve_variable_name)) if resolve_variable_references

  names
end

#i386?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


143
144
145
# File 'os/mac/mach.rb', line 143

def i386?
  arch == :i386
end

#mach_o_bundle?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


169
170
171
# File 'os/mac/mach.rb', line 169

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

#mach_o_executable?Boolean Also known as: binary_executable?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


163
164
165
# File 'os/mac/mach.rb', line 163

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

#ppc64?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


155
156
157
# File 'os/mac/mach.rb', line 155

def ppc64?
  arch == :ppc64
end

#ppc7400?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


151
152
153
# File 'os/mac/mach.rb', line 151

def ppc7400?
  arch == :ppc7400
end

#resolve_rpath(name) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



118
119
120
121
122
123
124
125
# File 'os/mac/mach.rb', line 118

def resolve_rpath(name)
  target = T.let(nil, T.nilable(String))
  return unless rpaths(resolve_variable_references: true).find do |rpath|
    File.exist?(target = File.join(rpath, name.delete_prefix("@rpath")))
  end

  target
end

#resolve_variable_name(name, resolve_rpaths: true) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



106
107
108
109
110
111
112
113
114
115
116
# File 'os/mac/mach.rb', line 106

def resolve_variable_name(name, resolve_rpaths: true)
  if name.start_with? "@loader_path"
    Pathname(name.sub("@loader_path", dirname)).cleanpath.to_s
  elsif name.start_with?("@executable_path") && binary_executable?
    Pathname(name.sub("@executable_path", dirname)).cleanpath.to_s
  elsif resolve_rpaths && name.start_with?("@rpath") && (target = resolve_rpath(name)).present?
    target
  else
    name
  end
end

#rpaths(resolve_variable_references: true) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



98
99
100
101
102
103
104
# File 'os/mac/mach.rb', line 98

def rpaths(resolve_variable_references: true)
  names = macho.rpaths
  # Don't recursively resolve rpaths to avoid infinite loops.
  names.map! { |name| resolve_variable_name(name, resolve_rpaths: false) } if resolve_variable_references

  names
end

#universal?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


139
140
141
# File 'os/mac/mach.rb', line 139

def universal?
  arch == :universal
end

#x86_64?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


147
148
149
# File 'os/mac/mach.rb', line 147

def x86_64?
  arch == :x86_64
end