diff options
| author | Jack Nagel | 2012-02-23 21:05:49 -0600 |
|---|---|---|
| committer | Jack Nagel | 2012-02-25 22:37:29 -0600 |
| commit | dbde2615121a102a7ea0638c5cc95f3c49daa950 (patch) | |
| tree | b0614e62554ff662abccc243998535bddf1fb0da /Library | |
| parent | a4926b84c2b4ef7b0777e679a88d4c44f0fa20a7 (diff) | |
| download | homebrew-dbde2615121a102a7ea0638c5cc95f3c49daa950.tar.bz2 | |
inreplace: warn if no substitutions were made
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/extend/string.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 6 |
2 files changed, 9 insertions, 3 deletions
diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index 3238f97df..a0cd4d635 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -17,7 +17,8 @@ module StringInreplaceExtension # value with "new_value", or removes the definition entirely. def change_make_var! flag, new_value new_value = "#{flag}=#{new_value}" - gsub! Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$"), new_value + sub = gsub! Regexp.new("^#{flag}[ \\t]*=[ \\t]*(.*)$"), new_value + opoo "inreplace: changing '#{flag}' to '#{new_value}' failed" if sub.nil? end # Removes variable assignments completely. @@ -26,7 +27,8 @@ module StringInreplaceExtension flags = [flags] unless flags.kind_of? Array flags.each do |flag| # Also remove trailing \n, if present. - gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), "" + sub = gsub! Regexp.new("^#{flag}[ \\t]*=(.*)$\n?"), "" + opoo "inreplace: removing '#{flag}' failed" if sub.nil? end end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index bb2e7dd83..6c29ba105 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -216,7 +216,11 @@ def inreplace path, before=nil, after=nil s.extend(StringInreplaceExtension) yield s else - s.gsub!(before, after) + sub = s.gsub!(before, after) + if sub.nil? + opoo "inreplace in '#{path}' failed" + puts "Expected replacement of '#{before}' with '#{after}'" + end end f.reopen(path, 'w').write(s) |
