diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index f9818d6f84..38f52dc4c9 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -110,11 +110,22 @@ module MachOShim 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 name.start_with?("@rpath") && (target = resolve_rpath(name)).present? + target else name end end + 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 + def archs mach_data.map { |m| m.fetch :arch } end