os/mac/keg_relocate: avoid changing to an already existing rpath

Doing `change_rpath(old, new, file)` will error if `new` is already an
rpath for `file`. When this happens, `old` is no longer needed, so we
can delete it.

Fixes a build failure at shivammathur/homebrew-php#1848.
This commit is contained in:
Carlo Cabrera 2023-07-18 20:47:10 +08:00
parent 8bfe579e8a
commit 27032e002f
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -62,7 +62,15 @@ class Keg
else
new_name = opt_name_for(bad_name)
loader_name = loader_name_for(file, new_name)
change_rpath(bad_name, loader_name, file) if loader_name != bad_name
next if loader_name == bad_name
if file.rpaths(resolve_variable_references: false).include?(loader_name)
# The wanted loader_name is already an rpath, so the existing bad_name is not needed.
# Attempting to change bad_name to an already existing rpath will produce an error.
delete_rpath(bad_name, file)
else
change_rpath(bad_name, loader_name, file)
end
end
end
end