Skip to content

Commit

Permalink
Install default and bundled gems into dedicated directories
Browse files Browse the repository at this point in the history
Previously, all default/bundled gems were installed into single location
such as `/usr/local/lib/ruby/gems/3.3.0+0`. However, the same location
is used for user installed gems, which is not optimal.

With this change, the default gems goes into
`/usr/local/lib/ruby/default_gems/3.3.0+0` while the bundled gems goes
into `/usr/local/lib/ruby/bundled_gems/3.3.0+0`. User installed gems
continues to land in `/usr/local/lib/ruby/gems/3.3.0+0`.
  • Loading branch information
voxik committed Nov 21, 2023
1 parent f100c64 commit 0034b22
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions lib/rubygems/defaults/ruby.rb
@@ -0,0 +1,37 @@
module Gem
class << self

def bundled_gems_dir
File.join(RbConfig::CONFIG["rubylibprefix"], "bundled_gems", RbConfig::CONFIG["ruby_version"])
end

def default_gems_dir
File.join(RbConfig::CONFIG["rubylibprefix"], "default_gems", RbConfig::CONFIG["ruby_version"])
end

undef :default_specifications_dir if method_defined? :default_specifications_dir

if method_defined? :default_path
alias orig_default_path default_path
undef :default_path
end

##
# Path to specification files of default gems.

def default_specifications_dir
@default_specifications_dir ||= File.join(Gem.default_gems_dir, "specifications", "default")
end

##
# Default gem load path

def default_path
path = orig_default_path
path << bundled_gems_dir
path << default_gems_dir
path
end

end
end
4 changes: 2 additions & 2 deletions tool/rbinstall.rb
Expand Up @@ -942,7 +942,7 @@ def load_gemspec(file, base = nil)
end

def install_default_gem(dir, srcdir, bindir)
gem_dir = Gem.default_dir
gem_dir = Gem.default_gems_dir
install_dir = with_destdir(gem_dir)
prepare "default gems from #{dir}", gem_dir
RbInstall.no_write do
Expand Down Expand Up @@ -991,7 +991,7 @@ def install_default_gem(dir, srcdir, bindir)
end

install?(:ext, :comm, :gem, :'bundled-gems') do
gem_dir = Gem.default_dir
gem_dir = Gem.bundled_gems_dir
install_dir = with_destdir(gem_dir)
prepare "bundled gems", gem_dir
RbInstall.no_write do
Expand Down

0 comments on commit 0034b22

Please sign in to comment.