Merge pull request #2083 from kke/prepend_suitable_ruby_to_path
Prepend suitable ruby to path
This commit is contained in:
commit
0b33428e79
@ -8,16 +8,14 @@ class RubyRequirement < Requirement
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
satisfy build_env: false do
|
satisfy(build_env: false) { new_enough_ruby }
|
||||||
which_all("ruby").detect do |ruby|
|
|
||||||
version = /\d\.\d/.match Utils.popen_read(ruby, "--version")
|
env do
|
||||||
next unless version
|
ENV.prepend_path "PATH", new_enough_ruby
|
||||||
Version.create(version.to_s) >= Version.create(@version)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def message
|
def message
|
||||||
s = "Ruby #{@version} is required to install this formula."
|
s = "Ruby >= #{@version} is required to install this formula."
|
||||||
s += super
|
s += super
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
@ -33,4 +31,28 @@ class RubyRequirement < Requirement
|
|||||||
name
|
name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def new_enough_ruby
|
||||||
|
rubies.detect { |ruby| new_enough?(ruby) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def rubies
|
||||||
|
rubies = which_all("ruby")
|
||||||
|
ruby_formula = Formula["ruby"]
|
||||||
|
if ruby_formula && ruby_formula.installed?
|
||||||
|
rubies.unshift ruby_formula.bin/"ruby"
|
||||||
|
end
|
||||||
|
rubies.uniq
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_enough?(ruby)
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user