2015-04-11 19:18:40 +01:00
|
|
|
class RubyRequirement < Requirement
|
|
|
|
fatal true
|
2015-04-27 14:06:43 +01:00
|
|
|
default_formula "ruby"
|
2015-04-11 19:18:40 +01:00
|
|
|
|
|
|
|
def initialize(tags)
|
2016-09-11 17:42:44 +01:00
|
|
|
@version = tags.shift if /(\d\.)+\d/ =~ tags.first
|
2015-04-11 19:18:40 +01:00
|
|
|
raise "RubyRequirement requires a version!" unless @version
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2017-02-22 09:21:31 +02:00
|
|
|
satisfy(build_env: false) { new_enough_ruby }
|
2017-02-21 11:24:53 +02:00
|
|
|
|
|
|
|
env do
|
2017-03-27 16:43:02 -04:00
|
|
|
ENV.prepend_path "PATH", new_enough_ruby.dirname
|
2015-04-11 19:18:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
2017-02-21 11:12:34 +02:00
|
|
|
s = "Ruby >= #{@version} is required to install this formula."
|
2015-04-11 19:18:40 +01:00
|
|
|
s += super
|
|
|
|
s
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name}: #{name.inspect} #{tags.inspect} version=#{@version.inspect}>"
|
|
|
|
end
|
2016-09-18 00:37:02 -04:00
|
|
|
|
|
|
|
def display_s
|
|
|
|
if @version
|
|
|
|
"#{name} >= #{@version}"
|
|
|
|
else
|
|
|
|
name
|
|
|
|
end
|
|
|
|
end
|
2017-02-21 11:12:34 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-02-22 09:21:31 +02:00
|
|
|
def new_enough_ruby
|
|
|
|
rubies.detect { |ruby| new_enough?(ruby) }
|
2017-02-21 11:24:53 +02:00
|
|
|
end
|
|
|
|
|
2017-02-21 11:12:34 +02:00
|
|
|
def rubies
|
|
|
|
rubies = which_all("ruby")
|
2017-02-22 09:21:31 +02:00
|
|
|
ruby_formula = Formula["ruby"]
|
2017-09-24 19:24:46 +01:00
|
|
|
rubies.unshift ruby_formula.bin/"ruby" if ruby_formula&.installed?
|
2017-02-21 11:12:34 +02:00
|
|
|
rubies.uniq
|
|
|
|
end
|
|
|
|
|
2017-02-22 09:21:31 +02:00
|
|
|
def new_enough?(ruby)
|
2017-02-21 11:12:34 +02:00
|
|
|
version = Utils.popen_read(ruby, "-e", "print RUBY_VERSION").strip
|
|
|
|
version =~ /^\d+\.\d+/ && Version.create(version) >= min_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def min_version
|
|
|
|
@min_version ||= Version.create(@version)
|
|
|
|
end
|
2015-04-11 19:18:40 +01:00
|
|
|
end
|