[前][次][番号順一覧][スレッド一覧]

ruby-changes:67420

From: David <ko1@a...>
Date: Tue, 31 Aug 2021 19:07:08 +0900 (JST)
Subject: [ruby-changes:67420] 87dfb55c16 (master): [rubygems/rubygems] Use `Gem.use_gemdeps` only from binstubs

https://git.ruby-lang.org/ruby.git/commit/?id=87dfb55c16

From 87dfb55c164b46d8f5c7968e20e4d03fe8831799 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Mon, 28 Oct 2019 19:11:57 +0100
Subject: [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
---
 lib/rubygems.rb                     |  2 --
 lib/rubygems/installer.rb           |  2 ++
 test/rubygems/helper.rb             |  6 +++-
 test/rubygems/test_gem.rb           | 62 ++++++++++++++++++++++++++++---------
 test/rubygems/test_gem_installer.rb |  2 ++
 5 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 4cf24ec..68af2c9 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -1350,5 +1350,3 @@ Gem::Specification.load_defaults https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1350
 require 'rubygems/core_ext/kernel_gem'
 require 'rubygems/core_ext/kernel_require'
 require 'rubygems/core_ext/kernel_warn'
-
-Gem.use_gemdeps
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 7cc9bc6..b374b3f 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -762,6 +762,8 @@ class Gem::Installer https://github.com/ruby/ruby/blob/trunk/lib/rubygems/installer.rb#L762
 
 require 'rubygems'
 
+Gem.use_gemdeps
+
 version = "#{Gem::Requirement.default_prerelease}"
 
 str = ARGV.first
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb
index 36be6a2..b25c9a9 100644
--- a/test/rubygems/helper.rb
+++ b/test/rubygems/helper.rb
@@ -1295,7 +1295,11 @@ Also, a list: https://github.com/ruby/ruby/blob/trunk/test/rubygems/helper.rb#L1295
   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
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 6ab5537..98cad54 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -1730,10 +1730,18 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1730
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1755
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1805
 
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L2138
   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
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index a2b390d..988f141 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -33,6 +33,8 @@ class TestGemInstaller < Gem::InstallerTestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_installer.rb#L33
 
 require 'rubygems'
 
+Gem.use_gemdeps
+
 version = \">= 0.a\"
 
 str = ARGV.first
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]