1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Use Gem.use_gemdeps only from binstubs

The previous behavior was to automatically require `bundler/setup`
everytime `rubygems` was required, which I think was too much.

https://github.com/rubygems/rubygems/commit/b25379a295
This commit is contained in:
David Rodríguez 2019-10-28 19:11:57 +01:00 committed by Hiroshi SHIBATA
parent a3b3fdc3cd
commit 87dfb55c16
Notes: git 2021-08-31 19:07:15 +09:00
5 changed files with 57 additions and 17 deletions

View file

@ -1350,5 +1350,3 @@ Gem::Specification.load_defaults
require 'rubygems/core_ext/kernel_gem'
require 'rubygems/core_ext/kernel_require'
require 'rubygems/core_ext/kernel_warn'
Gem.use_gemdeps

View file

@ -762,6 +762,8 @@ class Gem::Installer
require 'rubygems'
Gem.use_gemdeps
version = "#{Gem::Requirement.default_prerelease}"
str = ARGV.first

View file

@ -1295,7 +1295,11 @@ Also, a list:
end
def ruby_with_rubygems_in_load_path
[Gem.ruby, "-I", $LOAD_PATH.find{|p| p == File.dirname($LOADED_FEATURES.find{|f| f.end_with?("/rubygems.rb") }) }]
[Gem.ruby, "-I", rubygems_path]
end
def rubygems_path
$LOAD_PATH.find{|p| p == File.dirname($LOADED_FEATURES.find{|f| f.end_with?("/rubygems.rb") }) }
end
def with_clean_path_to_ruby

View file

@ -1730,10 +1730,18 @@ class TestGem < Gem::TestCase
names
end
def test_looks_for_gemdeps_files_automatically_on_start
def test_looks_for_gemdeps_files_automatically_from_binstubs
pend "Requiring bundler messes things up" if Gem.java_platform?
a = util_spec "a", "1", nil, "lib/a.rb"
a = util_spec "a", "1" do |s|
s.executables = %w[foo]
s.bindir = "exe"
end
write_file File.join(@tempdir, 'exe', 'foo') do |fp|
fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
end
b = util_spec "b", "1", nil, "lib/b.rb"
c = util_spec "c", "1", nil, "lib/c.rb"
@ -1747,29 +1755,41 @@ class TestGem < Gem::TestCase
ENV['GEM_PATH'] = path
ENV['RUBYGEMS_GEMDEPS'] = "-"
new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
path = File.join @tempdir, "gem.deps.rb"
cmd = [*ruby_with_rubygems_in_load_path,
"-I#{BUNDLER_LIB_PATH}"]
cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
File.open path, "w" do |f|
f.puts "gem 'a'"
end
out0 = IO.popen(cmd, &:read).split(/\n/)
out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
IO.popen("foo", &:read).split(/\n/)
end
File.open path, "a" do |f|
f.puts "gem 'b'"
f.puts "gem 'c'"
end
out = IO.popen(cmd, &:read).split(/\n/)
out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
IO.popen("foo", &:read).split(/\n/)
end
assert_equal ["b-1", "c-1"], out - out0
end
def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir
def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
pend "Requiring bundler messes things up" if Gem.java_platform?
a = util_spec "a", "1", nil, "lib/a.rb"
a = util_spec "a", "1" do |s|
s.executables = %w[foo]
s.bindir = "exe"
end
write_file File.join(@tempdir, 'exe', 'foo') do |fp|
fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
end
b = util_spec "b", "1", nil, "lib/b.rb"
c = util_spec "c", "1", nil, "lib/c.rb"
@ -1785,21 +1805,25 @@ class TestGem < Gem::TestCase
Dir.mkdir "sub1"
new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
path = File.join @tempdir, "gem.deps.rb"
cmd = [*ruby_with_rubygems_in_load_path, "-Csub1",
"-I#{BUNDLER_LIB_PATH}"]
cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"
File.open path, "w" do |f|
f.puts "gem 'a'"
end
out0 = IO.popen(cmd, &:read).split(/\n/)
out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
end
File.open path, "a" do |f|
f.puts "gem 'b'"
f.puts "gem 'c'"
end
out = IO.popen(cmd, &:read).split(/\n/)
out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
end
Dir.rmdir "sub1"
@ -2114,4 +2138,14 @@ You may need to `gem install -g` to install missing gems
def util_cache_dir
File.join Gem.dir, "cache"
end
def with_path_and_rubyopt(path_value, rubyopt_value)
path, ENV['PATH'] = ENV['PATH'], path_value
rubyopt, ENV['RUBYOPT'] = ENV['RUBYOPT'], rubyopt_value
yield
ensure
ENV['PATH'] = path
ENV['RUBYOPT'] = rubyopt
end
end

View file

@ -33,6 +33,8 @@ class TestGemInstaller < Gem::InstallerTestCase
require 'rubygems'
Gem.use_gemdeps
version = \">= 0.a\"
str = ARGV.first