@@ -664,6 +664,7 @@ def process_options # :nodoc:
664664 @env_shebang = options [ :env_shebang ]
665665 @force = options [ :force ]
666666 @install_dir = options [ :install_dir ]
667+ @user_install = options [ :user_install ]
667668 @ignore_dependencies = options [ :ignore_dependencies ]
668669 @format_executable = options [ :format_executable ]
669670 @wrappers = options [ :wrappers ]
@@ -675,22 +676,7 @@ def process_options # :nodoc:
675676
676677 @build_args = options [ :build_args ]
677678
678- @gem_home = @install_dir
679-
680- unless @gem_home
681- # `--build-root` overrides `--user-install` and auto-user-install
682- if @build_root . nil?
683- # Please note that `options[:user_install]` might have three states:
684- # * `true`: `--user-install`
685- # * `false`: `--no-user-install` and
686- # * `nil`: option was not specified
687- if options [ :user_install ] || ( options [ :user_install ] . nil? && Gem . default_user_install )
688- @gem_home = Gem . user_dir
689- end
690- end
691-
692- @gem_home ||= Gem . dir
693- end
679+ @gem_home = @install_dir || user_install_dir || Gem . dir
694680
695681 # If the user has asked for the gem to be installed in a directory that is
696682 # the system gem directory, then use the system bin directory, else create
@@ -986,6 +972,19 @@ def ensure_writable_dir(dir) # :nodoc:
986972
987973 private
988974
975+ def user_install_dir
976+ # never install to user home in --build-root mode
977+ return unless @build_root . nil?
978+
979+ # Please note that @user_install might have three states:
980+ # * `true`: `--user-install`
981+ # * `false`: `--no-user-install` and
982+ # * `nil`: option was not specified
983+ if @user_install || ( @user_install . nil? && Gem . default_user_install )
984+ Gem . user_dir
985+ end
986+ end
987+
989988 def build_args
990989 @build_args ||= begin
991990 require_relative "command"
0 commit comments