Skip to content

Commit

Permalink
[rubygems/rubygems] More improves to default gem home selection for i…
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and hsbt committed Dec 16, 2023
1 parent 299eb8d commit 0ff34aa
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions lib/rubygems/installer.rb
Expand Up @@ -664,6 +664,7 @@ def process_options # :nodoc:
@env_shebang = options[:env_shebang]
@force = options[:force]
@install_dir = options[:install_dir]
@user_install = options[:user_install]
@ignore_dependencies = options[:ignore_dependencies]
@format_executable = options[:format_executable]
@wrappers = options[:wrappers]
Expand All @@ -675,22 +676,7 @@ def process_options # :nodoc:

@build_args = options[:build_args]

@gem_home = @install_dir

unless @gem_home
# `--build-root` overrides `--user-install` and auto-user-install
if @build_root.nil?
# Please note that `options[:user_install]` might have three states:
# * `true`: `--user-install`
# * `false`: `--no-user-install` and
# * `nil`: option was not specified
if options[:user_install] || (options[:user_install].nil? && Gem.default_user_install)
@gem_home = Gem.user_dir
end
end

@gem_home ||= Gem.dir
end
@gem_home = @install_dir || user_install_dir || Gem.dir

# If the user has asked for the gem to be installed in a directory that is
# the system gem directory, then use the system bin directory, else create
Expand Down Expand Up @@ -986,6 +972,19 @@ def ensure_writable_dir(dir) # :nodoc:

private

def user_install_dir
# never install to user home in --build-root mode
return unless @build_root.nil?

# Please note that @user_install might have three states:
# * `true`: `--user-install`
# * `false`: `--no-user-install` and
# * `nil`: option was not specified
if @user_install || (@user_install.nil? && Gem.default_user_install)
Gem.user_dir
end
end

def build_args
@build_args ||= begin
require_relative "command"
Expand Down

0 comments on commit 0ff34aa

Please sign in to comment.