Skip to content

Commit

Permalink
Merge pull request #15769 from carlocab/resolve-rpath
Browse files Browse the repository at this point in the history
os/mac/mach: resolve rpaths too
  • Loading branch information
carlocab authored Jul 27, 2023
2 parents 954fc88 + b80940e commit 4c612ab
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Library/Homebrew/os/mac/mach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,15 @@ def change_install_name(old, new, **options)

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! { |name| resolve_variable_name(name) } if resolve_variable_references
names.map!(&method(:resolve_variable_name)) if resolve_variable_references

names
end

def rpaths(resolve_variable_references: true)
names = macho.rpaths

names.map! { |name| resolve_variable_name(name) } if resolve_variable_references
names.map!(&method(:resolve_variable_name)) if resolve_variable_references

names
end
Expand All @@ -110,11 +107,22 @@ def resolve_variable_name(name)
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
Expand Down

0 comments on commit 4c612ab

Please sign in to comment.