Module: MachOShim Private
- Extended by:
- T::Helpers
- Defined in:
- os/mac/mach.rb,
extend/pathname.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
- #arch ⇒ Symbol private
- #archs ⇒ Array<Symbol> private
- #change_dylib_id(id, strict: true) ⇒ void private
- #change_install_name(old, new, strict: true) ⇒ void private
- #change_rpath(old, new, uniq: false, last: false, strict: true) ⇒ void private
-
#delete_rpath(rpath, strict: true) ⇒ String?
private
Returns the deleted rpath, or nil when there's nothing to delete.
- #dylib? ⇒ Boolean private
- #dylib_id ⇒ String? private
- #dynamically_linked_libraries(except: :none, resolve_variable_references: true) ⇒ Array<String> private
- #i386? ⇒ Boolean private
- #initialize(*args) ⇒ void private
- #mach_o_bundle? ⇒ Boolean private
- #mach_o_executable? ⇒ Boolean (also: #binary_executable?) private
- #ppc64? ⇒ Boolean private
- #ppc7400? ⇒ Boolean private
- #resolve_rpath(name) ⇒ String? private
- #resolve_variable_name(name, resolve_rpaths: true) ⇒ String private
- #rpaths(resolve_variable_references: true) ⇒ Array<String> private
- #universal? ⇒ Boolean private
- #x86_64? ⇒ Boolean private
Instance Method Details
#arch ⇒ 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.
159 160 161 162 163 164 165 |
# File 'os/mac/mach.rb', line 159 def arch case archs.length when 0 then :dunno when 1 then archs.fetch(0) else :universal end end |
#archs ⇒ Array<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.
154 155 156 |
# File 'os/mac/mach.rb', line 154 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.
100 101 102 103 |
# File 'os/mac/mach.rb', line 100 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.
106 107 108 109 |
# File 'os/mac/mach.rb', line 106 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.
94 95 96 97 |
# File 'os/mac/mach.rb', line 94 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) ⇒ 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.
Returns the deleted rpath, or nil when there's nothing to delete.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'os/mac/mach.rb', line 78 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 # Avoid writing the whole binary back to disk when there's nothing to delete. return if rpath_to_delete.nil? macho.delete_rpath(rpath_to_delete, { last: true, strict: }) macho.write! rpath_to_delete 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.
193 194 195 |
# File 'os/mac/mach.rb', line 193 def dylib? mach_data.any? { |m| m.fetch(:type) == :dylib } end |
#dylib_id ⇒ 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.
24 |
# File 'os/mac/mach.rb', line 24 def dylib_id = macho.dylib_id |
#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.
112 113 114 115 116 117 118 119 |
# File 'os/mac/mach.rb', line 112 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(it) } 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.
173 174 175 |
# File 'os/mac/mach.rb', line 173 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.
14 15 16 17 18 19 20 21 |
# File 'os/mac/mach.rb', line 14 def initialize(*args) require "macho" @macho = T.let(nil, T.nilable(MachOFile)) @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.
205 206 207 |
# File 'os/mac/mach.rb', line 205 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.
198 199 200 |
# File 'os/mac/mach.rb', line 198 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.
188 189 190 |
# File 'os/mac/mach.rb', line 188 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.
183 184 185 |
# File 'os/mac/mach.rb', line 183 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.
144 145 146 147 148 149 150 151 |
# File 'os/mac/mach.rb', line 144 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.
131 132 133 134 135 136 137 138 139 140 141 |
# File 'os/mac/mach.rb', line 131 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.
122 123 124 125 126 127 128 |
# File 'os/mac/mach.rb', line 122 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.
168 169 170 |
# File 'os/mac/mach.rb', line 168 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.
178 179 180 |
# File 'os/mac/mach.rb', line 178 def x86_64? arch == :x86_64 end |