Module: MachOShim Private
- Extended by:
- Forwardable, T::Helpers
- Included in:
- Pathname
- Defined in:
- os/mac/mach.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.
Pathname extension for dealing with Mach-O files.
Instance Method Summary collapse
- #arch ⇒ Object private
- #archs ⇒ Object private
- #change_dylib_id(id, **options) ⇒ Object private
- #change_install_name(old, new, **options) ⇒ Object private
- #change_rpath(old, new, **options) ⇒ Object private
-
#delete_rpath(rpath, **options) ⇒ Object
private
we know we're not making any changes to the rpaths.
- #dylib? ⇒ Boolean private
- #dylib_id(*args, &block) ⇒ T.untyped private
- #dynamically_linked_libraries(except: :none, resolve_variable_references: true) ⇒ Object private
- #i386? ⇒ Boolean private
- #initialize(*args) ⇒ Object private
- #mach_o_bundle? ⇒ Boolean private
- #mach_o_executable? ⇒ Boolean (also: #binary_executable?) private
- #ppc64? ⇒ Boolean private
- #ppc7400? ⇒ Boolean private
- #resolve_rpath(name) ⇒ Object private
- #resolve_variable_name(name, resolve_rpaths: true) ⇒ Object private
- #rpaths(resolve_variable_references: true) ⇒ Object private
- #universal? ⇒ Boolean private
- #x86_64? ⇒ Boolean private
Instance Method Details
#arch ⇒ 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.
141 142 143 144 145 146 147 |
# File 'os/mac/mach.rb', line 141 def arch case archs.length when 0 then :dunno when 1 then archs.first else :universal end end |
#archs ⇒ 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.
137 138 139 |
# File 'os/mac/mach.rb', line 137 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.
89 90 91 92 |
# File 'os/mac/mach.rb', line 89 def change_dylib_id(id, **) macho.change_dylib_id(id, ) 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.
94 95 96 97 |
# File 'os/mac/mach.rb', line 94 def change_install_name(old, new, **) macho.change_install_name(old, new, ) 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.
84 85 86 87 |
# File 'os/mac/mach.rb', line 84 def change_rpath(old, new, **) macho.change_rpath(old, new, ) 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.
See if the #write!
call can be delayed until
we know we're not making any changes to the rpaths.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'os/mac/mach.rb', line 71 def delete_rpath(rpath, **) 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 [:last] = true macho.delete_rpath(rpath_to_delete, ) 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.
169 170 171 |
# File 'os/mac/mach.rb', line 169 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.
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) ⇒ 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.
99 100 101 102 103 104 105 106 |
# File 'os/mac/mach.rb', line 99 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.
153 154 155 |
# File 'os/mac/mach.rb', line 153 def i386? arch == :i386 end |
#initialize(*args) ⇒ 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.
15 16 17 18 19 20 |
# File 'os/mac/mach.rb', line 15 def initialize(*args) @macho = T.let(nil, T.nilable(MachO::MachOFile)) @mach_data = T.let(nil, T.nilable(T::Array[T::Hash[Symbol, T.untyped]])) 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.
179 180 181 |
# File 'os/mac/mach.rb', line 179 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.
173 174 175 |
# File 'os/mac/mach.rb', line 173 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.
165 166 167 |
# File 'os/mac/mach.rb', line 165 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.
161 162 163 |
# File 'os/mac/mach.rb', line 161 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.
128 129 130 131 132 133 134 135 |
# File 'os/mac/mach.rb', line 128 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.
116 117 118 119 120 121 122 123 124 125 126 |
# File 'os/mac/mach.rb', line 116 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.
108 109 110 111 112 113 114 |
# File 'os/mac/mach.rb', line 108 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.
149 150 151 |
# File 'os/mac/mach.rb', line 149 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.
157 158 159 |
# File 'os/mac/mach.rb', line 157 def x86_64? arch == :x86_64 end |