ruby-changes:73773
From: David <ko1@a...>
Date: Thu, 29 Sep 2022 03:42:09 +0900 (JST)
Subject: [ruby-changes:73773] ac56e5c1ab (master): [rubygems/rubygems] Put bundler gemspec stub at the right place
https://git.ruby-lang.org/ruby.git/commit/?id=ac56e5c1ab From ac56e5c1ab6eb133102c395f63101060bad6725d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Sat, 4 Dec 2021 13:44:07 +0100 Subject: [rubygems/rubygems] Put bundler gemspec stub at the right place So that it's found when needed, rather than dynamically modifying loaded stubs and thus messing with RubyGems internals. https://github.com/rubygems/rubygems/commit/cd3e7cb9e5 --- test/rubygems/test_gem.rb | 53 +++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 02d128f352..f4c6e8ce76 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -615,7 +615,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L615 end def test_self_use_gemdeps - with_local_bundler do + with_local_bundler_at(Gem.dir) do with_rubygems_gemdeps("-") do FileUtils.mkdir_p "detect/a/b" FileUtils.mkdir_p "detect/a/Isolate" @@ -775,7 +775,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L775 end def test_self_find_files_with_gemfile - with_local_bundler do + with_local_bundler_at(Gem.dir) do cwd = File.expand_path("test/rubygems", PROJECT_DIR) actual_load_path = $LOAD_PATH.unshift(cwd).dup @@ -1635,7 +1635,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1635 end def test_auto_activation_of_specific_gemdeps_file - with_local_bundler do + with_local_bundler_at(Gem.dir) do a = util_spec "a", "1", nil, "lib/a.rb" b = util_spec "b", "1", nil, "lib/b.rb" c = util_spec "c", "1", nil, "lib/c.rb" @@ -1659,7 +1659,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1659 end def test_auto_activation_of_used_gemdeps_file - with_local_bundler do + with_local_bundler_at(Gem.dir) do a = util_spec "a", "1", nil, "lib/a.rb" b = util_spec "b", "1", nil, "lib/b.rb" c = util_spec "c", "1", nil, "lib/c.rb" @@ -1691,7 +1691,9 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1691 end def test_looks_for_gemdeps_files_automatically_from_binstubs - with_local_bundler do + path = File.join(@tempdir, "gd-tmp") + + with_local_bundler_at(path) do a = util_spec "a", "1" do |s| s.executables = %w[foo] s.bindir = "exe" @@ -1706,7 +1708,6 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1708 install_specs a, b, c - path = File.join(@tempdir, "gd-tmp") install_gem a, :install_dir => path install_gem b, :install_dir => path install_gem c, :install_dir => path @@ -1740,7 +1741,9 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1741 end def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir - with_local_bundler do + path = File.join(@tempdir, "gd-tmp") + + with_local_bundler_at(path) do pend "IO.popen has issues on JRuby when passed :chdir" if Gem.java_platform? a = util_spec "a", "1" do |s| @@ -1757,7 +1760,6 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1760 install_specs a, b, c - path = File.join(@tempdir, "gd-tmp") install_gem a, :install_dir => path install_gem b, :install_dir => path install_gem c, :install_dir => path @@ -1835,7 +1837,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1837 end def test_use_gemdeps - with_local_bundler do + with_local_bundler_at(Gem.dir) do gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT) spec = util_spec "a", 1 install_specs spec @@ -1857,7 +1859,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1859 end def test_use_gemdeps_ENV - with_local_bundler do + with_local_bundler_at(Gem.dir) do with_rubygems_gemdeps(nil) do spec = util_spec "a", 1 @@ -1875,7 +1877,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1877 end def test_use_gemdeps_argument_missing - with_local_bundler do + with_local_bundler_at(Gem.dir) do e = assert_raise ArgumentError do Gem.use_gemdeps "gem.deps.rb" end @@ -1886,7 +1888,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1888 end def test_use_gemdeps_argument_missing_match_ENV - with_local_bundler do + with_local_bundler_at(Gem.dir) do with_rubygems_gemdeps("gem.deps.rb") do e = assert_raise ArgumentError do Gem.use_gemdeps "gem.deps.rb" @@ -1899,7 +1901,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1901 end def test_use_gemdeps_automatic - with_local_bundler do + with_local_bundler_at(Gem.dir) do with_rubygems_gemdeps("-") do spec = util_spec "a", 1 install_specs spec @@ -1919,7 +1921,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1921 end def test_use_gemdeps_automatic_missing - with_local_bundler do + with_local_bundler_at(Gem.dir) do with_rubygems_gemdeps("-") do Gem.use_gemdeps @@ -1929,7 +1931,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1931 end def test_use_gemdeps_disabled - with_local_bundler do + with_local_bundler_at(Gem.dir) do with_rubygems_gemdeps("") do spec = util_spec "a", 1 @@ -1947,7 +1949,7 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1949 end def test_use_gemdeps_missing_gem - with_local_bundler do + with_local_bundler_at(Gem.dir) do with_rubygems_gemdeps("x") do File.open "x", "w" do |io| io.write 'gem "a"' @@ -1971,7 +1973,7 @@ You may need to `bundle install` to install missing gems https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1973 end def test_use_gemdeps_specific - with_local_bundler do + with_local_bundler_at(Gem.dir) do with_rubygems_gemdeps("x") do spec = util_spec "a", 1 install_specs spec @@ -2121,17 +2123,18 @@ You may need to `bundle install` to install missing gems https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L2123 ENV["RUBYGEMS_GEMDEPS"] = rubygems_gemdeps end - def with_local_bundler - # If bundler gemspec exists, add to stubs + def with_local_bundler_at(path) + require "bundler" + + # If bundler gemspec exists, pretend it's installed bundler_gemspec = File.expand_path("../../bundler/bundler.gemspec", __dir__) if File.exist?(bundler_gemspec) - Gem::Specification.dirs.unshift File.dirname(bundler_gemspec) - Gem::Specification.class_variable_set :@@stubs, nil - Gem::Specification.stubs - Gem::Specification.dirs.shift - end + target_gemspec_location = "#{path}/specifications/bundler-#{Bundler::VERSION}.gemspec" - require "bundler" + FileUtils.mkdir_p File.dirname(target_gemspec_location) + + File.write target_gemspec_location, Gem::Specification.load(bundler_gemspec).to_ruby_for_cache + end yield ensure -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/