Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install default and bundled gems into dedicated directories #8761

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions lib/rubygems/defaults/ruby.rb
Original file line number Diff line number Diff line change
@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this cached while bundled_gems_dir and default_gems_dir aren't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cached also by RubyGems:

https://github.com/ruby/ruby/blame/209a0253f5869678d7228731605a1a5f21c76f32/lib/rubygems/defaults.rb#L63

and some parts of the test suite overrides the cached value (if I am not mistaken).

Also, I don't expect that bundled_gems_dir and default_gems_dir would be used by anything else then just by the default_specifications_dir and the default_path method, where the latter is cached here:

@paths ||= Gem::PathSupport.new(ENV)

Therefore the need for caching is minimal IMHO

end

##
# Default gem load path

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

end
end
14 changes: 14 additions & 0 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ def test_self_default_exec_format_jruby
end

def test_default_path
original_gem_default_path?

vendordir(File.join(@tempdir, "vendor")) do
FileUtils.rm_rf Gem.user_home

Expand All @@ -584,6 +586,8 @@ def test_default_path
end

def test_default_path_missing_vendor
original_gem_default_path?

vendordir(nil) do
FileUtils.rm_rf Gem.user_home

Expand All @@ -594,6 +598,8 @@ def test_default_path_missing_vendor
end

def test_default_path_user_home
original_gem_default_path?

vendordir(File.join(@tempdir, "vendor")) do
expected = [Gem.user_dir, Gem.default_dir]

Expand All @@ -602,6 +608,8 @@ def test_default_path_user_home
end

def test_default_path_vendor_dir
original_gem_default_path?

vendordir(File.join(@tempdir, "vendor")) do
FileUtils.mkdir_p Gem.vendor_dir

Expand Down Expand Up @@ -1796,4 +1804,10 @@ def util_remove_interrupt_command
def util_cache_dir
File.join Gem.dir, "cache"
end

def original_gem_default_path?
unless Gem.method(:default_path).source_location.first.match? "lib/rubygems/defaults.rb"
pend "Gem.default_path likely differs from original RubyGems implementation"
end
end
end
4 changes: 2 additions & 2 deletions tool/rbinstall.rb
Original file line number Diff line number Diff line change
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