aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-11-30 19:38:48 -0600
committerJack Nagel2013-12-01 17:05:02 -0600
commit0224bce9f6f217f12803951695e3033cb0c987be (patch)
treea82c47540c269bc2c806285e1d58639b3d83a5f2 /Library
parent4ed9efd99520f96a2db03e9ce861a41e64f16633 (diff)
downloadbrew-0224bce9f6f217f12803951695e3033cb0c987be.tar.bz2
Extract repeated regexp to a method
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/keg_fix_install_names.rb20
1 files changed, 12 insertions, 8 deletions
diff --git a/Library/Homebrew/keg_fix_install_names.rb b/Library/Homebrew/keg_fix_install_names.rb
index bff97842c..e60ba72f1 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