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`.
This commit is contained in:
Carlo Cabrera 2023-05-22 17:18:43 +08:00
parent 4446fe603c
commit 59d92ab73f
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -47,8 +47,7 @@ class Keg
each_linkage_for(file, :dynamically_linked_libraries) do |bad_name| each_linkage_for(file, :dynamically_linked_libraries) do |bad_name|
# Don't fix absolute paths unless they are rooted in the build directory # Don't fix absolute paths unless they are rooted in the build directory
next if bad_name.start_with?("/") && next if bad_name.start_with?("/") &&
!bad_name.start_with?(HOMEBREW_TEMP.to_s) && !rooted_in_build_directory?(bad_name)
!bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s)
new_name = fixed_name(file, bad_name) new_name = fixed_name(file, bad_name)
change_install_name(bad_name, new_name, file) if new_name != 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| each_linkage_for(file, :rpaths) do |bad_name|
# Strip duplicate rpaths and rpaths rooted in the build directory. # Strip duplicate rpaths and rpaths rooted in the build directory.
next if !bad_name.start_with?(HOMEBREW_TEMP.to_s) && next if !rooted_in_build_directory?(bad_name) &&
!bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) &&
(file.rpaths.count(bad_name) == 1) (file.rpaths.count(bad_name) == 1)
delete_rpath(bad_name, file) delete_rpath(bad_name, file)
@ -189,4 +187,14 @@ class Keg
grep_args = "--files-with-matches" grep_args = "--files-with-matches"
[grep_bin, grep_args] [grep_bin, grep_args]
end 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 end