diff --git a/Library/Homebrew/keg_fix_install_names.rb b/Library/Homebrew/keg_fix_install_names.rb index bff97842ce..e60ba72f1a 100644 --- a/Library/Homebrew/keg_fix_install_names.rb +++ b/Library/Homebrew/keg_fix_install_names.rb @@ -44,18 +44,12 @@ class Keg old_cellar = HOMEBREW_CELLAR if old_cellar == :any old_prefix = HOMEBREW_PREFIX if old_prefix == :any - old_cellar = Regexp.escape(old_cellar) - old_prefix = Regexp.escape(old_prefix) - pkgconfig_files.each do |pcfile| pcfile.ensure_writable do pcfile.open('rb') do |f| s = f.read - # These regexes match lines of the form: prefix=/usr/local/Cellar/foo/1.2.3/lib - # and (assuming new_cellar is "/tmp") transform them into: prefix="/tmp/foo/1.2.3/lib" - # If the original line did not have quotes, we add them in automatically - s.gsub!(%r[([\S]+)="?#{old_cellar}(.*?)"?$], "\\1=\"#{new_cellar}\\2\"") - s.gsub!(%r[([\S]+)="?#{old_prefix}(.*?)"?$], "\\1=\"#{new_prefix}\\2\"") + replace_pkgconfig_file_path(s, old_cellar, new_cellar) + replace_pkgconfig_file_path(s, old_prefix, new_prefix) f.reopen(pcfile, 'wb') f.write(s) end @@ -63,6 +57,16 @@ class Keg end end + # Given old == "/usr/local/Cellar" and new == "/opt/homebrew/Cellar", + # then update lines of the form + # some_variable=/usr/local/Cellar/foo/1.0/lib + # to + # some_variable="/opt/homebrew/Cellar/foo/1.0/lib" + # and add quotes to protect against paths containing spaces. + def replace_pkgconfig_file_path(s, old, new) + s.gsub!(%r[([\S]+)="?#{Regexp.escape(old)}(.*?)"?$], "\\1=\"#{new}\\2\"") + end + # Detects the C++ dynamic libraries in place, scanning the dynamic links # of the files within the keg. This searches only libs contained within # lib/, and ignores binaries and other mach-o objects