aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/test_inreplace.rb12
-rw-r--r--Library/Homebrew/utils.rb12
2 files changed, 18 insertions, 6 deletions
diff --git a/Library/Homebrew/test/test_inreplace.rb b/Library/Homebrew/test/test_inreplace.rb
index af961101e..ab9659b36 100644
--- a/Library/Homebrew/test/test_inreplace.rb
+++ b/Library/Homebrew/test/test_inreplace.rb
@@ -14,13 +14,21 @@ class InreplaceTest < Test::Unit::TestCase
s1.change_make_var! "FLAG", "\\1 def"
assert_equal "FLAG=abc def", s1
end
+
+ def test_change_make_var_shell_style
+ # Shell variables have no spaces around =
+ s1="FLAG=abc"
+ s1.extend(HomebrewInreplaceExtension)
+ s1.change_make_var! "FLAG", "def"
+ assert_equal "FLAG=def", s1
+ end
def test_remove_make_var
# Replace flag
s1="FLAG = abc\nFLAG2 = def"
s1.extend(HomebrewInreplaceExtension)
s1.remove_make_var! "FLAG"
- assert_equal "FLAG=\nFLAG2 = def", s1
+ assert_equal "FLAG2 = def", s1
end
def test_remove_make_vars
@@ -28,6 +36,6 @@ class InreplaceTest < Test::Unit::TestCase
s1="FLAG = abc\nFLAG2 = def"
s1.extend(HomebrewInreplaceExtension)
s1.remove_make_var! ["FLAG", "FLAG2"]
- assert_equal "FLAG=\nFLAG2=", s1
+ assert_equal "", s1
end
end
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index ae6ca50b9..3f89e187a 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -177,16 +177,20 @@ def archs_for_command cmd
end
end
+# String extensions added by inreplace below.
module HomebrewInreplaceExtension
# Looks for Makefile style variable defintions and replaces the
# value with "new_value", or removes the definition entirely.
- # See inreplace in utils.rb
- def change_make_var! flag, new_value=nil
- new_value = "#{flag}=#{new_value}" unless new_value == nil
+ def change_make_var! flag, new_value
+ new_value = "#{flag}=#{new_value}"
gsub! Regexp.new("^#{flag}\\s*=\\s*(.*)$"), new_value
end
+ # Removes variable assignments completely.
def remove_make_var! flags
- flags.each { |flag| change_make_var! flag, "" }
+ flags.each do |flag|
+ # Also remove trailing \n, if present.
+ gsub! Regexp.new("^#{flag}\\s*=(.*)$\n?"), ""
+ end
end
end