utils: native rewrite of install_gem_setup_path!
Setting the environment variable `HOMEBREW_RUBY_PATH` allows one to run Homebrew with a non-standard Ruby, even one that is not in `PATH`. This creates the problem that the `gem` in `PATH` might not be the right one to call, possibly leading to confusing results as the wrong RubyGems installation is queried/manipulated. Closes Homebrew/homebrew#46185. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
aeb8aad1e0
commit
fde1614670
@ -190,12 +190,23 @@ module Homebrew
|
|||||||
require "rubygems"
|
require "rubygems"
|
||||||
ENV["PATH"] = "#{Gem.user_dir}/bin:#{ENV["PATH"]}"
|
ENV["PATH"] = "#{Gem.user_dir}/bin:#{ENV["PATH"]}"
|
||||||
|
|
||||||
args = [gem]
|
if Gem::Specification.find_all_by_name(gem, version).empty?
|
||||||
args << "-v" << version if version
|
ohai "Installing or updating '#{gem}' gem"
|
||||||
|
install_args = %W[--no-ri --no-rdoc --user-install #{gem}]
|
||||||
|
install_args << "--version" << version if version
|
||||||
|
|
||||||
unless quiet_system "gem", "list", "--installed", *args
|
# Do `gem install [...]` without having to spawn a separate process or
|
||||||
safe_system "gem", "install", "--no-ri", "--no-rdoc",
|
# having to find the right `gem` binary for the running Ruby interpreter.
|
||||||
"--user-install", *args
|
require "rubygems/commands/install_command"
|
||||||
|
install_cmd = Gem::Commands::InstallCommand.new
|
||||||
|
install_cmd.handle_options(install_args)
|
||||||
|
exit_code = 1 # Should not matter as `install_cmd.execute` always throws.
|
||||||
|
begin
|
||||||
|
install_cmd.execute
|
||||||
|
rescue Gem::SystemExitException => e
|
||||||
|
exit_code = e.exit_code
|
||||||
|
end
|
||||||
|
odie "Failed to install/update the '#{gem}' gem." if exit_code != 0
|
||||||
end
|
end
|
||||||
|
|
||||||
unless which executable
|
unless which executable
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user