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:
parent
a3b3fdc3cd
commit
87dfb55c16
Notes:
git
2021-08-31 19:07:15 +09:00
5 changed files with 57 additions and 17 deletions
|
@ -1350,5 +1350,3 @@ Gem::Specification.load_defaults
|
||||||
require 'rubygems/core_ext/kernel_gem'
|
require 'rubygems/core_ext/kernel_gem'
|
||||||
require 'rubygems/core_ext/kernel_require'
|
require 'rubygems/core_ext/kernel_require'
|
||||||
require 'rubygems/core_ext/kernel_warn'
|
require 'rubygems/core_ext/kernel_warn'
|
||||||
|
|
||||||
Gem.use_gemdeps
|
|
||||||
|
|
|
@ -762,6 +762,8 @@ class Gem::Installer
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
||||||
|
Gem.use_gemdeps
|
||||||
|
|
||||||
version = "#{Gem::Requirement.default_prerelease}"
|
version = "#{Gem::Requirement.default_prerelease}"
|
||||||
|
|
||||||
str = ARGV.first
|
str = ARGV.first
|
||||||
|
|
|
@ -1295,7 +1295,11 @@ Also, a list:
|
||||||
end
|
end
|
||||||
|
|
||||||
def ruby_with_rubygems_in_load_path
|
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
|
end
|
||||||
|
|
||||||
def with_clean_path_to_ruby
|
def with_clean_path_to_ruby
|
||||||
|
|
|
@ -1730,10 +1730,18 @@ class TestGem < Gem::TestCase
|
||||||
names
|
names
|
||||||
end
|
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?
|
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"
|
b = util_spec "b", "1", nil, "lib/b.rb"
|
||||||
c = util_spec "c", "1", nil, "lib/c.rb"
|
c = util_spec "c", "1", nil, "lib/c.rb"
|
||||||
|
|
||||||
|
@ -1747,29 +1755,41 @@ class TestGem < Gem::TestCase
|
||||||
ENV['GEM_PATH'] = path
|
ENV['GEM_PATH'] = path
|
||||||
ENV['RUBYGEMS_GEMDEPS'] = "-"
|
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"
|
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|
|
File.open path, "w" do |f|
|
||||||
f.puts "gem 'a'"
|
f.puts "gem 'a'"
|
||||||
end
|
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|
|
File.open path, "a" do |f|
|
||||||
f.puts "gem 'b'"
|
f.puts "gem 'b'"
|
||||||
f.puts "gem 'c'"
|
f.puts "gem 'c'"
|
||||||
end
|
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
|
assert_equal ["b-1", "c-1"], out - out0
|
||||||
end
|
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?
|
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"
|
b = util_spec "b", "1", nil, "lib/b.rb"
|
||||||
c = util_spec "c", "1", nil, "lib/c.rb"
|
c = util_spec "c", "1", nil, "lib/c.rb"
|
||||||
|
|
||||||
|
@ -1785,21 +1805,25 @@ class TestGem < Gem::TestCase
|
||||||
|
|
||||||
Dir.mkdir "sub1"
|
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"
|
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|
|
File.open path, "w" do |f|
|
||||||
f.puts "gem 'a'"
|
f.puts "gem 'a'"
|
||||||
end
|
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|
|
File.open path, "a" do |f|
|
||||||
f.puts "gem 'b'"
|
f.puts "gem 'b'"
|
||||||
f.puts "gem 'c'"
|
f.puts "gem 'c'"
|
||||||
end
|
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"
|
Dir.rmdir "sub1"
|
||||||
|
|
||||||
|
@ -2114,4 +2138,14 @@ You may need to `gem install -g` to install missing gems
|
||||||
def util_cache_dir
|
def util_cache_dir
|
||||||
File.join Gem.dir, "cache"
|
File.join Gem.dir, "cache"
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -33,6 +33,8 @@ class TestGemInstaller < Gem::InstallerTestCase
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
||||||
|
Gem.use_gemdeps
|
||||||
|
|
||||||
version = \">= 0.a\"
|
version = \">= 0.a\"
|
||||||
|
|
||||||
str = ARGV.first
|
str = ARGV.first
|
||||||
|
|
Loading…
Add table
Reference in a new issue