From b300f5a0e1b75dfd27d58890521a1085d44284b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 13 Dec 2023 21:23:07 +0100 Subject: [PATCH] [rubygems/rubygems] Revert "Improve default gem handling" This reverts commit https://github.com/rubygems/rubygems/commit/091b4fcf2b99. https://github.com/rubygems/rubygems/commit/dcade3235f --- 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, 23 insertions(+), 9 deletions(-) diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 571b303816bc67..fdbe85b4d2b12d 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.reject(&:default_gem?).map do |stub| + Gem::Specification.stubs.map do |stub| StubSpecification.from_stub(stub) end end diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 7e0b00700685f2..dfcedb5b16d5ba 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -225,7 +225,11 @@ def cached_built_in_gem(spec) cached_path = cached_path(spec) if cached_path.nil? remote_spec = remote_specs.search(spec).first - cached_path = fetch_gem(remote_spec) + 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 end cached_path end diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb index b4ca4885621544..abbc2c3cf240c8 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_repo2)}"; gem 'json', '#{default_json_version}'), verbose: true - expect(out).to include("Installing json #{default_json_version}") + install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'json', '#{default_json_version}'), verbose: true + expect(out).to include("Using json #{default_json_version}") end it "caches remote and builtin gems" do @@ -143,6 +143,19 @@ 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 5348580448ecb1..97374f30c3f97c 100644 --- a/spec/bundler/commands/open_spec.rb +++ b/spec/bundler/commands/open_spec.rb @@ -164,6 +164,7 @@ 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 df0cb0e556872e..ba53f3b1db32ee 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -1281,10 +1281,6 @@ 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 @@ -1303,7 +1299,7 @@ def lock_with(ruby_version = nil) end gemfile <<-G - source "#{file_uri_for(gem_repo2)}" + source "#{file_uri_for(gem_repo1)}" gem "bar", :git => "#{lib_path("bar-1.0")}" G