From 0034b22cb7d24ba45863c0ab0ae0c995faf649f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Wed, 25 Oct 2023 16:57:33 +0200 Subject: [PATCH] Install default and bundled gems into dedicated directories 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`. --- lib/rubygems/defaults/ruby.rb | 37 +++++++++++++++++++++++++++++++++++ tool/rbinstall.rb | 4 ++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lib/rubygems/defaults/ruby.rb diff --git a/lib/rubygems/defaults/ruby.rb b/lib/rubygems/defaults/ruby.rb new file mode 100644 index 00000000000000..6f0ed9213dd2f4 --- /dev/null +++ b/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 diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index 90697bfe923b20..d1e6eb816ee4b9 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -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 @@ -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