From 27032e002fb51fc5554145cef1a54fba2b32505f Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 18 Jul 2023 20:47:10 +0800 Subject: [PATCH] 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. --- Library/Homebrew/extend/os/mac/keg_relocate.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 1667c1e016..6ad9c06d08 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -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