Skip to content

Commit

Permalink
Yeet.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Sep 3, 2024
1 parent 2861d1e commit 51b49ec
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions brew-pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,25 @@ def patchelf(root_dir, prefix_path, binary, format='@executable_path')
next
end

# If the library is linked to itself, skip the recursive call to patchelf
self_referencing = false

# Define new library relative path
if lib_path == binary_path
opoo "The link '#{File.join(root_dir, lib)}' refers to itself: '#{binary_path}'"
next

# Skip recursive call
self_referencing = true

# Obtain the relative path from the library
relative_path = Pathname.new(lib).relative_path_from(Pathname.new(File.join(prefix_path, binary)))
else
# Obtain the relative path from the executable
lib_relative_path = lib_path.delete_prefix(full_prefix_path)
binary_relative_path = File.dirname(binary_path).delete_prefix(full_prefix_path)
relative_path = Pathname.new(lib_relative_path).relative_path_from(Pathname.new(binary_relative_path))
end

# Obtain the relative path from the executable
lib_relative_path = lib_path.delete_prefix(full_prefix_path)
binary_relative_path = File.dirname(binary_path).delete_prefix(full_prefix_path)
relative_path = Pathname.new(lib_relative_path).relative_path_from(Pathname.new(binary_relative_path))
new_lib = File.join(format, relative_path)

# Patch the library path relative to the binary path
Expand All @@ -68,7 +78,9 @@ def patchelf(root_dir, prefix_path, binary, format='@executable_path')
ohai "patchelf(#{root_dir}, #{prefix_path}, #{lib.delete_prefix(prefix_path)})"

# Recursively iterate through libraries
patchelf(root_dir, prefix_path, lib.delete_prefix(prefix_path), '@rpath')
unless self_referencing
patchelf(root_dir, prefix_path, lib.delete_prefix(prefix_path), '@loader_path')
end
end
end

Expand Down

0 comments on commit 51b49ec

Please sign in to comment.