Module: MachOShim Private

Extended by:
Forwardable, T::Helpers
Defined in:
os/mac/mach.rb,
extend/pathname.rb,
sorbet/rbi/dsl/mach_o_shim.rbi

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.

Stubs needed to keep Sorbet happy.

Instance Method Summary collapse

Instance Method Details

#archSymbol

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:



153
154
155
156
157
158
159
# File 'os/mac/mach.rb', line 153

def arch
  case archs.length
  when 0 then :dunno
  when 1 then archs.fetch(0)
  else :universal
  end
end

#archsArray<Symbol>

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:



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

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

#change_dylib_id(id, strict: true) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • id (String)
  • strict (Boolean) (defaults to: true)


94
95
96
97
# File 'os/mac/mach.rb', line 94

def change_dylib_id(id, strict: true)
  macho.change_dylib_id(id, { strict: })
  macho.write!
end

#change_install_name(old, new, strict: true) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • old (String)
  • new (String)
  • strict (Boolean) (defaults to: true)


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

def change_install_name(old, new, strict: true)
  macho.change_install_name(old, new, { strict: })
  macho.write!
end

#change_rpath(old, new, uniq: false, last: false, strict: true) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • old (String)
  • new (String)
  • uniq (Boolean) (defaults to: false)
  • last (Boolean) (defaults to: false)
  • strict (Boolean) (defaults to: true)


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

def change_rpath(old, new, uniq: false, last: false, strict: true)
  macho.change_rpath(old, new, { uniq:, last:, strict: })
  macho.write!
end

#delete_rpath(rpath, strict: true) ⇒ void

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.

TODO:

See if the #write! call can be delayed until we know we're not making any changes to the rpaths.

This method returns an undefined value.

Parameters:

  • rpath (String)
  • strict (Boolean) (defaults to: true)


75
76
77
78
79
80
81
82
83
84
85
# File 'os/mac/mach.rb', line 75

def delete_rpath(rpath, strict: true)
  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

  macho.delete_rpath(rpath_to_delete, { last: true, strict: })
  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)


187
188
189
# File 'os/mac/mach.rb', line 187

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

#dylib_id(*args, &block) ⇒ T.untyped

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.

Parameters:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


10
# File 'sorbet/rbi/dsl/mach_o_shim.rbi', line 10

def dylib_id(*args, &block); end

#dynamically_linked_libraries(except: :none, resolve_variable_references: true) ⇒ Array<String>

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.

Parameters:

  • except (Symbol) (defaults to: :none)
  • resolve_variable_references (Boolean) (defaults to: true)

Returns:



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

def dynamically_linked_libraries(except: :none, resolve_variable_references: true)
  lcs = macho.dylib_load_commands
  lcs.reject! { |lc| lc.flag?(except) } if except != :none
  names = lcs.map { |lc| lc.name.to_s }.uniq
  names.map! { resolve_variable_name(_1) } 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)


167
168
169
# File 'os/mac/mach.rb', line 167

def i386?
  arch == :i386
end

#initialize(*args) ⇒ void

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.

Parameters:

  • args (T.untyped)


16
17
18
19
20
21
# File 'os/mac/mach.rb', line 16

def initialize(*args)
  @macho = T.let(nil, T.nilable(T.any(MachO::MachOFile, MachO::FatFile)))
  @mach_data = T.let(nil, T.nilable(T::Array[T::Hash[Symbol, Symbol]]))

  super
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)


199
200
201
# File 'os/mac/mach.rb', line 199

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)


192
193
194
# File 'os/mac/mach.rb', line 192

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)


182
183
184
# File 'os/mac/mach.rb', line 182

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)


177
178
179
# File 'os/mac/mach.rb', line 177

def ppc7400?
  arch == :ppc7400
end

#resolve_rpath(name) ⇒ String?

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.

Parameters:

Returns:



138
139
140
141
142
143
144
145
# File 'os/mac/mach.rb', line 138

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) ⇒ String

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.

Parameters:

  • name (String)
  • resolve_rpaths (Boolean) (defaults to: true)

Returns:



125
126
127
128
129
130
131
132
133
134
135
# File 'os/mac/mach.rb', line 125

def resolve_variable_name(name, resolve_rpaths: true)
  if name.start_with? "@loader_path"
    Pathname(name.sub("@loader_path", dirname.to_s)).cleanpath.to_s
  elsif name.start_with?("@executable_path") && binary_executable?
    Pathname(name.sub("@executable_path", dirname.to_s)).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) ⇒ Array<String>

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.

Parameters:

  • resolve_variable_references (Boolean) (defaults to: true)

Returns:



116
117
118
119
120
121
122
# File 'os/mac/mach.rb', line 116

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)


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

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)


172
173
174
# File 'os/mac/mach.rb', line 172

def x86_64?
  arch == :x86_64
end