From 59d92ab73fe41b4f39f53d7ceeb2524a40441f61 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 22 May 2023 17:18:43 +0800 Subject: [PATCH] keg_relocate: fix check for paths rooted in build directory Stuff built by CMake evades this check because CMake normalises `/private/tmp` (which is the default `HOMEBREW_TEMP`) to `/tmp`. See https://gitlab.kitware.com/cmake/cmake/-/issues/23251. Let's fix that my taking this into account when `HOMEBREW_TEMP` is `/private/tmp`. --- Library/Homebrew/extend/os/mac/keg_relocate.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 52b3cf890c..003a860dc2 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -47,8 +47,7 @@ class Keg each_linkage_for(file, :dynamically_linked_libraries) do |bad_name| # Don't fix absolute paths unless they are rooted in the build directory next if bad_name.start_with?("/") && - !bad_name.start_with?(HOMEBREW_TEMP.to_s) && - !bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) + !rooted_in_build_directory?(bad_name) new_name = fixed_name(file, bad_name) change_install_name(bad_name, new_name, file) if new_name != bad_name @@ -56,8 +55,7 @@ class Keg each_linkage_for(file, :rpaths) do |bad_name| # Strip duplicate rpaths and rpaths rooted in the build directory. - next if !bad_name.start_with?(HOMEBREW_TEMP.to_s) && - !bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) && + next if !rooted_in_build_directory?(bad_name) && (file.rpaths.count(bad_name) == 1) delete_rpath(bad_name, file) @@ -189,4 +187,14 @@ class Keg grep_args = "--files-with-matches" [grep_bin, grep_args] end + + private + + def rooted_in_build_directory?(filename) + # CMake normalises `/private/tmp` to `/tmp`. + # https://gitlab.kitware.com/cmake/cmake/-/issues/23251 + return true if HOMEBREW_TEMP.to_s == "/private/tmp" && filename.start_with?("/tmp") + + filename.start_with?(HOMEBREW_TEMP.to_s) || filename.start_with?(HOMEBREW_TEMP.realpath.to_s) + end end