Extract repeated regexp to a method
This commit is contained in:
parent
4ed9efd995
commit
0224bce9f6
@ -44,18 +44,12 @@ class Keg
|
|||||||
old_cellar = HOMEBREW_CELLAR if old_cellar == :any
|
old_cellar = HOMEBREW_CELLAR if old_cellar == :any
|
||||||
old_prefix = HOMEBREW_PREFIX if old_prefix == :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|
|
pkgconfig_files.each do |pcfile|
|
||||||
pcfile.ensure_writable do
|
pcfile.ensure_writable do
|
||||||
pcfile.open('rb') do |f|
|
pcfile.open('rb') do |f|
|
||||||
s = f.read
|
s = f.read
|
||||||
# These regexes match lines of the form: prefix=/usr/local/Cellar/foo/1.2.3/lib
|
replace_pkgconfig_file_path(s, old_cellar, new_cellar)
|
||||||
# and (assuming new_cellar is "/tmp") transform them into: prefix="/tmp/foo/1.2.3/lib"
|
replace_pkgconfig_file_path(s, old_prefix, new_prefix)
|
||||||
# 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\"")
|
|
||||||
f.reopen(pcfile, 'wb')
|
f.reopen(pcfile, 'wb')
|
||||||
f.write(s)
|
f.write(s)
|
||||||
end
|
end
|
||||||
@ -63,6 +57,16 @@ class Keg
|
|||||||
end
|
end
|
||||||
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
|
# Detects the C++ dynamic libraries in place, scanning the dynamic links
|
||||||
# of the files within the keg. This searches only libs contained within
|
# of the files within the keg. This searches only libs contained within
|
||||||
# lib/, and ignores binaries and other mach-o objects
|
# lib/, and ignores binaries and other mach-o objects
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user