aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/extend')
-rw-r--r--Library/Homebrew/extend/string.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb
index a0cd4d635..c76df4d31 100644
--- a/Library/Homebrew/extend/string.rb
+++ b/Library/Homebrew/extend/string.rb
@@ -13,11 +13,20 @@ end
# used by the inreplace function (in utils.rb)
module StringInreplaceExtension
+ # Warn if nothing was replaced
+ def gsub! before, after, audit_result=true
+ sub = super(before, after)
+ if audit_result and sub.nil?
+ opoo "inreplace: replacement of '#{before}' with '#{after}' failed"
+ end
+ return sub
+ end
+
# Looks for Makefile style variable defintions and replaces the
# value with "new_value", or removes the definition entirely.
def change_make_var! flag, new_value
new_value = "#{flag}=#{new_value}"
- sub = gsub! Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$"), new_value
+ sub = gsub! Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$"), new_value, false
opoo "inreplace: changing '#{flag}' to '#{new_value}' failed" if sub.nil?
end
@@ -27,7 +36,7 @@ module StringInreplaceExtension
flags = [flags] unless flags.kind_of? Array
flags.each do |flag|
# Also remove trailing \n, if present.
- sub = gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), ""
+ sub = gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), "", false
opoo "inreplace: removing '#{flag}' failed" if sub.nil?
end
end