From ac939d9ca3164a748c656ea7f33c356d7b91b0f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 11 Dec 2023 13:19:45 +0100 Subject: [PATCH] [rubygems/rubygems] Improve default gem handling If a gem is specified in the Gemfile (or resolved as a transitive dependency), it's always resolved from remote/installed sources. Default gems are only used as a fallback for gems not included in the bundle. I believe this leads to more consistent behavior and more portable apps, since all gems will be installed to the configured bundle path, regardless of whether they are default gems or not. https://github.com/rubygems/rubygems/commit/091b4fcf2b --- lib/bundler/rubygems_integration.rb | 2 +- lib/bundler/source/rubygems.rb | 6 +----- spec/bundler/cache/gems_spec.rb | 17 ++--------------- spec/bundler/commands/open_spec.rb | 1 - spec/bundler/runtime/setup_spec.rb | 6 +++++- 5 files changed, 9 insertions(+), 23 deletions(-) diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index fdbe85b4d2b12d..571b303816bc67 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -509,7 +509,7 @@ def path_separator end def all_specs - Gem::Specification.stubs.map do |stub| + Gem::Specification.stubs.reject(&:default_gem?).map do |stub| StubSpecification.from_stub(stub) end end diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index dfcedb5b16d5ba..7e0b00700685f2 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -225,11 +225,7 @@ def cached_built_in_gem(spec) cached_path = cached_path(spec) if cached_path.nil? remote_spec = remote_specs.search(spec).first - if remote_spec - cached_path = fetch_gem(remote_spec) - else - Bundler.ui.warn "#{spec.full_name} is built in to Ruby, and can't be cached because your Gemfile doesn't have any sources that contain it." - end + cached_path = fetch_gem(remote_spec) end cached_path end diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb index abbc2c3cf240c8..b4ca4885621544 100644 --- a/spec/bundler/cache/gems_spec.rb +++ b/spec/bundler/cache/gems_spec.rb @@ -102,8 +102,8 @@ it "uses builtin gems when installing to system gems" do bundle "config set path.system true" - install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'json', '#{default_json_version}'), verbose: true - expect(out).to include("Using json #{default_json_version}") + install_gemfile %(source "#{file_uri_for(gem_repo2)}"; gem 'json', '#{default_json_version}'), verbose: true + expect(out).to include("Installing json #{default_json_version}") end it "caches remote and builtin gems" do @@ -143,19 +143,6 @@ bundle "install --local" expect(the_bundle).to include_gems("builtin_gem_2 1.0.2") end - - it "errors if the builtin gem isn't available to cache" do - bundle "config set path.system true" - - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'json', '#{default_json_version}' - G - - bundle :cache, raise_on_error: false - expect(exitstatus).to_not eq(0) - expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached") - end end describe "when there are also git sources" do diff --git a/spec/bundler/commands/open_spec.rb b/spec/bundler/commands/open_spec.rb index 97374f30c3f97c..5348580448ecb1 100644 --- a/spec/bundler/commands/open_spec.rb +++ b/spec/bundler/commands/open_spec.rb @@ -164,7 +164,6 @@ install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - gem "json" G end diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index ba53f3b1db32ee..df0cb0e556872e 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -1281,6 +1281,10 @@ def lock_with(ruby_version = nil) describe "with gemified standard libraries" do it "does not load Digest", :ruby_repo do + build_repo2 do + build_gem "digest" + end + build_git "bar", gemspec: false do |s| s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0') s.write "bar.gemspec", <<-G @@ -1299,7 +1303,7 @@ def lock_with(ruby_version = nil) end gemfile <<-G - source "#{file_uri_for(gem_repo1)}" + source "#{file_uri_for(gem_repo2)}" gem "bar", :git => "#{lib_path("bar-1.0")}" G