
Rather than having to manually keep track of what version each thing in here is and copy files around by hand on update let's use Bundler's standalone mode and careful use of `.gitignore` to help us do it. This means a `bundle update --standalone` will allow us to update all gems in vendor. We could consider vendoring other gems this way in future but I'd suggest only doing this for gems with no dependencies or at least gems with no native extensions. The only gem this applies to that we currently use is `ruby-prof` and I'm not convinced it's widely used enough to warrant vendoring for everyone. Perhaps that's another criteria: it should be functionality that's used by non-developer commands and/or normal Homebrew usage.
68 lines
1.7 KiB
Ruby
68 lines
1.7 KiB
Ruby
# Contains backports from newer versions of Ruby
|
|
require "backports/2.4.0/string/match"
|
|
|
|
class String
|
|
# String.chomp, but if result is empty: returns nil instead.
|
|
# Allows `chuzzle || foo` short-circuits.
|
|
def chuzzle
|
|
s = chomp
|
|
s unless s.empty?
|
|
end
|
|
|
|
def strip_prefix(prefix)
|
|
start_with?(prefix) ? self[prefix.length..-1] : self
|
|
end
|
|
end
|
|
|
|
class NilClass
|
|
def chuzzle; end
|
|
end
|
|
|
|
# used by the inreplace function (in utils.rb)
|
|
module StringInreplaceExtension
|
|
attr_accessor :errors
|
|
|
|
def self.extended(str)
|
|
str.errors = []
|
|
end
|
|
|
|
def sub!(before, after)
|
|
result = super
|
|
unless result
|
|
errors << "expected replacement of #{before.inspect} with #{after.inspect}"
|
|
end
|
|
result
|
|
end
|
|
|
|
# Warn if nothing was replaced
|
|
def gsub!(before, after, audit_result = true)
|
|
result = super(before, after)
|
|
if audit_result && result.nil?
|
|
errors << "expected replacement of #{before.inspect} with #{after.inspect}"
|
|
end
|
|
result
|
|
end
|
|
|
|
# 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)
|
|
errors << "expected to change #{flag.inspect} to #{new_value.inspect}"
|
|
end
|
|
|
|
# Removes variable assignments completely.
|
|
def remove_make_var!(flags)
|
|
Array(flags).each do |flag|
|
|
# Also remove trailing \n, if present.
|
|
unless 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]
|
|
end
|
|
end
|