aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Vandenberg2012-02-25 16:57:03 -0800
committerJack Nagel2012-02-25 22:41:20 -0600
commit42d44053ef5d9a3fd46e96be57b73a690a4501fa (patch)
tree5573bd99a211340e4daa54306b5637e4156b263a
parenta3edec8b88a3490477f5a60b3262fb4ceb2f8166 (diff)
downloadbrew-42d44053ef5d9a3fd46e96be57b73a690a4501fa.tar.bz2
inreplace: also warn on plain gsub! usage
-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