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

ruby-changes:67406

From: David <ko1@a...>
Date: Tue, 31 Aug 2021 19:06:47 +0900 (JST)
Subject: [ruby-changes:67406] c2f376bcc0 (master): [rubygems/rubygems] Fix standalone install of default gems

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

From c2f376bcc006c3602ffd005fa1cb3cdf5c9d97fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Sun, 25 Jul 2021 16:23:15 +0200
Subject: [rubygems/rubygems] Fix standalone install of default gems

Rubygems source replacement was broken.

https://github.com/rubygems/rubygems/commit/3549c122f6
---
 lib/bundler/lockfile_parser.rb               |  1 +
 lib/bundler/source_list.rb                   | 13 ++++++++--
 spec/bundler/install/gems/standalone_spec.rb | 39 ++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
index afc21fd..8d0e44d 100644
--- a/lib/bundler/lockfile_parser.rb
+++ b/lib/bundler/lockfile_parser.rb
@@ -195,6 +195,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/lockfile_parser.rb#L195
         platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
         @current_spec = LazySpecification.new(name, version, platform)
         @current_spec.source = @current_source
+        @current_source.add_dependency_names(name)
 
         @specs[@current_spec.identifier] = @current_spec
       elsif spaces.size == 6
diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb
index c7dfa3d..1c0105b 100644
--- a/lib/bundler/source_list.rb
+++ b/lib/bundler/source_list.rb
@@ -121,7 +121,8 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source_list.rb#L121
     def replace_sources!(replacement_sources)
       return false if replacement_sources.empty?
 
-      @path_sources, @git_sources, @plugin_sources = map_sources(replacement_sources)
+      @rubygems_sources, @path_sources, @git_sources, @plugin_sources = map_sources(replacement_sources)
+      @global_rubygems_source = global_replacement_source(replacement_sources)
 
       different_sources?(lock_sources, replacement_sources)
     end
@@ -156,13 +157,21 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source_list.rb#L157
     end
 
     def map_sources(replacement_sources)
-      [path_sources, git_sources, plugin_sources].map do |sources|
+      [@rubygems_sources, @path_sources, @git_sources, @plugin_sources].map do |sources|
         sources.map do |source|
           replacement_sources.find {|s| s == source } || source
         end
       end
     end
 
+    def global_replacement_source(replacement_sources)
+      replacement_source = replacement_sources.find {|s| s == global_rubygems_source }
+      return global_rubygems_source unless replacement_source
+
+      replacement_source.local!
+      replacement_source
+    end
+
     def different_sources?(lock_sources, replacement_sources)
       !equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources)
     end
diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb
index b3b9d4d..6578997 100644
--- a/spec/bundler/install/gems/standalone_spec.rb
+++ b/spec/bundler/install/gems/standalone_spec.rb
@@ -108,6 +108,45 @@ RSpec.shared_examples "bundle install --standalone" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gems/standalone_spec.rb#L108
     include_examples "common functionality"
   end
 
+  describe "with default gems and a lockfile", :ruby_repo do
+    before do
+      skip "does not work on rubygems versions where `--install_dir` doesn't respect --default" unless Gem::Installer.for_spec(loaded_gemspec, :install_dir => "/foo").default_spec_file == "/foo/specifications/default/bundler-#{Bundler::VERSION}.gemspec" # Since rubygems 3.2.0.rc.2
+      skip "does not work on old rubies because the realworld gems that need to be installed don't support them" if RUBY_VERSION < "2.7.0"
+
+      realworld_system_gems "fiddle --version 1.0.6", "tsort --version 0.1.0"
+
+      necessary_system_gems = ["optparse --version 0.1.1", "psych --version 3.3.2", "yaml --version 0.1.1", "logger --version 1.4.3", "etc --version 1.2.0"]
+      necessary_system_gems += ["shellwords --version 0.1.0", "base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.3.a")
+      realworld_system_gems(*necessary_system_gems, :path => scoped_gem_path(bundled_app("bundle")))
+
+      build_gem "foo", "1.0.0", :to_system => true, :default => true do |s|
+        s.add_dependency "bar"
+      end
+
+      build_gem "bar", "1.0.0", :to_system => true, :default => true
+
+      build_repo4 do
+        build_gem "foo", "1.0.0" do |s|
+          s.add_dependency "bar"
+        end
+
+        build_gem "bar", "1.0.0"
+      end
+
+      gemfile <<-G
+        source "https://gem.repo4"
+        gem "foo"
+      G
+
+      bundle "lock", :dir => cwd, :artifice => "compact_index"
+    end
+
+    it "works" do
+      bundle "config set --local path #{bundled_app("bundle")}"
+      bundle :install, :standalone => true, :dir => cwd, :artifice => "compact_index", :env => { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s }
+    end
+  end
+
   describe "with gems with native extension", :ruby_repo do
     before do
       bundle "config set --local path #{bundled_app("bundle")}"
-- 
cgit v1.1


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

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