Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with GMake Makefile conditional assignment operators. #6623

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions Library/Homebrew/extend/string.rb
Expand Up @@ -41,7 +41,7 @@ def gsub!(before, after, audit_result = true)
# Looks for Makefile style variable definitions and replaces the
# value with "new_value", or removes the definition entirely.
def change_make_var!(flag, new_value)
return if gsub!(/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, "#{flag}=#{new_value}", false)
return if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=[ \t]*(.*)$/, "#{flag}=#{new_value}", false)

errors << "expected to change #{flag.inspect} to #{new_value.inspect}"
end
Expand All @@ -50,12 +50,14 @@ def change_make_var!(flag, new_value)
def remove_make_var!(flags)
Array(flags).each do |flag|
# Also remove trailing \n, if present.
errors << "expected to remove #{flag.inspect}" unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=.*$\n?/, "", false)
if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=.*$\n?/, "", false)
errors << "expected to remove #{flag.inspect}"
end
end
end

# Finds the specified variable
def get_make_var(flag)
self[/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, 1]
self[/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=[ \t]*(.*)$/, 1]
end
end