Skip to content

Commit

Permalink
[rubygems/rubygems] Make the user installation less exceptional
Browse files Browse the repository at this point in the history
The main purpose is to put handling of user installation into the same
place as e.g. handling the --build-root option handling. There is no
reason why the --build-root option should not prefix also paths used for
user installation.

Please note that the `util_installer` in
`test_generate_plugins_with_user_install` enforced the `:install_dir`,
which is against what user install is about.

rubygems/rubygems@0b10cb41aa
  • Loading branch information
voxik authored and hsbt committed Nov 8, 2023
1 parent acd428c commit 42cf130
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions lib/rubygems/installer.rb
Expand Up @@ -189,12 +189,6 @@ def initialize(package, options={})
@package.prog_mode = options[:prog_mode]
@package.data_mode = options[:data_mode]

if options[:user_install]
@gem_home = Gem.user_dir
@bin_dir = Gem.bindir gem_home unless options[:bin_dir]
@plugins_dir = Gem.plugindir(gem_home)
end

if @gem_home == Gem.user_dir
# If we get here, then one of the following likely happened:
# - `--user-install` was specified
Expand Down Expand Up @@ -673,22 +667,27 @@ def process_options # :nodoc:
@env_shebang = options[:env_shebang]
@force = options[:force]
@install_dir = options[:install_dir]
@gem_home = options[:install_dir] || Gem.dir
@plugins_dir = Gem.plugindir(@gem_home)
@ignore_dependencies = options[:ignore_dependencies]
@format_executable = options[:format_executable]
@wrappers = options[:wrappers]
@only_install_dir = options[:only_install_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
# (or use) a new bin dir under the gem_home.
@bin_dir = options[:bin_dir] || Gem.bindir(gem_home)
@bin_dir = options[:bin_dir]
@development = options[:development]
@build_root = options[:build_root]

@build_args = options[:build_args]

@gem_home = @install_dir
@gem_home ||= options[:user_install] ? Gem.user_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
# (or use) a new bin dir under the gem_home.
@bin_dir ||= Gem.bindir(@gem_home)

@plugins_dir = Gem.plugindir(@gem_home)

unless @build_root.nil?
@bin_dir = File.join(@build_root, @bin_dir.gsub(/^[a-zA-Z]:/, ""))
@gem_home = File.join(@build_root, @gem_home.gsub(/^[a-zA-Z]:/, ""))
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_installer.rb
Expand Up @@ -821,7 +821,7 @@ def test_generate_plugins_with_user_install
File.chmod(0o555, Gem.plugindir)
system_path = File.join(Gem.plugindir, "a_plugin.rb")
user_path = File.join(Gem.plugindir(Gem.user_dir), "a_plugin.rb")
installer = util_installer spec, Gem.dir, :user
installer = Gem::Installer.at spec.cache_file, :user_install => true, :force => true

assert_equal spec, installer.install

Expand Down

0 comments on commit 42cf130

Please sign in to comment.